@@ -15,54 +15,54 @@ |
||
15 | 15 | */ |
16 | 16 | class IssuerAlternativeNameExtension extends Extension |
17 | 17 | { |
18 | - /** |
|
19 | - * Names. |
|
20 | - * |
|
21 | - * @var GeneralNames |
|
22 | - */ |
|
23 | - protected $_names; |
|
18 | + /** |
|
19 | + * Names. |
|
20 | + * |
|
21 | + * @var GeneralNames |
|
22 | + */ |
|
23 | + protected $_names; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param bool $critical |
|
29 | - * @param GeneralNames $names |
|
30 | - */ |
|
31 | - public function __construct(bool $critical, GeneralNames $names) |
|
32 | - { |
|
33 | - parent::__construct(self::OID_ISSUER_ALT_NAME, $critical); |
|
34 | - $this->_names = $names; |
|
35 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param bool $critical |
|
29 | + * @param GeneralNames $names |
|
30 | + */ |
|
31 | + public function __construct(bool $critical, GeneralNames $names) |
|
32 | + { |
|
33 | + parent::__construct(self::OID_ISSUER_ALT_NAME, $critical); |
|
34 | + $this->_names = $names; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * |
|
39 | - * {@inheritdoc} |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - protected static function _fromDER(string $data, bool $critical) |
|
43 | - { |
|
44 | - return new self($critical, |
|
45 | - GeneralNames::fromASN1( |
|
46 | - UnspecifiedType::fromDER($data)->asSequence())); |
|
47 | - } |
|
37 | + /** |
|
38 | + * |
|
39 | + * {@inheritdoc} |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + protected static function _fromDER(string $data, bool $critical) |
|
43 | + { |
|
44 | + return new self($critical, |
|
45 | + GeneralNames::fromASN1( |
|
46 | + UnspecifiedType::fromDER($data)->asSequence())); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get names. |
|
51 | - * |
|
52 | - * @return GeneralNames |
|
53 | - */ |
|
54 | - public function names(): GeneralNames |
|
55 | - { |
|
56 | - return $this->_names; |
|
57 | - } |
|
49 | + /** |
|
50 | + * Get names. |
|
51 | + * |
|
52 | + * @return GeneralNames |
|
53 | + */ |
|
54 | + public function names(): GeneralNames |
|
55 | + { |
|
56 | + return $this->_names; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * |
|
61 | - * {@inheritdoc} |
|
62 | - * @return Sequence |
|
63 | - */ |
|
64 | - protected function _valueASN1(): Sequence |
|
65 | - { |
|
66 | - return $this->_names->toASN1(); |
|
67 | - } |
|
59 | + /** |
|
60 | + * |
|
61 | + * {@inheritdoc} |
|
62 | + * @return Sequence |
|
63 | + */ |
|
64 | + protected function _valueASN1(): Sequence |
|
65 | + { |
|
66 | + return $this->_names->toASN1(); |
|
67 | + } |
|
68 | 68 | } |
@@ -14,133 +14,133 @@ |
||
14 | 14 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.12 |
15 | 15 | */ |
16 | 16 | class ExtendedKeyUsageExtension extends Extension implements |
17 | - \Countable, |
|
18 | - \IteratorAggregate |
|
17 | + \Countable, |
|
18 | + \IteratorAggregate |
|
19 | 19 | { |
20 | - const OID_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"; |
|
21 | - const OID_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"; |
|
22 | - const OID_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"; |
|
23 | - const OID_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"; |
|
24 | - const OID_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"; |
|
25 | - const OID_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"; |
|
26 | - const OID_IPSEC_USER = "1.3.6.1.5.5.7.3.7"; |
|
27 | - const OID_TIME_STAMPING = "1.3.6.1.5.5.7.3.8"; |
|
28 | - const OID_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"; |
|
29 | - const OID_DVCS = "1.3.6.1.5.5.7.3.10"; |
|
30 | - const OID_SBGP_CERT_AA_SERVER_AUTH = "1.3.6.1.5.5.7.3.11"; |
|
31 | - const OID_SCVP_RESPONDER = "1.3.6.1.5.5.7.3.12"; |
|
32 | - const OID_EAP_OVER_PPP = "1.3.6.1.5.5.7.3.13"; |
|
33 | - const OID_EAP_OVER_LAN = "1.3.6.1.5.5.7.3.14"; |
|
34 | - const OID_SCVP_SERVER = "1.3.6.1.5.5.7.3.15"; |
|
35 | - const OID_SCVP_CLIENT = "1.3.6.1.5.5.7.3.16"; |
|
36 | - const OID_IPSEC_IKE = "1.3.6.1.5.5.7.3.17"; |
|
37 | - const OID_CAPWAP_AC = "1.3.6.1.5.5.7.3.18"; |
|
38 | - const OID_CAPWAP_WTP = "1.3.6.1.5.5.7.3.19"; |
|
39 | - const OID_SIP_DOMAIN = "1.3.6.1.5.5.7.3.20"; |
|
40 | - const OID_SECURE_SHELL_CLIENT = "1.3.6.1.5.5.7.3.21"; |
|
41 | - const OID_SECURE_SHELL_SERVER = "1.3.6.1.5.5.7.3.22"; |
|
42 | - const OID_SEND_ROUTER = "1.3.6.1.5.5.7.3.23"; |
|
43 | - const OID_SEND_PROXY = "1.3.6.1.5.5.7.3.24"; |
|
44 | - const OID_SEND_OWNER = "1.3.6.1.5.5.7.3.25"; |
|
45 | - const OID_SEND_PROXIED_OWNER = "1.3.6.1.5.5.7.3.26"; |
|
46 | - const OID_CMC_CA = "1.3.6.1.5.5.7.3.27"; |
|
47 | - const OID_CMC_RA = "1.3.6.1.5.5.7.3.28"; |
|
48 | - const OID_CMC_ARCHIVE = "1.3.6.1.5.5.7.3.29"; |
|
20 | + const OID_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"; |
|
21 | + const OID_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"; |
|
22 | + const OID_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"; |
|
23 | + const OID_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"; |
|
24 | + const OID_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"; |
|
25 | + const OID_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"; |
|
26 | + const OID_IPSEC_USER = "1.3.6.1.5.5.7.3.7"; |
|
27 | + const OID_TIME_STAMPING = "1.3.6.1.5.5.7.3.8"; |
|
28 | + const OID_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"; |
|
29 | + const OID_DVCS = "1.3.6.1.5.5.7.3.10"; |
|
30 | + const OID_SBGP_CERT_AA_SERVER_AUTH = "1.3.6.1.5.5.7.3.11"; |
|
31 | + const OID_SCVP_RESPONDER = "1.3.6.1.5.5.7.3.12"; |
|
32 | + const OID_EAP_OVER_PPP = "1.3.6.1.5.5.7.3.13"; |
|
33 | + const OID_EAP_OVER_LAN = "1.3.6.1.5.5.7.3.14"; |
|
34 | + const OID_SCVP_SERVER = "1.3.6.1.5.5.7.3.15"; |
|
35 | + const OID_SCVP_CLIENT = "1.3.6.1.5.5.7.3.16"; |
|
36 | + const OID_IPSEC_IKE = "1.3.6.1.5.5.7.3.17"; |
|
37 | + const OID_CAPWAP_AC = "1.3.6.1.5.5.7.3.18"; |
|
38 | + const OID_CAPWAP_WTP = "1.3.6.1.5.5.7.3.19"; |
|
39 | + const OID_SIP_DOMAIN = "1.3.6.1.5.5.7.3.20"; |
|
40 | + const OID_SECURE_SHELL_CLIENT = "1.3.6.1.5.5.7.3.21"; |
|
41 | + const OID_SECURE_SHELL_SERVER = "1.3.6.1.5.5.7.3.22"; |
|
42 | + const OID_SEND_ROUTER = "1.3.6.1.5.5.7.3.23"; |
|
43 | + const OID_SEND_PROXY = "1.3.6.1.5.5.7.3.24"; |
|
44 | + const OID_SEND_OWNER = "1.3.6.1.5.5.7.3.25"; |
|
45 | + const OID_SEND_PROXIED_OWNER = "1.3.6.1.5.5.7.3.26"; |
|
46 | + const OID_CMC_CA = "1.3.6.1.5.5.7.3.27"; |
|
47 | + const OID_CMC_RA = "1.3.6.1.5.5.7.3.28"; |
|
48 | + const OID_CMC_ARCHIVE = "1.3.6.1.5.5.7.3.29"; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Purpose OID's. |
|
52 | - * |
|
53 | - * @var string[] $_purposes |
|
54 | - */ |
|
55 | - protected $_purposes; |
|
50 | + /** |
|
51 | + * Purpose OID's. |
|
52 | + * |
|
53 | + * @var string[] $_purposes |
|
54 | + */ |
|
55 | + protected $_purposes; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Constructor. |
|
59 | - * |
|
60 | - * @param bool $critical |
|
61 | - * @param string ...$purposes |
|
62 | - */ |
|
63 | - public function __construct(bool $critical, string ...$purposes) |
|
64 | - { |
|
65 | - parent::__construct(self::OID_EXT_KEY_USAGE, $critical); |
|
66 | - $this->_purposes = $purposes; |
|
67 | - } |
|
57 | + /** |
|
58 | + * Constructor. |
|
59 | + * |
|
60 | + * @param bool $critical |
|
61 | + * @param string ...$purposes |
|
62 | + */ |
|
63 | + public function __construct(bool $critical, string ...$purposes) |
|
64 | + { |
|
65 | + parent::__construct(self::OID_EXT_KEY_USAGE, $critical); |
|
66 | + $this->_purposes = $purposes; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * |
|
71 | - * {@inheritdoc} |
|
72 | - * @return self |
|
73 | - */ |
|
74 | - protected static function _fromDER(string $data, bool $critical): self |
|
75 | - { |
|
76 | - $purposes = array_map( |
|
77 | - function (UnspecifiedType $el) { |
|
78 | - return $el->asObjectIdentifier()->oid(); |
|
79 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
80 | - return new self($critical, ...$purposes); |
|
81 | - } |
|
69 | + /** |
|
70 | + * |
|
71 | + * {@inheritdoc} |
|
72 | + * @return self |
|
73 | + */ |
|
74 | + protected static function _fromDER(string $data, bool $critical): self |
|
75 | + { |
|
76 | + $purposes = array_map( |
|
77 | + function (UnspecifiedType $el) { |
|
78 | + return $el->asObjectIdentifier()->oid(); |
|
79 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
80 | + return new self($critical, ...$purposes); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Whether purposes are present. |
|
85 | - * |
|
86 | - * If multiple purposes are checked, all must be present. |
|
87 | - * |
|
88 | - * @param string ...$oids |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function has(string ...$oids): bool |
|
92 | - { |
|
93 | - foreach ($oids as $oid) { |
|
94 | - if (!in_array($oid, $this->_purposes)) { |
|
95 | - return false; |
|
96 | - } |
|
97 | - } |
|
98 | - return true; |
|
99 | - } |
|
83 | + /** |
|
84 | + * Whether purposes are present. |
|
85 | + * |
|
86 | + * If multiple purposes are checked, all must be present. |
|
87 | + * |
|
88 | + * @param string ...$oids |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function has(string ...$oids): bool |
|
92 | + { |
|
93 | + foreach ($oids as $oid) { |
|
94 | + if (!in_array($oid, $this->_purposes)) { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
98 | + return true; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get key usage purpose OID's. |
|
103 | - * |
|
104 | - * @return string[] |
|
105 | - */ |
|
106 | - public function purposes(): array |
|
107 | - { |
|
108 | - return $this->_purposes; |
|
109 | - } |
|
101 | + /** |
|
102 | + * Get key usage purpose OID's. |
|
103 | + * |
|
104 | + * @return string[] |
|
105 | + */ |
|
106 | + public function purposes(): array |
|
107 | + { |
|
108 | + return $this->_purposes; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * |
|
113 | - * {@inheritdoc} |
|
114 | - * @return Sequence |
|
115 | - */ |
|
116 | - protected function _valueASN1(): Sequence |
|
117 | - { |
|
118 | - $elements = array_map( |
|
119 | - function ($oid) { |
|
120 | - return new ObjectIdentifier($oid); |
|
121 | - }, $this->_purposes); |
|
122 | - return new Sequence(...$elements); |
|
123 | - } |
|
111 | + /** |
|
112 | + * |
|
113 | + * {@inheritdoc} |
|
114 | + * @return Sequence |
|
115 | + */ |
|
116 | + protected function _valueASN1(): Sequence |
|
117 | + { |
|
118 | + $elements = array_map( |
|
119 | + function ($oid) { |
|
120 | + return new ObjectIdentifier($oid); |
|
121 | + }, $this->_purposes); |
|
122 | + return new Sequence(...$elements); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Get the number of purposes. |
|
127 | - * |
|
128 | - * @see \Countable::count() |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function count(): int |
|
132 | - { |
|
133 | - return count($this->_purposes); |
|
134 | - } |
|
125 | + /** |
|
126 | + * Get the number of purposes. |
|
127 | + * |
|
128 | + * @see \Countable::count() |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function count(): int |
|
132 | + { |
|
133 | + return count($this->_purposes); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Get iterator for usage purposes. |
|
138 | - * |
|
139 | - * @see \IteratorAggregate::getIterator() |
|
140 | - * @return \ArrayIterator |
|
141 | - */ |
|
142 | - public function getIterator(): \ArrayIterator |
|
143 | - { |
|
144 | - return new \ArrayIterator($this->_purposes); |
|
145 | - } |
|
136 | + /** |
|
137 | + * Get iterator for usage purposes. |
|
138 | + * |
|
139 | + * @see \IteratorAggregate::getIterator() |
|
140 | + * @return \ArrayIterator |
|
141 | + */ |
|
142 | + public function getIterator(): \ArrayIterator |
|
143 | + { |
|
144 | + return new \ArrayIterator($this->_purposes); |
|
145 | + } |
|
146 | 146 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | protected static function _fromDER(string $data, bool $critical): self |
75 | 75 | { |
76 | 76 | $purposes = array_map( |
77 | - function (UnspecifiedType $el) { |
|
77 | + function(UnspecifiedType $el) { |
|
78 | 78 | return $el->asObjectIdentifier()->oid(); |
79 | 79 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
80 | 80 | return new self($critical, ...$purposes); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | protected function _valueASN1(): Sequence |
117 | 117 | { |
118 | 118 | $elements = array_map( |
119 | - function ($oid) { |
|
119 | + function($oid) { |
|
120 | 120 | return new ObjectIdentifier($oid); |
121 | 121 | }, $this->_purposes); |
122 | 122 | return new Sequence(...$elements); |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class InhibitAnyPolicyExtension extends Extension |
16 | 16 | { |
17 | - /** |
|
18 | - * |
|
19 | - * @var int $_skipCerts |
|
20 | - */ |
|
21 | - protected $_skipCerts; |
|
17 | + /** |
|
18 | + * |
|
19 | + * @var int $_skipCerts |
|
20 | + */ |
|
21 | + protected $_skipCerts; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param bool $critical |
|
27 | - * @param int $skip_certs |
|
28 | - */ |
|
29 | - public function __construct(bool $critical, int $skip_certs) |
|
30 | - { |
|
31 | - parent::__construct(self::OID_INHIBIT_ANY_POLICY, $critical); |
|
32 | - $this->_skipCerts = $skip_certs; |
|
33 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param bool $critical |
|
27 | + * @param int $skip_certs |
|
28 | + */ |
|
29 | + public function __construct(bool $critical, int $skip_certs) |
|
30 | + { |
|
31 | + parent::__construct(self::OID_INHIBIT_ANY_POLICY, $critical); |
|
32 | + $this->_skipCerts = $skip_certs; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * {@inheritdoc} |
|
38 | - * @return self |
|
39 | - */ |
|
40 | - protected static function _fromDER(string $data, bool $critical): self |
|
41 | - { |
|
42 | - return new self($critical, |
|
43 | - UnspecifiedType::fromDER($data)->asInteger()->intNumber()); |
|
44 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * {@inheritdoc} |
|
38 | + * @return self |
|
39 | + */ |
|
40 | + protected static function _fromDER(string $data, bool $critical): self |
|
41 | + { |
|
42 | + return new self($critical, |
|
43 | + UnspecifiedType::fromDER($data)->asInteger()->intNumber()); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get value. |
|
48 | - * |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - public function skipCerts(): int |
|
52 | - { |
|
53 | - return $this->_skipCerts; |
|
54 | - } |
|
46 | + /** |
|
47 | + * Get value. |
|
48 | + * |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + public function skipCerts(): int |
|
52 | + { |
|
53 | + return $this->_skipCerts; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * |
|
58 | - * {@inheritdoc} |
|
59 | - * @return Integer |
|
60 | - */ |
|
61 | - protected function _valueASN1(): Integer |
|
62 | - { |
|
63 | - return new Integer($this->_skipCerts); |
|
64 | - } |
|
56 | + /** |
|
57 | + * |
|
58 | + * {@inheritdoc} |
|
59 | + * @return Integer |
|
60 | + */ |
|
61 | + protected function _valueASN1(): Integer |
|
62 | + { |
|
63 | + return new Integer($this->_skipCerts); |
|
64 | + } |
|
65 | 65 | } |
@@ -21,203 +21,203 @@ |
||
21 | 21 | */ |
22 | 22 | class AttributeCertificate |
23 | 23 | { |
24 | - /** |
|
25 | - * Attribute certificate info. |
|
26 | - * |
|
27 | - * @var AttributeCertificateInfo $_acinfo |
|
28 | - */ |
|
29 | - protected $_acinfo; |
|
30 | - |
|
31 | - /** |
|
32 | - * Signature algorithm identifier. |
|
33 | - * |
|
34 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
35 | - */ |
|
36 | - protected $_signatureAlgorithm; |
|
37 | - |
|
38 | - /** |
|
39 | - * Signature value. |
|
40 | - * |
|
41 | - * @var Signature $_signatureValue |
|
42 | - */ |
|
43 | - protected $_signatureValue; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor. |
|
47 | - * |
|
48 | - * @param AttributeCertificateInfo $acinfo |
|
49 | - * @param SignatureAlgorithmIdentifier $algo |
|
50 | - * @param Signature $signature |
|
51 | - */ |
|
52 | - public function __construct(AttributeCertificateInfo $acinfo, |
|
53 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
54 | - { |
|
55 | - $this->_acinfo = $acinfo; |
|
56 | - $this->_signatureAlgorithm = $algo; |
|
57 | - $this->_signatureValue = $signature; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Initialize from ASN.1. |
|
62 | - * |
|
63 | - * @param Sequence $seq |
|
64 | - * @return self |
|
65 | - */ |
|
66 | - public static function fromASN1(Sequence $seq): self |
|
67 | - { |
|
68 | - $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
69 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
70 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
71 | - throw new \UnexpectedValueException( |
|
72 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
73 | - } |
|
74 | - $signature = Signature::fromSignatureData( |
|
75 | - $seq->at(2) |
|
76 | - ->asBitString() |
|
77 | - ->string(), $algo); |
|
78 | - return new self($acinfo, $algo, $signature); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Initialize from DER data. |
|
83 | - * |
|
84 | - * @param string $data |
|
85 | - * @return self |
|
86 | - */ |
|
87 | - public static function fromDER(string $data): self |
|
88 | - { |
|
89 | - return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Initialize from PEM. |
|
94 | - * |
|
95 | - * @param PEM $pem |
|
96 | - * @throws \UnexpectedValueException |
|
97 | - * @return self |
|
98 | - */ |
|
99 | - public static function fromPEM(PEM $pem): self |
|
100 | - { |
|
101 | - if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
102 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
103 | - } |
|
104 | - return self::fromDER($pem->data()); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get attribute certificate info. |
|
109 | - * |
|
110 | - * @return AttributeCertificateInfo |
|
111 | - */ |
|
112 | - public function acinfo(): AttributeCertificateInfo |
|
113 | - { |
|
114 | - return $this->_acinfo; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get signature algorithm identifier. |
|
119 | - * |
|
120 | - * @return SignatureAlgorithmIdentifier |
|
121 | - */ |
|
122 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
123 | - { |
|
124 | - return $this->_signatureAlgorithm; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get signature value. |
|
129 | - * |
|
130 | - * @return Signature |
|
131 | - */ |
|
132 | - public function signatureValue(): Signature |
|
133 | - { |
|
134 | - return $this->_signatureValue; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get ASN.1 structure. |
|
139 | - * |
|
140 | - * @return Sequence |
|
141 | - */ |
|
142 | - public function toASN1(): Sequence |
|
143 | - { |
|
144 | - return new Sequence($this->_acinfo->toASN1(), |
|
145 | - $this->_signatureAlgorithm->toASN1(), |
|
146 | - $this->_signatureValue->bitString()); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Get attribute certificate as a DER. |
|
151 | - * |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function toDER(): string |
|
155 | - { |
|
156 | - return $this->toASN1()->toDER(); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Get attribute certificate as a PEM. |
|
161 | - * |
|
162 | - * @return PEM |
|
163 | - */ |
|
164 | - public function toPEM(): PEM |
|
165 | - { |
|
166 | - return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Check whether attribute certificate is issued to the subject identified |
|
171 | - * by given public key certificate. |
|
172 | - * |
|
173 | - * @param Certificate $cert Certificate |
|
174 | - * @return boolean |
|
175 | - */ |
|
176 | - public function isHeldBy(Certificate $cert): bool |
|
177 | - { |
|
178 | - if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - return true; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Check whether attribute certificate is issued by given public key |
|
186 | - * certificate. |
|
187 | - * |
|
188 | - * @param Certificate $cert Certificate |
|
189 | - * @return boolean |
|
190 | - */ |
|
191 | - public function isIssuedBy(Certificate $cert): bool |
|
192 | - { |
|
193 | - if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
194 | - return false; |
|
195 | - } |
|
196 | - return true; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Verify signature. |
|
201 | - * |
|
202 | - * @param PublicKeyInfo $pubkey_info Signer's public key |
|
203 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
207 | - { |
|
208 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
209 | - $data = $this->_acinfo->toASN1()->toDER(); |
|
210 | - return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
211 | - $this->_signatureAlgorithm); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Get attribute certificate as a PEM formatted string. |
|
216 | - * |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function __toString() |
|
220 | - { |
|
221 | - return $this->toPEM()->string(); |
|
222 | - } |
|
24 | + /** |
|
25 | + * Attribute certificate info. |
|
26 | + * |
|
27 | + * @var AttributeCertificateInfo $_acinfo |
|
28 | + */ |
|
29 | + protected $_acinfo; |
|
30 | + |
|
31 | + /** |
|
32 | + * Signature algorithm identifier. |
|
33 | + * |
|
34 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
35 | + */ |
|
36 | + protected $_signatureAlgorithm; |
|
37 | + |
|
38 | + /** |
|
39 | + * Signature value. |
|
40 | + * |
|
41 | + * @var Signature $_signatureValue |
|
42 | + */ |
|
43 | + protected $_signatureValue; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor. |
|
47 | + * |
|
48 | + * @param AttributeCertificateInfo $acinfo |
|
49 | + * @param SignatureAlgorithmIdentifier $algo |
|
50 | + * @param Signature $signature |
|
51 | + */ |
|
52 | + public function __construct(AttributeCertificateInfo $acinfo, |
|
53 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
54 | + { |
|
55 | + $this->_acinfo = $acinfo; |
|
56 | + $this->_signatureAlgorithm = $algo; |
|
57 | + $this->_signatureValue = $signature; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Initialize from ASN.1. |
|
62 | + * |
|
63 | + * @param Sequence $seq |
|
64 | + * @return self |
|
65 | + */ |
|
66 | + public static function fromASN1(Sequence $seq): self |
|
67 | + { |
|
68 | + $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
69 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
70 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
71 | + throw new \UnexpectedValueException( |
|
72 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
73 | + } |
|
74 | + $signature = Signature::fromSignatureData( |
|
75 | + $seq->at(2) |
|
76 | + ->asBitString() |
|
77 | + ->string(), $algo); |
|
78 | + return new self($acinfo, $algo, $signature); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Initialize from DER data. |
|
83 | + * |
|
84 | + * @param string $data |
|
85 | + * @return self |
|
86 | + */ |
|
87 | + public static function fromDER(string $data): self |
|
88 | + { |
|
89 | + return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Initialize from PEM. |
|
94 | + * |
|
95 | + * @param PEM $pem |
|
96 | + * @throws \UnexpectedValueException |
|
97 | + * @return self |
|
98 | + */ |
|
99 | + public static function fromPEM(PEM $pem): self |
|
100 | + { |
|
101 | + if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
102 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
103 | + } |
|
104 | + return self::fromDER($pem->data()); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get attribute certificate info. |
|
109 | + * |
|
110 | + * @return AttributeCertificateInfo |
|
111 | + */ |
|
112 | + public function acinfo(): AttributeCertificateInfo |
|
113 | + { |
|
114 | + return $this->_acinfo; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get signature algorithm identifier. |
|
119 | + * |
|
120 | + * @return SignatureAlgorithmIdentifier |
|
121 | + */ |
|
122 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
123 | + { |
|
124 | + return $this->_signatureAlgorithm; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get signature value. |
|
129 | + * |
|
130 | + * @return Signature |
|
131 | + */ |
|
132 | + public function signatureValue(): Signature |
|
133 | + { |
|
134 | + return $this->_signatureValue; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get ASN.1 structure. |
|
139 | + * |
|
140 | + * @return Sequence |
|
141 | + */ |
|
142 | + public function toASN1(): Sequence |
|
143 | + { |
|
144 | + return new Sequence($this->_acinfo->toASN1(), |
|
145 | + $this->_signatureAlgorithm->toASN1(), |
|
146 | + $this->_signatureValue->bitString()); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Get attribute certificate as a DER. |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function toDER(): string |
|
155 | + { |
|
156 | + return $this->toASN1()->toDER(); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Get attribute certificate as a PEM. |
|
161 | + * |
|
162 | + * @return PEM |
|
163 | + */ |
|
164 | + public function toPEM(): PEM |
|
165 | + { |
|
166 | + return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Check whether attribute certificate is issued to the subject identified |
|
171 | + * by given public key certificate. |
|
172 | + * |
|
173 | + * @param Certificate $cert Certificate |
|
174 | + * @return boolean |
|
175 | + */ |
|
176 | + public function isHeldBy(Certificate $cert): bool |
|
177 | + { |
|
178 | + if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + return true; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Check whether attribute certificate is issued by given public key |
|
186 | + * certificate. |
|
187 | + * |
|
188 | + * @param Certificate $cert Certificate |
|
189 | + * @return boolean |
|
190 | + */ |
|
191 | + public function isIssuedBy(Certificate $cert): bool |
|
192 | + { |
|
193 | + if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + return true; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Verify signature. |
|
201 | + * |
|
202 | + * @param PublicKeyInfo $pubkey_info Signer's public key |
|
203 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
207 | + { |
|
208 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
209 | + $data = $this->_acinfo->toASN1()->toDER(); |
|
210 | + return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
211 | + $this->_signatureAlgorithm); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Get attribute certificate as a PEM formatted string. |
|
216 | + * |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function __toString() |
|
220 | + { |
|
221 | + return $this->toPEM()->string(); |
|
222 | + } |
|
223 | 223 | } |
@@ -19,172 +19,172 @@ |
||
19 | 19 | */ |
20 | 20 | class CertificationRequest |
21 | 21 | { |
22 | - /** |
|
23 | - * Certification request info. |
|
24 | - * |
|
25 | - * @var CertificationRequestInfo $_certificationRequestInfo |
|
26 | - */ |
|
27 | - protected $_certificationRequestInfo; |
|
22 | + /** |
|
23 | + * Certification request info. |
|
24 | + * |
|
25 | + * @var CertificationRequestInfo $_certificationRequestInfo |
|
26 | + */ |
|
27 | + protected $_certificationRequestInfo; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Signature algorithm. |
|
31 | - * |
|
32 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
33 | - */ |
|
34 | - protected $_signatureAlgorithm; |
|
29 | + /** |
|
30 | + * Signature algorithm. |
|
31 | + * |
|
32 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
33 | + */ |
|
34 | + protected $_signatureAlgorithm; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Signature. |
|
38 | - * |
|
39 | - * @var Signature $_signature |
|
40 | - */ |
|
41 | - protected $_signature; |
|
36 | + /** |
|
37 | + * Signature. |
|
38 | + * |
|
39 | + * @var Signature $_signature |
|
40 | + */ |
|
41 | + protected $_signature; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param CertificationRequestInfo $info |
|
47 | - * @param SignatureAlgorithmIdentifier $algo |
|
48 | - * @param Signature $signature |
|
49 | - */ |
|
50 | - public function __construct(CertificationRequestInfo $info, |
|
51 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
52 | - { |
|
53 | - $this->_certificationRequestInfo = $info; |
|
54 | - $this->_signatureAlgorithm = $algo; |
|
55 | - $this->_signature = $signature; |
|
56 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param CertificationRequestInfo $info |
|
47 | + * @param SignatureAlgorithmIdentifier $algo |
|
48 | + * @param Signature $signature |
|
49 | + */ |
|
50 | + public function __construct(CertificationRequestInfo $info, |
|
51 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
52 | + { |
|
53 | + $this->_certificationRequestInfo = $info; |
|
54 | + $this->_signatureAlgorithm = $algo; |
|
55 | + $this->_signature = $signature; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Initialize from ASN.1. |
|
60 | - * |
|
61 | - * @param Sequence $seq |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public static function fromASN1(Sequence $seq): self |
|
65 | - { |
|
66 | - $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
67 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
68 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
69 | - throw new \UnexpectedValueException( |
|
70 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
71 | - } |
|
72 | - $signature = Signature::fromSignatureData( |
|
73 | - $seq->at(2) |
|
74 | - ->asBitString() |
|
75 | - ->string(), $algo); |
|
76 | - return new self($info, $algo, $signature); |
|
77 | - } |
|
58 | + /** |
|
59 | + * Initialize from ASN.1. |
|
60 | + * |
|
61 | + * @param Sequence $seq |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public static function fromASN1(Sequence $seq): self |
|
65 | + { |
|
66 | + $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
67 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
68 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
69 | + throw new \UnexpectedValueException( |
|
70 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
71 | + } |
|
72 | + $signature = Signature::fromSignatureData( |
|
73 | + $seq->at(2) |
|
74 | + ->asBitString() |
|
75 | + ->string(), $algo); |
|
76 | + return new self($info, $algo, $signature); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Initialize from DER. |
|
81 | - * |
|
82 | - * @param string $data |
|
83 | - * @return self |
|
84 | - */ |
|
85 | - public static function fromDER(string $data): self |
|
86 | - { |
|
87 | - return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
88 | - } |
|
79 | + /** |
|
80 | + * Initialize from DER. |
|
81 | + * |
|
82 | + * @param string $data |
|
83 | + * @return self |
|
84 | + */ |
|
85 | + public static function fromDER(string $data): self |
|
86 | + { |
|
87 | + return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Initialize from PEM. |
|
92 | - * |
|
93 | - * @param PEM $pem |
|
94 | - * @throws \UnexpectedValueException |
|
95 | - * @return self |
|
96 | - */ |
|
97 | - public static function fromPEM(PEM $pem): self |
|
98 | - { |
|
99 | - if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
100 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
101 | - } |
|
102 | - return self::fromDER($pem->data()); |
|
103 | - } |
|
90 | + /** |
|
91 | + * Initialize from PEM. |
|
92 | + * |
|
93 | + * @param PEM $pem |
|
94 | + * @throws \UnexpectedValueException |
|
95 | + * @return self |
|
96 | + */ |
|
97 | + public static function fromPEM(PEM $pem): self |
|
98 | + { |
|
99 | + if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
100 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
101 | + } |
|
102 | + return self::fromDER($pem->data()); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Get certification request info. |
|
107 | - * |
|
108 | - * @return CertificationRequestInfo |
|
109 | - */ |
|
110 | - public function certificationRequestInfo(): CertificationRequestInfo |
|
111 | - { |
|
112 | - return $this->_certificationRequestInfo; |
|
113 | - } |
|
105 | + /** |
|
106 | + * Get certification request info. |
|
107 | + * |
|
108 | + * @return CertificationRequestInfo |
|
109 | + */ |
|
110 | + public function certificationRequestInfo(): CertificationRequestInfo |
|
111 | + { |
|
112 | + return $this->_certificationRequestInfo; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get signature algorithm. |
|
117 | - * |
|
118 | - * @return SignatureAlgorithmIdentifier |
|
119 | - */ |
|
120 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
121 | - { |
|
122 | - return $this->_signatureAlgorithm; |
|
123 | - } |
|
115 | + /** |
|
116 | + * Get signature algorithm. |
|
117 | + * |
|
118 | + * @return SignatureAlgorithmIdentifier |
|
119 | + */ |
|
120 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
121 | + { |
|
122 | + return $this->_signatureAlgorithm; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Get signature. |
|
127 | - * |
|
128 | - * @return Signature |
|
129 | - */ |
|
130 | - public function signature(): Signature |
|
131 | - { |
|
132 | - return $this->_signature; |
|
133 | - } |
|
125 | + /** |
|
126 | + * Get signature. |
|
127 | + * |
|
128 | + * @return Signature |
|
129 | + */ |
|
130 | + public function signature(): Signature |
|
131 | + { |
|
132 | + return $this->_signature; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Generate ASN.1 structure. |
|
137 | - * |
|
138 | - * @return Sequence |
|
139 | - */ |
|
140 | - public function toASN1(): Sequence |
|
141 | - { |
|
142 | - return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
143 | - $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
144 | - } |
|
135 | + /** |
|
136 | + * Generate ASN.1 structure. |
|
137 | + * |
|
138 | + * @return Sequence |
|
139 | + */ |
|
140 | + public function toASN1(): Sequence |
|
141 | + { |
|
142 | + return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
143 | + $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Get certification request as a DER. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function toDER(): string |
|
152 | - { |
|
153 | - return $this->toASN1()->toDER(); |
|
154 | - } |
|
146 | + /** |
|
147 | + * Get certification request as a DER. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function toDER(): string |
|
152 | + { |
|
153 | + return $this->toASN1()->toDER(); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Get certification request as a PEM. |
|
158 | - * |
|
159 | - * @return PEM |
|
160 | - */ |
|
161 | - public function toPEM(): PEM |
|
162 | - { |
|
163 | - return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
164 | - } |
|
156 | + /** |
|
157 | + * Get certification request as a PEM. |
|
158 | + * |
|
159 | + * @return PEM |
|
160 | + */ |
|
161 | + public function toPEM(): PEM |
|
162 | + { |
|
163 | + return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Verify certification request signature. |
|
168 | - * |
|
169 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
170 | - * @return bool True if signature matches |
|
171 | - */ |
|
172 | - public function verify(Crypto $crypto = null): bool |
|
173 | - { |
|
174 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
175 | - $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
176 | - $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
177 | - return $crypto->verify($data, $this->_signature, $pk_info, |
|
178 | - $this->_signatureAlgorithm); |
|
179 | - } |
|
166 | + /** |
|
167 | + * Verify certification request signature. |
|
168 | + * |
|
169 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
170 | + * @return bool True if signature matches |
|
171 | + */ |
|
172 | + public function verify(Crypto $crypto = null): bool |
|
173 | + { |
|
174 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
175 | + $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
176 | + $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
177 | + return $crypto->verify($data, $this->_signature, $pk_info, |
|
178 | + $this->_signatureAlgorithm); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get certification request as a PEM formatted string. |
|
183 | - * |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - public function __toString() |
|
187 | - { |
|
188 | - return $this->toPEM()->string(); |
|
189 | - } |
|
181 | + /** |
|
182 | + * Get certification request as a PEM formatted string. |
|
183 | + * |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + public function __toString() |
|
187 | + { |
|
188 | + return $this->toPEM()->string(); |
|
189 | + } |
|
190 | 190 | } |
@@ -20,181 +20,181 @@ |
||
20 | 20 | */ |
21 | 21 | class AuthorityKeyIdentifierExtension extends Extension |
22 | 22 | { |
23 | - /** |
|
24 | - * Key identifier. |
|
25 | - * |
|
26 | - * @var string|null $_keyIdentifier |
|
27 | - */ |
|
28 | - protected $_keyIdentifier; |
|
23 | + /** |
|
24 | + * Key identifier. |
|
25 | + * |
|
26 | + * @var string|null $_keyIdentifier |
|
27 | + */ |
|
28 | + protected $_keyIdentifier; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Issuer name. |
|
32 | - * |
|
33 | - * @var GeneralNames|null $_authorityCertIssuer |
|
34 | - */ |
|
35 | - protected $_authorityCertIssuer; |
|
30 | + /** |
|
31 | + * Issuer name. |
|
32 | + * |
|
33 | + * @var GeneralNames|null $_authorityCertIssuer |
|
34 | + */ |
|
35 | + protected $_authorityCertIssuer; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Issuer serial number. |
|
39 | - * |
|
40 | - * @var string|null $_authorityCertSerialNumber |
|
41 | - */ |
|
42 | - protected $_authorityCertSerialNumber; |
|
37 | + /** |
|
38 | + * Issuer serial number. |
|
39 | + * |
|
40 | + * @var string|null $_authorityCertSerialNumber |
|
41 | + */ |
|
42 | + protected $_authorityCertSerialNumber; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor. |
|
46 | - * |
|
47 | - * @param bool $critical Conforming CA's must mark as non-critical (false) |
|
48 | - * @param string|null $keyIdentifier |
|
49 | - * @param GeneralNames|null $issuer |
|
50 | - * @param string|null $serial |
|
51 | - */ |
|
52 | - public function __construct(bool $critical, $keyIdentifier, |
|
53 | - GeneralNames $issuer = null, $serial = null) |
|
54 | - { |
|
55 | - parent::__construct(self::OID_AUTHORITY_KEY_IDENTIFIER, $critical); |
|
56 | - $this->_keyIdentifier = $keyIdentifier; |
|
57 | - $this->_authorityCertIssuer = $issuer; |
|
58 | - $this->_authorityCertSerialNumber = isset($serial) ? strval($serial) : null; |
|
59 | - } |
|
44 | + /** |
|
45 | + * Constructor. |
|
46 | + * |
|
47 | + * @param bool $critical Conforming CA's must mark as non-critical (false) |
|
48 | + * @param string|null $keyIdentifier |
|
49 | + * @param GeneralNames|null $issuer |
|
50 | + * @param string|null $serial |
|
51 | + */ |
|
52 | + public function __construct(bool $critical, $keyIdentifier, |
|
53 | + GeneralNames $issuer = null, $serial = null) |
|
54 | + { |
|
55 | + parent::__construct(self::OID_AUTHORITY_KEY_IDENTIFIER, $critical); |
|
56 | + $this->_keyIdentifier = $keyIdentifier; |
|
57 | + $this->_authorityCertIssuer = $issuer; |
|
58 | + $this->_authorityCertSerialNumber = isset($serial) ? strval($serial) : null; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Create from public key info. |
|
63 | - * |
|
64 | - * @param PublicKeyInfo $pki |
|
65 | - * @return AuthorityKeyIdentifierExtension |
|
66 | - */ |
|
67 | - public static function fromPublicKeyInfo(PublicKeyInfo $pki) |
|
68 | - { |
|
69 | - return new self(false, $pki->keyIdentifier()); |
|
70 | - } |
|
61 | + /** |
|
62 | + * Create from public key info. |
|
63 | + * |
|
64 | + * @param PublicKeyInfo $pki |
|
65 | + * @return AuthorityKeyIdentifierExtension |
|
66 | + */ |
|
67 | + public static function fromPublicKeyInfo(PublicKeyInfo $pki) |
|
68 | + { |
|
69 | + return new self(false, $pki->keyIdentifier()); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * |
|
74 | - * {@inheritdoc} |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - protected static function _fromDER(string $data, bool $critical): self |
|
78 | - { |
|
79 | - $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
80 | - $keyIdentifier = null; |
|
81 | - $issuer = null; |
|
82 | - $serial = null; |
|
83 | - if ($seq->hasTagged(0)) { |
|
84 | - $keyIdentifier = $seq->getTagged(0) |
|
85 | - ->asImplicit(Element::TYPE_OCTET_STRING) |
|
86 | - ->asOctetString() |
|
87 | - ->string(); |
|
88 | - } |
|
89 | - if ($seq->hasTagged(1) || $seq->hasTagged(2)) { |
|
90 | - if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) { |
|
91 | - throw new \UnexpectedValueException( |
|
92 | - "AuthorityKeyIdentifier must have both" . |
|
93 | - " authorityCertIssuer and authorityCertSerialNumber" . |
|
94 | - " present or both absent."); |
|
95 | - } |
|
96 | - $issuer = GeneralNames::fromASN1( |
|
97 | - $seq->getTagged(1) |
|
98 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
99 | - ->asSequence()); |
|
100 | - $serial = $seq->getTagged(2) |
|
101 | - ->asImplicit(Element::TYPE_INTEGER) |
|
102 | - ->asInteger() |
|
103 | - ->number(); |
|
104 | - } |
|
105 | - return new self($critical, $keyIdentifier, $issuer, $serial); |
|
106 | - } |
|
72 | + /** |
|
73 | + * |
|
74 | + * {@inheritdoc} |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + protected static function _fromDER(string $data, bool $critical): self |
|
78 | + { |
|
79 | + $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
80 | + $keyIdentifier = null; |
|
81 | + $issuer = null; |
|
82 | + $serial = null; |
|
83 | + if ($seq->hasTagged(0)) { |
|
84 | + $keyIdentifier = $seq->getTagged(0) |
|
85 | + ->asImplicit(Element::TYPE_OCTET_STRING) |
|
86 | + ->asOctetString() |
|
87 | + ->string(); |
|
88 | + } |
|
89 | + if ($seq->hasTagged(1) || $seq->hasTagged(2)) { |
|
90 | + if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) { |
|
91 | + throw new \UnexpectedValueException( |
|
92 | + "AuthorityKeyIdentifier must have both" . |
|
93 | + " authorityCertIssuer and authorityCertSerialNumber" . |
|
94 | + " present or both absent."); |
|
95 | + } |
|
96 | + $issuer = GeneralNames::fromASN1( |
|
97 | + $seq->getTagged(1) |
|
98 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
99 | + ->asSequence()); |
|
100 | + $serial = $seq->getTagged(2) |
|
101 | + ->asImplicit(Element::TYPE_INTEGER) |
|
102 | + ->asInteger() |
|
103 | + ->number(); |
|
104 | + } |
|
105 | + return new self($critical, $keyIdentifier, $issuer, $serial); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Whether key identifier is present. |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function hasKeyIdentifier(): bool |
|
114 | - { |
|
115 | - return isset($this->_keyIdentifier); |
|
116 | - } |
|
108 | + /** |
|
109 | + * Whether key identifier is present. |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function hasKeyIdentifier(): bool |
|
114 | + { |
|
115 | + return isset($this->_keyIdentifier); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Get key identifier. |
|
120 | - * |
|
121 | - * @throws \LogicException |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function keyIdentifier(): string |
|
125 | - { |
|
126 | - if (!$this->hasKeyIdentifier()) { |
|
127 | - throw new \LogicException("keyIdentifier not set."); |
|
128 | - } |
|
129 | - return $this->_keyIdentifier; |
|
130 | - } |
|
118 | + /** |
|
119 | + * Get key identifier. |
|
120 | + * |
|
121 | + * @throws \LogicException |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function keyIdentifier(): string |
|
125 | + { |
|
126 | + if (!$this->hasKeyIdentifier()) { |
|
127 | + throw new \LogicException("keyIdentifier not set."); |
|
128 | + } |
|
129 | + return $this->_keyIdentifier; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Whether issuer is present. |
|
134 | - * |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - public function hasIssuer(): bool |
|
138 | - { |
|
139 | - return isset($this->_authorityCertIssuer); |
|
140 | - } |
|
132 | + /** |
|
133 | + * Whether issuer is present. |
|
134 | + * |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + public function hasIssuer(): bool |
|
138 | + { |
|
139 | + return isset($this->_authorityCertIssuer); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Get issuer. |
|
144 | - * |
|
145 | - * @throws \LogicException |
|
146 | - * @return GeneralNames |
|
147 | - */ |
|
148 | - public function issuer(): GeneralNames |
|
149 | - { |
|
150 | - if (!$this->hasIssuer()) { |
|
151 | - throw new \LogicException("authorityCertIssuer not set."); |
|
152 | - } |
|
153 | - return $this->_authorityCertIssuer; |
|
154 | - } |
|
142 | + /** |
|
143 | + * Get issuer. |
|
144 | + * |
|
145 | + * @throws \LogicException |
|
146 | + * @return GeneralNames |
|
147 | + */ |
|
148 | + public function issuer(): GeneralNames |
|
149 | + { |
|
150 | + if (!$this->hasIssuer()) { |
|
151 | + throw new \LogicException("authorityCertIssuer not set."); |
|
152 | + } |
|
153 | + return $this->_authorityCertIssuer; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Get serial number. |
|
158 | - * |
|
159 | - * @throws \LogicException |
|
160 | - * @return string Base 10 integer string |
|
161 | - */ |
|
162 | - public function serial(): string |
|
163 | - { |
|
164 | - // both issuer and serial must be present or both absent |
|
165 | - if (!$this->hasIssuer()) { |
|
166 | - throw new \LogicException("authorityCertSerialNumber not set."); |
|
167 | - } |
|
168 | - return $this->_authorityCertSerialNumber; |
|
169 | - } |
|
156 | + /** |
|
157 | + * Get serial number. |
|
158 | + * |
|
159 | + * @throws \LogicException |
|
160 | + * @return string Base 10 integer string |
|
161 | + */ |
|
162 | + public function serial(): string |
|
163 | + { |
|
164 | + // both issuer and serial must be present or both absent |
|
165 | + if (!$this->hasIssuer()) { |
|
166 | + throw new \LogicException("authorityCertSerialNumber not set."); |
|
167 | + } |
|
168 | + return $this->_authorityCertSerialNumber; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * |
|
173 | - * {@inheritdoc} |
|
174 | - * @return Sequence |
|
175 | - */ |
|
176 | - protected function _valueASN1(): Sequence |
|
177 | - { |
|
178 | - $elements = array(); |
|
179 | - if (isset($this->_keyIdentifier)) { |
|
180 | - $elements[] = new ImplicitlyTaggedType(0, |
|
181 | - new OctetString($this->_keyIdentifier)); |
|
182 | - } |
|
183 | - // if either issuer or serial is set, both must be set |
|
184 | - if (isset($this->_authorityCertIssuer) || |
|
185 | - isset($this->_authorityCertSerialNumber)) { |
|
186 | - if (!isset($this->_authorityCertIssuer, |
|
187 | - $this->_authorityCertSerialNumber)) { |
|
188 | - throw new \LogicException( |
|
189 | - "AuthorityKeyIdentifier must have both" . |
|
190 | - " authorityCertIssuer and authorityCertSerialNumber" . |
|
191 | - " present or both absent."); |
|
192 | - } |
|
193 | - $elements[] = new ImplicitlyTaggedType(1, |
|
194 | - $this->_authorityCertIssuer->toASN1()); |
|
195 | - $elements[] = new ImplicitlyTaggedType(2, |
|
196 | - new Integer($this->_authorityCertSerialNumber)); |
|
197 | - } |
|
198 | - return new Sequence(...$elements); |
|
199 | - } |
|
171 | + /** |
|
172 | + * |
|
173 | + * {@inheritdoc} |
|
174 | + * @return Sequence |
|
175 | + */ |
|
176 | + protected function _valueASN1(): Sequence |
|
177 | + { |
|
178 | + $elements = array(); |
|
179 | + if (isset($this->_keyIdentifier)) { |
|
180 | + $elements[] = new ImplicitlyTaggedType(0, |
|
181 | + new OctetString($this->_keyIdentifier)); |
|
182 | + } |
|
183 | + // if either issuer or serial is set, both must be set |
|
184 | + if (isset($this->_authorityCertIssuer) || |
|
185 | + isset($this->_authorityCertSerialNumber)) { |
|
186 | + if (!isset($this->_authorityCertIssuer, |
|
187 | + $this->_authorityCertSerialNumber)) { |
|
188 | + throw new \LogicException( |
|
189 | + "AuthorityKeyIdentifier must have both" . |
|
190 | + " authorityCertIssuer and authorityCertSerialNumber" . |
|
191 | + " present or both absent."); |
|
192 | + } |
|
193 | + $elements[] = new ImplicitlyTaggedType(1, |
|
194 | + $this->_authorityCertIssuer->toASN1()); |
|
195 | + $elements[] = new ImplicitlyTaggedType(2, |
|
196 | + new Integer($this->_authorityCertSerialNumber)); |
|
197 | + } |
|
198 | + return new Sequence(...$elements); |
|
199 | + } |
|
200 | 200 | } |
@@ -36,106 +36,106 @@ discard block |
||
36 | 36 | |
37 | 37 | // CA private key |
38 | 38 | openssl_pkey_export( |
39 | - openssl_pkey_new( |
|
40 | - ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
41 | - "private_key_bits" => 2048]), $pkey); |
|
39 | + openssl_pkey_new( |
|
40 | + ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
41 | + "private_key_bits" => 2048]), $pkey); |
|
42 | 42 | $ca_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
43 | 43 | // Issuer private key |
44 | 44 | openssl_pkey_export( |
45 | - openssl_pkey_new( |
|
46 | - ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
47 | - "private_key_bits" => 2048]), $pkey); |
|
45 | + openssl_pkey_new( |
|
46 | + ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
47 | + "private_key_bits" => 2048]), $pkey); |
|
48 | 48 | $issuer_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
49 | 49 | // Holder private key |
50 | 50 | openssl_pkey_export( |
51 | - openssl_pkey_new( |
|
52 | - ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
53 | - "private_key_bits" => 2048]), $pkey); |
|
51 | + openssl_pkey_new( |
|
52 | + ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
53 | + "private_key_bits" => 2048]), $pkey); |
|
54 | 54 | $holder_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
55 | 55 | |
56 | 56 | // create trust anchor certificate (self signed) |
57 | 57 | $tbs_cert = new TBSCertificate( |
58 | - Name::fromString("cn=CA"), |
|
59 | - $ca_private_key->publicKeyInfo(), |
|
60 | - Name::fromString("cn=CA"), |
|
61 | - Validity::fromStrings("now", "now + 1 year")); |
|
58 | + Name::fromString("cn=CA"), |
|
59 | + $ca_private_key->publicKeyInfo(), |
|
60 | + Name::fromString("cn=CA"), |
|
61 | + Validity::fromStrings("now", "now + 1 year")); |
|
62 | 62 | $tbs_cert = $tbs_cert->withRandomSerialNumber() |
63 | - ->withAdditionalExtensions( |
|
64 | - new BasicConstraintsExtension(true, true), |
|
65 | - new SubjectKeyIdentifierExtension(false, |
|
66 | - $ca_private_key->publicKeyInfo()->keyIdentifier()), |
|
67 | - new KeyUsageExtension(true, |
|
68 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
69 | - KeyUsageExtension::KEY_CERT_SIGN)); |
|
63 | + ->withAdditionalExtensions( |
|
64 | + new BasicConstraintsExtension(true, true), |
|
65 | + new SubjectKeyIdentifierExtension(false, |
|
66 | + $ca_private_key->publicKeyInfo()->keyIdentifier()), |
|
67 | + new KeyUsageExtension(true, |
|
68 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
69 | + KeyUsageExtension::KEY_CERT_SIGN)); |
|
70 | 70 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
71 | - $ca_private_key->algorithmIdentifier(), |
|
72 | - new SHA256AlgorithmIdentifier()); |
|
71 | + $ca_private_key->algorithmIdentifier(), |
|
72 | + new SHA256AlgorithmIdentifier()); |
|
73 | 73 | $ca_cert = $tbs_cert->sign($algo, $ca_private_key); |
74 | 74 | |
75 | 75 | // create AC issuer certificate |
76 | 76 | $tbs_cert = new TBSCertificate( |
77 | - Name::fromString("cn=Issuer"), |
|
78 | - $issuer_private_key->publicKeyInfo(), |
|
79 | - new Name(), |
|
80 | - Validity::fromStrings("now", "now + 6 months")); |
|
77 | + Name::fromString("cn=Issuer"), |
|
78 | + $issuer_private_key->publicKeyInfo(), |
|
79 | + new Name(), |
|
80 | + Validity::fromStrings("now", "now + 6 months")); |
|
81 | 81 | $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert) |
82 | - ->withRandomSerialNumber() |
|
83 | - ->withAdditionalExtensions( |
|
84 | - // issuer must not be a CA |
|
85 | - new BasicConstraintsExtension(true, false), |
|
86 | - new KeyUsageExtension(true, |
|
87 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
88 | - KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
82 | + ->withRandomSerialNumber() |
|
83 | + ->withAdditionalExtensions( |
|
84 | + // issuer must not be a CA |
|
85 | + new BasicConstraintsExtension(true, false), |
|
86 | + new KeyUsageExtension(true, |
|
87 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
88 | + KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
89 | 89 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
90 | - $ca_private_key->algorithmIdentifier(), |
|
91 | - new SHA256AlgorithmIdentifier()); |
|
90 | + $ca_private_key->algorithmIdentifier(), |
|
91 | + new SHA256AlgorithmIdentifier()); |
|
92 | 92 | $issuer_cert = $tbs_cert->sign($algo, $ca_private_key); |
93 | 93 | |
94 | 94 | // create AC holder certificate |
95 | 95 | $tbs_cert = new TBSCertificate( |
96 | - Name::fromString("cn=Holder, gn=John, sn=Doe"), |
|
97 | - $holder_private_key->publicKeyInfo(), |
|
98 | - new Name(), |
|
99 | - Validity::fromStrings("now", "now + 6 months")); |
|
96 | + Name::fromString("cn=Holder, gn=John, sn=Doe"), |
|
97 | + $holder_private_key->publicKeyInfo(), |
|
98 | + new Name(), |
|
99 | + Validity::fromStrings("now", "now + 6 months")); |
|
100 | 100 | $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert) |
101 | - ->withRandomSerialNumber() |
|
102 | - ->withAdditionalExtensions( |
|
103 | - new BasicConstraintsExtension(true, false), |
|
104 | - new KeyUsageExtension(true, |
|
105 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
106 | - KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
101 | + ->withRandomSerialNumber() |
|
102 | + ->withAdditionalExtensions( |
|
103 | + new BasicConstraintsExtension(true, false), |
|
104 | + new KeyUsageExtension(true, |
|
105 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
106 | + KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
107 | 107 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
108 | - $ca_private_key->algorithmIdentifier(), |
|
109 | - new SHA256AlgorithmIdentifier()); |
|
108 | + $ca_private_key->algorithmIdentifier(), |
|
109 | + new SHA256AlgorithmIdentifier()); |
|
110 | 110 | $holder_cert = $tbs_cert->sign($algo, $ca_private_key); |
111 | 111 | |
112 | 112 | // named authority that grants the attributes |
113 | 113 | $authority = new GeneralNames( |
114 | - new UniformResourceIdentifier("uri:trusted_authority")); |
|
114 | + new UniformResourceIdentifier("uri:trusted_authority")); |
|
115 | 115 | // role attribute |
116 | 116 | $attribs = new Attributes( |
117 | - Attribute::fromAttributeValues( |
|
118 | - RoleAttributeValue::fromString("role-name", $authority))); |
|
117 | + Attribute::fromAttributeValues( |
|
118 | + RoleAttributeValue::fromString("role-name", $authority))); |
|
119 | 119 | $aci = new AttributeCertificateInfo( |
120 | - // holder is identified by the holder's public key certificate |
|
121 | - new Holder(IssuerSerial::fromPKC($holder_cert)), |
|
122 | - AttCertIssuer::fromPKC($issuer_cert), |
|
123 | - AttCertValidityPeriod::fromStrings("now - 1 hour", "now + 3 months"), |
|
124 | - $attribs); |
|
120 | + // holder is identified by the holder's public key certificate |
|
121 | + new Holder(IssuerSerial::fromPKC($holder_cert)), |
|
122 | + AttCertIssuer::fromPKC($issuer_cert), |
|
123 | + AttCertValidityPeriod::fromStrings("now - 1 hour", "now + 3 months"), |
|
124 | + $attribs); |
|
125 | 125 | $aci = $aci->withRandomSerialNumber() |
126 | - ->withAdditionalExtensions( |
|
127 | - // named target identifier |
|
128 | - TargetInformationExtension::fromTargets( |
|
129 | - new TargetName( |
|
130 | - new UniformResourceIdentifier("uri:target_identifier"))), |
|
131 | - // key identifier of the AC issuer |
|
132 | - new AuthorityKeyIdentifierExtension(false, |
|
133 | - $issuer_cert->tbsCertificate() |
|
134 | - ->subjectPublicKeyInfo() |
|
135 | - ->keyIdentifier())); |
|
126 | + ->withAdditionalExtensions( |
|
127 | + // named target identifier |
|
128 | + TargetInformationExtension::fromTargets( |
|
129 | + new TargetName( |
|
130 | + new UniformResourceIdentifier("uri:target_identifier"))), |
|
131 | + // key identifier of the AC issuer |
|
132 | + new AuthorityKeyIdentifierExtension(false, |
|
133 | + $issuer_cert->tbsCertificate() |
|
134 | + ->subjectPublicKeyInfo() |
|
135 | + ->keyIdentifier())); |
|
136 | 136 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
137 | - $issuer_private_key->algorithmIdentifier(), |
|
138 | - new SHA256AlgorithmIdentifier()); |
|
137 | + $issuer_private_key->algorithmIdentifier(), |
|
138 | + new SHA256AlgorithmIdentifier()); |
|
139 | 139 | $ac = $aci->sign($algo, $issuer_private_key); |
140 | 140 | |
141 | 141 | // validate AC |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $validator_config = $validator_config->withTargets($target); |
148 | 148 | $validator = new ACValidator($ac, $validator_config); |
149 | 149 | if ($validator->validate()) { |
150 | - fprintf(STDERR, "AC validation succeeded.\n"); |
|
150 | + fprintf(STDERR, "AC validation succeeded.\n"); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | fprintf(STDERR, "Root certificate:\n"); |