|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\saml2debug\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Configuration; |
|
8
|
|
|
use SimpleSAML\Error; |
|
9
|
|
|
use SimpleSAML\Module; |
|
10
|
|
|
use SimpleSAML\Session; |
|
11
|
|
|
use SimpleSAML\XHTML\Template; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Controller class for the saml2debug module. |
|
17
|
|
|
* |
|
18
|
|
|
* This class serves the different views available in the module. |
|
19
|
|
|
* |
|
20
|
|
|
* @package simplesamlphp/simplesamlphp-module-saml2debug |
|
21
|
|
|
*/ |
|
22
|
|
|
class Debug |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var \SimpleSAML\Configuration */ |
|
25
|
|
|
protected Configuration $config; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \SimpleSAML\Session */ |
|
28
|
|
|
protected Session $session; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Controller constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* It initializes the global configuration and session for the controllers implemented here. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
|
37
|
|
|
* @param \SimpleSAML\Session $session The session to use by the controllers. |
|
38
|
|
|
* |
|
39
|
|
|
* @throws \Exception |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
Configuration $config, |
|
43
|
|
|
Session $session |
|
44
|
|
|
) { |
|
45
|
|
|
$this->config = $config; |
|
46
|
|
|
$this->session = $session; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Show SAML2 debugging info. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
54
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
55
|
|
|
* @throws \Exception |
|
56
|
|
|
*/ |
|
57
|
|
|
public function decode(Request $request): Template |
|
58
|
|
|
{ |
|
59
|
|
|
$decoded = ''; |
|
60
|
|
|
$encoded = ''; |
|
61
|
|
|
|
|
62
|
|
|
if ($request->query->has('encoded')) { |
|
63
|
|
|
if (!$request->query->has('binding')) { |
|
64
|
|
|
throw new Error\BadRequest('Missing binding'); |
|
65
|
|
|
} |
|
66
|
|
|
$decoded = $this->parseEncodedMessage($request->query->get('encoded'), $request->query->get('binding')); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$t = new Template($this->config, 'saml2debug:decode.twig'); |
|
70
|
|
|
$t->data['encoded'] = $encoded; |
|
71
|
|
|
$t->data['decoded'] = $decoded; |
|
72
|
|
|
|
|
73
|
|
|
return $t; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Show SAML2 debugging info. |
|
79
|
|
|
* |
|
80
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
81
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
82
|
|
|
* @throws \Exception |
|
83
|
|
|
*/ |
|
84
|
|
|
public function encode(Request $request): Template |
|
85
|
|
|
{ |
|
86
|
|
|
$decoded = ''; |
|
87
|
|
|
$encoded = 'fZJNT%2BMwEIbvSPwHy%2Fd8tMvHympSdUGISuwS0cCBm%2BtMUwfbk%2FU4zfLvSVMq2Euv45n3fd7xzOb%2FrGE78KTRZXwSp5yBU1hp' . |
|
88
|
|
|
'V2f8ubyLfvJ5fn42I2lNKxZd2Lon%2BNsBBTZMOhLjQ8Y77wRK0iSctEAiKLFa%2FH4Q0zgVrceACg1ny9uMy7rCdaM2%2Bs0BWrtppK2U' . |
|
89
|
|
|
'AdeoVjW2ruq1bevGImcvR6zpHmtJ1MHSUZAuDKU0vY7Si2h6VU5%2BiMuJuLx65az4dPql3SHBKaz1oYnEfVkWUfG4KkeBna7A%2Fxm6M1' . |
|
90
|
|
|
'4j1gZihZazBRH4MODcoKPOgl%2BB32kFz08PGd%2BG0JJIkr7v46%2BhRCaEpod17DCRivYZCkmkd4N28B3wfNyrGKP5bws9DS6PKDz%2F' . |
|
91
|
|
|
'Mpsl36Tyz%2F%2Fax1jeFmi0emcLY7C%2F8SDD0Z7dobcynHbbV3QVbcZW0TlqQemNhoqzJD%2B4%2Fn8Yw7l8AA%3D%3D'; |
|
92
|
|
|
|
|
93
|
|
|
if ($request->query->has('decoded')) { |
|
94
|
|
|
$encoded = $this->parseDecodeMessage($request->query->get('decoded')); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$t = new Template($this->config, 'saml2debug:encode.twig'); |
|
98
|
|
|
$t->data['encoded'] = $encoded; |
|
99
|
|
|
$t->data['decoded'] = $decoded; |
|
100
|
|
|
|
|
101
|
|
|
return $t; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param string $raw |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
private function getValue(string $raw): string |
|
110
|
|
|
{ |
|
111
|
|
|
$val = $raw; |
|
112
|
|
|
|
|
113
|
|
|
$url = parse_url($raw, PHP_URL_QUERY); |
|
114
|
|
|
if (!empty($url)) { |
|
115
|
|
|
$val = $url; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$arr = []; |
|
119
|
|
|
parse_str($val, $arr); |
|
120
|
|
|
|
|
121
|
|
|
if (array_key_exists('SAMLResponse', $arr)) { |
|
122
|
|
|
return $arr['SAMLResponse']; |
|
123
|
|
|
} |
|
124
|
|
|
if (array_key_exists('SAMLRequest', $arr)) { |
|
125
|
|
|
return $arr['SAMLRequest']; |
|
126
|
|
|
} |
|
127
|
|
|
if (array_key_exists('LogoutRequest', $arr)) { |
|
128
|
|
|
return $arr['LogoutRequest']; |
|
129
|
|
|
} |
|
130
|
|
|
if (array_key_exists('LogoutResponse', $arr)) { |
|
131
|
|
|
return $arr['LogoutResponse']; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return rawurldecode(stripslashes($val)); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param string $raw |
|
140
|
|
|
* @return string |
|
141
|
|
|
*/ |
|
142
|
|
|
private function parseDecodedMessage(string $raw): string |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
|
|
$message = $this->getValue($raw); |
|
145
|
|
|
|
|
146
|
|
|
$base64decoded = base64_decode($message); |
|
147
|
|
|
$gzinflated = gzinflate($base64decoded); |
|
148
|
|
|
if ($gzinflated !== false) { |
|
149
|
|
|
$base64decoded = $gzinflated; |
|
150
|
|
|
} |
|
151
|
|
|
$decoded = htmlspecialchars($base64decoded); |
|
152
|
|
|
return $decoded; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param string $message |
|
158
|
|
|
* @param string $binding |
|
159
|
|
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
|
|
private function parseEncodedMessage(string $message, string $binding): string |
|
162
|
|
|
{ |
|
163
|
|
|
if ($binding === 'redirect') { |
|
164
|
|
|
return urlencode(base64_encode(gzdeflate(stripslashes($message)))); |
|
165
|
|
|
} else { |
|
166
|
|
|
return base64_encode(stripslashes($message)); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.