diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 3bacd2b58c70e37d2d27bf90caa9e2954eba6c52..3251ce8cc2f22d2b9c9517d02c7d200addce2266 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -186,8 +186,18 @@ class SimpleSAML_Utilities { return $key; } - public static function generateTimestamp() { - return gmdate("Y-m-d\TH:i:s\Z"); + + /** + * This function generates a timestamp on the form used by the SAML protocols. + * + * @param $instant The time the timestamp should represent. + * @return The timestamp. + */ + public static function generateTimestamp($instant = NULL) { + if($instant === NULL) { + $instant = time(); + } + return gmdate('Y-m-d\TH:i:s\Z', $instant); } public static function generateTrackID() { diff --git a/lib/SimpleSAML/XML/AuthnResponse.php b/lib/SimpleSAML/XML/AuthnResponse.php index 7ae6048eb93d9c1eeee37f73c15d9ead5791ce78..fc1d370b155449086cdc8b0db19af83388d51948 100644 --- a/lib/SimpleSAML/XML/AuthnResponse.php +++ b/lib/SimpleSAML/XML/AuthnResponse.php @@ -83,25 +83,7 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'xmlsecli return null; } - - - - public static function generateID() { - - $length = 42; - $key = "_"; - for ( $i=0; $i < $length; $i++ ) - { - $key .= dechex( rand(0,15) ); - } - return $key; - } - - public static function generateIssueInstant($offset = 0) { - return gmdate("Y-m-d\TH:i:s\Z", time() + $offset); - } - } ?> \ No newline at end of file diff --git a/lib/SimpleSAML/XML/SAML20/AuthnResponse.php b/lib/SimpleSAML/XML/SAML20/AuthnResponse.php index a9bdddeb1def7844f1a6a6427cce418bcf396d24..7ac0a60aa9124ae13021ec010a76ced1c951ade0 100644 --- a/lib/SimpleSAML/XML/SAML20/AuthnResponse.php +++ b/lib/SimpleSAML/XML/SAML20/AuthnResponse.php @@ -583,13 +583,13 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse { /** * Generating IDs and timestamps. */ - $id = self::generateID(); - $issueInstant = self::generateIssueInstant(); - $assertionExpire = self::generateIssueInstant(60 * 5); # 5 minutes - $notBefore = self::generateIssueInstant(-30); + $id = SimpleSAML_Utilities::generateID(); + $issueInstant = SimpleSAML_Utilities::generateTimestamp(); + $assertionExpire = SimpleSAML_Utilities::generateTimestamp(time() + 60 * 5);# 5 minutes + $notBefore = SimpleSAML_Utilities::generateTimestamp(time() - 30); - $assertionid = self::generateID(); - $sessionindex = self::generateID(); + $assertionid = SimpleSAML_Utilities::generateID(); + $sessionindex = SimpleSAML_Utilities::generateID(); /** @@ -618,7 +618,7 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse { if ($nameidformat == self::EMAIL) { $nameid = $this->generateNameID($nameidformat, $attributes[$spmd['simplesaml.nameidattribute']][0], $spnamequalifier); } else { - $nameid = $this->generateNameID($nameidformat, self::generateID(), $spnamequalifier); + $nameid = $this->generateNameID($nameidformat, SimpleSAML_Utilities::generateID(), $spnamequalifier); } $assertion = ""; diff --git a/lib/SimpleSAML/XML/Shib13/AuthnRequest.php b/lib/SimpleSAML/XML/Shib13/AuthnRequest.php index cda9062cf1b02631f680d90e1512512ca52d6ee0..4f67c3a8aed86d96377c7982b7f998b86732c3aa 100644 --- a/lib/SimpleSAML/XML/Shib13/AuthnRequest.php +++ b/lib/SimpleSAML/XML/Shib13/AuthnRequest.php @@ -1,6 +1,7 @@ <?php require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Configuration.php'); +require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Utilities.php'); require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Metadata/MetaDataStorageHandler.php'); /** @@ -30,7 +31,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest { $this->configuration = $configuration; $this->metadata = $metadatastore; - $this->requestid = $this->generateID(); + $this->requestid = SimpleSAML_Utilities::generateID(); } public function setRelayState($relayState) { @@ -71,7 +72,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest { } public function setNewRequestID() { - $this->requestid = $this->generateID(); + $this->requestid = SimpleSAML_Utilities::generateID(); } public function getRequestID() { @@ -97,17 +98,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest { (isset($target) ? '&target=' . urlencode($target) : ''); return $url; } - - public static function generateID() { - $length = 42; - $key = "_"; - for ( $i=0; $i < $length; $i++ ) { - $key .= dechex( rand(0,15) ); - } - return $key; - } - - + } ?> \ No newline at end of file diff --git a/lib/SimpleSAML/XML/Shib13/AuthnResponse.php b/lib/SimpleSAML/XML/Shib13/AuthnResponse.php index 12176fe3f2aa42ad4f6f121b699df67d9c3a1075..05ffe1cbef3cdbacd7b22cc622220ca375ac992c 100644 --- a/lib/SimpleSAML/XML/Shib13/AuthnResponse.php +++ b/lib/SimpleSAML/XML/Shib13/AuthnResponse.php @@ -263,15 +263,15 @@ class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse { $idpmd = $this->metadata->getMetaData($idpentityid, 'shib13-idp-hosted'); $spmd = $this->metadata->getMetaData($spentityid, 'shib13-sp-remote'); - $id = self::generateID(); - $issueInstant = self::generateIssueInstant(); - $assertionExpire = self::generateIssueInstant(60 * 5); # 5 minutes + $id = SimpleSAML_Utilities::generateID(); + $issueInstant = SimpleSAML_Utilities::generateTimestamp(); + $assertionExpire = SimpleSAML_Utilities::generateTimestamp(time() + 60 * 5);# 5 minutes - $assertionid = self::generateID(); + $assertionid = SimpleSAML_Utilities::generateID(); if (is_null($nameid)) { - $nameid = self::generateID(); + $nameid = SimpleSAML_Utilities::generateID(); } $issuer = $idpentityid;