From e391cf63f3d2dc903642826f5cfa4dd640bd4de6 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Mon, 20 Apr 2015 15:06:39 +0200
Subject: [PATCH] Move SimpleSAML_Utilities::generateTimestamp() to
 SimpleSAML\Utils\Time::generateTimestamp(). Deprecate the former.

---
 lib/SimpleSAML/Bindings/Shib13/Artifact.php   |  2 +-
 .../Metadata/MetaDataStorageHandler.php       |  2 +-
 lib/SimpleSAML/Utilities.php                  | 10 ++-----
 lib/SimpleSAML/Utils/Time.php                 | 29 +++++++++++++++++++
 lib/SimpleSAML/XML/Shib13/AuthnResponse.php   |  6 ++--
 modules/adfs/lib/IdP/ADFS.php                 |  6 ++--
 6 files changed, 39 insertions(+), 16 deletions(-)
 create mode 100644 lib/SimpleSAML/Utils/Time.php

diff --git a/lib/SimpleSAML/Bindings/Shib13/Artifact.php b/lib/SimpleSAML/Bindings/Shib13/Artifact.php
index 0623bd175..73c7592c7 100644
--- a/lib/SimpleSAML/Bindings/Shib13/Artifact.php
+++ b/lib/SimpleSAML/Bindings/Shib13/Artifact.php
@@ -50,7 +50,7 @@ class SimpleSAML_Bindings_Shib13_Artifact {
 			'<samlp:Request xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"' .
 			' RequestID="' . SimpleSAML_Utils_Random::generateID() . '"' .
 			' MajorVersion="1" MinorVersion="1"' .
-			' IssueInstant="' . SimpleSAML_Utilities::generateTimestamp() . '"' .
+			' IssueInstant="' . SimpleSAML\Utils\Time::generateTimestamp() . '"' .
 			'>';
 
 		foreach ($artifacts as $a) {
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
index 3e086193f..70aba6d1d 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
@@ -144,7 +144,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler {
 						unset($srcList[$key]);
 						SimpleSAML_Logger::warning("Dropping metadata entity " .
 							var_export($key,true) . ", expired " .
-							SimpleSAML_Utilities::generateTimestamp($le['expire']) .
+                            SimpleSAML\Utils\Time::generateTimestamp($le['expire']) .
 							".");
 					}
 				}
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 94c5fe56c..2b825caef 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -390,16 +390,10 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * This function generates a timestamp on the form used by the SAML protocols.
-	 *
-	 * @param $instant  The time the timestamp should represent.
-	 * @return The timestamp.
+	 * @deprecated This function will be removed in SSP 2.0. Please use \SimpleSAML\Utils\Time::generateTimestamp() instead.
 	 */
 	public static function generateTimestamp($instant = NULL) {
-		if($instant === NULL) {
-			$instant = time();
-		}
-		return gmdate('Y-m-d\TH:i:s\Z', $instant);
+		return SimpleSAML\Utils\Time::generateTimestamp($instant);
 	}
 
 
diff --git a/lib/SimpleSAML/Utils/Time.php b/lib/SimpleSAML/Utils/Time.php
new file mode 100644
index 000000000..50d8f5b67
--- /dev/null
+++ b/lib/SimpleSAML/Utils/Time.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Time-related utility methods.
+ *
+ * @package SimpleSAMLphp
+ */
+
+namespace SimpleSAML\Utils;
+
+
+class Time
+{
+
+    /**
+     * This function generates a timestamp on the form used by the SAML protocols.
+     *
+     * @param int $instant The time the timestamp should represent. Defaults to current time.
+     *
+     * @return string The timestamp.
+     * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+     */
+    public static function generateTimestamp($instant = null)
+    {
+        if ($instant === null) {
+            $instant = time();
+        }
+        return gmdate('Y-m-d\TH:i:s\Z', $instant);
+    }
+}
\ No newline at end of file
diff --git a/lib/SimpleSAML/XML/Shib13/AuthnResponse.php b/lib/SimpleSAML/XML/Shib13/AuthnResponse.php
index 563882e94..a70dcb16a 100644
--- a/lib/SimpleSAML/XML/Shib13/AuthnResponse.php
+++ b/lib/SimpleSAML/XML/Shib13/AuthnResponse.php
@@ -306,13 +306,13 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
 
 		$id = SimpleSAML_Utils_Random::generateID();
 		
-		$issueInstant = SimpleSAML_Utilities::generateTimestamp();
+		$issueInstant = SimpleSAML\Utils\Time::generateTimestamp();
 		
 		// 30 seconds timeskew back in time to allow differing clocks.
-		$notBefore = SimpleSAML_Utilities::generateTimestamp(time() - 30);
+		$notBefore = SimpleSAML\Utils\Time::generateTimestamp(time() - 30);
 		
 		
-		$assertionExpire = SimpleSAML_Utilities::generateTimestamp(time() + 60 * 5);# 5 minutes
+		$assertionExpire = SimpleSAML\Utils\Time::generateTimestamp(time() + 60 * 5);# 5 minutes
 		$assertionid = SimpleSAML_Utils_Random::generateID();
 
 		$spEntityId = $sp->getString('entityid');
diff --git a/modules/adfs/lib/IdP/ADFS.php b/modules/adfs/lib/IdP/ADFS.php
index cdb23f957..341f91e29 100644
--- a/modules/adfs/lib/IdP/ADFS.php
+++ b/modules/adfs/lib/IdP/ADFS.php
@@ -47,9 +47,9 @@ class sspmod_adfs_IdP_ADFS {
 
 	public static function ADFS_GenerateResponse($issuer, $target, $nameid, $attributes) {
 		#$nameid = 'hans@surfnet.nl';
-		$issueInstant = SimpleSAML_Utilities::generateTimestamp();
-		$notBefore = SimpleSAML_Utilities::generateTimestamp(time() - 30);
-		$assertionExpire = SimpleSAML_Utilities::generateTimestamp(time() + 60 * 5);
+		$issueInstant = SimpleSAML\Utils\Time::generateTimestamp();
+		$notBefore = SimpleSAML\Utils\Time::generateTimestamp(time() - 30);
+		$assertionExpire = SimpleSAML\Utils\Time::generateTimestamp(time() + 60 * 5);
 		$assertionID = SimpleSAML_Utils_Random::generateID();
 		$nameidFormat = 'http://schemas.xmlsoap.org/claims/UPN';
 		$result =
-- 
GitLab