Skip to content
Snippets Groups Projects
Commit bb8d9f5f authored by Olav Morken's avatar Olav Morken
Browse files

xmlseclibs: Make our changes to xmlseclibs easier to integrate.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@706 44740490-163a-0410-bde0-09ae8108e29a
parent c4ef2ba2
No related branches found
No related tags found
No related merge requests found
...@@ -45,21 +45,6 @@ Functions to generate simple cases of Exclusive Canonical XML - Callable functio ...@@ -45,21 +45,6 @@ Functions to generate simple cases of Exclusive Canonical XML - Callable functio
i.e.: $canonical = C14NGeneral($domelement, TRUE); i.e.: $canonical = C14NGeneral($domelement, TRUE);
*/ */
/**
* Older versions of PHP does not have the hash function, so we implement it
* if it does not exists
*/
if(!function_exists('hash')) {
function hash($algo, $data, $raw_output = 0) {
if($algo == 'md5') return(md5($data, $raw_output));
if($algo == 'sha1') return(sha1($data, $raw_output));
throw new Exception('xmlseclibs added hash() method: Hashing algoritm: ' . $algo . ' is not implemented');
}
}
/* helper function */ /* helper function */
function sortAndAddAttrs($element, $arAtts) { function sortAndAddAttrs($element, $arAtts) {
$newAtts = array(); $newAtts = array();
...@@ -206,8 +191,11 @@ class XMLSecurityKey { ...@@ -206,8 +191,11 @@ class XMLSecurityKey {
public $encryptedCtx = NULL; public $encryptedCtx = NULL;
public $guid = NULL; public $guid = NULL;
/* This variable contains the certificate ifif this key represents an X509-certificate. */ /**
private $X509Certificate = NULL; * This variable contains the certificate as a string if this key represents an X509-certificate.
* If this key doesn't represent a certificate, this will be NULL.
*/
private $x509Certificate = NULL;
public function __construct($type, $params=NULL) { public function __construct($type, $params=NULL) {
srand(); srand();
...@@ -314,8 +302,10 @@ class XMLSecurityKey { ...@@ -314,8 +302,10 @@ class XMLSecurityKey {
if ($isCert) { if ($isCert) {
$this->key = openssl_x509_read($this->key); $this->key = openssl_x509_read($this->key);
openssl_x509_export($this->key, $str_cert); openssl_x509_export($this->key, $str_cert);
$this->X509Certificate = $str_cert; $this->x509Certificate = $str_cert;
$this->key = $str_cert; $this->key = $str_cert;
} else {
$this->x509Certificate = NULL;
} }
if ($this->cryptParams['library'] == 'openssl') { if ($this->cryptParams['library'] == 'openssl') {
if ($this->cryptParams['type'] == 'public') { if ($this->cryptParams['type'] == 'public') {
...@@ -519,7 +509,7 @@ class XMLSecurityKey { ...@@ -519,7 +509,7 @@ class XMLSecurityKey {
* @return The X509 certificate or NULL if this key doesn't represent an X509-certificate. * @return The X509 certificate or NULL if this key doesn't represent an X509-certificate.
*/ */
public function getX509Certificate() { public function getX509Certificate() {
return $this->X509Certificate; return $this->x509Certificate;
} }
} }
...@@ -702,9 +692,13 @@ class XMLSecurityDSig { ...@@ -702,9 +692,13 @@ class XMLSecurityDSig {
} }
if (function_exists('hash')) { if (function_exists('hash')) {
return base64_encode(hash($alg, $data, TRUE)); return base64_encode(hash($alg, $data, TRUE));
} else { } elseif (function_exists('mhash')) {
$alg = "MHASH_" . strtoupper($alg); $alg = "MHASH_" . strtoupper($alg);
return base64_encode(mhash(constant($alg), $data)); return base64_encode(mhash(constant($alg), $data));
} elseif ($alg === 'sha1') {
return base64_encode(sha1($data, TRUE));
} else {
throw new Exception('xmlseclibs is unable to calculate a digest. Maybe you need the mhash library?');
} }
} }
...@@ -1063,31 +1057,30 @@ class XMLSecurityDSig { ...@@ -1063,31 +1057,30 @@ class XMLSecurityDSig {
} }
} }
/**
/** * This function inserts the signature element.
* This function inserts the signature element. *
* * The signature element will be appended to the element, unless $beforeNode is specified. If $beforeNode
* The signature element will be appended to the element, unless $beforeNode is specified. If $beforeNode * is specified, the signature element will be inserted as the last element before $beforeNode.
* is specified, the signature element will be inserted as the last element before $beforeNode. *
* * @param $node The node the signature element should be inserted into.
* @param $node The node the signature element should be inserted into. * @param $beforeNode The node the signature element should be located before.
* @param $beforeNode The node the signature element should be located before. */
*/ public function insertSignature($node, $beforeNode = NULL) {
public function insertSignature($node, $beforeNode = NULL) {
if($node instanceof DOMDocument) {
if($node instanceof DOMDocument) { $node = $node->firstChild;
$node = $node->firstChild; }
}
$document = $node->ownerDocument;
$document = $node->ownerDocument; $signatureElement = $document->importNode($this->sigNode, TRUE);
$signatureElement = $document->importNode($this->sigNode, TRUE);
if($beforeNode == NULL) {
if($beforeNode == NULL) { $node->insertBefore($signatureElement);
$node->insertBefore($signatureElement); } else {
} else { $node->insertBefore($signatureElement, $beforeNode);
$node->insertBefore($signatureElement, $beforeNode); }
} }
}
static function get509XCert($cert, $isPEMFormat=TRUE) { static function get509XCert($cert, $isPEMFormat=TRUE) {
$certs = XMLSecurityDSig::staticGet509XCerts($cert, $isPEMFormat); $certs = XMLSecurityDSig::staticGet509XCerts($cert, $isPEMFormat);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment