Skip to content

Commit f46e38a

Browse files
committed
Log encrypted and decrypted messages.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2544 44740490-163a-0410-bde0-09ae8108e29a
1 parent 6db59b7 commit f46e38a

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

config-templates/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* If you enable this option, simpleSAMLphp will log all sent and received messages
2929
* to the log file.
3030
*
31+
* This option also enables logging of the messages that are encrypted and decrypted.
32+
*
3133
* Note: The messages are logged with the DEBUG log level, so you also need to set
3234
* the 'logging.level' option to LOG_DEBUG.
3335
*/

lib/SAML2/EncryptedAssertion.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function setAssertion(SAML2_Assertion $assertion, XMLSecurityKey $key) {
4646

4747
$xml = $assertion->toXML();
4848

49+
$xmlStr = $xml->ownerDocument->saveXML($xml);
50+
SimpleSAML_Utilities::debugMessage($xmlStr, 'encrypt');
51+
4952
$enc = new XMLSecEnc();
5053
$enc->setNode($xml);
5154
$enc->type = XMLSecEnc::Element;
@@ -84,6 +87,10 @@ public function setAssertion(SAML2_Assertion $assertion, XMLSecurityKey $key) {
8487
public function getAssertion(XMLSecurityKey $inputKey) {
8588

8689
$assertionXML = SAML2_Utils::decryptElement($this->encryptedData, $inputKey);
90+
91+
$xmlStr = $assertionXML->ownerDocument->saveXML($assertionXML);
92+
SimpleSAML_Utilities::debugMessage($xmlStr, 'decrypt');
93+
8794
return new SAML2_Assertion($assertionXML);
8895
}
8996

lib/SimpleSAML/Utilities.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,22 +1911,32 @@ public static function checkCookie($retryURL = NULL) {
19111911
* Helper function to log messages that we send or receive.
19121912
*
19131913
* @param string $message The message, as an XML string.
1914-
* @param string $type Whether this message is sent or received.
1914+
* @param string $type Whether this message is sent or received, encrypted or decrypted.
19151915
*/
19161916
public static function debugMessage($message, $type) {
19171917
assert('is_string($message)');
1918-
assert('$type === "out" || $type === "in"');
19191918

19201919
$globalConfig = SimpleSAML_Configuration::getInstance();
19211920
if (!$globalConfig->getBoolean('debug', FALSE)) {
19221921
/* Message debug disabled. */
19231922
return;
19241923
}
19251924

1926-
if ($type === 'in') {
1925+
switch ($type) {
1926+
case 'in':
19271927
SimpleSAML_Logger::debug('Received message:');
1928-
} else {
1928+
break;
1929+
case 'out':
19291930
SimpleSAML_Logger::debug('Sending message:');
1931+
break;
1932+
case 'decrypt':
1933+
SimpleSAML_Logger::debug('Decrypted message:');
1934+
break;
1935+
case 'encrypt':
1936+
SimpleSAML_Logger::debug('Encrypted message:');
1937+
break;
1938+
default:
1939+
assert(FALSE);
19301940
}
19311941

19321942
$str = self::formatXMLString($message);

0 commit comments

Comments
 (0)