From 4f7e78f6b4d7e8cc7dea613f3beb45004776dfa3 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Thu, 16 Apr 2015 15:34:43 +0200 Subject: [PATCH] Schedule SimpleSAML_Utilities::stringToHex() for removal. Deprecate and stop using it. --- lib/SimpleSAML/Error/Error.php | 2 +- lib/SimpleSAML/Session.php | 2 +- lib/SimpleSAML/SessionHandlerCookie.php | 2 +- lib/SimpleSAML/SessionHandlerPHP.php | 2 +- lib/SimpleSAML/Utilities.php | 7 ++----- lib/SimpleSAML/XHTML/EMail.php | 2 +- modules/saml/lib/Auth/Process/SQLPersistentNameID.php | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php index 402eeeaef..a422e624e 100644 --- a/lib/SimpleSAML/Error/Error.php +++ b/lib/SimpleSAML/Error/Error.php @@ -202,7 +202,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { $emsg = array_shift($data); $etrace = implode("\n", $data); - $reportId = SimpleSAML_Utilities::stringToHex(openssl_random_pseudo_bytes(4)); + $reportId = bin2hex(openssl_random_pseudo_bytes(4)); SimpleSAML_Logger::error('Error report with id ' . $reportId . ' generated.'); $config = SimpleSAML_Configuration::getInstance(); diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php index dbe899f5d..df4343545 100644 --- a/lib/SimpleSAML/Session.php +++ b/lib/SimpleSAML/Session.php @@ -137,7 +137,7 @@ class SimpleSAML_Session $sh = SimpleSAML_SessionHandler::getSessionHandler(); $this->sessionId = $sh->newSessionId(); - $this->trackid = SimpleSAML_Utilities::stringToHex(openssl_random_pseudo_bytes(5)); + $this->trackid = bin2hex(openssl_random_pseudo_bytes(5)); $this->dirty = true; diff --git a/lib/SimpleSAML/SessionHandlerCookie.php b/lib/SimpleSAML/SessionHandlerCookie.php index 86486fd6e..9e47a8ab8 100644 --- a/lib/SimpleSAML/SessionHandlerCookie.php +++ b/lib/SimpleSAML/SessionHandlerCookie.php @@ -93,7 +93,7 @@ extends SimpleSAML_SessionHandler { * A random session id. */ private static function createSessionID() { - return SimpleSAML_Utilities::stringToHex(openssl_random_pseudo_bytes(16)); + return bin2hex(openssl_random_pseudo_bytes(16)); } diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php index 2fe63c390..36fe0753c 100644 --- a/lib/SimpleSAML/SessionHandlerPHP.php +++ b/lib/SimpleSAML/SessionHandlerPHP.php @@ -77,7 +77,7 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler { } /* Generate new (secure) session id. */ - $sessionId = SimpleSAML_Utilities::stringToHex(openssl_random_pseudo_bytes(16)); + $sessionId = bin2hex(openssl_random_pseudo_bytes(16)); SimpleSAML_Session::createSession($sessionId); if (session_id() !== '') { diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index e22fea3ed..b71a6e2a7 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -382,7 +382,7 @@ class SimpleSAML_Utilities { public static function generateID() { - return '_' . self::stringToHex(openssl_random_pseudo_bytes(21)); + return '_' . bin2hex(openssl_random_pseudo_bytes(21)); } @@ -967,10 +967,7 @@ class SimpleSAML_Utilities { /** - * This function converts a binary string to hexadecimal characters. - * - * @param $bytes Input string. - * @return String with lowercase hexadecimal characters. + * @deprecated This function will be removed in SSP 2.0. Please use bin2hex() instead. */ public static function stringToHex($bytes) { $ret = ''; diff --git a/lib/SimpleSAML/XHTML/EMail.php b/lib/SimpleSAML/XHTML/EMail.php index 761f5de77..5b69962e0 100644 --- a/lib/SimpleSAML/XHTML/EMail.php +++ b/lib/SimpleSAML/XHTML/EMail.php @@ -65,7 +65,7 @@ pre { if ($this->subject == NULL) throw new Exception('EMail field [subject] is required and not set.'); if ($this->body == NULL) throw new Exception('EMail field [body] is required and not set.'); - $random_hash = SimpleSAML_Utilities::stringToHex(openssl_random_pseudo_bytes(16)); + $random_hash = bin2hex(openssl_random_pseudo_bytes(16)); if (isset($this->from)) $this->headers[]= 'From: ' . $this->from; diff --git a/modules/saml/lib/Auth/Process/SQLPersistentNameID.php b/modules/saml/lib/Auth/Process/SQLPersistentNameID.php index ebfab8eef..767aec324 100644 --- a/modules/saml/lib/Auth/Process/SQLPersistentNameID.php +++ b/modules/saml/lib/Auth/Process/SQLPersistentNameID.php @@ -81,7 +81,7 @@ class sspmod_saml_Auth_Process_SQLPersistentNameID extends sspmod_saml_BaseNameI throw new sspmod_saml_Error(SAML2_Const::STATUS_RESPONDER, 'urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy'); } - $value = SimpleSAML_Utilities::stringToHex(openssl_random_pseudo_bytes(20)); + $value = bin2hex(openssl_random_pseudo_bytes(20)); SimpleSAML_Logger::debug('SQLPersistentNameID: Created persistent NameID ' . var_export($value, TRUE) . ' for user ' . var_export($uid, TRUE) . '.'); sspmod_saml_IdP_SQLNameID::add($idpEntityId, $spEntityId, $uid, $value); -- GitLab