1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SAML2; |
6
|
|
|
|
7
|
|
|
use RobRichards\XMLSecLibs\XMLSecurityKey; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Abstract class to a SAML 2 element which may be signed. |
11
|
|
|
* |
12
|
|
|
* @package SimpleSAMLphp |
13
|
|
|
*/ |
14
|
|
|
abstract class SignedElement |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The private key we should use to sign the message. |
18
|
|
|
* |
19
|
|
|
* The private key can be null, in which case the message is sent unsigned. |
20
|
|
|
* |
21
|
|
|
* @var XMLSecurityKey|null |
22
|
|
|
*/ |
23
|
|
|
protected $signatureKey; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* List of certificates that should be included in the message. |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $certificates; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Validate this element against a public key. |
35
|
|
|
* |
36
|
|
|
* If no signature is present, false is returned. If a signature is present, |
37
|
|
|
* but cannot be verified, an exception will be thrown. |
38
|
|
|
* |
39
|
|
|
* @param XMLSecurityKey $key The key we should check against. |
40
|
|
|
* @return bool True if successful, false if we don't have a signature that can be verified. |
41
|
|
|
*/ |
42
|
|
|
abstract public function validate(XMLSecurityKey $key) : bool; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set the certificates that should be included in the element. |
47
|
|
|
* The certificates should be strings with the PEM encoded data. |
48
|
|
|
* |
49
|
|
|
* @param array $certificates An array of certificates. |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function setCertificates(array $certificates) |
53
|
|
|
{ |
54
|
|
|
$this->certificates = $certificates; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Retrieve the certificates that are included in the message. |
60
|
|
|
* |
61
|
|
|
* @return array An array of certificates |
62
|
|
|
*/ |
63
|
|
|
public function getCertificates() : array |
64
|
|
|
{ |
65
|
|
|
return $this->certificates; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Retrieve the private key we should use to sign the message. |
71
|
|
|
* |
72
|
|
|
* @return XMLSecurityKey|null The key, or NULL if no key is specified |
73
|
|
|
*/ |
74
|
|
|
public function getSignatureKey() |
75
|
|
|
{ |
76
|
|
|
return $this->signatureKey; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set the private key we should use to sign the message. |
82
|
|
|
* |
83
|
|
|
* If the key is null, the message will be sent unsigned. |
84
|
|
|
* |
85
|
|
|
* @param XMLSecurityKey|null $signatureKey |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function setSignatureKey(XMLSecurityKey $signatureKey = null) |
89
|
|
|
{ |
90
|
|
|
$this->signatureKey = $signatureKey; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|