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

Change SAML20 & Shib13 xml handlers to use generateID and generateTimestamp from Utilities.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@546 44740490-163a-0410-bde0-09ae8108e29a
parent 54550be4
No related branches found
No related tags found
No related merge requests found
...@@ -186,8 +186,18 @@ class SimpleSAML_Utilities { ...@@ -186,8 +186,18 @@ class SimpleSAML_Utilities {
return $key; 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() { public static function generateTrackID() {
......
...@@ -83,25 +83,7 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'xmlsecli ...@@ -83,25 +83,7 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'xmlsecli
return null; 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
...@@ -583,13 +583,13 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse { ...@@ -583,13 +583,13 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
/** /**
* Generating IDs and timestamps. * Generating IDs and timestamps.
*/ */
$id = self::generateID(); $id = SimpleSAML_Utilities::generateID();
$issueInstant = self::generateIssueInstant(); $issueInstant = SimpleSAML_Utilities::generateTimestamp();
$assertionExpire = self::generateIssueInstant(60 * 5); # 5 minutes $assertionExpire = SimpleSAML_Utilities::generateTimestamp(time() + 60 * 5);# 5 minutes
$notBefore = self::generateIssueInstant(-30); $notBefore = SimpleSAML_Utilities::generateTimestamp(time() - 30);
$assertionid = self::generateID(); $assertionid = SimpleSAML_Utilities::generateID();
$sessionindex = self::generateID(); $sessionindex = SimpleSAML_Utilities::generateID();
/** /**
...@@ -618,7 +618,7 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse { ...@@ -618,7 +618,7 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
if ($nameidformat == self::EMAIL) { if ($nameidformat == self::EMAIL) {
$nameid = $this->generateNameID($nameidformat, $attributes[$spmd['simplesaml.nameidattribute']][0], $spnamequalifier); $nameid = $this->generateNameID($nameidformat, $attributes[$spmd['simplesaml.nameidattribute']][0], $spnamequalifier);
} else { } else {
$nameid = $this->generateNameID($nameidformat, self::generateID(), $spnamequalifier); $nameid = $this->generateNameID($nameidformat, SimpleSAML_Utilities::generateID(), $spnamequalifier);
} }
$assertion = ""; $assertion = "";
......
<?php <?php
require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Configuration.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'); require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Metadata/MetaDataStorageHandler.php');
/** /**
...@@ -30,7 +31,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest { ...@@ -30,7 +31,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest {
$this->configuration = $configuration; $this->configuration = $configuration;
$this->metadata = $metadatastore; $this->metadata = $metadatastore;
$this->requestid = $this->generateID(); $this->requestid = SimpleSAML_Utilities::generateID();
} }
public function setRelayState($relayState) { public function setRelayState($relayState) {
...@@ -71,7 +72,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest { ...@@ -71,7 +72,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest {
} }
public function setNewRequestID() { public function setNewRequestID() {
$this->requestid = $this->generateID(); $this->requestid = SimpleSAML_Utilities::generateID();
} }
public function getRequestID() { public function getRequestID() {
...@@ -97,17 +98,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest { ...@@ -97,17 +98,7 @@ class SimpleSAML_XML_Shib13_AuthnRequest {
(isset($target) ? '&target=' . urlencode($target) : ''); (isset($target) ? '&target=' . urlencode($target) : '');
return $url; 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
...@@ -263,15 +263,15 @@ class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse { ...@@ -263,15 +263,15 @@ class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
$idpmd = $this->metadata->getMetaData($idpentityid, 'shib13-idp-hosted'); $idpmd = $this->metadata->getMetaData($idpentityid, 'shib13-idp-hosted');
$spmd = $this->metadata->getMetaData($spentityid, 'shib13-sp-remote'); $spmd = $this->metadata->getMetaData($spentityid, 'shib13-sp-remote');
$id = self::generateID(); $id = SimpleSAML_Utilities::generateID();
$issueInstant = self::generateIssueInstant(); $issueInstant = SimpleSAML_Utilities::generateTimestamp();
$assertionExpire = self::generateIssueInstant(60 * 5); # 5 minutes $assertionExpire = SimpleSAML_Utilities::generateTimestamp(time() + 60 * 5);# 5 minutes
$assertionid = self::generateID(); $assertionid = SimpleSAML_Utilities::generateID();
if (is_null($nameid)) { if (is_null($nameid)) {
$nameid = self::generateID(); $nameid = SimpleSAML_Utilities::generateID();
} }
$issuer = $idpentityid; $issuer = $idpentityid;
......
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