Skip to content

Commit

Permalink
Fix #136. Support lowercase Urlencoding (ADFS compatibility).
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed Sep 19, 2016
1 parent 7608453 commit 3738c11
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ $advancedSettings = array (
// 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'
// 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512'
'signatureAlgorithm' => 'http://www.w3.org/2000/09/xmldsig#rsa-sha1',

// ADFS URL-Encodes SAML data as lowercase, and the toolkit by default uses
// uppercase. Turn it True for ADFS compatibility on signature verification
'lowercaseUrlencoding' => false,
),

// Contact information template, it is recommended to supply a
Expand Down
4 changes: 4 additions & 0 deletions advanced_settings_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
// 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'
// 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512'
'signatureAlgorithm' => 'http://www.w3.org/2000/09/xmldsig#rsa-sha1',

// ADFS URL-Encodes SAML data as lowercase, and the toolkit by default uses
// uppercase. Turn it True for ADFS compatibility on signature verification
'lowercaseUrlencoding' => false,
),

// Contact information template, it is recommended to suply a technical and support contacts
Expand Down
32 changes: 24 additions & 8 deletions lib/Saml2/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,19 @@ public function buildRequestSignature($samlRequest, $relayState, $signAlgorithm
$objKey = new XMLSecurityKey($signAlgorithm, array('type' => 'private'));
$objKey->loadKey($key, false);

$msg = 'SAMLRequest='.urlencode($samlRequest);
if (isset($relayState)) {
$msg .= '&RelayState='.urlencode($relayState);
if ($this->_security['lowercaseUrlencoding']) {
$msg = 'SAMLRequest='.rawurlencode($samlRequest);
if (isset($relayState)) {
$msg .= '&RelayState='.rawurlencode($relayState);
}
$msg .= '&SigAlg=' . rawurlencode($signAlgorithm);
} else {
$msg = 'SAMLRequest='.urlencode($samlRequest);
if (isset($relayState)) {
$msg .= '&RelayState='.urlencode($relayState);
}
$msg .= '&SigAlg=' . urlencode($signAlgorithm);
}
$msg .= '&SigAlg=' . urlencode($signAlgorithm);
$signature = $objKey->signData($msg);
return base64_encode($signature);
}
Expand Down Expand Up @@ -510,11 +518,19 @@ public function buildResponseSignature($samlResponse, $relayState, $signAlgorith
$objKey = new XMLSecurityKey($signAlgorithm, array('type' => 'private'));
$objKey->loadKey($key, false);

$msg = 'SAMLResponse='.urlencode($samlResponse);
if (isset($relayState)) {
$msg .= '&RelayState='.urlencode($relayState);
if ($this->_security['lowercaseUrlencoding']) {
$msg = 'SAMLResponse='.rawurlencode($samlResponse);
if (isset($relayState)) {
$msg .= '&RelayState='.rawurlencode($relayState);
}
$msg .= '&SigAlg=' . rawurlencode($signAlgorithm);
} else {
$msg = 'SAMLResponse='.urlencode($samlResponse);
if (isset($relayState)) {
$msg .= '&RelayState='.urlencode($relayState);
}
$msg .= '&SigAlg=' . urlencode($signAlgorithm);
}
$msg .= '&SigAlg=' . urlencode($signAlgorithm);
$signature = $objKey->signData($msg);
return base64_encode($signature);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Saml2/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ private function _addDefaultValues()
$this->_security['signatureAlgorithm'] = XMLSecurityKey::RSA_SHA1;
}

if (!isset($this->_security['lowercaseUrlencoding'])) {
$this->_security['lowercaseUrlencoding'] = false;
}

// Certificates / Private key /Fingerprint
if (!isset($this->_idp['x509cert'])) {
$this->_idp['x509cert'] = '';
Expand Down

0 comments on commit 3738c11

Please sign in to comment.