Policy2005   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 495
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 265
dl 0
loc 495
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
B getUserNameWSTrustBindingPolicy() 0 91 1
B getIssuedTokenWSTrustBinding() 0 99 1
A getPolicies() 0 8 1
B getIssuedTokenWSTrustBinding1() 0 100 1
A __construct() 0 2 1
A getCertificateWSTrustBinding1() 0 33 1
B getCertificateWSTrustBinding() 0 92 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\mssp\RsaToken;
9
use SimpleSAML\WSSecurity\XML\sp_200507\AlgorithmSuite;
10
use SimpleSAML\WSSecurity\XML\sp_200507\Basic256;
11
use SimpleSAML\WSSecurity\XML\sp_200507\EndorsingSupportingTokens;
12
use SimpleSAML\WSSecurity\XML\sp_200507\Header;
13
use SimpleSAML\WSSecurity\XML\sp_200507\HttpsToken;
14
use SimpleSAML\WSSecurity\XML\sp_200507\IncludeTimestamp;
15
use SimpleSAML\WSSecurity\XML\sp_200507\IncludeToken;
16
use SimpleSAML\WSSecurity\XML\sp_200507\IssuedToken;
17
use SimpleSAML\WSSecurity\XML\sp_200507\Layout;
18
use SimpleSAML\WSSecurity\XML\sp_200507\MustSupportIssuedTokens;
19
use SimpleSAML\WSSecurity\XML\sp_200507\MustSupportRefThumbprint;
20
use SimpleSAML\WSSecurity\XML\sp_200507\RequestSecurityTokenTemplate;
21
use SimpleSAML\WSSecurity\XML\sp_200507\RequireClientEntropy;
22
use SimpleSAML\WSSecurity\XML\sp_200507\RequireInternalReference;
23
use SimpleSAML\WSSecurity\XML\sp_200507\RequireServerEntropy;
24
use SimpleSAML\WSSecurity\XML\sp_200507\RequireThumbprintReference;
25
use SimpleSAML\WSSecurity\XML\sp_200507\SignedParts;
26
use SimpleSAML\WSSecurity\XML\sp_200507\SignedSupportingTokens;
27
use SimpleSAML\WSSecurity\XML\sp_200507\Strict;
28
use SimpleSAML\WSSecurity\XML\sp_200507\TransportBinding;
29
use SimpleSAML\WSSecurity\XML\sp_200507\TransportToken;
30
use SimpleSAML\WSSecurity\XML\sp_200507\Trust10;
31
use SimpleSAML\WSSecurity\XML\sp_200507\UsernameToken;
32
use SimpleSAML\WSSecurity\XML\sp_200507\Wss11;
33
use SimpleSAML\WSSecurity\XML\sp_200507\WssUsernameToken10;
34
use SimpleSAML\WSSecurity\XML\sp_200507\WssX509V3Token10;
35
use SimpleSAML\WSSecurity\XML\sp_200507\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_200502\CanonicalizationAlgorithm;
41
use SimpleSAML\WSSecurity\XML\wst_200502\EncryptionAlgorithm;
42
use SimpleSAML\WSSecurity\XML\wst_200502\EncryptWith;
43
use SimpleSAML\WSSecurity\XML\wst_200502\KeySize;
44
use SimpleSAML\WSSecurity\XML\wst_200502\KeyType;
45
use SimpleSAML\WSSecurity\XML\wst_200502\KeyTypeEnum;
46
use SimpleSAML\WSSecurity\XML\wst_200502\SignatureAlgorithm;
47
use SimpleSAML\XML\Attribute as XMLAttribute;
48
49
/**
50
 * @package simplesamlphp/simplesamlphp-module-adfs
51
 */
52
class Policy2005
53
{
54
    /**
55
     * Constructor.
56
     */
57
    public function __construct()
58
    {
59
    }
60
61
62
    /**
63
     * This method builds the wsp:Policy elements
64
     *
65
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy[]
66
     */
67
    public function getPolicies(): array
68
    {
69
        return [
70
            $this->getCertificateWSTrustBinding(),
71
            $this->getCertificateWSTrustBinding1(),
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(false)],
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_11,
122
                                'sp',
123
                                'IncludeToken',
124
                                IncludeToken::AlwaysToRecipient->value,
125
                            ),
126
                        ],
127
                    ),
128
                    new RsaToken(
129
                        namespacedAttributes: [
130
                            new XMLAttribute(C::NS_SEC_POLICY_11, '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 Trust10(
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_IWSTrustFeb2005Async_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 CertificateWSTrustBinding1 policy.
185
     *
186
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
187
     */
188
    private function getCertificateWSTrustBinding1(): Policy
189
    {
190
        $transportBinding = new TransportBinding(
191
            elements: [new Policy(
192
                children: [
193
                    new TransportToken(
194
                        elements: [new Policy(
195
                            children: [new HttpsToken(true)],
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
                ],
209
            )],
210
        );
211
212
        $usingAddressing = new UsingAddressing();
213
214
        return new Policy(
215
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'CertificateWSTrustBinding_IWSTrustFeb2005Async1_policy'),
216
            operatorContent: [new ExactlyOne(
217
                operatorContent: [new All(
218
                    children: [
219
                        $transportBinding,
220
                        $usingAddressing,
221
                    ],
222
                )],
223
            )],
224
        );
225
    }
226
227
228
    /**
229
     * This method builds the UserNameWSTrustBinding policy.
230
     *
231
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
232
     */
233
    private function getUserNameWSTrustBindingPolicy(): Policy
234
    {
235
        $transportBinding = new TransportBinding(
236
            elements: [new Policy(
237
                children: [
238
                    new TransportToken(
239
                        elements: [new Policy(
240
                            children: [new HttpsToken(false)],
241
                        )],
242
                    ),
243
                    new AlgorithmSuite(
244
                        elements: [new Policy(
245
                            children: [new Basic256()],
246
                        )],
247
                    ),
248
                    new Layout(
249
                        elements: [new Policy(
250
                            children: [new Strict()],
251
                        )],
252
                    ),
253
                    new IncludeTimestamp(),
254
                ],
255
            )],
256
        );
257
258
        $signedSupportingTokens = new SignedSupportingTokens(
259
            elements: [new Policy(
260
                children: [new UsernameToken(
261
                    elts: [new Policy(
262
                        children: [new WssUsernameToken10()],
263
                    )],
264
                    namespacedAttributes: [
265
                        new XMLAttribute(
266
                            C::NS_SEC_POLICY_11,
267
                            'sp',
268
                            'IncludeToken',
269
                            IncludeToken::AlwaysToRecipient->value,
270
                        ),
271
                    ],
272
                )],
273
            )],
274
        );
275
276
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
277
            elements: [new Policy(
278
                children: [
279
                    new RsaToken(
280
                        namespacedAttributes: [
281
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
282
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
283
                        ],
284
                    ),
285
                    new SignedParts(
286
                        header: [
287
                            new Header(
288
                                namespace: C::NS_ADDR_200508,
289
                                name: 'To',
290
                            ),
291
                        ],
292
                    ),
293
                ],
294
            )],
295
        );
296
297
        $wss11 = new Wss11(
298
            elements: [new Policy()],
299
        );
300
301
        $trust10 = new Trust10(
302
            elements: [new Policy(
303
                children: [
304
                    new MustSupportIssuedTokens(),
305
                    new RequireClientEntropy(),
306
                    new RequireServerEntropy(),
307
                ],
308
            )],
309
        );
310
311
        $usingAddressing = new UsingAddressing();
312
313
        return new Policy(
314
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'UserNameWSTrustBinding_IWSTrustFeb2005Async_policy'),
315
            operatorContent: [new ExactlyOne(
316
                operatorContent: [new All(
317
                    children: [
318
                        $transportBinding,
319
                        $signedSupportingTokens,
320
                        $endorsingSupportingTokens,
321
                        $wss11,
322
                        $trust10,
323
                        $usingAddressing,
324
                    ],
325
                )],
326
            )],
327
        );
328
    }
329
330
331
    /**
332
     * This method builds the IssuedTokenWSTrustBinding policy.
333
     *
334
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
335
     */
336
    private function getIssuedTokenWSTrustBinding(): Policy
337
    {
338
        $transportBinding = new TransportBinding(
339
            elements: [new Policy(
340
                children: [
341
                    new TransportToken(
342
                        elements: [new Policy(
343
                            children: [new HttpsToken(false)],
344
                        )],
345
                    ),
346
                    new AlgorithmSuite(
347
                        elements: [new Policy(
348
                            children: [new Basic256()],
349
                        )],
350
                    ),
351
                    new Layout(
352
                        elements: [new Policy(
353
                            children: [new Strict()],
354
                        )],
355
                    ),
356
                    new IncludeTimestamp(),
357
                ],
358
            )],
359
        );
360
361
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
362
            elements: [new Policy(
363
                children: [
364
                    new IssuedToken(
365
                        requestSecurityTokenTemplate: new RequestSecurityTokenTemplate(
366
                            elts: [
367
                                new KeyType([KeyTypeEnum::PublicKey]),
368
                                new EncryptWith(C::KEY_TRANSPORT_OAEP_MGF1P),
369
                                new SignatureAlgorithm(C::SIG_RSA_SHA1),
370
                                new CanonicalizationAlgorithm(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
371
                                new EncryptionAlgorithm(C::BLOCK_ENC_AES256),
372
                            ],
373
                        ),
374
                        elts: [
375
                            new Policy(
376
                                children: [
377
                                    new RequireInternalReference(),
378
                                ],
379
                            ),
380
                        ],
381
                        namespacedAttributes: [
382
                            new XMLAttribute(
383
                                C::NS_SEC_POLICY_11,
384
                                'sp',
385
                                'IncludeToken',
386
                                IncludeToken::AlwaysToRecipient->value,
387
                            ),
388
                        ],
389
                    ),
390
                    new RsaToken(
391
                        namespacedAttributes: [
392
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
393
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
394
                        ],
395
                    ),
396
                    new SignedParts(
397
                        header: [
398
                            new Header(
399
                                namespace: C::NS_ADDR_200508,
400
                                name: 'To',
401
                            ),
402
                        ],
403
                    ),
404
                ],
405
            )],
406
        );
407
408
        $wss11 = new Wss11(
409
            elements: [new Policy(
410
            )],
411
        );
412
413
        $trust10 = new Trust10(
414
            elements: [new Policy(
415
                children: [
416
                    new MustSupportIssuedTokens(),
417
                    new RequireClientEntropy(),
418
                    new RequireServerEntropy(),
419
                ],
420
            )],
421
        );
422
423
        $usingAddressing = new UsingAddressing();
424
425
        return new Policy(
426
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async_policy'),
427
            operatorContent: [new ExactlyOne(
428
                operatorContent: [new All(
429
                    children: [
430
                        $transportBinding,
431
                        $endorsingSupportingTokens,
432
                        $wss11,
433
                        $trust10,
434
                        $usingAddressing,
435
                    ],
436
                )],
437
            )],
438
        );
439
    }
440
441
442
    /**
443
     * This method builds the IssuedTokenWSTrustBinding1 policy.
444
     *
445
     * @return \SimpleSAML\WSSecurity\XML\wsp\Policy
446
     */
447
    private function getIssuedTokenWSTrustBinding1(): Policy
448
    {
449
        $transportBinding = new TransportBinding(
450
            elements: [new Policy(
451
                children: [
452
                    new TransportToken(
453
                        elements: [new Policy(
454
                            children: [new HttpsToken(false)],
455
                        )],
456
                    ),
457
                    new AlgorithmSuite(
458
                        elements: [new Policy(
459
                            children: [new Basic256()],
460
                        )],
461
                    ),
462
                    new Layout(
463
                        elements: [new Policy(
464
                            children: [new Strict()],
465
                        )],
466
                    ),
467
                    new IncludeTimestamp(),
468
                ],
469
            )],
470
        );
471
472
        $endorsingSupportingTokens = new EndorsingSupportingTokens(
473
            elements: [new Policy(
474
                children: [
475
                    new IssuedToken(
476
                        requestSecurityTokenTemplate: new RequestSecurityTokenTemplate(
477
                            elts: [
478
                                new KeyType([KeyTypeEnum::SymmetricKey]),
479
                                new KeySize('256'),
480
                                new EncryptWith(C::BLOCK_ENC_AES256),
481
                                new SignatureAlgorithm(C::SIG_HMAC_SHA1),
482
                                new CanonicalizationAlgorithm(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
483
                                new EncryptionAlgorithm(C::BLOCK_ENC_AES256),
484
                            ],
485
                        ),
486
                        elts: [
487
                            new Policy(
488
                                children: [
489
                                    new RequireInternalReference(),
490
                                ],
491
                            ),
492
                        ],
493
                        namespacedAttributes: [
494
                            new XMLAttribute(
495
                                C::NS_SEC_POLICY_11,
496
                                'sp',
497
                                'IncludeToken',
498
                                IncludeToken::AlwaysToRecipient->value,
499
                            ),
500
                        ],
501
                    ),
502
                    new RsaToken(
503
                        namespacedAttributes: [
504
                            new XMLAttribute(C::NS_SEC_POLICY_11, 'sp', 'IncludeToken', IncludeToken::Never->value),
505
                            new XMLAttribute(C::NS_POLICY, 'wsp', 'Optional', 'true'),
506
                        ],
507
                    ),
508
                    new SignedParts(
509
                        header: [
510
                            new Header(
511
                                namespace: C::NS_ADDR_200508,
512
                                name: 'To',
513
                            ),
514
                        ],
515
                    ),
516
                ],
517
            )],
518
        );
519
520
        $wss11 = new Wss11(
521
            elements: [new Policy(
522
            )],
523
        );
524
525
        $trust10 = new Trust10(
526
            elements: [new Policy(
527
                children: [
528
                    new MustSupportIssuedTokens(),
529
                    new RequireClientEntropy(),
530
                    new RequireServerEntropy(),
531
                ],
532
            )],
533
        );
534
535
        $usingAddressing = new UsingAddressing();
536
537
        return new Policy(
538
            Id: new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', 'IssuedTokenWSTrustBinding_IWSTrustFeb2005Async1_policy'),
539
            operatorContent: [new ExactlyOne(
540
                operatorContent: [new All(
541
                    children: [
542
                        $transportBinding,
543
                        $endorsingSupportingTokens,
544
                        $wss11,
545
                        $trust10,
546
                        $usingAddressing,
547
                    ],
548
                )],
549
            )],
550
        );
551
    }
552
}
553