-
Notifications
You must be signed in to change notification settings - Fork 2
/
saml_test.go
365 lines (342 loc) · 15.3 KB
/
saml_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package saml_test
import (
"crypto/rsa"
"crypto/x509"
"encoding/asn1"
"encoding/base64"
"encoding/pem"
"encoding/xml"
"fmt"
"io/ioutil"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/ucarion/dsig"
"github.com/ucarion/saml"
)
// The cert and key used in these tests were generated by running:
//
// openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
// -nodes -subj "/C=US/ST=Oregon/L=Portland/O=Company
// Name/OU=Org/CN=www.example.com"
//
// Which generated the certificate used in TestVerify. It also generated this
// corresponding RSA private key:
//
// -----BEGIN PRIVATE KEY-----
// MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQC4yrnAdbSwMQz8
// CPL0ir2TbhNadYCjukgxQxxjGeVVuRxHFzKyLlaM17ZG6x67F7DqvxXwO8Bvfnur
// eFDG8uq13eIni3Tvl38G4pFQOLHgY/hvKS9E4L8bBPDaXag6jD463arduvOo0ZzB
// movgoqw4ryze53I2z8D+eIPa3WmRX93gZ69UemcAo7MJv/WzpByimefah/+TSTFd
// r5q1kVOxaJclcoAbTcDRxZEVGc6l/BRZQHrz5VG3JEO8M1KuzAq0nMyFkyP1ynGv
// P66syV+DYcqjSJ3cB+fgeIC1VT2ZgwzdxBWJeRIgCNT8YOmI9FpiYrurEcU9iLnf
// HQ0O3422QLZrJVxyY47c7q9kBPUNUZ+ewWgPeSeRDSl3L0wfknNebemmZr7IRYUV
// h6bTIqB/MRORp70E/Vnp5QBrofdkaF8Z6zslnz50FAj3pZVsmEaQjh/yBqxghV4H
// qivNmf+6p8/38PjhlU9x/M1dmmjr1NKau4ILrS9meEL2+rweqV4TZq++T7d57Bor
// oz1zytKXp/QwvGQcpD+TRtuhHZkpLHROyGSdCR9XnYBI5FeQOVi53vhT+BDrbrXE
// +CkfmALylLFsflBeF/9IhmyHAcEpkj/0FZYjAXoEZEEeAphawd/qVspt30J7X35O
// cqTIPDilNVL+WWMi0lHsWO5h9FzPMwIDAQABAoICAH3d353ezp8AGgcFlW7JnYzw
// +g+wX1mmBYxAWPKLbfDwr/kgLPC+rUcrmsU9WuY2odOTKj9Cg7WtolDOF78bMJGF
// u4gR7ilPuD8ZTb8ljsr3bP1SQRcaOjEOMXubNX4DjlOMLtjugQ6pD6uzN7lfNA08
// DEUbwmjhI2Rw8+a8zy4s7TTvirXw1X3TAp0Oei3NB5AdYpYv8f4BabWVabxoa2g4
// hFMGZYmzcTWw6zxDI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3ZGhfGes7JZ8+dBQI96WVbJhGkI4f8gasYIVe
B6orzZn/uqfP9/D44ZVPcfzNXZpo69TSmruCC60vZnhC9vq8HqleE2avvk+3eewa
K6M9c8rSl6f0MLxkHKQ/k0bboR2ZKSx0TshknQkfV52ASORXkDlYud74U/gQ6261
xPgpH5gC8pSxbH5QXhf/SIZshwHBKZI/9BWWIwF6BGRBHgKYWsHf6lbKbd9Ce19+
TnKkyDw4pTVS/lljItJR7FjuYfRczzMCAwEAATANBgkqhkiG9w0BAQsFAAOCAgEA
r6UAa9n4FkiA4ZqugCJEoC5Ehc1X/qdNFkY4EIHc33sqscqVZhHC0MbfNmKuiirk
XKTR+M3U62IvD8HXpkBMTYMpnvsH4jFuP3SpTFfUuqarueqsawiPAejhjF9829fg
K1+s1rD/fI3H3UuHWChTXKA4KpnCYr5B1om4ZoCcTVVdZjhO256iM7p/DHze08Eo
Rdhaj+rgs6NC5vLHWX9bezACeqA3YwJYHRH0zuoCQfRKXkikIjj18wpWNARFhDoQ
FEhJXIAO/skpuK6Q9Ml1wWuFaqgXtKN1iVzuGi7P8O3bCLexwmqnmsnEZPPpzjoQ
T8zVIjCH6jBX533f1B745IrGNzMSr6YC/9RT3DrPoNT9pCAozSoZxldqIegxLgWG
zBT6jj/fR92E5kJh8Hy3koeXGkyAkcHB0PH8yyFtYIlP0stENkG/fDCLuMUqf6GZ
P/oSyJH1Ro/qV6kwc1XYDB+6NGC8Xd1JQKZD49c/GZYpo77ZYKQtCoTrMuPKSG5/
jP7OTrdylTj+V4r7jYLLpvWCUe0ON0QPKClo+15tXATWep6PFk0U5W+efvavG70e
Fu9GKMOkTgv5F/ngzDgXKo7T6poRDZAgolUAq2kwDUp42AVx/7UqmOdp0yUTNmJG
A70UwPLAvWk5vX1IMpaEFjBd3LqWLeSmbKZ03zr1jnA=
-----END CERTIFICATE-----`))
cert, err := x509.ParseCertificate(block.Bytes)
assert.NoError(t, err)
now, err := time.Parse(time.RFC3339, "2020-05-23T01:46:00Z")
assert.NoError(t, err)
type testCase struct {
Name string
Response saml.Response
Error error
}
testCases := []testCase{
testCase{
Name: "unsigned",
Error: saml.ErrResponseNotSigned,
},
testCase{
Name: "invalid_signature",
Error: rsa.ErrVerification,
},
testCase{
Name: "wrong_issuer",
Error: saml.ErrInvalidIssuer,
},
testCase{
Name: "wrong_recipient",
Error: saml.ErrInvalidRecipient,
},
testCase{
Name: "before_conditions_not_before",
Error: saml.ErrAssertionExpired,
},
testCase{
Name: "after_conditions_not_on_or_after",
Error: saml.ErrAssertionExpired,
},
testCase{
Name: "after_subject_confirmation_data_not_on_or_after",
Error: saml.ErrAssertionExpired,
},
testCase{
Name: "valid",
Response: saml.Response{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:protocol", Local: "Response"},
Assertion: saml.Assertion{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "Assertion"},
Issuer: saml.Issuer{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "Issuer"},
Name: "alice",
},
Subject: saml.Subject{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "Subject"},
NameID: saml.NameID{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "NameID"},
Format: "format",
Value: "[email protected]",
},
SubjectConfirmation: saml.SubjectConfirmation{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "SubjectConfirmation"},
SubjectConfirmationData: saml.SubjectConfirmationData{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "SubjectConfirmationData"},
NotOnOrAfter: now.Add(time.Minute),
Recipient: "bob",
},
},
},
Conditions: saml.Conditions{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "Conditions"},
NotBefore: now.Add(-time.Minute),
NotOnOrAfter: now.Add(time.Minute),
},
AttributeStatement: saml.AttributeStatement{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "AttributeStatement"},
Attributes: []saml.Attribute{
saml.Attribute{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "Attribute"},
Name: "attr1",
NameFormat: "fmt1",
Value: "value1",
},
saml.Attribute{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:assertion", Local: "Attribute"},
Name: "attr2",
NameFormat: "fmt2",
Value: "value2",
},
},
},
},
},
},
}
for _, tt := range testCases {
t.Run(tt.Name, func(t *testing.T) {
b, err := ioutil.ReadFile(fmt.Sprintf("tests/%s.xml", tt.Name))
assert.NoError(t, err)
res, err := saml.Verify(base64.StdEncoding.EncodeToString(b), "alice", cert, "bob", now)
res.Signature = dsig.Signature{} // clear this out to make test cases a bit less verbose
assert.Equal(t, tt.Response, res)
assert.Equal(t, tt.Error, err)
})
}
}
func TestVerify_InvalidBase64(t *testing.T) {
_, err := saml.Verify("NOT BASE64", "", nil, "", time.Now())
assert.Equal(t, base64.CorruptInputError(3), err)
}
func TestVerify_InvalidXML(t *testing.T) {
_, err := saml.Verify(base64.StdEncoding.EncodeToString([]byte("<foo")), "", nil, "", time.Now())
assert.Equal(t, &xml.SyntaxError{Msg: "unexpected EOF", Line: 1}, err)
}
func TestGetEntityIDCertificateAndRedirectURL(t *testing.T) {
block, _ := pem.Decode([]byte(`-----BEGIN CERTIFICATE-----
MIIFXDCCA0QCCQCl4WZtbTlavDANBgkqhkiG9w0BAQsFADBwMQswCQYDVQQGEwJV
UzEPMA0GA1UECAwGT3JlZ29uMREwDwYDVQQHDAhQb3J0bGFuZDEVMBMGA1UECgwM
Q29tcGFueSBOYW1lMQwwCgYDVQQLDANPcmcxGDAWBgNVBAMMD3d3dy5leGFtcGxl
LmNvbTAeFw0yMDA1MjAxNzI0MzFaFw0yMTA1MjAxNzI0MzFaMHAxCzAJBgNVBAYT
AlVTMQ8wDQYDVQQIDAZPcmVnb24xETAPBgNVBAcMCFBvcnRsYW5kMR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zuoCQfRKXkikIjj18wpWNARFhDoQ
FEhJXIAO/skpuK6Q9Ml1wWuFaqgXtKN1iVzuGi7P8O3bCLexwmqnmsnEZPPpzjoQ
T8zVIjCH6jBX533f1B745IrGNzMSr6YC/9RT3DrPoNT9pCAozSoZxldqIegxLgWG
zBT6jj/fR92E5kJh8Hy3koeXGkyAkcHB0PH8yyFtYIlP0stENkG/fDCLuMUqf6GZ
P/oSyJH1Ro/qV6kwc1XYDB+6NGC8Xd1JQKZD49c/GZYpo77ZYKQtCoTrMuPKSG5/
jP7OTrdylTj+V4r7jYLLpvWCUe0ON0QPKClo+15tXATWep6PFk0U5W+efvavG70e
Fu9GKMOkTgv5F/ngzDgXKo7T6poRDZAgolUAq2kwDUp42AVx/7UqmOdp0yUTNmJG
A70UwPLAvWk5vX1IMpaEFjBd3LqWLeSmbKZ03zr1jnA=
-----END CERTIFICATE-----`))
expectedCert, err := x509.ParseCertificate(block.Bytes)
assert.NoError(t, err)
b, err := ioutil.ReadFile("tests/valid_idp_metadata.xml")
assert.NoError(t, err)
var metadata saml.EntityDescriptor
assert.NoError(t, xml.Unmarshal(b, &metadata))
entityID, cert, location, err := metadata.GetEntityIDCertificateAndRedirectURL()
assert.NoError(t, err)
assert.Equal(t, "https://example.com", entityID)
assert.True(t, expectedCert.Equal(cert))
assert.Equal(t, "https://example.com/saml/redirect", location.String())
}
func TestGetEntityIDCertificateAndRedirectURL_InvalidBase64(t *testing.T) {
metadata := saml.EntityDescriptor{
IDPSSODescriptor: saml.IDPSSODescriptor{
KeyDescriptor: saml.KeyDescriptor{
KeyInfo: saml.KeyInfo{
X509Data: saml.X509Data{
X509Certificate: saml.X509Certificate{
Value: "NOT BASE64",
},
},
},
},
},
}
_, _, _, err := metadata.GetEntityIDCertificateAndRedirectURL()
assert.Equal(t, base64.CorruptInputError(3), err)
}
func TestGetEntityIDCertificateAndRedirectURL_InvalidX509(t *testing.T) {
metadata := saml.EntityDescriptor{
IDPSSODescriptor: saml.IDPSSODescriptor{
KeyDescriptor: saml.KeyDescriptor{
KeyInfo: saml.KeyInfo{
X509Data: saml.X509Data{
X509Certificate: saml.X509Certificate{
// echo 'not x509' | base64
Value: "bm90IHg1MDkK",
},
},
},
},
},
}
_, _, _, err := metadata.GetEntityIDCertificateAndRedirectURL()
assert.IsType(t, asn1.StructuralError{}, err)
}
func TestGetEntityIDCertificateAndRedirectURL_NoRedirectBinding(t *testing.T) {
metadata := saml.EntityDescriptor{
IDPSSODescriptor: saml.IDPSSODescriptor{
KeyDescriptor: saml.KeyDescriptor{
KeyInfo: saml.KeyInfo{
X509Data: saml.X509Data{
X509Certificate: saml.X509Certificate{
Value: `MIIFXDCCA0QCCQCl4WZtbTlavDANBgkqhkiG9w0BAQsFADBwMQswCQYDVQQGEwJV
UzEPMA0GA1UECAwGT3JlZ29uMREwDwYDVQQHDAhQb3J0bGFuZDEVMBMGA1UECgwM
Q29tcGFueSBOYW1lMQwwCgYDVQQLDANPcmcxGDAWBgNVBAMMD3d3dy5leGFtcGxl
LmNvbTAeFw0yMDA1MjAxNzI0MzFaFw0yMTA1MjAxNzI0MzFaMHAxCzAJBgNVBAYT
AlVTMQ8wDQYDVQQIDAZPcmVnb24xETAPBgNVBAcMCFBvcnRsYW5kMRUwEwYDVQQK
DAxDb21wYW55IE5hbWUxDDAKBgNVBAsMA09yZzEYMBYGA1UEAwwPd3d3LmV4YW1w
bGUuY29tMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuMq5wHW0sDEM
/Ajy9Iq9k24TWnWAo7pIMUMcYxnlVbkcRxcysi5WjNe2Ruseuxew6r8V8DvAb357
q3hQxvLqtd3iJ4t075d/BuKRUDix4GP4bykvROC/GwTw2l2oOow+Ot2q3brzqNGc
wZqL4KKsOK8s3udyNs/A/niD2t1pkV/d4GevVHpnAKOzCb/1s6Qcopnn2of/k0kx
Xa+atZFTsWiXJXKAG03A0cWRFRnOpfwUWUB68+VRtyRDvDNSrswKtJzMhZMj9cpx
rz+ur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/7UqmOdp0yUTNmJG
A70UwPLAvWk5vX1IMpaEFjBd3LqWLeSmbKZ03zr1jnA=`,
},
},
},
},
},
}
_, _, _, err := metadata.GetEntityIDCertificateAndRedirectURL()
assert.Equal(t, saml.ErrNoRedirectBinding, err)
}