From e93b57e28d9981908afe1db9463cedd766ed2816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Tue, 17 Feb 2009 15:32:05 +0000 Subject: [PATCH] adding saml 2.0 debugger module git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1283 44740490-163a-0410-bde0-09ae8108e29a --- modules/saml2debug/default-disable | 0 modules/saml2debug/hooks/hook_frontpage.php | 19 ++++++ modules/saml2debug/templates/debug.tpl.php | 67 ++++++++++++++++++++ modules/saml2debug/www/debug.php | 68 +++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 modules/saml2debug/default-disable create mode 100644 modules/saml2debug/hooks/hook_frontpage.php create mode 100644 modules/saml2debug/templates/debug.tpl.php create mode 100644 modules/saml2debug/www/debug.php diff --git a/modules/saml2debug/default-disable b/modules/saml2debug/default-disable new file mode 100644 index 000000000..e69de29bb diff --git a/modules/saml2debug/hooks/hook_frontpage.php b/modules/saml2debug/hooks/hook_frontpage.php new file mode 100644 index 000000000..e29146733 --- /dev/null +++ b/modules/saml2debug/hooks/hook_frontpage.php @@ -0,0 +1,19 @@ +<?php +/** + * Hook to add the simple consenet admin module to the frontpage. + * + * @param array &$links The links on the frontpage, split into sections. + */ +function saml2debug_hook_frontpage(&$links) { + assert('is_array($links)'); + assert('array_key_exists("links", $links)'); + + $links['links'][] = array( + 'href' => SimpleSAML_Module::getModuleURL('saml2debug/debug.php'), + 'text' => array('en' => 'SAML 2.0 Degbugger'), + ); + +} + + +?> diff --git a/modules/saml2debug/templates/debug.tpl.php b/modules/saml2debug/templates/debug.tpl.php new file mode 100644 index 000000000..3fdc760b7 --- /dev/null +++ b/modules/saml2debug/templates/debug.tpl.php @@ -0,0 +1,67 @@ +<?php + +$this->data['head'] = '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery.js"></script>'; +$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-ui.js"></script>'; +$this->data['head'] .= '<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 'resources/uitheme/jquery-ui-themeroller.css" />'; + +$this->data['head'] .= '<script type="text/javascript"> + +$(document).ready(function() { + $("#tabdiv > ul").tabs({ selected: ' . $this->data['activeTab'] . ' }); +}); +</script>'; + +$this->data['header'] = 'SAML 2.0 Debugger'; +$this->includeAtTemplateBase('includes/header.php'); +?> + + + +<div id="tabdiv"> +<ul> + <li><a href="#decode">Decode</a></li> + <li><a href="#encode">Encode</a></li> +</ul> + + +<div id="decode"> + + <p>Paste in a SAML message encoded with the HTTP-POST or HTTP-REDIRECT encoding. You can both use the full URL that you copied from LiveHTTPHeaders, or you can paste in only the SAMLRequest or SAMLResponse parameter. It will be automatically detected whether you post an URL or the value it self and whether you post a HTTP-REDIRECT or HTTP-POST encoded value. enjoy!</p> + + <form method="post" action="debug.php"> + <textarea style="width: 95%; border: 1px solid #999; font-family: monospace" cols="50" rows="10" name="encoded"><?php echo $this->data['encoded']; ?></textarea> + <p><input type="submit" name="decode" value="Decode SAML message »" /></p> + </form> + +</div> <!-- #redirect --> + +<div id="encode"> + + <p>Type in the SAML Message below, and select which binding to use.</p> + + <form method="post" action="debug.php"> + <textarea style="width: 95%; border: 1px solid #999" cols="50" rows="20" name="decoded"><?php echo $this->data['decoded']; ?></textarea> + + <div style="margin: 1em"> + Use this binding: + <select name="binding"> + <option value="redirect">HTTP-REDIRECT</option> + <option value="post">HTTP-POST</option> + </select> + </div> + + <p><input type="submit" name="decode" value="« Encode SAML message" /></p> + </form> + +</div> <!-- #redirect --> + + + + +</div> <!-- #tabdiv --> + + + + + +<?php $this->includeAtTemplateBase('includes/footer.php'); ?> \ No newline at end of file diff --git a/modules/saml2debug/www/debug.php b/modules/saml2debug/www/debug.php new file mode 100644 index 000000000..e976baaa9 --- /dev/null +++ b/modules/saml2debug/www/debug.php @@ -0,0 +1,68 @@ +<?php + +$config = SimpleSAML_Configuration::getInstance(); + + +function getValue($raw) { + + $val = $raw; + + $url = parse_url($raw, PHP_URL_QUERY); + if (!empty($url)) $val = $url; + + $arr = array(); + $query = parse_str($val, &$arr); + + #echo('<pre>');print_r($arr); + + if (array_key_exists('SAMLResponse', $arr)) return $arr['SAMLResponse']; + if (array_key_exists('SAMLRequest', $arr)) return $arr['SAMLRequest']; + if (array_key_exists('LogoutRequest', $arr)) return $arr['LogoutRequest']; + if (array_key_exists('LogoutResponse', $arr)) return $arr['LogoutResponse']; + + return urldecode(stripslashes($val)); +} + +function decode($raw) { + $message = getValue($raw); + #echo 'using value: ' . $message; exit; + + $base64decoded = base64_decode($message); + $gzinflated = gzinflate($base64decoded); + if ($gzinflated != FALSE) { + $base64decoded = $gzinflated; + } + $decoded = htmlentities($base64decoded); + return $decoded; +} + +function encode($message) { + if (!array_key_exists('binding', $_REQUEST)) throw new Exception('missing binding'); + if ($_REQUEST['binding'] === 'redirect') { + return urlencode(base64_encode(gzdeflate(stripslashes($message)))); + } else { + return urlencode(base64_encode(stripslashes($message))); + } +} + + +$decoded = '<html>'; +$encoded = 'fZJNT%2BMwEIbvSPwHy%2Fd8tMvHympSdUGISuwS0cCBm%2BtMUwfbk%2FU4zfLvSVMq2Euv45n3fd7xzOb%2FrGE78KTRZXwSp5yBU1hpV2f8ubyLfvJ5fn42I2lNKxZd2Lon%2BNsBBTZMOhLjQ8Y77wRK0iSctEAiKLFa%2FH4Q0zgVrceACg1ny9uMy7rCdaM2%2Bs0BWrtppK2UAdeoVjW2ruq1bevGImcvR6zpHmtJ1MHSUZAuDKU0vY7Si2h6VU5%2BiMuJuLx65az4dPql3SHBKaz1oYnEfVkWUfG4KkeBna7A%2Fxm6M14j1gZihZazBRH4MODcoKPOgl%2BB32kFz08PGd%2BG0JJIkr7v46%2BhRCaEpod17DCRivYZCkmkd4N28B3wfNyrGKP5bws9DS6PKDz%2FMpsl36Tyz%2F%2Fax1jeFmi0emcLY7C%2F8SDD0Z7dobcynHbbV3QVbcZW0TlqQemNhoqzJD%2B4%2Fn8Yw7l8AA%3D%3D'; + +$activeTab = 0; + +if (array_key_exists('encoded', $_REQUEST)) { + $decoded = decode($_REQUEST['encoded']); + $activeTab = 1; +} +if (array_key_exists('decoded', $_REQUEST)) { + $encoded = encode($_REQUEST['decoded']); +} + +$t = new SimpleSAML_XHTML_Template($config, 'saml2debug:debug.tpl.php'); +$t->data['encoded'] = $encoded; +$t->data['decoded'] = $decoded; +$t->data['activeTab'] = $activeTab; +$t->show(); + +?> \ No newline at end of file -- GitLab