|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert; |
|
8
|
|
|
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmInterface; |
|
9
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
|
10
|
|
|
use SimpleSAML\XMLSecurity\Exception\UnsupportedAlgorithmException; |
|
11
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; |
|
12
|
|
|
use SimpleSAML\XMLSecurity\XML\SignableElementTrait as BaseSignableElementTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Helper trait for processing signable elements. |
|
16
|
|
|
* |
|
17
|
|
|
* @package simplesamlphp/saml2 |
|
18
|
|
|
*/ |
|
19
|
|
|
trait SignableElementTrait |
|
20
|
|
|
{ |
|
21
|
|
|
use BaseSignableElementTrait; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Sign the current element. |
|
26
|
|
|
* |
|
27
|
|
|
* The signature will not be applied until toXML() is called. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmInterface $signer The actual signer implementation |
|
30
|
|
|
* to use. |
|
31
|
|
|
* @param string $canonicalizationAlg The identifier of the canonicalization algorithm to use. |
|
32
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo A KeyInfo object to add to the signature. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function sign( |
|
35
|
|
|
SignatureAlgorithmInterface $signer, |
|
36
|
|
|
string $canonicalizationAlg = C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, |
|
37
|
|
|
?KeyInfo $keyInfo = null, |
|
38
|
|
|
): void { |
|
39
|
|
|
Assert::notNull($this->getID(), "Signable element must have an ID set before it can be signed."); |
|
40
|
|
|
|
|
41
|
|
|
$this->signer = $signer; |
|
42
|
|
|
$this->keyInfo = $keyInfo; |
|
43
|
|
|
Assert::oneOf( |
|
44
|
|
|
$canonicalizationAlg, |
|
45
|
|
|
[ |
|
46
|
|
|
C::C14N_INCLUSIVE_WITH_COMMENTS, |
|
47
|
|
|
C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, |
|
48
|
|
|
C::C14N_EXCLUSIVE_WITH_COMMENTS, |
|
49
|
|
|
C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, |
|
50
|
|
|
], |
|
51
|
|
|
'Unsupported canonicalization algorithm: %s', |
|
52
|
|
|
UnsupportedAlgorithmException::class, |
|
53
|
|
|
); |
|
54
|
|
|
$this->c14nAlg = $canonicalizationAlg; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|