Policy13   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 451
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 246
dl 0
loc 451
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
B getIssuedTokenWSTrustBinding1() 0 101 1
B getUserNameWSTrustBindingPolicy() 0 91 1
B getIssuedTokenWSTrustBinding() 0 100 1
B getCertificateWSTrustBinding() 0 92 1
A __construct() 0 2 1
A getPolicies() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\adfs\Trust;
6
7
use SimpleSAML\WSSecurity\Constants as C;
8
use SimpleSAML\WSSecurity\XML\sp_200702\AlgorithmSuite;
9
use SimpleSAML\WSSecurity\XML\sp_200702\Basic256;
10
use SimpleSAML\WSSecurity\XML\sp_200702\EndorsingSupportingTokens;
11
use SimpleSAML\WSSecurity\XML\sp_200702\Header;
12
use SimpleSAML\WSSecurity\XML\sp_200702\HttpsToken;
13
use SimpleSAML\WSSecurity\XML\sp_200702\IncludeTimestamp;
14
use SimpleSAML\WSSecurity\XML\sp_200702\IncludeToken;
15
use SimpleSAML\WSSecurity\XML\sp_200702\IssuedToken;
16
use SimpleSAML\WSSecurity\XML\sp_200702\KeyValueToken;
17
use SimpleSAML\WSSecurity\XML\sp_200702\Layout;
18
use SimpleSAML\WSSecurity\XML\sp_200702\MustSupportIssuedTokens;
19
use SimpleSAML\WSSecurity\XML\sp_200702\MustSupportRefThumbprint;
20
use SimpleSAML\WSSecurity\XML\sp_200702\RequestSecurityTokenTemplate;
21
use SimpleSAML\WSSecurity\XML\sp_200702\RequireClientEntropy;
22
use SimpleSAML\WSSecurity\XML\sp_200702\RequireInternalReference;
23
use SimpleSAML\WSSecurity\XML\sp_200702\RequireServerEntropy;
24
use SimpleSAML\WSSecurity\XML\sp_200702\RequireThumbprintReference;
25
use SimpleSAML\WSSecurity\XML\sp_200702\SignedEncryptedSupportingTokens;
26
use SimpleSAML\WSSecurity\XML\sp_200702\SignedParts;
27
use SimpleSAML\WSSecurity\XML\sp_200702\Strict;
28
use SimpleSAML\WSSecurity\XML\sp_200702\TransportBinding;
29
use SimpleSAML\WSSecurity\XML\sp_200702\TransportToken;
30
use SimpleSAML\WSSecurity\XML\sp_200702\Trust13;
31
use SimpleSAML\WSSecurity\XML\sp_200702\UsernameToken;
32
use SimpleSAML\WSSecurity\XML\sp_200702\Wss11;
33
use SimpleSAML\WSSecurity\XML\sp_200702\WssUsernameToken10;
34
use SimpleSAML\WSSecurity\XML\sp_200702\WssX509V3Token10;
35
use SimpleSAML\WSSecurity\XML\sp_200702\X509Token;
36
use SimpleSAML\WSSecurity\XML\wsaw\UsingAddressing;
37
use SimpleSAML\WSSecurity\XML\wsp\All;
38
use SimpleSAML\WSSecurity\XML\wsp\ExactlyOne;
39
use SimpleSAML\WSSecurity\XML\wsp\Policy;
40
use SimpleSAML\WSSecurity\XML\wst_200512\CanonicalizationAlgorithm;
41
use SimpleSAML\WSSecurity\XML\wst_200512\EncryptionAlgorithm;
42
use SimpleSAML\WSSecurity\XML\wst_200512\EncryptWith;
43
use SimpleSAML\WSSecurity\XML\wst_200512\KeySize;
44
use SimpleSAML\WSSecurity\XML\wst_200512\KeyType;
45
use SimpleSAML\WSSecurity\XML\wst_200512\KeyTypeEnum;
46
use SimpleSAML\WSSecurity\XML\wst_200512\KeyWrapAlgorithm;
47
use SimpleSAML\WSSecurity\XML\wst_200512\SignatureAlgorithm;
48
use SimpleSAML\XML\Attribute as XMLAttribute;
49
50
/**
51
 * @package simplesamlphp/simplesamlphp-module-adfs
52
 */
53
class Policy13
54
{
55
    /**
56
     * Constructor.
57
     */
58
    public function __construct()
59
    {
60
    }
61
62
63
    /**
64
     * This method builds the wsp:Policy elements
65
     *
66
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy[]
67
     */
68
    public function getPolicies(): array
69
    {
70
        return [
71
            $this->getCertificateWSTrustBinding(),
72
            $this->getUserNameWSTrustBindingPolicy(),
73
            $this->getIssuedTokenWSTrustBinding(),
74
            $this->getIssuedTokenWSTrustBinding1(),
75
        ];
76
    }
77
78
79
    /**
80
     * This method builds the CertificateWSTrustBinding policy.
81
     *
82
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
83
     */
84
    private function getCertificateWSTrustBinding(): Policy
85
    {
86
        $transportBinding = new TransportBinding(
87
            elements: [new Policy(
88
                children: [
89
                    new TransportToken(
90
                        elements: [new Policy(
91
                            children: [new HttpsToken()],
92
                        )],
93
                    ),
94
                    new AlgorithmSuite(
95
                        elements: [new Policy(
96
                            children: [new Basic256()],
97
                        )],
98
                    ),
99
                    new Layout(
100
                        elements: [new Policy(
101
                            children: [new Strict()],
102
                        )],
103
                    ),
104
                    new IncludeTimestamp(),
105
                ],
106
            )],
107
        );
108
109
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
110
            elements: [new Policy(
111
                children: [
112
                    new X509Token(
113
                        elts: [new Policy(
114
                            children: [
115
                                new RequireThumbprintReference(),
116
                                new WssX509V3Token10(),
117
                            ],
118
                        )],
119
                        namespacedAttributes: [
120
                            new XMLAttribute(
121
                                C::NS_SEC_POLICY_12,
122
                                'sp',
123
                                'IncludeToken',
124
                                IncludeToken::AlwaysToRecipient->value,
125
                            ),
126
                        ],
127
                    ),
128
                    new KeyValueToken(
129
                        namespacedAttributes: [
130
                            new XMLAttribute(C::NS_SEC_POLICY_12, 'sp', 'IncludeToken', IncludeToken::Never->value),
131
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
132
                        ],
133
                    ),
134
                    new SignedParts(
135
                        header: [
136
                            new Header(
137
                                namespace: C::NS_ADDR_200508,
138
                                name: 'To',
139
                            ),
140
                        ],
141
                    ),
142
                ],
143
            )],
144
        );
145
146
        $wss11 = new Wss11(
147
            elements: [new Policy(
148
                children: [
149
                    new MustSupportRefThumbprint(),
150
                ],
151
            )],
152
        );
153
154
        $trust10 = new Trust13(
155
            elements: [new Policy(
156
                children: [
157
                    new MustSupportIssuedTokens(),
158
                    new RequireClientEntropy(),
159
                    new RequireServerEntropy(),
160
                ],
161
            )],
162
        );
163
164
        $usingAddressing = new UsingAddressing();
165
166
        return new Policy(
167
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'CertificateWSTrustBinding_IWSTrust13Async_policy'),
168
            operatorContent: [new ExactlyOne(
169
                operatorContent: [new All(
170
                    children: [
171
                        $transportBinding,
172
                        $endorsingSupportingTokens,
173
                        $wss11,
174
                        $trust10,
175
                        $usingAddressing,
176
                    ],
177
                )],
178
            )],
179
        );
180
    }
181
182
183
    /**
184
     * This method builds the UserNameWSTrustBinding policy.
185
     *
186
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
187
     */
188
    private function getUserNameWSTrustBindingPolicy(): Policy
189
    {
190
        $transportBinding = new TransportBinding(
191
            elements: [new Policy(
192
                children: [
193
                    new TransportToken(
194
                        elements: [new Policy(
195
                            children: [new HttpsToken()],
196
                        )],
197
                    ),
198
                    new AlgorithmSuite(
199
                        elements: [new Policy(
200
                            children: [new Basic256()],
201
                        )],
202
                    ),
203
                    new Layout(
204
                        elements: [new Policy(
205
                            children: [new Strict()],
206
                        )],
207
                    ),
208
                    new IncludeTimestamp(),
209
                ],
210
            )],
211
        );
212
213
        $signedEncryptedSupportingTokens = new SignedEncryptedSupportingTokens(
214
            elements: [new Policy(
215
                children: [new UsernameToken(
216
                    elts: [new Policy(
217
                        children: [new WssUsernameToken10()],
218
                    )],
219
                    namespacedAttributes: [
220
                        new XMLAttribute(
221
                            C::NS_SEC_POLICY_12,
222
                            'sp',
223
                            'IncludeToken',
224
                            IncludeToken::AlwaysToRecipient->value,
225
                        ),
226
                    ],
227
                )],
228
            )],
229
        );
230
231
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
232
            elements: [new Policy(
233
                children: [
234
                    new KeyValueToken(
235
                        namespacedAttributes: [
236
                            new XMLAttribute(C::NS_SEC_POLICY_12, 'sp', 'IncludeToken', IncludeToken::Never->value),
237
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
238
                        ],
239
                    ),
240
                    new SignedParts(
241
                        header: [
242
                            new Header(
243
                                namespace: C::NS_ADDR_200508,
244
                                name: 'To',
245
                            ),
246
                        ],
247
                    ),
248
                ],
249
            )],
250
        );
251
252
        $wss11 = new Wss11(
253
            elements: [new Policy()],
254
        );
255
256
        $trust13 = new Trust13(
257
            elements: [new Policy(
258
                children: [
259
                    new MustSupportIssuedTokens(),
260
                    new RequireClientEntropy(),
261
                    new RequireServerEntropy(),
262
                ],
263
            )],
264
        );
265
266
        $usingAddressing = new UsingAddressing();
267
268
        return new Policy(
269
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'UserNameWSTrustBinding_IWSTrustFeb2005Async_policy'),
270
            operatorContent: [new ExactlyOne(
271
                operatorContent: [new All(
272
                    children: [
273
                        $transportBinding,
274
                        $signedEncryptedSupportingTokens,
275
                        $endorsingSupportingTokens,
276
                        $wss11,
277
                        $trust13,
278
                        $usingAddressing,
279
                    ],
280
                )],
281
            )],
282
        );
283
    }
284
285
286
    /**
287
     * This method builds the IssuedTokenWSTrustBinding policy.
288
     *
289
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
290
     */
291
    private function getIssuedTokenWSTrustBinding(): Policy
292
    {
293
        $transportBinding = new TransportBinding(
294
            elements: [new Policy(
295
                children: [
296
                    new TransportToken(
297
                        elements: [new Policy(
298
                            children: [new HttpsToken()],
299
                        )],
300
                    ),
301
                    new AlgorithmSuite(
302
                        elements: [new Policy(
303
                            children: [new Basic256()],
304
                        )],
305
                    ),
306
                    new Layout(
307
                        elements: [new Policy(
308
                            children: [new Strict()],
309
                        )],
310
                    ),
311
                    new IncludeTimestamp(),
312
                ],
313
            )],
314
        );
315
316
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
317
            elements: [new Policy(
318
                children: [
319
                    new IssuedToken(
320
                        requestSecurityTokenTemplate: new RequestSecurityTokenTemplate(
321
                            elts: [
322
                                new KeyType([KeyTypeEnum::PublicKey]),
323
                                new KeyWrapAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P),
324
                                new EncryptWith(C::KEY_TRANSPORT_OAEP_MGF1P),
325
                                new SignatureAlgorithm(C::SIG_RSA_SHA1),
326
                                new CanonicalizationAlgorithm(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
327
                                new EncryptionAlgorithm(C::BLOCK_ENC_AES256),
328
                            ],
329
                        ),
330
                        elts: [
331
                            new Policy(
332
                                children: [
333
                                    new RequireInternalReference(),
334
                                ],
335
                            ),
336
                        ],
337
                        namespacedAttributes: [
338
                            new XMLAttribute(
339
                                C::NS_SEC_POLICY_12,
340
                                'sp',
341
                                'IncludeToken',
342
                                IncludeToken::AlwaysToRecipient->value,
343
                            ),
344
                        ],
345
                    ),
346
                    new KeyValueToken(
347
                        namespacedAttributes: [
348
                            new XMLAttribute(C::NS_SEC_POLICY_12, 'sp', 'IncludeToken', IncludeToken::Never->value),
349
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
350
                        ],
351
                    ),
352
                    new SignedParts(
353
                        header: [
354
                            new Header(
355
                                namespace: C::NS_ADDR_200508,
356
                                name: 'To',
357
                            ),
358
                        ],
359
                    ),
360
                ],
361
            )],
362
        );
363
364
        $wss11 = new Wss11(
365
            elements: [new Policy(
366
            )],
367
        );
368
369
        $trust13 = new Trust13(
370
            elements: [new Policy(
371
                children: [
372
                    new MustSupportIssuedTokens(),
373
                    new RequireClientEntropy(),
374
                    new RequireServerEntropy(),
375
                ],
376
            )],
377
        );
378
379
        $usingAddressing = new UsingAddressing();
380
381
        return new Policy(
382
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'IssuedTokenWSTrustBinding_IWSTrust13Async_policy'),
383
            operatorContent: [new ExactlyOne(
384
                operatorContent: [new All(
385
                    children: [
386
                        $transportBinding,
387
                        $endorsingSupportingTokens,
388
                        $wss11,
389
                        $trust13,
390
                        $usingAddressing,
391
                    ],
392
                )],
393
            )],
394
        );
395
    }
396
397
398
    /**
399
     * This method builds the IssuedTokenWSTrustBinding1 policy.
400
     *
401
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
402
     */
403
    private function getIssuedTokenWSTrustBinding1(): Policy
404
    {
405
        $transportBinding = new TransportBinding(
406
            elements: [new Policy(
407
                children: [
408
                    new TransportToken(
409
                        elements: [new Policy(
410
                            children: [new HttpsToken()],
411
                        )],
412
                    ),
413
                    new AlgorithmSuite(
414
                        elements: [new Policy(
415
                            children: [new Basic256()],
416
                        )],
417
                    ),
418
                    new Layout(
419
                        elements: [new Policy(
420
                            children: [new Strict()],
421
                        )],
422
                    ),
423
                    new IncludeTimestamp(),
424
                ],
425
            )],
426
        );
427
428
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
429
            elements: [new Policy(
430
                children: [
431
                    new IssuedToken(
432
                        requestSecurityTokenTemplate: new RequestSecurityTokenTemplate(
433
                            elts: [
434
                                new KeyType([KeyTypeEnum::SymmetricKey]),
435
                                new KeySize('256'),
436
                                new KeyWrapAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P),
437
                                new EncryptWith(C::BLOCK_ENC_AES256),
438
                                new SignatureAlgorithm(C::SIG_HMAC_SHA1),
439
                                new CanonicalizationAlgorithm(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
440
                                new EncryptionAlgorithm(C::BLOCK_ENC_AES256),
441
                            ],
442
                        ),
443
                        elts: [
444
                            new Policy(
445
                                children: [
446
                                    new RequireInternalReference(),
447
                                ],
448
                            ),
449
                        ],
450
                        namespacedAttributes: [
451
                            new XMLAttribute(
452
                                C::NS_SEC_POLICY_12,
453
                                'sp',
454
                                'IncludeToken',
455
                                IncludeToken::AlwaysToRecipient->value,
456
                            ),
457
                        ],
458
                    ),
459
                    new KeyValueToken(
460
                        namespacedAttributes: [
461
                            new XMLAttribute(C::NS_SEC_POLICY_12, 'sp', 'IncludeToken', IncludeToken::Never->value),
462
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
463
                        ],
464
                    ),
465
                    new SignedParts(
466
                        header: [
467
                            new Header(
468
                                namespace: C::NS_ADDR_200508,
469
                                name: 'To',
470
                            ),
471
                        ],
472
                    ),
473
                ],
474
            )],
475
        );
476
477
        $wss11 = new Wss11(
478
            elements: [new Policy(
479
            )],
480
        );
481
482
        $trust13 = new Trust13(
483
            elements: [new Policy(
484
                children: [
485
                    new MustSupportIssuedTokens(),
486
                    new RequireClientEntropy(),
487
                    new RequireServerEntropy(),
488
                ],
489
            )],
490
        );
491
492
        $usingAddressing = new UsingAddressing();
493
494
        return new Policy(
495
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'IssuedTokenWSTrustBinding_IWSTrust13Async1_policy'),
496
            operatorContent: [new ExactlyOne(
497
                operatorContent: [new All(
498
                    children: [
499
                        $transportBinding,
500
                        $endorsingSupportingTokens,
501
                        $wss11,
502
                        $trust13,
503
                        $usingAddressing,
504
                    ],
505
                )],
506
            )],
507
        );
508
    }
509
}
510