@@ -161,8 +161,8 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
161161
162162 $ security = $ this ->_settings ->getSecurityData ();
163163 if (isset ($ security ['logoutResponseSigned ' ]) && $ security ['logoutResponseSigned ' ]) {
164- $ signature = $ this ->buildResponseSignature ($ logoutResponse , $ parameters ['RelayState ' ]);
165- $ parameters ['SigAlg ' ] = XMLSecurityKey:: RSA_SHA1 ;
164+ $ signature = $ this ->buildResponseSignature ($ logoutResponse , $ parameters ['RelayState ' ], $ security [ ' signatureAlgorithm ' ] );
165+ $ parameters ['SigAlg ' ] = $ security [ ' signatureAlgorithm ' ] ;
166166 $ parameters ['Signature ' ] = $ signature ;
167167 }
168168
@@ -300,8 +300,8 @@ public function login($returnTo = null, $parameters = array(), $forceAuthn = fal
300300
301301 $ security = $ this ->_settings ->getSecurityData ();
302302 if (isset ($ security ['authnRequestsSigned ' ]) && $ security ['authnRequestsSigned ' ]) {
303- $ signature = $ this ->buildRequestSignature ($ samlRequest , $ parameters ['RelayState ' ]);
304- $ parameters ['SigAlg ' ] = XMLSecurityKey:: RSA_SHA1 ;
303+ $ signature = $ this ->buildRequestSignature ($ samlRequest , $ parameters ['RelayState ' ], $ security [ ' signatureAlgorithm ' ] );
304+ $ parameters ['SigAlg ' ] = $ security [ ' signatureAlgorithm ' ] ;
305305 $ parameters ['Signature ' ] = $ signature ;
306306 }
307307 $ this ->redirectTo ($ this ->getSSOurl (), $ parameters );
@@ -344,8 +344,8 @@ public function logout($returnTo = null, $parameters = array(), $nameId = null,
344344
345345 $ security = $ this ->_settings ->getSecurityData ();
346346 if (isset ($ security ['logoutRequestSigned ' ]) && $ security ['logoutRequestSigned ' ]) {
347- $ signature = $ this ->buildRequestSignature ($ samlRequest , $ parameters ['RelayState ' ]);
348- $ parameters ['SigAlg ' ] = XMLSecurityKey:: RSA_SHA1 ;
347+ $ signature = $ this ->buildRequestSignature ($ samlRequest , $ parameters ['RelayState ' ], $ security [ ' signatureAlgorithm ' ] );
348+ $ parameters ['SigAlg ' ] = $ security [ ' signatureAlgorithm ' ] ;
349349 $ parameters ['Signature ' ] = $ signature ;
350350 }
351351
@@ -381,12 +381,13 @@ public function getSLOurl()
381381 /**
382382 * Generates the Signature for a SAML Request
383383 *
384- * @param string $samlRequest The SAML Request
385- * @param string $relayState The RelayState
384+ * @param string $samlRequest The SAML Request
385+ * @param string $relayState The RelayState
386+ * @param string $sign_algorithm Signature algorithm method
386387 *
387388 * @return string A base64 encoded signature
388389 */
389- public function buildRequestSignature ($ samlRequest , $ relayState )
390+ public function buildRequestSignature ($ samlRequest , $ relayState, $ sign_algorithm = XMLSecurityKey:: RSA_SHA1 )
390391 {
391392 if (!$ this ->_settings ->checkSPCerts ()) {
392393 throw new OneLogin_Saml2_Error (
@@ -397,25 +398,26 @@ public function buildRequestSignature($samlRequest, $relayState)
397398
398399 $ key = $ this ->_settings ->getSPkey ();
399400
400- $ objKey = new XMLSecurityKey (XMLSecurityKey:: RSA_SHA1 , array ('type ' => 'private ' ));
401+ $ objKey = new XMLSecurityKey ($ sign_algorithm , array ('type ' => 'private ' ));
401402 $ objKey ->loadKey ($ key , false );
402403
403404 $ msg = 'SAMLRequest= ' .urlencode ($ samlRequest );
404405 $ msg .= '&RelayState= ' .urlencode ($ relayState );
405- $ msg .= '&SigAlg= ' . urlencode (XMLSecurityKey:: RSA_SHA1 );
406+ $ msg .= '&SigAlg= ' . urlencode ($ sign_algorithm );
406407 $ signature = $ objKey ->signData ($ msg );
407408 return base64_encode ($ signature );
408409 }
409410
410411 /**
411412 * Generates the Signature for a SAML Response
412413 *
413- * @param string $samlResponse The SAML Response
414- * @param string $relayState The RelayState
414+ * @param string $samlResponse The SAML Response
415+ * @param string $relayState The RelayState
416+ * @param string $sign_algorithm Signature algorithm method
415417 *
416418 * @return string A base64 encoded signature
417419 */
418- public function buildResponseSignature ($ samlResponse , $ relayState )
420+ public function buildResponseSignature ($ samlResponse , $ relayState, $ sign_algorithm = XMLSecurityKey:: RSA_SHA1 )
419421 {
420422 if (!$ this ->_settings ->checkSPCerts ()) {
421423 throw new OneLogin_Saml2_Error (
@@ -426,12 +428,12 @@ public function buildResponseSignature($samlResponse, $relayState)
426428
427429 $ key = $ this ->_settings ->getSPkey ();
428430
429- $ objKey = new XMLSecurityKey (XMLSecurityKey:: RSA_SHA1 , array ('type ' => 'private ' ));
431+ $ objKey = new XMLSecurityKey ($ sign_algorithm , array ('type ' => 'private ' ));
430432 $ objKey ->loadKey ($ key , false );
431433
432434 $ msg = 'SAMLResponse= ' .urlencode ($ samlResponse );
433435 $ msg .= '&RelayState= ' .urlencode ($ relayState );
434- $ msg .= '&SigAlg= ' . urlencode (XMLSecurityKey:: RSA_SHA1 );
436+ $ msg .= '&SigAlg= ' . urlencode ($ sign_algorithm );
435437 $ signature = $ objKey ->signData ($ msg );
436438 return base64_encode ($ signature );
437439 }
0 commit comments