@@ -50,6 +50,7 @@ |
||
50 | 50 | * @param PathValidationConfig $config Validation config |
51 | 51 | * @param Certificate ...$certificates Certificates from the trust anchor to |
52 | 52 | * the end-entity certificate |
53 | + * @param Certificate[] $certificates |
|
53 | 54 | */ |
54 | 55 | public function __construct(Crypto $crypto, PathValidationConfig $config, |
55 | 56 | Certificate ...$certificates) |
@@ -15,584 +15,584 @@ |
||
15 | 15 | */ |
16 | 16 | class PathValidator |
17 | 17 | { |
18 | - /** |
|
19 | - * Crypto engine. |
|
20 | - * |
|
21 | - * @var Crypto $_crypto |
|
22 | - */ |
|
23 | - protected $_crypto; |
|
18 | + /** |
|
19 | + * Crypto engine. |
|
20 | + * |
|
21 | + * @var Crypto $_crypto |
|
22 | + */ |
|
23 | + protected $_crypto; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Path validation configuration. |
|
27 | - * |
|
28 | - * @var PathValidationConfig $_config |
|
29 | - */ |
|
30 | - protected $_config; |
|
25 | + /** |
|
26 | + * Path validation configuration. |
|
27 | + * |
|
28 | + * @var PathValidationConfig $_config |
|
29 | + */ |
|
30 | + protected $_config; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Certification path. |
|
34 | - * |
|
35 | - * @var Certificate[] $_certificates |
|
36 | - */ |
|
37 | - protected $_certificates; |
|
32 | + /** |
|
33 | + * Certification path. |
|
34 | + * |
|
35 | + * @var Certificate[] $_certificates |
|
36 | + */ |
|
37 | + protected $_certificates; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Certification path trust anchor. |
|
41 | - * |
|
42 | - * @var Certificate $_trustAnchor |
|
43 | - */ |
|
44 | - protected $_trustAnchor; |
|
39 | + /** |
|
40 | + * Certification path trust anchor. |
|
41 | + * |
|
42 | + * @var Certificate $_trustAnchor |
|
43 | + */ |
|
44 | + protected $_trustAnchor; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Constructor. |
|
48 | - * |
|
49 | - * @param Crypto $crypto Crypto engine |
|
50 | - * @param PathValidationConfig $config Validation config |
|
51 | - * @param Certificate ...$certificates Certificates from the trust anchor to |
|
52 | - * the end-entity certificate |
|
53 | - */ |
|
54 | - public function __construct(Crypto $crypto, PathValidationConfig $config, |
|
55 | - Certificate ...$certificates) |
|
56 | - { |
|
57 | - if (!count($certificates)) { |
|
58 | - throw new \LogicException("No certificates."); |
|
59 | - } |
|
60 | - $this->_crypto = $crypto; |
|
61 | - $this->_config = $config; |
|
62 | - $this->_certificates = $certificates; |
|
63 | - // if trust anchor is explicitly given in configuration |
|
64 | - if ($config->hasTrustAnchor()) { |
|
65 | - $this->_trustAnchor = $config->trustAnchor(); |
|
66 | - } else { |
|
67 | - $this->_trustAnchor = $certificates[0]; |
|
68 | - } |
|
69 | - } |
|
46 | + /** |
|
47 | + * Constructor. |
|
48 | + * |
|
49 | + * @param Crypto $crypto Crypto engine |
|
50 | + * @param PathValidationConfig $config Validation config |
|
51 | + * @param Certificate ...$certificates Certificates from the trust anchor to |
|
52 | + * the end-entity certificate |
|
53 | + */ |
|
54 | + public function __construct(Crypto $crypto, PathValidationConfig $config, |
|
55 | + Certificate ...$certificates) |
|
56 | + { |
|
57 | + if (!count($certificates)) { |
|
58 | + throw new \LogicException("No certificates."); |
|
59 | + } |
|
60 | + $this->_crypto = $crypto; |
|
61 | + $this->_config = $config; |
|
62 | + $this->_certificates = $certificates; |
|
63 | + // if trust anchor is explicitly given in configuration |
|
64 | + if ($config->hasTrustAnchor()) { |
|
65 | + $this->_trustAnchor = $config->trustAnchor(); |
|
66 | + } else { |
|
67 | + $this->_trustAnchor = $certificates[0]; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Validate certification path. |
|
73 | - * |
|
74 | - * @throws PathValidationException |
|
75 | - * @return PathValidationResult |
|
76 | - */ |
|
77 | - public function validate() |
|
78 | - { |
|
79 | - $n = count($this->_certificates); |
|
80 | - $state = ValidatorState::initialize($this->_config, $this->_trustAnchor, |
|
81 | - $n); |
|
82 | - for ($i = 0; $i < $n; ++$i) { |
|
83 | - $state = $state->withIndex($i + 1); |
|
84 | - $cert = $this->_certificates[$i]; |
|
85 | - // process certificate (section 6.1.3.) |
|
86 | - $state = $this->_processCertificate($state, $cert); |
|
87 | - if (!$state->isFinal()) { |
|
88 | - // prepare next certificate (section 6.1.4.) |
|
89 | - $state = $this->_prepareNext($state, $cert); |
|
90 | - } |
|
91 | - } |
|
92 | - if (!isset($cert)) { |
|
93 | - throw new \LogicException("No certificates."); |
|
94 | - } |
|
95 | - // wrap-up (section 6.1.5.) |
|
96 | - $state = $this->_wrapUp($state, $cert); |
|
97 | - // return outputs |
|
98 | - return $state->getResult($this->_certificates); |
|
99 | - } |
|
71 | + /** |
|
72 | + * Validate certification path. |
|
73 | + * |
|
74 | + * @throws PathValidationException |
|
75 | + * @return PathValidationResult |
|
76 | + */ |
|
77 | + public function validate() |
|
78 | + { |
|
79 | + $n = count($this->_certificates); |
|
80 | + $state = ValidatorState::initialize($this->_config, $this->_trustAnchor, |
|
81 | + $n); |
|
82 | + for ($i = 0; $i < $n; ++$i) { |
|
83 | + $state = $state->withIndex($i + 1); |
|
84 | + $cert = $this->_certificates[$i]; |
|
85 | + // process certificate (section 6.1.3.) |
|
86 | + $state = $this->_processCertificate($state, $cert); |
|
87 | + if (!$state->isFinal()) { |
|
88 | + // prepare next certificate (section 6.1.4.) |
|
89 | + $state = $this->_prepareNext($state, $cert); |
|
90 | + } |
|
91 | + } |
|
92 | + if (!isset($cert)) { |
|
93 | + throw new \LogicException("No certificates."); |
|
94 | + } |
|
95 | + // wrap-up (section 6.1.5.) |
|
96 | + $state = $this->_wrapUp($state, $cert); |
|
97 | + // return outputs |
|
98 | + return $state->getResult($this->_certificates); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Apply basic certificate processing according to RFC 5280 section 6.1.3. |
|
103 | - * |
|
104 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.3 |
|
105 | - * @param ValidatorState $state |
|
106 | - * @param Certificate $cert |
|
107 | - * @throws PathValidationException |
|
108 | - * @return ValidatorState |
|
109 | - */ |
|
110 | - private function _processCertificate(ValidatorState $state, Certificate $cert) |
|
111 | - { |
|
112 | - // (a.1) verify signature |
|
113 | - $this->_verifySignature($state, $cert); |
|
114 | - // (a.2) check validity period |
|
115 | - $this->_checkValidity($cert); |
|
116 | - // (a.3) check that certificate is not revoked |
|
117 | - $this->_checkRevocation($cert); |
|
118 | - // (a.4) check issuer |
|
119 | - $this->_checkIssuer($state, $cert); |
|
120 | - // (b)(c) if certificate is self-issued and it is not |
|
121 | - // the final certificate in the path, skip this step |
|
122 | - if (!($cert->isSelfIssued() && !$state->isFinal())) { |
|
123 | - // (b) check permitted subtrees |
|
124 | - $this->_checkPermittedSubtrees($state, $cert); |
|
125 | - // (c) check excluded subtrees |
|
126 | - $this->_checkExcludedSubtrees($state, $cert); |
|
127 | - } |
|
128 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
129 | - if ($extensions->hasCertificatePolicies()) { |
|
130 | - // (d) process policy information |
|
131 | - if ($state->hasValidPolicyTree()) { |
|
132 | - $state = $state->validPolicyTree()->processPolicies($state, |
|
133 | - $cert); |
|
134 | - } |
|
135 | - } else { |
|
136 | - // (e) certificate policies extension not present, |
|
137 | - // set the valid_policy_tree to NULL |
|
138 | - $state = $state->withoutValidPolicyTree(); |
|
139 | - } |
|
140 | - // (f) check that explicit_policy > 0 or valid_policy_tree is set |
|
141 | - if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
142 | - throw new PathValidationException("No valid policies."); |
|
143 | - } |
|
144 | - return $state; |
|
145 | - } |
|
101 | + /** |
|
102 | + * Apply basic certificate processing according to RFC 5280 section 6.1.3. |
|
103 | + * |
|
104 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.3 |
|
105 | + * @param ValidatorState $state |
|
106 | + * @param Certificate $cert |
|
107 | + * @throws PathValidationException |
|
108 | + * @return ValidatorState |
|
109 | + */ |
|
110 | + private function _processCertificate(ValidatorState $state, Certificate $cert) |
|
111 | + { |
|
112 | + // (a.1) verify signature |
|
113 | + $this->_verifySignature($state, $cert); |
|
114 | + // (a.2) check validity period |
|
115 | + $this->_checkValidity($cert); |
|
116 | + // (a.3) check that certificate is not revoked |
|
117 | + $this->_checkRevocation($cert); |
|
118 | + // (a.4) check issuer |
|
119 | + $this->_checkIssuer($state, $cert); |
|
120 | + // (b)(c) if certificate is self-issued and it is not |
|
121 | + // the final certificate in the path, skip this step |
|
122 | + if (!($cert->isSelfIssued() && !$state->isFinal())) { |
|
123 | + // (b) check permitted subtrees |
|
124 | + $this->_checkPermittedSubtrees($state, $cert); |
|
125 | + // (c) check excluded subtrees |
|
126 | + $this->_checkExcludedSubtrees($state, $cert); |
|
127 | + } |
|
128 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
129 | + if ($extensions->hasCertificatePolicies()) { |
|
130 | + // (d) process policy information |
|
131 | + if ($state->hasValidPolicyTree()) { |
|
132 | + $state = $state->validPolicyTree()->processPolicies($state, |
|
133 | + $cert); |
|
134 | + } |
|
135 | + } else { |
|
136 | + // (e) certificate policies extension not present, |
|
137 | + // set the valid_policy_tree to NULL |
|
138 | + $state = $state->withoutValidPolicyTree(); |
|
139 | + } |
|
140 | + // (f) check that explicit_policy > 0 or valid_policy_tree is set |
|
141 | + if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
142 | + throw new PathValidationException("No valid policies."); |
|
143 | + } |
|
144 | + return $state; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Apply preparation for the certificate i+1 according to rfc5280 section |
|
149 | - * 6.1.4. |
|
150 | - * |
|
151 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.4 |
|
152 | - * @param ValidatorState $state |
|
153 | - * @param Certificate $cert |
|
154 | - * @return ValidatorState |
|
155 | - */ |
|
156 | - private function _prepareNext(ValidatorState $state, Certificate $cert) |
|
157 | - { |
|
158 | - // (a)(b) if policy mappings extension is present |
|
159 | - $state = $this->_preparePolicyMappings($state, $cert); |
|
160 | - // (c) assign working_issuer_name |
|
161 | - $state = $state->withWorkingIssuerName( |
|
162 | - $cert->tbsCertificate() |
|
163 | - ->subject()); |
|
164 | - // (d)(e)(f) |
|
165 | - $state = $this->_setPublicKeyState($state, $cert); |
|
166 | - // (g) if name constraints extension is present |
|
167 | - $state = $this->_prepareNameConstraints($state, $cert); |
|
168 | - // (h) if certificate is not self-issued |
|
169 | - if (!$cert->isSelfIssued()) { |
|
170 | - $state = $this->_prepareNonSelfIssued($state); |
|
171 | - } |
|
172 | - // (i) if policy constraints extension is present |
|
173 | - $state = $this->_preparePolicyConstraints($state, $cert); |
|
174 | - // (j) if inhibit any policy extension is present |
|
175 | - $state = $this->_prepareInhibitAnyPolicy($state, $cert); |
|
176 | - // (k) check basic constraints |
|
177 | - $this->_processBasicContraints($cert); |
|
178 | - // (l) verify max_path_length |
|
179 | - $state = $this->_verifyMaxPathLength($state, $cert); |
|
180 | - // (m) check pathLenContraint |
|
181 | - $state = $this->_processPathLengthContraint($state, $cert); |
|
182 | - // (n) check key usage |
|
183 | - $this->_checkKeyUsage($cert); |
|
184 | - // (o) process relevant extensions |
|
185 | - $state = $this->_processExtensions($state, $cert); |
|
186 | - return $state; |
|
187 | - } |
|
147 | + /** |
|
148 | + * Apply preparation for the certificate i+1 according to rfc5280 section |
|
149 | + * 6.1.4. |
|
150 | + * |
|
151 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.4 |
|
152 | + * @param ValidatorState $state |
|
153 | + * @param Certificate $cert |
|
154 | + * @return ValidatorState |
|
155 | + */ |
|
156 | + private function _prepareNext(ValidatorState $state, Certificate $cert) |
|
157 | + { |
|
158 | + // (a)(b) if policy mappings extension is present |
|
159 | + $state = $this->_preparePolicyMappings($state, $cert); |
|
160 | + // (c) assign working_issuer_name |
|
161 | + $state = $state->withWorkingIssuerName( |
|
162 | + $cert->tbsCertificate() |
|
163 | + ->subject()); |
|
164 | + // (d)(e)(f) |
|
165 | + $state = $this->_setPublicKeyState($state, $cert); |
|
166 | + // (g) if name constraints extension is present |
|
167 | + $state = $this->_prepareNameConstraints($state, $cert); |
|
168 | + // (h) if certificate is not self-issued |
|
169 | + if (!$cert->isSelfIssued()) { |
|
170 | + $state = $this->_prepareNonSelfIssued($state); |
|
171 | + } |
|
172 | + // (i) if policy constraints extension is present |
|
173 | + $state = $this->_preparePolicyConstraints($state, $cert); |
|
174 | + // (j) if inhibit any policy extension is present |
|
175 | + $state = $this->_prepareInhibitAnyPolicy($state, $cert); |
|
176 | + // (k) check basic constraints |
|
177 | + $this->_processBasicContraints($cert); |
|
178 | + // (l) verify max_path_length |
|
179 | + $state = $this->_verifyMaxPathLength($state, $cert); |
|
180 | + // (m) check pathLenContraint |
|
181 | + $state = $this->_processPathLengthContraint($state, $cert); |
|
182 | + // (n) check key usage |
|
183 | + $this->_checkKeyUsage($cert); |
|
184 | + // (o) process relevant extensions |
|
185 | + $state = $this->_processExtensions($state, $cert); |
|
186 | + return $state; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Apply wrap-up procedure according to RFC 5280 section 6.1.5. |
|
191 | - * |
|
192 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.5 |
|
193 | - * @param ValidatorState $state |
|
194 | - * @param Certificate $cert |
|
195 | - * @throws PathValidationException |
|
196 | - */ |
|
197 | - private function _wrapUp(ValidatorState $state, Certificate $cert) |
|
198 | - { |
|
199 | - $tbs_cert = $cert->tbsCertificate(); |
|
200 | - $extensions = $tbs_cert->extensions(); |
|
201 | - // (a) |
|
202 | - if ($state->explicitPolicy() > 0) { |
|
203 | - $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
204 | - } |
|
205 | - // (b) |
|
206 | - if ($extensions->hasPolicyConstraints()) { |
|
207 | - $ext = $extensions->policyConstraints(); |
|
208 | - if ($ext->hasRequireExplicitPolicy() && |
|
209 | - $ext->requireExplicitPolicy() == 0) { |
|
210 | - $state = $state->withExplicitPolicy(0); |
|
211 | - } |
|
212 | - } |
|
213 | - // (c)(d)(e) |
|
214 | - $state = $this->_setPublicKeyState($state, $cert); |
|
215 | - // (f) process relevant extensions |
|
216 | - $state = $this->_processExtensions($state, $cert); |
|
217 | - // (g) intersection of valid_policy_tree and the initial-policy-set |
|
218 | - $state = $this->_calculatePolicyIntersection($state); |
|
219 | - // check that explicit_policy > 0 or valid_policy_tree is set |
|
220 | - if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
221 | - throw new PathValidationException("No valid policies."); |
|
222 | - } |
|
223 | - // path validation succeeded |
|
224 | - return $state; |
|
225 | - } |
|
189 | + /** |
|
190 | + * Apply wrap-up procedure according to RFC 5280 section 6.1.5. |
|
191 | + * |
|
192 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.5 |
|
193 | + * @param ValidatorState $state |
|
194 | + * @param Certificate $cert |
|
195 | + * @throws PathValidationException |
|
196 | + */ |
|
197 | + private function _wrapUp(ValidatorState $state, Certificate $cert) |
|
198 | + { |
|
199 | + $tbs_cert = $cert->tbsCertificate(); |
|
200 | + $extensions = $tbs_cert->extensions(); |
|
201 | + // (a) |
|
202 | + if ($state->explicitPolicy() > 0) { |
|
203 | + $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
204 | + } |
|
205 | + // (b) |
|
206 | + if ($extensions->hasPolicyConstraints()) { |
|
207 | + $ext = $extensions->policyConstraints(); |
|
208 | + if ($ext->hasRequireExplicitPolicy() && |
|
209 | + $ext->requireExplicitPolicy() == 0) { |
|
210 | + $state = $state->withExplicitPolicy(0); |
|
211 | + } |
|
212 | + } |
|
213 | + // (c)(d)(e) |
|
214 | + $state = $this->_setPublicKeyState($state, $cert); |
|
215 | + // (f) process relevant extensions |
|
216 | + $state = $this->_processExtensions($state, $cert); |
|
217 | + // (g) intersection of valid_policy_tree and the initial-policy-set |
|
218 | + $state = $this->_calculatePolicyIntersection($state); |
|
219 | + // check that explicit_policy > 0 or valid_policy_tree is set |
|
220 | + if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
221 | + throw new PathValidationException("No valid policies."); |
|
222 | + } |
|
223 | + // path validation succeeded |
|
224 | + return $state; |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * Update working_public_key, working_public_key_parameters and |
|
229 | - * working_public_key_algorithm state variables from certificate. |
|
230 | - * |
|
231 | - * @param ValidatorState $state |
|
232 | - * @param Certificate $cert |
|
233 | - * @return ValidatorState |
|
234 | - */ |
|
235 | - private function _setPublicKeyState(ValidatorState $state, Certificate $cert) |
|
236 | - { |
|
237 | - $pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo(); |
|
238 | - // assign working_public_key |
|
239 | - $state = $state->withWorkingPublicKey($pk_info); |
|
240 | - // assign working_public_key_parameters |
|
241 | - $params = ValidatorState::getAlgorithmParameters( |
|
242 | - $pk_info->algorithmIdentifier()); |
|
243 | - if (null !== $params) { |
|
244 | - $state = $state->withWorkingPublicKeyParameters($params); |
|
245 | - } else { |
|
246 | - // if algorithms differ, set parameters to null |
|
247 | - if ($pk_info->algorithmIdentifier()->oid() !== |
|
248 | - $state->workingPublicKeyAlgorithm()->oid()) { |
|
249 | - $state = $state->withWorkingPublicKeyParameters(null); |
|
250 | - } |
|
251 | - } |
|
252 | - // assign working_public_key_algorithm |
|
253 | - $state = $state->withWorkingPublicKeyAlgorithm( |
|
254 | - $pk_info->algorithmIdentifier()); |
|
255 | - return $state; |
|
256 | - } |
|
227 | + /** |
|
228 | + * Update working_public_key, working_public_key_parameters and |
|
229 | + * working_public_key_algorithm state variables from certificate. |
|
230 | + * |
|
231 | + * @param ValidatorState $state |
|
232 | + * @param Certificate $cert |
|
233 | + * @return ValidatorState |
|
234 | + */ |
|
235 | + private function _setPublicKeyState(ValidatorState $state, Certificate $cert) |
|
236 | + { |
|
237 | + $pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo(); |
|
238 | + // assign working_public_key |
|
239 | + $state = $state->withWorkingPublicKey($pk_info); |
|
240 | + // assign working_public_key_parameters |
|
241 | + $params = ValidatorState::getAlgorithmParameters( |
|
242 | + $pk_info->algorithmIdentifier()); |
|
243 | + if (null !== $params) { |
|
244 | + $state = $state->withWorkingPublicKeyParameters($params); |
|
245 | + } else { |
|
246 | + // if algorithms differ, set parameters to null |
|
247 | + if ($pk_info->algorithmIdentifier()->oid() !== |
|
248 | + $state->workingPublicKeyAlgorithm()->oid()) { |
|
249 | + $state = $state->withWorkingPublicKeyParameters(null); |
|
250 | + } |
|
251 | + } |
|
252 | + // assign working_public_key_algorithm |
|
253 | + $state = $state->withWorkingPublicKeyAlgorithm( |
|
254 | + $pk_info->algorithmIdentifier()); |
|
255 | + return $state; |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Verify certificate signature. |
|
260 | - * |
|
261 | - * @param ValidatorState $state |
|
262 | - * @param Certificate $cert |
|
263 | - * @throws PathValidationException |
|
264 | - */ |
|
265 | - private function _verifySignature(ValidatorState $state, Certificate $cert) |
|
266 | - { |
|
267 | - try { |
|
268 | - $valid = $cert->verify($state->workingPublicKey(), $this->_crypto); |
|
269 | - } catch (\RuntimeException $e) { |
|
270 | - throw new PathValidationException( |
|
271 | - "Failed to verify signature: " . $e->getMessage(), null, $e); |
|
272 | - } |
|
273 | - if (!$valid) { |
|
274 | - throw new PathValidationException( |
|
275 | - "Certificate signature doesn't match."); |
|
276 | - } |
|
277 | - } |
|
258 | + /** |
|
259 | + * Verify certificate signature. |
|
260 | + * |
|
261 | + * @param ValidatorState $state |
|
262 | + * @param Certificate $cert |
|
263 | + * @throws PathValidationException |
|
264 | + */ |
|
265 | + private function _verifySignature(ValidatorState $state, Certificate $cert) |
|
266 | + { |
|
267 | + try { |
|
268 | + $valid = $cert->verify($state->workingPublicKey(), $this->_crypto); |
|
269 | + } catch (\RuntimeException $e) { |
|
270 | + throw new PathValidationException( |
|
271 | + "Failed to verify signature: " . $e->getMessage(), null, $e); |
|
272 | + } |
|
273 | + if (!$valid) { |
|
274 | + throw new PathValidationException( |
|
275 | + "Certificate signature doesn't match."); |
|
276 | + } |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * Check certificate validity. |
|
281 | - * |
|
282 | - * @param Certificate $cert |
|
283 | - * @throws PathValidationException |
|
284 | - */ |
|
285 | - private function _checkValidity(Certificate $cert) |
|
286 | - { |
|
287 | - $refdt = $this->_config->dateTime(); |
|
288 | - $validity = $cert->tbsCertificate()->validity(); |
|
289 | - if ($validity->notBefore() |
|
290 | - ->dateTime() |
|
291 | - ->diff($refdt)->invert) { |
|
292 | - throw new PathValidationException( |
|
293 | - "Certificate validity period has not started."); |
|
294 | - } |
|
295 | - if ($refdt->diff($validity->notAfter() |
|
296 | - ->dateTime())->invert) { |
|
297 | - throw new PathValidationException("Certificate has expired."); |
|
298 | - } |
|
299 | - } |
|
279 | + /** |
|
280 | + * Check certificate validity. |
|
281 | + * |
|
282 | + * @param Certificate $cert |
|
283 | + * @throws PathValidationException |
|
284 | + */ |
|
285 | + private function _checkValidity(Certificate $cert) |
|
286 | + { |
|
287 | + $refdt = $this->_config->dateTime(); |
|
288 | + $validity = $cert->tbsCertificate()->validity(); |
|
289 | + if ($validity->notBefore() |
|
290 | + ->dateTime() |
|
291 | + ->diff($refdt)->invert) { |
|
292 | + throw new PathValidationException( |
|
293 | + "Certificate validity period has not started."); |
|
294 | + } |
|
295 | + if ($refdt->diff($validity->notAfter() |
|
296 | + ->dateTime())->invert) { |
|
297 | + throw new PathValidationException("Certificate has expired."); |
|
298 | + } |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Check certificate revocation. |
|
303 | - * |
|
304 | - * @param Certificate $cert |
|
305 | - */ |
|
306 | - private function _checkRevocation(Certificate $cert) |
|
307 | - { |
|
308 | - // @todo Implement CRL handling |
|
309 | - } |
|
301 | + /** |
|
302 | + * Check certificate revocation. |
|
303 | + * |
|
304 | + * @param Certificate $cert |
|
305 | + */ |
|
306 | + private function _checkRevocation(Certificate $cert) |
|
307 | + { |
|
308 | + // @todo Implement CRL handling |
|
309 | + } |
|
310 | 310 | |
311 | - /** |
|
312 | - * Check certificate issuer. |
|
313 | - * |
|
314 | - * @param ValidatorState $state |
|
315 | - * @param Certificate $cert |
|
316 | - * @throws PathValidationException |
|
317 | - */ |
|
318 | - private function _checkIssuer(ValidatorState $state, Certificate $cert) |
|
319 | - { |
|
320 | - if (!$cert->tbsCertificate() |
|
321 | - ->issuer() |
|
322 | - ->equals($state->workingIssuerName())) { |
|
323 | - throw new PathValidationException("Certification issuer mismatch."); |
|
324 | - } |
|
325 | - } |
|
311 | + /** |
|
312 | + * Check certificate issuer. |
|
313 | + * |
|
314 | + * @param ValidatorState $state |
|
315 | + * @param Certificate $cert |
|
316 | + * @throws PathValidationException |
|
317 | + */ |
|
318 | + private function _checkIssuer(ValidatorState $state, Certificate $cert) |
|
319 | + { |
|
320 | + if (!$cert->tbsCertificate() |
|
321 | + ->issuer() |
|
322 | + ->equals($state->workingIssuerName())) { |
|
323 | + throw new PathValidationException("Certification issuer mismatch."); |
|
324 | + } |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * |
|
329 | - * @param ValidatorState $state |
|
330 | - * @param Certificate $cert |
|
331 | - */ |
|
332 | - private function _checkPermittedSubtrees(ValidatorState $state, |
|
333 | - Certificate $cert) |
|
334 | - { |
|
335 | - // @todo Implement |
|
336 | - $state->permittedSubtrees(); |
|
337 | - } |
|
327 | + /** |
|
328 | + * |
|
329 | + * @param ValidatorState $state |
|
330 | + * @param Certificate $cert |
|
331 | + */ |
|
332 | + private function _checkPermittedSubtrees(ValidatorState $state, |
|
333 | + Certificate $cert) |
|
334 | + { |
|
335 | + // @todo Implement |
|
336 | + $state->permittedSubtrees(); |
|
337 | + } |
|
338 | 338 | |
339 | - /** |
|
340 | - * |
|
341 | - * @param ValidatorState $state |
|
342 | - * @param Certificate $cert |
|
343 | - */ |
|
344 | - private function _checkExcludedSubtrees(ValidatorState $state, |
|
345 | - Certificate $cert) |
|
346 | - { |
|
347 | - // @todo Implement |
|
348 | - $state->excludedSubtrees(); |
|
349 | - } |
|
339 | + /** |
|
340 | + * |
|
341 | + * @param ValidatorState $state |
|
342 | + * @param Certificate $cert |
|
343 | + */ |
|
344 | + private function _checkExcludedSubtrees(ValidatorState $state, |
|
345 | + Certificate $cert) |
|
346 | + { |
|
347 | + // @todo Implement |
|
348 | + $state->excludedSubtrees(); |
|
349 | + } |
|
350 | 350 | |
351 | - /** |
|
352 | - * Apply policy mappings handling for the preparation step. |
|
353 | - * |
|
354 | - * @param ValidatorState $state |
|
355 | - * @param Certificate $cert |
|
356 | - * @throws PathValidationException |
|
357 | - * @return ValidatorState |
|
358 | - */ |
|
359 | - private function _preparePolicyMappings(ValidatorState $state, |
|
360 | - Certificate $cert) |
|
361 | - { |
|
362 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
363 | - if ($extensions->hasPolicyMappings()) { |
|
364 | - // (a) verify that anyPolicy mapping is not used |
|
365 | - if ($extensions->policyMappings()->hasAnyPolicyMapping()) { |
|
366 | - throw new PathValidationException("anyPolicy mapping found."); |
|
367 | - } |
|
368 | - // (b) process policy mappings |
|
369 | - if ($state->hasValidPolicyTree()) { |
|
370 | - $state = $state->validPolicyTree()->processMappings($state, |
|
371 | - $cert); |
|
372 | - } |
|
373 | - } |
|
374 | - return $state; |
|
375 | - } |
|
351 | + /** |
|
352 | + * Apply policy mappings handling for the preparation step. |
|
353 | + * |
|
354 | + * @param ValidatorState $state |
|
355 | + * @param Certificate $cert |
|
356 | + * @throws PathValidationException |
|
357 | + * @return ValidatorState |
|
358 | + */ |
|
359 | + private function _preparePolicyMappings(ValidatorState $state, |
|
360 | + Certificate $cert) |
|
361 | + { |
|
362 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
363 | + if ($extensions->hasPolicyMappings()) { |
|
364 | + // (a) verify that anyPolicy mapping is not used |
|
365 | + if ($extensions->policyMappings()->hasAnyPolicyMapping()) { |
|
366 | + throw new PathValidationException("anyPolicy mapping found."); |
|
367 | + } |
|
368 | + // (b) process policy mappings |
|
369 | + if ($state->hasValidPolicyTree()) { |
|
370 | + $state = $state->validPolicyTree()->processMappings($state, |
|
371 | + $cert); |
|
372 | + } |
|
373 | + } |
|
374 | + return $state; |
|
375 | + } |
|
376 | 376 | |
377 | - /** |
|
378 | - * Apply name constraints handling for the preparation step. |
|
379 | - * |
|
380 | - * @param ValidatorState $state |
|
381 | - * @param Certificate $cert |
|
382 | - * @return ValidatorState |
|
383 | - */ |
|
384 | - private function _prepareNameConstraints(ValidatorState $state, |
|
385 | - Certificate $cert) |
|
386 | - { |
|
387 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
388 | - if ($extensions->hasNameConstraints()) { |
|
389 | - $state = $this->_processNameConstraints($state, $cert); |
|
390 | - } |
|
391 | - return $state; |
|
392 | - } |
|
377 | + /** |
|
378 | + * Apply name constraints handling for the preparation step. |
|
379 | + * |
|
380 | + * @param ValidatorState $state |
|
381 | + * @param Certificate $cert |
|
382 | + * @return ValidatorState |
|
383 | + */ |
|
384 | + private function _prepareNameConstraints(ValidatorState $state, |
|
385 | + Certificate $cert) |
|
386 | + { |
|
387 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
388 | + if ($extensions->hasNameConstraints()) { |
|
389 | + $state = $this->_processNameConstraints($state, $cert); |
|
390 | + } |
|
391 | + return $state; |
|
392 | + } |
|
393 | 393 | |
394 | - /** |
|
395 | - * Apply preparation for a non-self-signed certificate. |
|
396 | - * |
|
397 | - * @param ValidatorState $state |
|
398 | - * @return ValidatorState |
|
399 | - */ |
|
400 | - private function _prepareNonSelfIssued(ValidatorState $state) |
|
401 | - { |
|
402 | - // (h.1) |
|
403 | - if ($state->explicitPolicy() > 0) { |
|
404 | - $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
405 | - } |
|
406 | - // (h.2) |
|
407 | - if ($state->policyMapping() > 0) { |
|
408 | - $state = $state->withPolicyMapping($state->policyMapping() - 1); |
|
409 | - } |
|
410 | - // (h.3) |
|
411 | - if ($state->inhibitAnyPolicy() > 0) { |
|
412 | - $state = $state->withInhibitAnyPolicy( |
|
413 | - $state->inhibitAnyPolicy() - 1); |
|
414 | - } |
|
415 | - return $state; |
|
416 | - } |
|
394 | + /** |
|
395 | + * Apply preparation for a non-self-signed certificate. |
|
396 | + * |
|
397 | + * @param ValidatorState $state |
|
398 | + * @return ValidatorState |
|
399 | + */ |
|
400 | + private function _prepareNonSelfIssued(ValidatorState $state) |
|
401 | + { |
|
402 | + // (h.1) |
|
403 | + if ($state->explicitPolicy() > 0) { |
|
404 | + $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
405 | + } |
|
406 | + // (h.2) |
|
407 | + if ($state->policyMapping() > 0) { |
|
408 | + $state = $state->withPolicyMapping($state->policyMapping() - 1); |
|
409 | + } |
|
410 | + // (h.3) |
|
411 | + if ($state->inhibitAnyPolicy() > 0) { |
|
412 | + $state = $state->withInhibitAnyPolicy( |
|
413 | + $state->inhibitAnyPolicy() - 1); |
|
414 | + } |
|
415 | + return $state; |
|
416 | + } |
|
417 | 417 | |
418 | - /** |
|
419 | - * Apply policy constraints handling for the preparation step. |
|
420 | - * |
|
421 | - * @param ValidatorState $state |
|
422 | - * @param Certificate $cert |
|
423 | - * @return ValidatorState |
|
424 | - */ |
|
425 | - private function _preparePolicyConstraints(ValidatorState $state, |
|
426 | - Certificate $cert) |
|
427 | - { |
|
428 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
429 | - if (!$extensions->hasPolicyConstraints()) { |
|
430 | - return $state; |
|
431 | - } |
|
432 | - $ext = $extensions->policyConstraints(); |
|
433 | - // (i.1) |
|
434 | - if ($ext->hasRequireExplicitPolicy() && |
|
435 | - $ext->requireExplicitPolicy() < $state->explicitPolicy()) { |
|
436 | - $state = $state->withExplicitPolicy($ext->requireExplicitPolicy()); |
|
437 | - } |
|
438 | - // (i.2) |
|
439 | - if ($ext->hasInhibitPolicyMapping() && |
|
440 | - $ext->inhibitPolicyMapping() < $state->policyMapping()) { |
|
441 | - $state = $state->withPolicyMapping($ext->inhibitPolicyMapping()); |
|
442 | - } |
|
443 | - return $state; |
|
444 | - } |
|
418 | + /** |
|
419 | + * Apply policy constraints handling for the preparation step. |
|
420 | + * |
|
421 | + * @param ValidatorState $state |
|
422 | + * @param Certificate $cert |
|
423 | + * @return ValidatorState |
|
424 | + */ |
|
425 | + private function _preparePolicyConstraints(ValidatorState $state, |
|
426 | + Certificate $cert) |
|
427 | + { |
|
428 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
429 | + if (!$extensions->hasPolicyConstraints()) { |
|
430 | + return $state; |
|
431 | + } |
|
432 | + $ext = $extensions->policyConstraints(); |
|
433 | + // (i.1) |
|
434 | + if ($ext->hasRequireExplicitPolicy() && |
|
435 | + $ext->requireExplicitPolicy() < $state->explicitPolicy()) { |
|
436 | + $state = $state->withExplicitPolicy($ext->requireExplicitPolicy()); |
|
437 | + } |
|
438 | + // (i.2) |
|
439 | + if ($ext->hasInhibitPolicyMapping() && |
|
440 | + $ext->inhibitPolicyMapping() < $state->policyMapping()) { |
|
441 | + $state = $state->withPolicyMapping($ext->inhibitPolicyMapping()); |
|
442 | + } |
|
443 | + return $state; |
|
444 | + } |
|
445 | 445 | |
446 | - /** |
|
447 | - * Apply inhibit any-policy handling for the preparation step. |
|
448 | - * |
|
449 | - * @param ValidatorState $state |
|
450 | - * @param Certificate $cert |
|
451 | - * @return ValidatorState |
|
452 | - */ |
|
453 | - private function _prepareInhibitAnyPolicy(ValidatorState $state, |
|
454 | - Certificate $cert) |
|
455 | - { |
|
456 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
457 | - if ($extensions->hasInhibitAnyPolicy()) { |
|
458 | - $ext = $extensions->inhibitAnyPolicy(); |
|
459 | - if ($ext->skipCerts() < $state->inhibitAnyPolicy()) { |
|
460 | - $state = $state->withInhibitAnyPolicy($ext->skipCerts()); |
|
461 | - } |
|
462 | - } |
|
463 | - return $state; |
|
464 | - } |
|
446 | + /** |
|
447 | + * Apply inhibit any-policy handling for the preparation step. |
|
448 | + * |
|
449 | + * @param ValidatorState $state |
|
450 | + * @param Certificate $cert |
|
451 | + * @return ValidatorState |
|
452 | + */ |
|
453 | + private function _prepareInhibitAnyPolicy(ValidatorState $state, |
|
454 | + Certificate $cert) |
|
455 | + { |
|
456 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
457 | + if ($extensions->hasInhibitAnyPolicy()) { |
|
458 | + $ext = $extensions->inhibitAnyPolicy(); |
|
459 | + if ($ext->skipCerts() < $state->inhibitAnyPolicy()) { |
|
460 | + $state = $state->withInhibitAnyPolicy($ext->skipCerts()); |
|
461 | + } |
|
462 | + } |
|
463 | + return $state; |
|
464 | + } |
|
465 | 465 | |
466 | - /** |
|
467 | - * Verify maximum certification path length for the preparation step. |
|
468 | - * |
|
469 | - * @param ValidatorState $state |
|
470 | - * @param Certificate $cert |
|
471 | - * @throws PathValidationException |
|
472 | - * @return ValidatorState |
|
473 | - */ |
|
474 | - private function _verifyMaxPathLength(ValidatorState $state, |
|
475 | - Certificate $cert) |
|
476 | - { |
|
477 | - if (!$cert->isSelfIssued()) { |
|
478 | - if ($state->maxPathLength() <= 0) { |
|
479 | - throw new PathValidationException( |
|
480 | - "Certification path length exceeded."); |
|
481 | - } |
|
482 | - $state = $state->withMaxPathLength($state->maxPathLength() - 1); |
|
483 | - } |
|
484 | - return $state; |
|
485 | - } |
|
466 | + /** |
|
467 | + * Verify maximum certification path length for the preparation step. |
|
468 | + * |
|
469 | + * @param ValidatorState $state |
|
470 | + * @param Certificate $cert |
|
471 | + * @throws PathValidationException |
|
472 | + * @return ValidatorState |
|
473 | + */ |
|
474 | + private function _verifyMaxPathLength(ValidatorState $state, |
|
475 | + Certificate $cert) |
|
476 | + { |
|
477 | + if (!$cert->isSelfIssued()) { |
|
478 | + if ($state->maxPathLength() <= 0) { |
|
479 | + throw new PathValidationException( |
|
480 | + "Certification path length exceeded."); |
|
481 | + } |
|
482 | + $state = $state->withMaxPathLength($state->maxPathLength() - 1); |
|
483 | + } |
|
484 | + return $state; |
|
485 | + } |
|
486 | 486 | |
487 | - /** |
|
488 | - * Check key usage extension for the preparation step. |
|
489 | - * |
|
490 | - * @param Certificate $cert |
|
491 | - * @throws PathValidationException |
|
492 | - */ |
|
493 | - private function _checkKeyUsage(Certificate $cert) |
|
494 | - { |
|
495 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
496 | - if ($extensions->hasKeyUsage()) { |
|
497 | - $ext = $extensions->keyUsage(); |
|
498 | - if (!$ext->isKeyCertSign()) { |
|
499 | - throw new PathValidationException("keyCertSign usage not set."); |
|
500 | - } |
|
501 | - } |
|
502 | - } |
|
487 | + /** |
|
488 | + * Check key usage extension for the preparation step. |
|
489 | + * |
|
490 | + * @param Certificate $cert |
|
491 | + * @throws PathValidationException |
|
492 | + */ |
|
493 | + private function _checkKeyUsage(Certificate $cert) |
|
494 | + { |
|
495 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
496 | + if ($extensions->hasKeyUsage()) { |
|
497 | + $ext = $extensions->keyUsage(); |
|
498 | + if (!$ext->isKeyCertSign()) { |
|
499 | + throw new PathValidationException("keyCertSign usage not set."); |
|
500 | + } |
|
501 | + } |
|
502 | + } |
|
503 | 503 | |
504 | - /** |
|
505 | - * |
|
506 | - * @param ValidatorState $state |
|
507 | - * @param Certificate $cert |
|
508 | - * @return ValidatorState |
|
509 | - */ |
|
510 | - private function _processNameConstraints(ValidatorState $state, |
|
511 | - Certificate $cert) |
|
512 | - { |
|
513 | - // @todo Implement |
|
514 | - return $state; |
|
515 | - } |
|
504 | + /** |
|
505 | + * |
|
506 | + * @param ValidatorState $state |
|
507 | + * @param Certificate $cert |
|
508 | + * @return ValidatorState |
|
509 | + */ |
|
510 | + private function _processNameConstraints(ValidatorState $state, |
|
511 | + Certificate $cert) |
|
512 | + { |
|
513 | + // @todo Implement |
|
514 | + return $state; |
|
515 | + } |
|
516 | 516 | |
517 | - /** |
|
518 | - * Process basic constraints extension. |
|
519 | - * |
|
520 | - * @param Certificate $cert |
|
521 | - * @throws PathValidationException |
|
522 | - */ |
|
523 | - private function _processBasicContraints(Certificate $cert) |
|
524 | - { |
|
525 | - if ($cert->tbsCertificate()->version() == TBSCertificate::VERSION_3) { |
|
526 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
527 | - if (!$extensions->hasBasicConstraints()) { |
|
528 | - throw new PathValidationException( |
|
529 | - "v3 certificate must have basicConstraints extension."); |
|
530 | - } |
|
531 | - // verify that cA is set to TRUE |
|
532 | - if (!$extensions->basicConstraints()->isCA()) { |
|
533 | - throw new PathValidationException( |
|
534 | - "Certificate is not a CA certificate."); |
|
535 | - } |
|
536 | - } |
|
537 | - } |
|
517 | + /** |
|
518 | + * Process basic constraints extension. |
|
519 | + * |
|
520 | + * @param Certificate $cert |
|
521 | + * @throws PathValidationException |
|
522 | + */ |
|
523 | + private function _processBasicContraints(Certificate $cert) |
|
524 | + { |
|
525 | + if ($cert->tbsCertificate()->version() == TBSCertificate::VERSION_3) { |
|
526 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
527 | + if (!$extensions->hasBasicConstraints()) { |
|
528 | + throw new PathValidationException( |
|
529 | + "v3 certificate must have basicConstraints extension."); |
|
530 | + } |
|
531 | + // verify that cA is set to TRUE |
|
532 | + if (!$extensions->basicConstraints()->isCA()) { |
|
533 | + throw new PathValidationException( |
|
534 | + "Certificate is not a CA certificate."); |
|
535 | + } |
|
536 | + } |
|
537 | + } |
|
538 | 538 | |
539 | - /** |
|
540 | - * Process pathLenConstraint. |
|
541 | - * |
|
542 | - * @param ValidatorState $state |
|
543 | - * @param Certificate $cert |
|
544 | - * @return ValidatorState |
|
545 | - */ |
|
546 | - private function _processPathLengthContraint(ValidatorState $state, |
|
547 | - Certificate $cert) |
|
548 | - { |
|
549 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
550 | - if ($extensions->hasBasicConstraints()) { |
|
551 | - $ext = $extensions->basicConstraints(); |
|
552 | - if ($ext->hasPathLen()) { |
|
553 | - if ($ext->pathLen() < $state->maxPathLength()) { |
|
554 | - $state = $state->withMaxPathLength($ext->pathLen()); |
|
555 | - } |
|
556 | - } |
|
557 | - } |
|
558 | - return $state; |
|
559 | - } |
|
539 | + /** |
|
540 | + * Process pathLenConstraint. |
|
541 | + * |
|
542 | + * @param ValidatorState $state |
|
543 | + * @param Certificate $cert |
|
544 | + * @return ValidatorState |
|
545 | + */ |
|
546 | + private function _processPathLengthContraint(ValidatorState $state, |
|
547 | + Certificate $cert) |
|
548 | + { |
|
549 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
550 | + if ($extensions->hasBasicConstraints()) { |
|
551 | + $ext = $extensions->basicConstraints(); |
|
552 | + if ($ext->hasPathLen()) { |
|
553 | + if ($ext->pathLen() < $state->maxPathLength()) { |
|
554 | + $state = $state->withMaxPathLength($ext->pathLen()); |
|
555 | + } |
|
556 | + } |
|
557 | + } |
|
558 | + return $state; |
|
559 | + } |
|
560 | 560 | |
561 | - /** |
|
562 | - * |
|
563 | - * @param ValidatorState $state |
|
564 | - * @param Certificate $cert |
|
565 | - * @return ValidatorState |
|
566 | - */ |
|
567 | - private function _processExtensions(ValidatorState $state, Certificate $cert) |
|
568 | - { |
|
569 | - // @todo Implement |
|
570 | - return $state; |
|
571 | - } |
|
561 | + /** |
|
562 | + * |
|
563 | + * @param ValidatorState $state |
|
564 | + * @param Certificate $cert |
|
565 | + * @return ValidatorState |
|
566 | + */ |
|
567 | + private function _processExtensions(ValidatorState $state, Certificate $cert) |
|
568 | + { |
|
569 | + // @todo Implement |
|
570 | + return $state; |
|
571 | + } |
|
572 | 572 | |
573 | - /** |
|
574 | - * |
|
575 | - * @param ValidatorState $state |
|
576 | - * @return ValidatorState |
|
577 | - */ |
|
578 | - private function _calculatePolicyIntersection(ValidatorState $state) |
|
579 | - { |
|
580 | - // (i) If the valid_policy_tree is NULL, the intersection is NULL |
|
581 | - if (!$state->hasValidPolicyTree()) { |
|
582 | - return $state; |
|
583 | - } |
|
584 | - // (ii) If the valid_policy_tree is not NULL and |
|
585 | - // the user-initial-policy-set is any-policy, the intersection |
|
586 | - // is the entire valid_policy_tree |
|
587 | - $initial_policies = $this->_config->policySet(); |
|
588 | - if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) { |
|
589 | - return $state; |
|
590 | - } |
|
591 | - // (iii) If the valid_policy_tree is not NULL and the |
|
592 | - // user-initial-policy-set is not any-policy, calculate |
|
593 | - // the intersection of the valid_policy_tree and the |
|
594 | - // user-initial-policy-set as follows |
|
595 | - return $state->validPolicyTree()->calculateIntersection($state, |
|
596 | - $initial_policies); |
|
597 | - } |
|
573 | + /** |
|
574 | + * |
|
575 | + * @param ValidatorState $state |
|
576 | + * @return ValidatorState |
|
577 | + */ |
|
578 | + private function _calculatePolicyIntersection(ValidatorState $state) |
|
579 | + { |
|
580 | + // (i) If the valid_policy_tree is NULL, the intersection is NULL |
|
581 | + if (!$state->hasValidPolicyTree()) { |
|
582 | + return $state; |
|
583 | + } |
|
584 | + // (ii) If the valid_policy_tree is not NULL and |
|
585 | + // the user-initial-policy-set is any-policy, the intersection |
|
586 | + // is the entire valid_policy_tree |
|
587 | + $initial_policies = $this->_config->policySet(); |
|
588 | + if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) { |
|
589 | + return $state; |
|
590 | + } |
|
591 | + // (iii) If the valid_policy_tree is not NULL and the |
|
592 | + // user-initial-policy-set is not any-policy, calculate |
|
593 | + // the intersection of the valid_policy_tree and the |
|
594 | + // user-initial-policy-set as follows |
|
595 | + return $state->validPolicyTree()->calculateIntersection($state, |
|
596 | + $initial_policies); |
|
597 | + } |
|
598 | 598 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
82 | 82 | * |
83 | 83 | * @param ValidatorState $state |
84 | - * @param array $policies |
|
84 | + * @param string[] $policies |
|
85 | 85 | * @return ValidatorState |
86 | 86 | */ |
87 | 87 | public function calculateIntersection(ValidatorState $state, array $policies) |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param Certificate $cert |
267 | 267 | * @param ValidatorState $state |
268 | 268 | * @param string $idp OID of the issuer domain policy |
269 | - * @param array $sdps Array of subject domain policy OIDs |
|
269 | + * @param string[] $sdps Array of subject domain policy OIDs |
|
270 | 270 | */ |
271 | 271 | protected function _applyAnyPolicyMapping(Certificate $cert, |
272 | 272 | ValidatorState $state, $idp, array $sdps) |
@@ -404,6 +404,7 @@ discard block |
||
404 | 404 | * Gather all children of given nodes to a flattened array. |
405 | 405 | * |
406 | 406 | * @param PolicyNode ...$nodes |
407 | + * @param PolicyNode[] $nodes |
|
407 | 408 | * @return PolicyNode[] |
408 | 409 | */ |
409 | 410 | private static function _gatherChildren(PolicyNode ...$nodes) |
@@ -8,410 +8,410 @@ |
||
8 | 8 | |
9 | 9 | class PolicyTree |
10 | 10 | { |
11 | - /** |
|
12 | - * Root node at depth zero. |
|
13 | - * |
|
14 | - * @var PolicyNode|null |
|
15 | - */ |
|
16 | - protected $_root; |
|
11 | + /** |
|
12 | + * Root node at depth zero. |
|
13 | + * |
|
14 | + * @var PolicyNode|null |
|
15 | + */ |
|
16 | + protected $_root; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Constructor. |
|
20 | - * |
|
21 | - * @param PolicyNode $root Initial root node |
|
22 | - */ |
|
23 | - public function __construct(PolicyNode $root) |
|
24 | - { |
|
25 | - $this->_root = $root; |
|
26 | - } |
|
18 | + /** |
|
19 | + * Constructor. |
|
20 | + * |
|
21 | + * @param PolicyNode $root Initial root node |
|
22 | + */ |
|
23 | + public function __construct(PolicyNode $root) |
|
24 | + { |
|
25 | + $this->_root = $root; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Process policy information from the certificate. |
|
30 | - * |
|
31 | - * Certificate policies extension must be present. |
|
32 | - * |
|
33 | - * @param ValidatorState $state |
|
34 | - * @param Certificate $cert |
|
35 | - * @return ValidatorState |
|
36 | - */ |
|
37 | - public function processPolicies(ValidatorState $state, Certificate $cert) |
|
38 | - { |
|
39 | - $policies = $cert->tbsCertificate() |
|
40 | - ->extensions() |
|
41 | - ->certificatePolicies(); |
|
42 | - $tree = clone $this; |
|
43 | - // (d.1) for each policy P not equal to anyPolicy |
|
44 | - foreach ($policies as $policy) { |
|
45 | - if ($policy->isAnyPolicy()) { |
|
46 | - $tree->_processAnyPolicy($policy, $cert, $state); |
|
47 | - } else { |
|
48 | - $tree->_processPolicy($policy, $state); |
|
49 | - } |
|
50 | - } |
|
51 | - // if whole tree is pruned |
|
52 | - if (!$tree->_pruneTree($state->index() - 1)) { |
|
53 | - return $state->withoutValidPolicyTree(); |
|
54 | - } |
|
55 | - return $state->withValidPolicyTree($tree); |
|
56 | - } |
|
28 | + /** |
|
29 | + * Process policy information from the certificate. |
|
30 | + * |
|
31 | + * Certificate policies extension must be present. |
|
32 | + * |
|
33 | + * @param ValidatorState $state |
|
34 | + * @param Certificate $cert |
|
35 | + * @return ValidatorState |
|
36 | + */ |
|
37 | + public function processPolicies(ValidatorState $state, Certificate $cert) |
|
38 | + { |
|
39 | + $policies = $cert->tbsCertificate() |
|
40 | + ->extensions() |
|
41 | + ->certificatePolicies(); |
|
42 | + $tree = clone $this; |
|
43 | + // (d.1) for each policy P not equal to anyPolicy |
|
44 | + foreach ($policies as $policy) { |
|
45 | + if ($policy->isAnyPolicy()) { |
|
46 | + $tree->_processAnyPolicy($policy, $cert, $state); |
|
47 | + } else { |
|
48 | + $tree->_processPolicy($policy, $state); |
|
49 | + } |
|
50 | + } |
|
51 | + // if whole tree is pruned |
|
52 | + if (!$tree->_pruneTree($state->index() - 1)) { |
|
53 | + return $state->withoutValidPolicyTree(); |
|
54 | + } |
|
55 | + return $state->withValidPolicyTree($tree); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Process policy mappings from the certificate. |
|
60 | - * |
|
61 | - * @param ValidatorState $state |
|
62 | - * @param Certificate $cert |
|
63 | - * @return ValidatorState |
|
64 | - */ |
|
65 | - public function processMappings(ValidatorState $state, Certificate $cert) |
|
66 | - { |
|
67 | - $tree = clone $this; |
|
68 | - if ($state->policyMapping() > 0) { |
|
69 | - $tree->_applyMappings($cert, $state); |
|
70 | - } else if ($state->policyMapping() == 0) { |
|
71 | - $tree->_deleteMappings($cert, $state); |
|
72 | - } |
|
73 | - // if whole tree is pruned |
|
74 | - if (!$tree->_root) { |
|
75 | - return $state->withoutValidPolicyTree(); |
|
76 | - } |
|
77 | - return $state->withValidPolicyTree($tree); |
|
78 | - } |
|
58 | + /** |
|
59 | + * Process policy mappings from the certificate. |
|
60 | + * |
|
61 | + * @param ValidatorState $state |
|
62 | + * @param Certificate $cert |
|
63 | + * @return ValidatorState |
|
64 | + */ |
|
65 | + public function processMappings(ValidatorState $state, Certificate $cert) |
|
66 | + { |
|
67 | + $tree = clone $this; |
|
68 | + if ($state->policyMapping() > 0) { |
|
69 | + $tree->_applyMappings($cert, $state); |
|
70 | + } else if ($state->policyMapping() == 0) { |
|
71 | + $tree->_deleteMappings($cert, $state); |
|
72 | + } |
|
73 | + // if whole tree is pruned |
|
74 | + if (!$tree->_root) { |
|
75 | + return $state->withoutValidPolicyTree(); |
|
76 | + } |
|
77 | + return $state->withValidPolicyTree($tree); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
|
82 | - * |
|
83 | - * @param ValidatorState $state |
|
84 | - * @param array $policies |
|
85 | - * @return ValidatorState |
|
86 | - */ |
|
87 | - public function calculateIntersection(ValidatorState $state, array $policies) |
|
88 | - { |
|
89 | - $tree = clone $this; |
|
90 | - $valid_policy_node_set = $tree->_validPolicyNodeSet(); |
|
91 | - // 2. If the valid_policy of any node in the valid_policy_node_set |
|
92 | - // is not in the user-initial-policy-set and is not anyPolicy, |
|
93 | - // delete this node and all its children. |
|
94 | - $valid_policy_node_set = array_filter($valid_policy_node_set, |
|
95 | - function (PolicyNode $node) use ($policies) { |
|
96 | - if ($node->isAnyPolicy()) { |
|
97 | - return true; |
|
98 | - } |
|
99 | - if (in_array($node->validPolicy(), $policies)) { |
|
100 | - return true; |
|
101 | - } |
|
102 | - $node->remove(); |
|
103 | - return false; |
|
104 | - }); |
|
105 | - // array of valid policy OIDs |
|
106 | - $valid_policy_set = array_map( |
|
107 | - function (PolicyNode $node) { |
|
108 | - return $node->validPolicy(); |
|
109 | - }, $valid_policy_node_set); |
|
110 | - // 3. If the valid_policy_tree includes a node of depth n with |
|
111 | - // the valid_policy anyPolicy and the user-initial-policy-set |
|
112 | - // is not any-policy |
|
113 | - foreach ($tree->_nodesAtDepth($state->index()) as $node) { |
|
114 | - if ($node->hasParent() && $node->isAnyPolicy()) { |
|
115 | - // a. Set P-Q to the qualifier_set in the node of depth n |
|
116 | - // with valid_policy anyPolicy. |
|
117 | - $pq = $node->qualifiers(); |
|
118 | - // b. For each P-OID in the user-initial-policy-set that is not |
|
119 | - // the valid_policy of a node in the valid_policy_node_set, |
|
120 | - // create a child node whose parent is the node of depth n-1 |
|
121 | - // with the valid_policy anyPolicy. |
|
122 | - $poids = array_diff($policies, $valid_policy_set); |
|
123 | - foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) { |
|
124 | - if ($parent->isAnyPolicy()) { |
|
125 | - // Set the values in the child node as follows: |
|
126 | - // set the valid_policy to P-OID, set the qualifier_set |
|
127 | - // to P-Q, and set the expected_policy_set to {P-OID}. |
|
128 | - foreach ($poids as $poid) { |
|
129 | - $parent->addChild( |
|
130 | - new PolicyNode($poid, $pq, array($poid))); |
|
131 | - } |
|
132 | - break; |
|
133 | - } |
|
134 | - } |
|
135 | - // c. Delete the node of depth n with the |
|
136 | - // valid_policy anyPolicy. |
|
137 | - $node->remove(); |
|
138 | - } |
|
139 | - } |
|
140 | - // 4. If there is a node in the valid_policy_tree of depth n-1 or less |
|
141 | - // without any child nodes, delete that node. Repeat this step until |
|
142 | - // there are no nodes of depth n-1 or less without children. |
|
143 | - if (!$tree->_pruneTree($state->index() - 1)) { |
|
144 | - return $state->withoutValidPolicyTree(); |
|
145 | - } |
|
146 | - return $state->withValidPolicyTree($tree); |
|
147 | - } |
|
80 | + /** |
|
81 | + * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
|
82 | + * |
|
83 | + * @param ValidatorState $state |
|
84 | + * @param array $policies |
|
85 | + * @return ValidatorState |
|
86 | + */ |
|
87 | + public function calculateIntersection(ValidatorState $state, array $policies) |
|
88 | + { |
|
89 | + $tree = clone $this; |
|
90 | + $valid_policy_node_set = $tree->_validPolicyNodeSet(); |
|
91 | + // 2. If the valid_policy of any node in the valid_policy_node_set |
|
92 | + // is not in the user-initial-policy-set and is not anyPolicy, |
|
93 | + // delete this node and all its children. |
|
94 | + $valid_policy_node_set = array_filter($valid_policy_node_set, |
|
95 | + function (PolicyNode $node) use ($policies) { |
|
96 | + if ($node->isAnyPolicy()) { |
|
97 | + return true; |
|
98 | + } |
|
99 | + if (in_array($node->validPolicy(), $policies)) { |
|
100 | + return true; |
|
101 | + } |
|
102 | + $node->remove(); |
|
103 | + return false; |
|
104 | + }); |
|
105 | + // array of valid policy OIDs |
|
106 | + $valid_policy_set = array_map( |
|
107 | + function (PolicyNode $node) { |
|
108 | + return $node->validPolicy(); |
|
109 | + }, $valid_policy_node_set); |
|
110 | + // 3. If the valid_policy_tree includes a node of depth n with |
|
111 | + // the valid_policy anyPolicy and the user-initial-policy-set |
|
112 | + // is not any-policy |
|
113 | + foreach ($tree->_nodesAtDepth($state->index()) as $node) { |
|
114 | + if ($node->hasParent() && $node->isAnyPolicy()) { |
|
115 | + // a. Set P-Q to the qualifier_set in the node of depth n |
|
116 | + // with valid_policy anyPolicy. |
|
117 | + $pq = $node->qualifiers(); |
|
118 | + // b. For each P-OID in the user-initial-policy-set that is not |
|
119 | + // the valid_policy of a node in the valid_policy_node_set, |
|
120 | + // create a child node whose parent is the node of depth n-1 |
|
121 | + // with the valid_policy anyPolicy. |
|
122 | + $poids = array_diff($policies, $valid_policy_set); |
|
123 | + foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) { |
|
124 | + if ($parent->isAnyPolicy()) { |
|
125 | + // Set the values in the child node as follows: |
|
126 | + // set the valid_policy to P-OID, set the qualifier_set |
|
127 | + // to P-Q, and set the expected_policy_set to {P-OID}. |
|
128 | + foreach ($poids as $poid) { |
|
129 | + $parent->addChild( |
|
130 | + new PolicyNode($poid, $pq, array($poid))); |
|
131 | + } |
|
132 | + break; |
|
133 | + } |
|
134 | + } |
|
135 | + // c. Delete the node of depth n with the |
|
136 | + // valid_policy anyPolicy. |
|
137 | + $node->remove(); |
|
138 | + } |
|
139 | + } |
|
140 | + // 4. If there is a node in the valid_policy_tree of depth n-1 or less |
|
141 | + // without any child nodes, delete that node. Repeat this step until |
|
142 | + // there are no nodes of depth n-1 or less without children. |
|
143 | + if (!$tree->_pruneTree($state->index() - 1)) { |
|
144 | + return $state->withoutValidPolicyTree(); |
|
145 | + } |
|
146 | + return $state->withValidPolicyTree($tree); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Get policies at given policy tree depth. |
|
151 | - * |
|
152 | - * @param int $i Depth in range 1..n |
|
153 | - * @return PolicyInformation[] |
|
154 | - */ |
|
155 | - public function policiesAtDepth($i) |
|
156 | - { |
|
157 | - $policies = array(); |
|
158 | - foreach ($this->_nodesAtDepth($i) as $node) { |
|
159 | - $policies[] = new PolicyInformation($node->validPolicy(), |
|
160 | - ...$node->qualifiers()); |
|
161 | - } |
|
162 | - return $policies; |
|
163 | - } |
|
149 | + /** |
|
150 | + * Get policies at given policy tree depth. |
|
151 | + * |
|
152 | + * @param int $i Depth in range 1..n |
|
153 | + * @return PolicyInformation[] |
|
154 | + */ |
|
155 | + public function policiesAtDepth($i) |
|
156 | + { |
|
157 | + $policies = array(); |
|
158 | + foreach ($this->_nodesAtDepth($i) as $node) { |
|
159 | + $policies[] = new PolicyInformation($node->validPolicy(), |
|
160 | + ...$node->qualifiers()); |
|
161 | + } |
|
162 | + return $policies; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Process single policy information. |
|
167 | - * |
|
168 | - * @param PolicyInformation $policy |
|
169 | - * @param ValidatorState $state |
|
170 | - */ |
|
171 | - protected function _processPolicy(PolicyInformation $policy, |
|
172 | - ValidatorState $state) |
|
173 | - { |
|
174 | - $p_oid = $policy->oid(); |
|
175 | - $i = $state->index(); |
|
176 | - $match_count = 0; |
|
177 | - // (d.1.i) for each node of depth i-1 in the valid_policy_tree... |
|
178 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
179 | - // ...where P-OID is in the expected_policy_set |
|
180 | - if ($node->hasExpectedPolicy($p_oid)) { |
|
181 | - $node->addChild( |
|
182 | - new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid))); |
|
183 | - ++$match_count; |
|
184 | - } |
|
185 | - } |
|
186 | - // (d.1.ii) if there was no match in step (i)... |
|
187 | - if (!$match_count) { |
|
188 | - // ...and the valid_policy_tree includes a node of depth i-1 with |
|
189 | - // the valid_policy anyPolicy |
|
190 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
191 | - if ($node->isAnyPolicy()) { |
|
192 | - $node->addChild( |
|
193 | - new PolicyNode($p_oid, $policy->qualifiers(), |
|
194 | - array($p_oid))); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
165 | + /** |
|
166 | + * Process single policy information. |
|
167 | + * |
|
168 | + * @param PolicyInformation $policy |
|
169 | + * @param ValidatorState $state |
|
170 | + */ |
|
171 | + protected function _processPolicy(PolicyInformation $policy, |
|
172 | + ValidatorState $state) |
|
173 | + { |
|
174 | + $p_oid = $policy->oid(); |
|
175 | + $i = $state->index(); |
|
176 | + $match_count = 0; |
|
177 | + // (d.1.i) for each node of depth i-1 in the valid_policy_tree... |
|
178 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
179 | + // ...where P-OID is in the expected_policy_set |
|
180 | + if ($node->hasExpectedPolicy($p_oid)) { |
|
181 | + $node->addChild( |
|
182 | + new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid))); |
|
183 | + ++$match_count; |
|
184 | + } |
|
185 | + } |
|
186 | + // (d.1.ii) if there was no match in step (i)... |
|
187 | + if (!$match_count) { |
|
188 | + // ...and the valid_policy_tree includes a node of depth i-1 with |
|
189 | + // the valid_policy anyPolicy |
|
190 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
191 | + if ($node->isAnyPolicy()) { |
|
192 | + $node->addChild( |
|
193 | + new PolicyNode($p_oid, $policy->qualifiers(), |
|
194 | + array($p_oid))); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Process anyPolicy policy information. |
|
202 | - * |
|
203 | - * @param PolicyInformation $policy |
|
204 | - * @param Certificate $cert |
|
205 | - * @param ValidatorState $state |
|
206 | - */ |
|
207 | - protected function _processAnyPolicy(PolicyInformation $policy, |
|
208 | - Certificate $cert, ValidatorState $state) |
|
209 | - { |
|
210 | - $i = $state->index(); |
|
211 | - // if (a) inhibit_anyPolicy is greater than 0 or |
|
212 | - // (b) i<n and the certificate is self-issued |
|
213 | - if (!($state->inhibitAnyPolicy() > 0 || |
|
214 | - ($i < $state->pathLength() && $cert->isSelfIssued()))) { |
|
215 | - return; |
|
216 | - } |
|
217 | - // for each node in the valid_policy_tree of depth i-1 |
|
218 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
219 | - // for each value in the expected_policy_set |
|
220 | - foreach ($node->expectedPolicies() as $p_oid) { |
|
221 | - // that does not appear in a child node |
|
222 | - if (!$node->hasChildWithValidPolicy($p_oid)) { |
|
223 | - $node->addChild( |
|
224 | - new PolicyNode($p_oid, $policy->qualifiers(), |
|
225 | - array($p_oid))); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
200 | + /** |
|
201 | + * Process anyPolicy policy information. |
|
202 | + * |
|
203 | + * @param PolicyInformation $policy |
|
204 | + * @param Certificate $cert |
|
205 | + * @param ValidatorState $state |
|
206 | + */ |
|
207 | + protected function _processAnyPolicy(PolicyInformation $policy, |
|
208 | + Certificate $cert, ValidatorState $state) |
|
209 | + { |
|
210 | + $i = $state->index(); |
|
211 | + // if (a) inhibit_anyPolicy is greater than 0 or |
|
212 | + // (b) i<n and the certificate is self-issued |
|
213 | + if (!($state->inhibitAnyPolicy() > 0 || |
|
214 | + ($i < $state->pathLength() && $cert->isSelfIssued()))) { |
|
215 | + return; |
|
216 | + } |
|
217 | + // for each node in the valid_policy_tree of depth i-1 |
|
218 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
219 | + // for each value in the expected_policy_set |
|
220 | + foreach ($node->expectedPolicies() as $p_oid) { |
|
221 | + // that does not appear in a child node |
|
222 | + if (!$node->hasChildWithValidPolicy($p_oid)) { |
|
223 | + $node->addChild( |
|
224 | + new PolicyNode($p_oid, $policy->qualifiers(), |
|
225 | + array($p_oid))); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * Apply policy mappings to the policy tree. |
|
233 | - * |
|
234 | - * @param Certificate $cert |
|
235 | - * @param ValidatorState $state |
|
236 | - */ |
|
237 | - protected function _applyMappings(Certificate $cert, ValidatorState $state) |
|
238 | - { |
|
239 | - $policy_mappings = $cert->tbsCertificate() |
|
240 | - ->extensions() |
|
241 | - ->policyMappings(); |
|
242 | - // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i... |
|
243 | - foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) { |
|
244 | - $match_count = 0; |
|
245 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
246 | - // ...where ID-P is the valid_policy |
|
247 | - if ($node->validPolicy() == $idp) { |
|
248 | - // set expected_policy_set to the set of subjectDomainPolicy |
|
249 | - // values that are specified as equivalent to ID-P by |
|
250 | - // the policy mappings extension |
|
251 | - $node->setExpectedPolicies(...$sdps); |
|
252 | - ++$match_count; |
|
253 | - } |
|
254 | - } |
|
255 | - // if no node of depth i in the valid_policy_tree has |
|
256 | - // a valid_policy of ID-P... |
|
257 | - if (!$match_count) { |
|
258 | - $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
231 | + /** |
|
232 | + * Apply policy mappings to the policy tree. |
|
233 | + * |
|
234 | + * @param Certificate $cert |
|
235 | + * @param ValidatorState $state |
|
236 | + */ |
|
237 | + protected function _applyMappings(Certificate $cert, ValidatorState $state) |
|
238 | + { |
|
239 | + $policy_mappings = $cert->tbsCertificate() |
|
240 | + ->extensions() |
|
241 | + ->policyMappings(); |
|
242 | + // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i... |
|
243 | + foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) { |
|
244 | + $match_count = 0; |
|
245 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
246 | + // ...where ID-P is the valid_policy |
|
247 | + if ($node->validPolicy() == $idp) { |
|
248 | + // set expected_policy_set to the set of subjectDomainPolicy |
|
249 | + // values that are specified as equivalent to ID-P by |
|
250 | + // the policy mappings extension |
|
251 | + $node->setExpectedPolicies(...$sdps); |
|
252 | + ++$match_count; |
|
253 | + } |
|
254 | + } |
|
255 | + // if no node of depth i in the valid_policy_tree has |
|
256 | + // a valid_policy of ID-P... |
|
257 | + if (!$match_count) { |
|
258 | + $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1). |
|
265 | - * |
|
266 | - * @param Certificate $cert |
|
267 | - * @param ValidatorState $state |
|
268 | - * @param string $idp OID of the issuer domain policy |
|
269 | - * @param array $sdps Array of subject domain policy OIDs |
|
270 | - */ |
|
271 | - protected function _applyAnyPolicyMapping(Certificate $cert, |
|
272 | - ValidatorState $state, $idp, array $sdps) |
|
273 | - { |
|
274 | - // (6.1.4. b.1.) ...but there is a node of depth i with |
|
275 | - // a valid_policy of anyPolicy |
|
276 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
277 | - if ($node->isAnyPolicy()) { |
|
278 | - // then generate a child node of the node of depth i-1 |
|
279 | - // that has a valid_policy of anyPolicy as follows... |
|
280 | - foreach ($this->_nodesAtDepth($state->index() - 1) as $node) { |
|
281 | - if ($node->isAnyPolicy()) { |
|
282 | - // try to fetch qualifiers of anyPolicy certificate policy |
|
283 | - $qualifiers = array(); |
|
284 | - try { |
|
285 | - $qualifiers = $cert->tbsCertificate() |
|
286 | - ->extensions() |
|
287 | - ->certificatePolicies() |
|
288 | - ->anyPolicy() |
|
289 | - ->qualifiers(); |
|
290 | - } catch (\LogicException $e) { |
|
291 | - } |
|
292 | - $node->addChild( |
|
293 | - new PolicyNode($idp, $qualifiers, $sdps)); |
|
294 | - // bail after first anyPolicy has been processed |
|
295 | - break; |
|
296 | - } |
|
297 | - } |
|
298 | - // bail after first anyPolicy has been processed |
|
299 | - break; |
|
300 | - } |
|
301 | - } |
|
302 | - } |
|
263 | + /** |
|
264 | + * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1). |
|
265 | + * |
|
266 | + * @param Certificate $cert |
|
267 | + * @param ValidatorState $state |
|
268 | + * @param string $idp OID of the issuer domain policy |
|
269 | + * @param array $sdps Array of subject domain policy OIDs |
|
270 | + */ |
|
271 | + protected function _applyAnyPolicyMapping(Certificate $cert, |
|
272 | + ValidatorState $state, $idp, array $sdps) |
|
273 | + { |
|
274 | + // (6.1.4. b.1.) ...but there is a node of depth i with |
|
275 | + // a valid_policy of anyPolicy |
|
276 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
277 | + if ($node->isAnyPolicy()) { |
|
278 | + // then generate a child node of the node of depth i-1 |
|
279 | + // that has a valid_policy of anyPolicy as follows... |
|
280 | + foreach ($this->_nodesAtDepth($state->index() - 1) as $node) { |
|
281 | + if ($node->isAnyPolicy()) { |
|
282 | + // try to fetch qualifiers of anyPolicy certificate policy |
|
283 | + $qualifiers = array(); |
|
284 | + try { |
|
285 | + $qualifiers = $cert->tbsCertificate() |
|
286 | + ->extensions() |
|
287 | + ->certificatePolicies() |
|
288 | + ->anyPolicy() |
|
289 | + ->qualifiers(); |
|
290 | + } catch (\LogicException $e) { |
|
291 | + } |
|
292 | + $node->addChild( |
|
293 | + new PolicyNode($idp, $qualifiers, $sdps)); |
|
294 | + // bail after first anyPolicy has been processed |
|
295 | + break; |
|
296 | + } |
|
297 | + } |
|
298 | + // bail after first anyPolicy has been processed |
|
299 | + break; |
|
300 | + } |
|
301 | + } |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * Delete nodes as specified in 6.1.4 (b)(2). |
|
306 | - * |
|
307 | - * @param Certificate $cert |
|
308 | - * @param ValidatorState $state |
|
309 | - */ |
|
310 | - protected function _deleteMappings(Certificate $cert, ValidatorState $state) |
|
311 | - { |
|
312 | - $idps = $cert->tbsCertificate() |
|
313 | - ->extensions() |
|
314 | - ->policyMappings() |
|
315 | - ->issuerDomainPolicies(); |
|
316 | - // delete each node of depth i in the valid_policy_tree |
|
317 | - // where ID-P is the valid_policy |
|
318 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
319 | - if (in_array($node->validPolicy(), $idps)) { |
|
320 | - $node->remove(); |
|
321 | - } |
|
322 | - } |
|
323 | - $this->_pruneTree($state->index() - 1); |
|
324 | - } |
|
304 | + /** |
|
305 | + * Delete nodes as specified in 6.1.4 (b)(2). |
|
306 | + * |
|
307 | + * @param Certificate $cert |
|
308 | + * @param ValidatorState $state |
|
309 | + */ |
|
310 | + protected function _deleteMappings(Certificate $cert, ValidatorState $state) |
|
311 | + { |
|
312 | + $idps = $cert->tbsCertificate() |
|
313 | + ->extensions() |
|
314 | + ->policyMappings() |
|
315 | + ->issuerDomainPolicies(); |
|
316 | + // delete each node of depth i in the valid_policy_tree |
|
317 | + // where ID-P is the valid_policy |
|
318 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
319 | + if (in_array($node->validPolicy(), $idps)) { |
|
320 | + $node->remove(); |
|
321 | + } |
|
322 | + } |
|
323 | + $this->_pruneTree($state->index() - 1); |
|
324 | + } |
|
325 | 325 | |
326 | - /** |
|
327 | - * Prune tree starting from given depth. |
|
328 | - * |
|
329 | - * @param int $depth |
|
330 | - * @return int The number of nodes left in a tree |
|
331 | - */ |
|
332 | - protected function _pruneTree($depth) |
|
333 | - { |
|
334 | - for ($i = $depth; $i > 0; --$i) { |
|
335 | - foreach ($this->_nodesAtDepth($i) as $node) { |
|
336 | - if (!count($node)) { |
|
337 | - $node->remove(); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - // if root has no children left |
|
342 | - if (!count($this->_root)) { |
|
343 | - $this->_root = null; |
|
344 | - return 0; |
|
345 | - } |
|
346 | - return $this->_root->nodeCount(); |
|
347 | - } |
|
326 | + /** |
|
327 | + * Prune tree starting from given depth. |
|
328 | + * |
|
329 | + * @param int $depth |
|
330 | + * @return int The number of nodes left in a tree |
|
331 | + */ |
|
332 | + protected function _pruneTree($depth) |
|
333 | + { |
|
334 | + for ($i = $depth; $i > 0; --$i) { |
|
335 | + foreach ($this->_nodesAtDepth($i) as $node) { |
|
336 | + if (!count($node)) { |
|
337 | + $node->remove(); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + // if root has no children left |
|
342 | + if (!count($this->_root)) { |
|
343 | + $this->_root = null; |
|
344 | + return 0; |
|
345 | + } |
|
346 | + return $this->_root->nodeCount(); |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
350 | - * Get all nodes at given depth. |
|
351 | - * |
|
352 | - * @param int $i |
|
353 | - * @return PolicyNode[] |
|
354 | - */ |
|
355 | - protected function _nodesAtDepth($i) |
|
356 | - { |
|
357 | - if (!$this->_root) { |
|
358 | - return array(); |
|
359 | - } |
|
360 | - $depth = 0; |
|
361 | - $nodes = array($this->_root); |
|
362 | - while ($depth < $i) { |
|
363 | - $nodes = self::_gatherChildren(...$nodes); |
|
364 | - if (!count($nodes)) { |
|
365 | - break; |
|
366 | - } |
|
367 | - ++$depth; |
|
368 | - } |
|
369 | - return $nodes; |
|
370 | - } |
|
349 | + /** |
|
350 | + * Get all nodes at given depth. |
|
351 | + * |
|
352 | + * @param int $i |
|
353 | + * @return PolicyNode[] |
|
354 | + */ |
|
355 | + protected function _nodesAtDepth($i) |
|
356 | + { |
|
357 | + if (!$this->_root) { |
|
358 | + return array(); |
|
359 | + } |
|
360 | + $depth = 0; |
|
361 | + $nodes = array($this->_root); |
|
362 | + while ($depth < $i) { |
|
363 | + $nodes = self::_gatherChildren(...$nodes); |
|
364 | + if (!count($nodes)) { |
|
365 | + break; |
|
366 | + } |
|
367 | + ++$depth; |
|
368 | + } |
|
369 | + return $nodes; |
|
370 | + } |
|
371 | 371 | |
372 | - /** |
|
373 | - * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1. |
|
374 | - * |
|
375 | - * @return PolicyNode[] |
|
376 | - */ |
|
377 | - protected function _validPolicyNodeSet() |
|
378 | - { |
|
379 | - // 1. Determine the set of policy nodes whose parent nodes have |
|
380 | - // a valid_policy of anyPolicy. This is the valid_policy_node_set. |
|
381 | - $set = array(); |
|
382 | - if (!$this->_root) { |
|
383 | - return $set; |
|
384 | - } |
|
385 | - // for each node in a tree |
|
386 | - $this->_root->walkNodes( |
|
387 | - function (PolicyNode $node) use (&$set) { |
|
388 | - $parents = $node->parents(); |
|
389 | - // node has parents |
|
390 | - if (count($parents)) { |
|
391 | - // check that each ancestor is an anyPolicy node |
|
392 | - foreach ($parents as $ancestor) { |
|
393 | - if (!$ancestor->isAnyPolicy()) { |
|
394 | - return; |
|
395 | - } |
|
396 | - } |
|
397 | - $set[] = $node; |
|
398 | - } |
|
399 | - }); |
|
400 | - return $set; |
|
401 | - } |
|
372 | + /** |
|
373 | + * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1. |
|
374 | + * |
|
375 | + * @return PolicyNode[] |
|
376 | + */ |
|
377 | + protected function _validPolicyNodeSet() |
|
378 | + { |
|
379 | + // 1. Determine the set of policy nodes whose parent nodes have |
|
380 | + // a valid_policy of anyPolicy. This is the valid_policy_node_set. |
|
381 | + $set = array(); |
|
382 | + if (!$this->_root) { |
|
383 | + return $set; |
|
384 | + } |
|
385 | + // for each node in a tree |
|
386 | + $this->_root->walkNodes( |
|
387 | + function (PolicyNode $node) use (&$set) { |
|
388 | + $parents = $node->parents(); |
|
389 | + // node has parents |
|
390 | + if (count($parents)) { |
|
391 | + // check that each ancestor is an anyPolicy node |
|
392 | + foreach ($parents as $ancestor) { |
|
393 | + if (!$ancestor->isAnyPolicy()) { |
|
394 | + return; |
|
395 | + } |
|
396 | + } |
|
397 | + $set[] = $node; |
|
398 | + } |
|
399 | + }); |
|
400 | + return $set; |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * Gather all children of given nodes to a flattened array. |
|
405 | - * |
|
406 | - * @param PolicyNode ...$nodes |
|
407 | - * @return PolicyNode[] |
|
408 | - */ |
|
409 | - private static function _gatherChildren(PolicyNode ...$nodes) |
|
410 | - { |
|
411 | - $children = array(); |
|
412 | - foreach ($nodes as $node) { |
|
413 | - $children = array_merge($children, $node->children()); |
|
414 | - } |
|
415 | - return $children; |
|
416 | - } |
|
403 | + /** |
|
404 | + * Gather all children of given nodes to a flattened array. |
|
405 | + * |
|
406 | + * @param PolicyNode ...$nodes |
|
407 | + * @return PolicyNode[] |
|
408 | + */ |
|
409 | + private static function _gatherChildren(PolicyNode ...$nodes) |
|
410 | + { |
|
411 | + $children = array(); |
|
412 | + foreach ($nodes as $node) { |
|
413 | + $children = array_merge($children, $node->children()); |
|
414 | + } |
|
415 | + return $children; |
|
416 | + } |
|
417 | 417 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | // is not in the user-initial-policy-set and is not anyPolicy, |
93 | 93 | // delete this node and all its children. |
94 | 94 | $valid_policy_node_set = array_filter($valid_policy_node_set, |
95 | - function (PolicyNode $node) use ($policies) { |
|
95 | + function(PolicyNode $node) use ($policies) { |
|
96 | 96 | if ($node->isAnyPolicy()) { |
97 | 97 | return true; |
98 | 98 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | }); |
105 | 105 | // array of valid policy OIDs |
106 | 106 | $valid_policy_set = array_map( |
107 | - function (PolicyNode $node) { |
|
107 | + function(PolicyNode $node) { |
|
108 | 108 | return $node->validPolicy(); |
109 | 109 | }, $valid_policy_node_set); |
110 | 110 | // 3. If the valid_policy_tree includes a node of depth n with |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | // for each node in a tree |
386 | 386 | $this->_root->walkNodes( |
387 | - function (PolicyNode $node) use (&$set) { |
|
387 | + function(PolicyNode $node) use (&$set) { |
|
388 | 388 | $parents = $node->parents(); |
389 | 389 | // node has parents |
390 | 390 | if (count($parents)) { |
@@ -4,42 +4,42 @@ |
||
4 | 4 | |
5 | 5 | class IPv4Address extends IPAddress |
6 | 6 | { |
7 | - /** |
|
8 | - * Initialize from octets. |
|
9 | - * |
|
10 | - * @param string $octets |
|
11 | - * @throws \InvalidArgumentException |
|
12 | - * @return self |
|
13 | - */ |
|
14 | - public static function fromOctets($octets) |
|
15 | - { |
|
16 | - $mask = null; |
|
17 | - $bytes = unpack("C*", $octets); |
|
18 | - switch (count($bytes)) { |
|
19 | - case 4: |
|
20 | - $ip = implode(".", $bytes); |
|
21 | - break; |
|
22 | - case 8: |
|
23 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
24 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
25 | - break; |
|
26 | - default: |
|
27 | - throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
28 | - } |
|
29 | - return new self($ip, $mask); |
|
30 | - } |
|
7 | + /** |
|
8 | + * Initialize from octets. |
|
9 | + * |
|
10 | + * @param string $octets |
|
11 | + * @throws \InvalidArgumentException |
|
12 | + * @return self |
|
13 | + */ |
|
14 | + public static function fromOctets($octets) |
|
15 | + { |
|
16 | + $mask = null; |
|
17 | + $bytes = unpack("C*", $octets); |
|
18 | + switch (count($bytes)) { |
|
19 | + case 4: |
|
20 | + $ip = implode(".", $bytes); |
|
21 | + break; |
|
22 | + case 8: |
|
23 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
24 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
25 | + break; |
|
26 | + default: |
|
27 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
28 | + } |
|
29 | + return new self($ip, $mask); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * {@inheritdoc} |
|
35 | - */ |
|
36 | - protected function _octets() |
|
37 | - { |
|
38 | - $bytes = array_map("intval", explode(".", $this->_ip)); |
|
39 | - if (isset($this->_mask)) { |
|
40 | - $bytes = array_merge($bytes, |
|
41 | - array_map("intval", explode(".", $this->_mask))); |
|
42 | - } |
|
43 | - return pack("C*", ...$bytes); |
|
44 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * {@inheritdoc} |
|
35 | + */ |
|
36 | + protected function _octets() |
|
37 | + { |
|
38 | + $bytes = array_map("intval", explode(".", $this->_ip)); |
|
39 | + if (isset($this->_mask)) { |
|
40 | + $bytes = array_merge($bytes, |
|
41 | + array_map("intval", explode(".", $this->_mask))); |
|
42 | + } |
|
43 | + return pack("C*", ...$bytes); |
|
44 | + } |
|
45 | 45 | } |
@@ -16,15 +16,15 @@ |
||
16 | 16 | $mask = null; |
17 | 17 | $bytes = unpack("C*", $octets); |
18 | 18 | switch (count($bytes)) { |
19 | - case 4: |
|
20 | - $ip = implode(".", $bytes); |
|
21 | - break; |
|
22 | - case 8: |
|
23 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
24 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
25 | - break; |
|
26 | - default: |
|
27 | - throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
19 | + case 4: |
|
20 | + $ip = implode(".", $bytes); |
|
21 | + break; |
|
22 | + case 8: |
|
23 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
24 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
25 | + break; |
|
26 | + default: |
|
27 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
28 | 28 | } |
29 | 29 | return new self($ip, $mask); |
30 | 30 | } |
@@ -16,97 +16,97 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class IPAddress extends GeneralName |
18 | 18 | { |
19 | - /** |
|
20 | - * IP address. |
|
21 | - * |
|
22 | - * @var string $_ip |
|
23 | - */ |
|
24 | - protected $_ip; |
|
19 | + /** |
|
20 | + * IP address. |
|
21 | + * |
|
22 | + * @var string $_ip |
|
23 | + */ |
|
24 | + protected $_ip; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Subnet mask. |
|
28 | - * |
|
29 | - * @var string|null $_mask |
|
30 | - */ |
|
31 | - protected $_mask; |
|
26 | + /** |
|
27 | + * Subnet mask. |
|
28 | + * |
|
29 | + * @var string|null $_mask |
|
30 | + */ |
|
31 | + protected $_mask; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Get octet representation of the IP address. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - abstract protected function _octets(); |
|
33 | + /** |
|
34 | + * Get octet representation of the IP address. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + abstract protected function _octets(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param string $ip |
|
44 | - * @param string|null $mask |
|
45 | - */ |
|
46 | - public function __construct($ip, $mask = null) |
|
47 | - { |
|
48 | - $this->_tag = self::TAG_IP_ADDRESS; |
|
49 | - $this->_ip = $ip; |
|
50 | - $this->_mask = $mask; |
|
51 | - } |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param string $ip |
|
44 | + * @param string|null $mask |
|
45 | + */ |
|
46 | + public function __construct($ip, $mask = null) |
|
47 | + { |
|
48 | + $this->_tag = self::TAG_IP_ADDRESS; |
|
49 | + $this->_ip = $ip; |
|
50 | + $this->_mask = $mask; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * @param UnspecifiedType $el |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
59 | - { |
|
60 | - $octets = $el->asOctetString()->string(); |
|
61 | - switch (strlen($octets)) { |
|
62 | - case 4: |
|
63 | - case 8: |
|
64 | - return IPv4Address::fromOctets($octets); |
|
65 | - case 16: |
|
66 | - case 32: |
|
67 | - return IPv6Address::fromOctets($octets); |
|
68 | - default: |
|
69 | - throw new \UnexpectedValueException( |
|
70 | - "Invalid octet length for IP address."); |
|
71 | - } |
|
72 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * @param UnspecifiedType $el |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
59 | + { |
|
60 | + $octets = $el->asOctetString()->string(); |
|
61 | + switch (strlen($octets)) { |
|
62 | + case 4: |
|
63 | + case 8: |
|
64 | + return IPv4Address::fromOctets($octets); |
|
65 | + case 16: |
|
66 | + case 32: |
|
67 | + return IPv6Address::fromOctets($octets); |
|
68 | + default: |
|
69 | + throw new \UnexpectedValueException( |
|
70 | + "Invalid octet length for IP address."); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * |
|
76 | - * {@inheritdoc} |
|
77 | - */ |
|
78 | - public function string() |
|
79 | - { |
|
80 | - return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
81 | - } |
|
74 | + /** |
|
75 | + * |
|
76 | + * {@inheritdoc} |
|
77 | + */ |
|
78 | + public function string() |
|
79 | + { |
|
80 | + return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Get IP address as a string. |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function address() |
|
89 | - { |
|
90 | - return $this->_ip; |
|
91 | - } |
|
83 | + /** |
|
84 | + * Get IP address as a string. |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function address() |
|
89 | + { |
|
90 | + return $this->_ip; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get subnet mask as a string. |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function mask() |
|
99 | - { |
|
100 | - return $this->_mask; |
|
101 | - } |
|
93 | + /** |
|
94 | + * Get subnet mask as a string. |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function mask() |
|
99 | + { |
|
100 | + return $this->_mask; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * |
|
105 | - * {@inheritdoc} |
|
106 | - */ |
|
107 | - protected function _choiceASN1() |
|
108 | - { |
|
109 | - return new ImplicitlyTaggedType($this->_tag, |
|
110 | - new OctetString($this->_octets())); |
|
111 | - } |
|
103 | + /** |
|
104 | + * |
|
105 | + * {@inheritdoc} |
|
106 | + */ |
|
107 | + protected function _choiceASN1() |
|
108 | + { |
|
109 | + return new ImplicitlyTaggedType($this->_tag, |
|
110 | + new OctetString($this->_octets())); |
|
111 | + } |
|
112 | 112 | } |
@@ -59,15 +59,15 @@ |
||
59 | 59 | { |
60 | 60 | $octets = $el->asOctetString()->string(); |
61 | 61 | switch (strlen($octets)) { |
62 | - case 4: |
|
63 | - case 8: |
|
64 | - return IPv4Address::fromOctets($octets); |
|
65 | - case 16: |
|
66 | - case 32: |
|
67 | - return IPv6Address::fromOctets($octets); |
|
68 | - default: |
|
69 | - throw new \UnexpectedValueException( |
|
70 | - "Invalid octet length for IP address."); |
|
62 | + case 4: |
|
63 | + case 8: |
|
64 | + return IPv4Address::fromOctets($octets); |
|
65 | + case 16: |
|
66 | + case 32: |
|
67 | + return IPv6Address::fromOctets($octets); |
|
68 | + default: |
|
69 | + throw new \UnexpectedValueException( |
|
70 | + "Invalid octet length for IP address."); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 |
@@ -14,59 +14,59 @@ |
||
14 | 14 | */ |
15 | 15 | class UniformResourceIdentifier extends GeneralName |
16 | 16 | { |
17 | - /** |
|
18 | - * URI. |
|
19 | - * |
|
20 | - * @var string $_uri |
|
21 | - */ |
|
22 | - protected $_uri; |
|
17 | + /** |
|
18 | + * URI. |
|
19 | + * |
|
20 | + * @var string $_uri |
|
21 | + */ |
|
22 | + protected $_uri; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - * |
|
27 | - * @param string $uri |
|
28 | - */ |
|
29 | - public function __construct($uri) |
|
30 | - { |
|
31 | - $this->_tag = self::TAG_URI; |
|
32 | - $this->_uri = $uri; |
|
33 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + * |
|
27 | + * @param string $uri |
|
28 | + */ |
|
29 | + public function __construct($uri) |
|
30 | + { |
|
31 | + $this->_tag = self::TAG_URI; |
|
32 | + $this->_uri = $uri; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * @param UnspecifiedType $el |
|
38 | - * @return self |
|
39 | - */ |
|
40 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
41 | - { |
|
42 | - return new self($el->asIA5String()->string()); |
|
43 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * @param UnspecifiedType $el |
|
38 | + * @return self |
|
39 | + */ |
|
40 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
41 | + { |
|
42 | + return new self($el->asIA5String()->string()); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * |
|
47 | - * {@inheritdoc} |
|
48 | - */ |
|
49 | - public function string() |
|
50 | - { |
|
51 | - return $this->_uri; |
|
52 | - } |
|
45 | + /** |
|
46 | + * |
|
47 | + * {@inheritdoc} |
|
48 | + */ |
|
49 | + public function string() |
|
50 | + { |
|
51 | + return $this->_uri; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Get URI. |
|
56 | - * |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function uri() |
|
60 | - { |
|
61 | - return $this->_uri; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Get URI. |
|
56 | + * |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function uri() |
|
60 | + { |
|
61 | + return $this->_uri; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - protected function _choiceASN1() |
|
69 | - { |
|
70 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
71 | - } |
|
64 | + /** |
|
65 | + * |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + protected function _choiceASN1() |
|
69 | + { |
|
70 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
71 | + } |
|
72 | 72 | } |
@@ -13,59 +13,59 @@ |
||
13 | 13 | */ |
14 | 14 | class DNSName extends GeneralName |
15 | 15 | { |
16 | - /** |
|
17 | - * DNS name. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $_name; |
|
16 | + /** |
|
17 | + * DNS name. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $_name; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param string $name Domain name |
|
27 | - */ |
|
28 | - public function __construct($name) |
|
29 | - { |
|
30 | - $this->_tag = self::TAG_DNS_NAME; |
|
31 | - $this->_name = $name; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param string $name Domain name |
|
27 | + */ |
|
28 | + public function __construct($name) |
|
29 | + { |
|
30 | + $this->_tag = self::TAG_DNS_NAME; |
|
31 | + $this->_name = $name; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param UnspecifiedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | - { |
|
41 | - return new self($el->asIA5String()->string()); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + return new self($el->asIA5String()->string()); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_name; |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_name; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get DNS name. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function name() |
|
59 | - { |
|
60 | - return $this->_name; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get DNS name. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function name() |
|
59 | + { |
|
60 | + return $this->_name; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - protected function _choiceASN1() |
|
68 | - { |
|
69 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name)); |
|
70 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + protected function _choiceASN1() |
|
68 | + { |
|
69 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name)); |
|
70 | + } |
|
71 | 71 | } |
@@ -15,47 +15,47 @@ |
||
15 | 15 | */ |
16 | 16 | class EDIPartyName extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * |
|
20 | - * @var \ASN1\Element |
|
21 | - */ |
|
22 | - protected $_element; |
|
18 | + /** |
|
19 | + * |
|
20 | + * @var \ASN1\Element |
|
21 | + */ |
|
22 | + protected $_element; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - */ |
|
27 | - protected function __construct() |
|
28 | - { |
|
29 | - $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
30 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + */ |
|
27 | + protected function __construct() |
|
28 | + { |
|
29 | + $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @param UnspecifiedType $el |
|
35 | - * @return self |
|
36 | - */ |
|
37 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | - { |
|
39 | - $obj = new self(); |
|
40 | - $obj->_element = $el->asSequence(); |
|
41 | - return $obj; |
|
42 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * @param UnspecifiedType $el |
|
35 | + * @return self |
|
36 | + */ |
|
37 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | + { |
|
39 | + $obj = new self(); |
|
40 | + $obj->_element = $el->asSequence(); |
|
41 | + return $obj; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return bin2hex($this->_element->toDER()); |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return bin2hex($this->_element->toDER()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - protected function _choiceASN1() |
|
58 | - { |
|
59 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + protected function _choiceASN1() |
|
58 | + { |
|
59 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | + } |
|
61 | 61 | } |
@@ -15,183 +15,183 @@ |
||
15 | 15 | */ |
16 | 16 | class GeneralNames implements \Countable, \IteratorAggregate |
17 | 17 | { |
18 | - /** |
|
19 | - * GeneralName objects. |
|
20 | - * |
|
21 | - * @var GeneralName[] $_names |
|
22 | - */ |
|
23 | - protected $_names; |
|
18 | + /** |
|
19 | + * GeneralName objects. |
|
20 | + * |
|
21 | + * @var GeneralName[] $_names |
|
22 | + */ |
|
23 | + protected $_names; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param GeneralName ...$names One or more GeneralName objects |
|
29 | - */ |
|
30 | - public function __construct(GeneralName ...$names) |
|
31 | - { |
|
32 | - $this->_names = $names; |
|
33 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param GeneralName ...$names One or more GeneralName objects |
|
29 | + */ |
|
30 | + public function __construct(GeneralName ...$names) |
|
31 | + { |
|
32 | + $this->_names = $names; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Initialize from ASN.1. |
|
37 | - * |
|
38 | - * @param Sequence $seq |
|
39 | - * @throws \UnexpectedValueException |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - public static function fromASN1(Sequence $seq) |
|
43 | - { |
|
44 | - if (!count($seq)) { |
|
45 | - throw new \UnexpectedValueException( |
|
46 | - "GeneralNames must have at least one GeneralName."); |
|
47 | - } |
|
48 | - $names = array_map( |
|
49 | - function (UnspecifiedType $el) { |
|
50 | - return GeneralName::fromASN1($el->asTagged()); |
|
51 | - }, $seq->elements()); |
|
52 | - return new self(...$names); |
|
53 | - } |
|
35 | + /** |
|
36 | + * Initialize from ASN.1. |
|
37 | + * |
|
38 | + * @param Sequence $seq |
|
39 | + * @throws \UnexpectedValueException |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + public static function fromASN1(Sequence $seq) |
|
43 | + { |
|
44 | + if (!count($seq)) { |
|
45 | + throw new \UnexpectedValueException( |
|
46 | + "GeneralNames must have at least one GeneralName."); |
|
47 | + } |
|
48 | + $names = array_map( |
|
49 | + function (UnspecifiedType $el) { |
|
50 | + return GeneralName::fromASN1($el->asTagged()); |
|
51 | + }, $seq->elements()); |
|
52 | + return new self(...$names); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Find first GeneralName by given tag. |
|
57 | - * |
|
58 | - * @param int $tag |
|
59 | - * @return GeneralName|null |
|
60 | - */ |
|
61 | - protected function _findFirst($tag) |
|
62 | - { |
|
63 | - foreach ($this->_names as $name) { |
|
64 | - if ($name->tag() == $tag) { |
|
65 | - return $name; |
|
66 | - } |
|
67 | - } |
|
68 | - return null; |
|
69 | - } |
|
55 | + /** |
|
56 | + * Find first GeneralName by given tag. |
|
57 | + * |
|
58 | + * @param int $tag |
|
59 | + * @return GeneralName|null |
|
60 | + */ |
|
61 | + protected function _findFirst($tag) |
|
62 | + { |
|
63 | + foreach ($this->_names as $name) { |
|
64 | + if ($name->tag() == $tag) { |
|
65 | + return $name; |
|
66 | + } |
|
67 | + } |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Check whether GeneralNames contains a GeneralName of given type. |
|
73 | - * |
|
74 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function has($tag) |
|
78 | - { |
|
79 | - return null !== $this->_findFirst($tag); |
|
80 | - } |
|
71 | + /** |
|
72 | + * Check whether GeneralNames contains a GeneralName of given type. |
|
73 | + * |
|
74 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function has($tag) |
|
78 | + { |
|
79 | + return null !== $this->_findFirst($tag); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Get first GeneralName of given type. |
|
84 | - * |
|
85 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
86 | - * @throws \OutOfBoundsException |
|
87 | - * @return GeneralName |
|
88 | - */ |
|
89 | - public function firstOf($tag) |
|
90 | - { |
|
91 | - $name = $this->_findFirst($tag); |
|
92 | - if (!$name) { |
|
93 | - throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
94 | - } |
|
95 | - return $name; |
|
96 | - } |
|
82 | + /** |
|
83 | + * Get first GeneralName of given type. |
|
84 | + * |
|
85 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
86 | + * @throws \OutOfBoundsException |
|
87 | + * @return GeneralName |
|
88 | + */ |
|
89 | + public function firstOf($tag) |
|
90 | + { |
|
91 | + $name = $this->_findFirst($tag); |
|
92 | + if (!$name) { |
|
93 | + throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
94 | + } |
|
95 | + return $name; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get all GeneralName objects of given type. |
|
100 | - * |
|
101 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
102 | - * @return GeneralName[] |
|
103 | - */ |
|
104 | - public function allOf($tag) |
|
105 | - { |
|
106 | - $names = array_filter($this->_names, |
|
107 | - function (GeneralName $name) use ($tag) { |
|
108 | - return $name->tag() == $tag; |
|
109 | - }); |
|
110 | - return array_values($names); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Get all GeneralName objects of given type. |
|
100 | + * |
|
101 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
102 | + * @return GeneralName[] |
|
103 | + */ |
|
104 | + public function allOf($tag) |
|
105 | + { |
|
106 | + $names = array_filter($this->_names, |
|
107 | + function (GeneralName $name) use ($tag) { |
|
108 | + return $name->tag() == $tag; |
|
109 | + }); |
|
110 | + return array_values($names); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get value of the first 'dNSName' type. |
|
115 | - * |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function firstDNS() |
|
119 | - { |
|
120 | - $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
121 | - if (!$gn instanceof DNSName) { |
|
122 | - throw new \RuntimeException( |
|
123 | - DNSName::class . " expected, got " . get_class($gn)); |
|
124 | - } |
|
125 | - return $gn->name(); |
|
126 | - } |
|
113 | + /** |
|
114 | + * Get value of the first 'dNSName' type. |
|
115 | + * |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function firstDNS() |
|
119 | + { |
|
120 | + $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
121 | + if (!$gn instanceof DNSName) { |
|
122 | + throw new \RuntimeException( |
|
123 | + DNSName::class . " expected, got " . get_class($gn)); |
|
124 | + } |
|
125 | + return $gn->name(); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Get value of the first 'directoryName' type. |
|
130 | - * |
|
131 | - * @return \X501\ASN1\Name |
|
132 | - */ |
|
133 | - public function firstDN() |
|
134 | - { |
|
135 | - $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
136 | - if (!$gn instanceof DirectoryName) { |
|
137 | - throw new \RuntimeException( |
|
138 | - DirectoryName::class . " expected, got " . get_class($gn)); |
|
139 | - } |
|
140 | - return $gn->dn(); |
|
141 | - } |
|
128 | + /** |
|
129 | + * Get value of the first 'directoryName' type. |
|
130 | + * |
|
131 | + * @return \X501\ASN1\Name |
|
132 | + */ |
|
133 | + public function firstDN() |
|
134 | + { |
|
135 | + $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
136 | + if (!$gn instanceof DirectoryName) { |
|
137 | + throw new \RuntimeException( |
|
138 | + DirectoryName::class . " expected, got " . get_class($gn)); |
|
139 | + } |
|
140 | + return $gn->dn(); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Get value of the first 'uniformResourceIdentifier' type. |
|
145 | - * |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function firstURI() |
|
149 | - { |
|
150 | - $gn = $this->firstOf(GeneralName::TAG_URI); |
|
151 | - if (!$gn instanceof UniformResourceIdentifier) { |
|
152 | - throw new \RuntimeException( |
|
153 | - UniformResourceIdentifier::class . " expected, got " . |
|
154 | - get_class($gn)); |
|
155 | - } |
|
156 | - return $gn->uri(); |
|
157 | - } |
|
143 | + /** |
|
144 | + * Get value of the first 'uniformResourceIdentifier' type. |
|
145 | + * |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function firstURI() |
|
149 | + { |
|
150 | + $gn = $this->firstOf(GeneralName::TAG_URI); |
|
151 | + if (!$gn instanceof UniformResourceIdentifier) { |
|
152 | + throw new \RuntimeException( |
|
153 | + UniformResourceIdentifier::class . " expected, got " . |
|
154 | + get_class($gn)); |
|
155 | + } |
|
156 | + return $gn->uri(); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Generate ASN.1 structure. |
|
161 | - * |
|
162 | - * @return Sequence |
|
163 | - */ |
|
164 | - public function toASN1() |
|
165 | - { |
|
166 | - if (!count($this->_names)) { |
|
167 | - throw new \LogicException( |
|
168 | - "GeneralNames must have at least one GeneralName."); |
|
169 | - } |
|
170 | - $elements = array_map( |
|
171 | - function (GeneralName $name) { |
|
172 | - return $name->toASN1(); |
|
173 | - }, $this->_names); |
|
174 | - return new Sequence(...$elements); |
|
175 | - } |
|
159 | + /** |
|
160 | + * Generate ASN.1 structure. |
|
161 | + * |
|
162 | + * @return Sequence |
|
163 | + */ |
|
164 | + public function toASN1() |
|
165 | + { |
|
166 | + if (!count($this->_names)) { |
|
167 | + throw new \LogicException( |
|
168 | + "GeneralNames must have at least one GeneralName."); |
|
169 | + } |
|
170 | + $elements = array_map( |
|
171 | + function (GeneralName $name) { |
|
172 | + return $name->toASN1(); |
|
173 | + }, $this->_names); |
|
174 | + return new Sequence(...$elements); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * |
|
179 | - * @see \Countable::count() |
|
180 | - * @return int |
|
181 | - */ |
|
182 | - public function count() |
|
183 | - { |
|
184 | - return count($this->_names); |
|
185 | - } |
|
177 | + /** |
|
178 | + * |
|
179 | + * @see \Countable::count() |
|
180 | + * @return int |
|
181 | + */ |
|
182 | + public function count() |
|
183 | + { |
|
184 | + return count($this->_names); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Get iterator for GeneralName objects. |
|
189 | - * |
|
190 | - * @see \IteratorAggregate::getIterator() |
|
191 | - * @return \ArrayIterator |
|
192 | - */ |
|
193 | - public function getIterator() |
|
194 | - { |
|
195 | - return new \ArrayIterator($this->_names); |
|
196 | - } |
|
187 | + /** |
|
188 | + * Get iterator for GeneralName objects. |
|
189 | + * |
|
190 | + * @see \IteratorAggregate::getIterator() |
|
191 | + * @return \ArrayIterator |
|
192 | + */ |
|
193 | + public function getIterator() |
|
194 | + { |
|
195 | + return new \ArrayIterator($this->_names); |
|
196 | + } |
|
197 | 197 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | "GeneralNames must have at least one GeneralName."); |
47 | 47 | } |
48 | 48 | $names = array_map( |
49 | - function (UnspecifiedType $el) { |
|
49 | + function(UnspecifiedType $el) { |
|
50 | 50 | return GeneralName::fromASN1($el->asTagged()); |
51 | 51 | }, $seq->elements()); |
52 | 52 | return new self(...$names); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function allOf($tag) |
105 | 105 | { |
106 | 106 | $names = array_filter($this->_names, |
107 | - function (GeneralName $name) use ($tag) { |
|
107 | + function(GeneralName $name) use ($tag) { |
|
108 | 108 | return $name->tag() == $tag; |
109 | 109 | }); |
110 | 110 | return array_values($names); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | "GeneralNames must have at least one GeneralName."); |
169 | 169 | } |
170 | 170 | $elements = array_map( |
171 | - function (GeneralName $name) { |
|
171 | + function(GeneralName $name) { |
|
172 | 172 | return $name->toASN1(); |
173 | 173 | }, $this->_names); |
174 | 174 | return new Sequence(...$elements); |
@@ -13,59 +13,59 @@ |
||
13 | 13 | */ |
14 | 14 | class RFC822Name extends GeneralName |
15 | 15 | { |
16 | - /** |
|
17 | - * Email. |
|
18 | - * |
|
19 | - * @var string $_email |
|
20 | - */ |
|
21 | - protected $_email; |
|
16 | + /** |
|
17 | + * Email. |
|
18 | + * |
|
19 | + * @var string $_email |
|
20 | + */ |
|
21 | + protected $_email; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param string $email |
|
27 | - */ |
|
28 | - public function __construct($email) |
|
29 | - { |
|
30 | - $this->_tag = self::TAG_RFC822_NAME; |
|
31 | - $this->_email = $email; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param string $email |
|
27 | + */ |
|
28 | + public function __construct($email) |
|
29 | + { |
|
30 | + $this->_tag = self::TAG_RFC822_NAME; |
|
31 | + $this->_email = $email; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param UnspecifiedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | - { |
|
41 | - return new self($el->asIA5String()->string()); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + return new self($el->asIA5String()->string()); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_email; |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_email; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get email. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function email() |
|
59 | - { |
|
60 | - return $this->_email; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get email. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function email() |
|
59 | + { |
|
60 | + return $this->_email; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - protected function _choiceASN1() |
|
68 | - { |
|
69 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
70 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + protected function _choiceASN1() |
|
68 | + { |
|
69 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
70 | + } |
|
71 | 71 | } |