@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class AccessIdentityAttributeValue extends SvceAuthInfo |
13 | 13 | { |
14 | - const OID = "1.3.6.1.5.5.7.10.2"; |
|
14 | + const OID = "1.3.6.1.5.5.7.10.2"; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param GeneralName $service |
|
20 | - * @param GeneralName $ident |
|
21 | - */ |
|
22 | - public function __construct(GeneralName $service, GeneralName $ident) |
|
23 | - { |
|
24 | - parent::__construct($service, $ident, null); |
|
25 | - $this->_oid = self::OID; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param GeneralName $service |
|
20 | + * @param GeneralName $ident |
|
21 | + */ |
|
22 | + public function __construct(GeneralName $service, GeneralName $ident) |
|
23 | + { |
|
24 | + parent::__construct($service, $ident, null); |
|
25 | + $this->_oid = self::OID; |
|
26 | + } |
|
27 | 27 | } |
@@ -9,16 +9,16 @@ |
||
9 | 9 | */ |
10 | 10 | class GroupAttributeValue extends IetfAttrSyntax |
11 | 11 | { |
12 | - const OID = "1.3.6.1.5.5.7.10.4"; |
|
12 | + const OID = "1.3.6.1.5.5.7.10.4"; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Constructor. |
|
16 | - * |
|
17 | - * @param IetfAttrValue ...$values |
|
18 | - */ |
|
19 | - public function __construct(IetfAttrValue ...$values) |
|
20 | - { |
|
21 | - parent::__construct(...$values); |
|
22 | - $this->_oid = self::OID; |
|
23 | - } |
|
14 | + /** |
|
15 | + * Constructor. |
|
16 | + * |
|
17 | + * @param IetfAttrValue ...$values |
|
18 | + */ |
|
19 | + public function __construct(IetfAttrValue ...$values) |
|
20 | + { |
|
21 | + parent::__construct(...$values); |
|
22 | + $this->_oid = self::OID; |
|
23 | + } |
|
24 | 24 | } |
@@ -24,200 +24,200 @@ |
||
24 | 24 | */ |
25 | 25 | class Attributes implements \Countable, \IteratorAggregate |
26 | 26 | { |
27 | - use AttributeContainer; |
|
28 | - |
|
29 | - /** |
|
30 | - * Mapping from OID to attribute value class name. |
|
31 | - * |
|
32 | - * @internal |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - const MAP_OID_TO_CLASS = array( |
|
37 | - /* @formatter:off */ |
|
38 | - AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
39 | - AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
40 | - ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
41 | - GroupAttributeValue::OID => GroupAttributeValue::class, |
|
42 | - AttributeType::OID_ROLE => RoleAttributeValue::class |
|
43 | - /* @formatter:on */ |
|
44 | - ); |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor. |
|
48 | - * |
|
49 | - * @param Attribute ...$attribs |
|
50 | - */ |
|
51 | - public function __construct(Attribute ...$attribs) |
|
52 | - { |
|
53 | - $this->_attributes = $attribs; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Initialize from attribute values. |
|
58 | - * |
|
59 | - * @param AttributeValue ...$values |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - public static function fromAttributeValues(AttributeValue ...$values) |
|
63 | - { |
|
64 | - $attribs = array_map( |
|
65 | - function (AttributeValue $value) { |
|
66 | - return $value->toAttribute(); |
|
67 | - }, $values); |
|
68 | - return new self(...$attribs); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Initialize from ASN.1. |
|
73 | - * |
|
74 | - * @param Sequence $seq |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - public static function fromASN1(Sequence $seq) |
|
78 | - { |
|
79 | - $attribs = array_map( |
|
80 | - function (UnspecifiedType $el) { |
|
81 | - return Attribute::fromASN1($el->asSequence()); |
|
82 | - }, $seq->elements()); |
|
83 | - // cast attributes |
|
84 | - $attribs = array_map( |
|
85 | - function (Attribute $attr) { |
|
86 | - $oid = $attr->oid(); |
|
87 | - if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
88 | - $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
89 | - $attr = $attr->castValues($cls); |
|
90 | - } |
|
91 | - return $attr; |
|
92 | - }, $attribs); |
|
93 | - return new self(...$attribs); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Check whether 'Access Identity' attribute is present. |
|
98 | - * |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function hasAccessIdentity() |
|
102 | - { |
|
103 | - return $this->has(AccessIdentityAttributeValue::OID); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Get the first 'Access Identity' attribute value. |
|
108 | - * |
|
109 | - * @return AccessIdentityAttributeValue |
|
110 | - */ |
|
111 | - public function accessIdentity() |
|
112 | - { |
|
113 | - return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Check whether 'Service Authentication Information' attribute is present. |
|
118 | - * |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public function hasAuthenticationInformation() |
|
122 | - { |
|
123 | - return $this->has(AuthenticationInfoAttributeValue::OID); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Get the first 'Service Authentication Information' attribute value. |
|
128 | - * |
|
129 | - * @return AuthenticationInfoAttributeValue |
|
130 | - */ |
|
131 | - public function authenticationInformation() |
|
132 | - { |
|
133 | - return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Check whether 'Charging Identity' attribute is present. |
|
138 | - * |
|
139 | - * @return bool |
|
140 | - */ |
|
141 | - public function hasChargingIdentity() |
|
142 | - { |
|
143 | - return $this->has(ChargingIdentityAttributeValue::OID); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get the first 'Charging Identity' attribute value. |
|
148 | - * |
|
149 | - * @return ChargingIdentityAttributeValue |
|
150 | - */ |
|
151 | - public function chargingIdentity() |
|
152 | - { |
|
153 | - return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Check whether 'Group' attribute is present. |
|
158 | - * |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function hasGroup() |
|
162 | - { |
|
163 | - return $this->has(GroupAttributeValue::OID); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Get the first 'Group' attribute value. |
|
168 | - * |
|
169 | - * @return GroupAttributeValue |
|
170 | - */ |
|
171 | - public function group() |
|
172 | - { |
|
173 | - return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Check whether 'Role' attribute is present. |
|
178 | - * |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function hasRole() |
|
182 | - { |
|
183 | - return $this->has(AttributeType::OID_ROLE); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Get the first 'Role' attribute value. |
|
188 | - * |
|
189 | - * @return RoleAttributeValue |
|
190 | - */ |
|
191 | - public function role() |
|
192 | - { |
|
193 | - return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Get all 'Role' attribute values. |
|
198 | - * |
|
199 | - * @return RoleAttributeValue[] |
|
200 | - */ |
|
201 | - public function roles() |
|
202 | - { |
|
203 | - return array_merge(array(), |
|
204 | - ...array_map( |
|
205 | - function (Attribute $attr) { |
|
206 | - return $attr->values(); |
|
207 | - }, $this->allOf(AttributeType::OID_ROLE))); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Generate ASN.1 structure. |
|
212 | - * |
|
213 | - * @return Sequence |
|
214 | - */ |
|
215 | - public function toASN1() |
|
216 | - { |
|
217 | - $elements = array_map( |
|
218 | - function (Attribute $attr) { |
|
219 | - return $attr->toASN1(); |
|
220 | - }, array_values($this->_attributes)); |
|
221 | - return new Sequence(...$elements); |
|
222 | - } |
|
27 | + use AttributeContainer; |
|
28 | + |
|
29 | + /** |
|
30 | + * Mapping from OID to attribute value class name. |
|
31 | + * |
|
32 | + * @internal |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + const MAP_OID_TO_CLASS = array( |
|
37 | + /* @formatter:off */ |
|
38 | + AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
39 | + AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
40 | + ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
41 | + GroupAttributeValue::OID => GroupAttributeValue::class, |
|
42 | + AttributeType::OID_ROLE => RoleAttributeValue::class |
|
43 | + /* @formatter:on */ |
|
44 | + ); |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor. |
|
48 | + * |
|
49 | + * @param Attribute ...$attribs |
|
50 | + */ |
|
51 | + public function __construct(Attribute ...$attribs) |
|
52 | + { |
|
53 | + $this->_attributes = $attribs; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Initialize from attribute values. |
|
58 | + * |
|
59 | + * @param AttributeValue ...$values |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + public static function fromAttributeValues(AttributeValue ...$values) |
|
63 | + { |
|
64 | + $attribs = array_map( |
|
65 | + function (AttributeValue $value) { |
|
66 | + return $value->toAttribute(); |
|
67 | + }, $values); |
|
68 | + return new self(...$attribs); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Initialize from ASN.1. |
|
73 | + * |
|
74 | + * @param Sequence $seq |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + public static function fromASN1(Sequence $seq) |
|
78 | + { |
|
79 | + $attribs = array_map( |
|
80 | + function (UnspecifiedType $el) { |
|
81 | + return Attribute::fromASN1($el->asSequence()); |
|
82 | + }, $seq->elements()); |
|
83 | + // cast attributes |
|
84 | + $attribs = array_map( |
|
85 | + function (Attribute $attr) { |
|
86 | + $oid = $attr->oid(); |
|
87 | + if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
88 | + $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
89 | + $attr = $attr->castValues($cls); |
|
90 | + } |
|
91 | + return $attr; |
|
92 | + }, $attribs); |
|
93 | + return new self(...$attribs); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Check whether 'Access Identity' attribute is present. |
|
98 | + * |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function hasAccessIdentity() |
|
102 | + { |
|
103 | + return $this->has(AccessIdentityAttributeValue::OID); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Get the first 'Access Identity' attribute value. |
|
108 | + * |
|
109 | + * @return AccessIdentityAttributeValue |
|
110 | + */ |
|
111 | + public function accessIdentity() |
|
112 | + { |
|
113 | + return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Check whether 'Service Authentication Information' attribute is present. |
|
118 | + * |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public function hasAuthenticationInformation() |
|
122 | + { |
|
123 | + return $this->has(AuthenticationInfoAttributeValue::OID); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Get the first 'Service Authentication Information' attribute value. |
|
128 | + * |
|
129 | + * @return AuthenticationInfoAttributeValue |
|
130 | + */ |
|
131 | + public function authenticationInformation() |
|
132 | + { |
|
133 | + return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Check whether 'Charging Identity' attribute is present. |
|
138 | + * |
|
139 | + * @return bool |
|
140 | + */ |
|
141 | + public function hasChargingIdentity() |
|
142 | + { |
|
143 | + return $this->has(ChargingIdentityAttributeValue::OID); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get the first 'Charging Identity' attribute value. |
|
148 | + * |
|
149 | + * @return ChargingIdentityAttributeValue |
|
150 | + */ |
|
151 | + public function chargingIdentity() |
|
152 | + { |
|
153 | + return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Check whether 'Group' attribute is present. |
|
158 | + * |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function hasGroup() |
|
162 | + { |
|
163 | + return $this->has(GroupAttributeValue::OID); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Get the first 'Group' attribute value. |
|
168 | + * |
|
169 | + * @return GroupAttributeValue |
|
170 | + */ |
|
171 | + public function group() |
|
172 | + { |
|
173 | + return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Check whether 'Role' attribute is present. |
|
178 | + * |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function hasRole() |
|
182 | + { |
|
183 | + return $this->has(AttributeType::OID_ROLE); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Get the first 'Role' attribute value. |
|
188 | + * |
|
189 | + * @return RoleAttributeValue |
|
190 | + */ |
|
191 | + public function role() |
|
192 | + { |
|
193 | + return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Get all 'Role' attribute values. |
|
198 | + * |
|
199 | + * @return RoleAttributeValue[] |
|
200 | + */ |
|
201 | + public function roles() |
|
202 | + { |
|
203 | + return array_merge(array(), |
|
204 | + ...array_map( |
|
205 | + function (Attribute $attr) { |
|
206 | + return $attr->values(); |
|
207 | + }, $this->allOf(AttributeType::OID_ROLE))); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Generate ASN.1 structure. |
|
212 | + * |
|
213 | + * @return Sequence |
|
214 | + */ |
|
215 | + public function toASN1() |
|
216 | + { |
|
217 | + $elements = array_map( |
|
218 | + function (Attribute $attr) { |
|
219 | + return $attr->toASN1(); |
|
220 | + }, array_values($this->_attributes)); |
|
221 | + return new Sequence(...$elements); |
|
222 | + } |
|
223 | 223 | } |
@@ -11,265 +11,265 @@ |
||
11 | 11 | */ |
12 | 12 | class PolicyNode implements \IteratorAggregate, \Countable |
13 | 13 | { |
14 | - /** |
|
15 | - * Policy OID. |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $_validPolicy; |
|
14 | + /** |
|
15 | + * Policy OID. |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $_validPolicy; |
|
20 | 20 | |
21 | - /** |
|
22 | - * List of qualifiers. |
|
23 | - * |
|
24 | - * @var \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
25 | - */ |
|
26 | - protected $_qualifiers; |
|
21 | + /** |
|
22 | + * List of qualifiers. |
|
23 | + * |
|
24 | + * @var \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
25 | + */ |
|
26 | + protected $_qualifiers; |
|
27 | 27 | |
28 | - /** |
|
29 | - * List of expected policy OIDs. |
|
30 | - * |
|
31 | - * @var string[] |
|
32 | - */ |
|
33 | - protected $_expectedPolicies; |
|
28 | + /** |
|
29 | + * List of expected policy OIDs. |
|
30 | + * |
|
31 | + * @var string[] |
|
32 | + */ |
|
33 | + protected $_expectedPolicies; |
|
34 | 34 | |
35 | - /** |
|
36 | - * List of child nodes. |
|
37 | - * |
|
38 | - * @var PolicyNode[] |
|
39 | - */ |
|
40 | - protected $_children; |
|
35 | + /** |
|
36 | + * List of child nodes. |
|
37 | + * |
|
38 | + * @var PolicyNode[] |
|
39 | + */ |
|
40 | + protected $_children; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Reference to the parent node. |
|
44 | - * |
|
45 | - * @var PolicyNode|null |
|
46 | - */ |
|
47 | - protected $_parent; |
|
42 | + /** |
|
43 | + * Reference to the parent node. |
|
44 | + * |
|
45 | + * @var PolicyNode|null |
|
46 | + */ |
|
47 | + protected $_parent; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Constructor. |
|
51 | - * |
|
52 | - * @param string $valid_policy Policy OID |
|
53 | - * @param \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] $qualifiers |
|
54 | - * @param string[] $expected_policies |
|
55 | - */ |
|
56 | - public function __construct($valid_policy, array $qualifiers, |
|
57 | - array $expected_policies) |
|
58 | - { |
|
59 | - $this->_validPolicy = $valid_policy; |
|
60 | - $this->_qualifiers = $qualifiers; |
|
61 | - $this->_expectedPolicies = $expected_policies; |
|
62 | - $this->_children = array(); |
|
63 | - } |
|
49 | + /** |
|
50 | + * Constructor. |
|
51 | + * |
|
52 | + * @param string $valid_policy Policy OID |
|
53 | + * @param \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] $qualifiers |
|
54 | + * @param string[] $expected_policies |
|
55 | + */ |
|
56 | + public function __construct($valid_policy, array $qualifiers, |
|
57 | + array $expected_policies) |
|
58 | + { |
|
59 | + $this->_validPolicy = $valid_policy; |
|
60 | + $this->_qualifiers = $qualifiers; |
|
61 | + $this->_expectedPolicies = $expected_policies; |
|
62 | + $this->_children = array(); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Create initial node for the policy tree. |
|
67 | - * |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public static function anyPolicyNode() |
|
71 | - { |
|
72 | - return new self(PolicyInformation::OID_ANY_POLICY, array(), |
|
73 | - array(PolicyInformation::OID_ANY_POLICY)); |
|
74 | - } |
|
65 | + /** |
|
66 | + * Create initial node for the policy tree. |
|
67 | + * |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public static function anyPolicyNode() |
|
71 | + { |
|
72 | + return new self(PolicyInformation::OID_ANY_POLICY, array(), |
|
73 | + array(PolicyInformation::OID_ANY_POLICY)); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Get the valid policy OID. |
|
78 | - * |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function validPolicy() |
|
82 | - { |
|
83 | - return $this->_validPolicy; |
|
84 | - } |
|
76 | + /** |
|
77 | + * Get the valid policy OID. |
|
78 | + * |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function validPolicy() |
|
82 | + { |
|
83 | + return $this->_validPolicy; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Check whether node has anyPolicy as a valid policy. |
|
88 | - * |
|
89 | - * @return boolean |
|
90 | - */ |
|
91 | - public function isAnyPolicy() |
|
92 | - { |
|
93 | - return PolicyInformation::OID_ANY_POLICY == $this->_validPolicy; |
|
94 | - } |
|
86 | + /** |
|
87 | + * Check whether node has anyPolicy as a valid policy. |
|
88 | + * |
|
89 | + * @return boolean |
|
90 | + */ |
|
91 | + public function isAnyPolicy() |
|
92 | + { |
|
93 | + return PolicyInformation::OID_ANY_POLICY == $this->_validPolicy; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Get the qualifier set. |
|
98 | - * |
|
99 | - * @return \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
100 | - */ |
|
101 | - public function qualifiers() |
|
102 | - { |
|
103 | - return $this->_qualifiers; |
|
104 | - } |
|
96 | + /** |
|
97 | + * Get the qualifier set. |
|
98 | + * |
|
99 | + * @return \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
100 | + */ |
|
101 | + public function qualifiers() |
|
102 | + { |
|
103 | + return $this->_qualifiers; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Check whether node has OID as an expected policy. |
|
108 | - * |
|
109 | - * @param string $oid |
|
110 | - * @return boolean |
|
111 | - */ |
|
112 | - public function hasExpectedPolicy($oid) |
|
113 | - { |
|
114 | - return in_array($oid, $this->_expectedPolicies); |
|
115 | - } |
|
106 | + /** |
|
107 | + * Check whether node has OID as an expected policy. |
|
108 | + * |
|
109 | + * @param string $oid |
|
110 | + * @return boolean |
|
111 | + */ |
|
112 | + public function hasExpectedPolicy($oid) |
|
113 | + { |
|
114 | + return in_array($oid, $this->_expectedPolicies); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Get the expected policy set. |
|
119 | - * |
|
120 | - * @return string[] |
|
121 | - */ |
|
122 | - public function expectedPolicies() |
|
123 | - { |
|
124 | - return $this->_expectedPolicies; |
|
125 | - } |
|
117 | + /** |
|
118 | + * Get the expected policy set. |
|
119 | + * |
|
120 | + * @return string[] |
|
121 | + */ |
|
122 | + public function expectedPolicies() |
|
123 | + { |
|
124 | + return $this->_expectedPolicies; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Set expected policies. |
|
129 | - * |
|
130 | - * @param string ...$oids Policy OIDs |
|
131 | - */ |
|
132 | - public function setExpectedPolicies(...$oids) |
|
133 | - { |
|
134 | - $this->_expectedPolicies = $oids; |
|
135 | - } |
|
127 | + /** |
|
128 | + * Set expected policies. |
|
129 | + * |
|
130 | + * @param string ...$oids Policy OIDs |
|
131 | + */ |
|
132 | + public function setExpectedPolicies(...$oids) |
|
133 | + { |
|
134 | + $this->_expectedPolicies = $oids; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Check whether node has a child node with given valid policy OID. |
|
139 | - * |
|
140 | - * @param string $oid |
|
141 | - * @return boolean |
|
142 | - */ |
|
143 | - public function hasChildWithValidPolicy($oid) |
|
144 | - { |
|
145 | - foreach ($this->_children as $node) { |
|
146 | - if ($node->validPolicy() == $oid) { |
|
147 | - return true; |
|
148 | - } |
|
149 | - } |
|
150 | - return false; |
|
151 | - } |
|
137 | + /** |
|
138 | + * Check whether node has a child node with given valid policy OID. |
|
139 | + * |
|
140 | + * @param string $oid |
|
141 | + * @return boolean |
|
142 | + */ |
|
143 | + public function hasChildWithValidPolicy($oid) |
|
144 | + { |
|
145 | + foreach ($this->_children as $node) { |
|
146 | + if ($node->validPolicy() == $oid) { |
|
147 | + return true; |
|
148 | + } |
|
149 | + } |
|
150 | + return false; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Add child node. |
|
155 | - * |
|
156 | - * @param PolicyNode $node |
|
157 | - * @return self |
|
158 | - */ |
|
159 | - public function addChild(PolicyNode $node) |
|
160 | - { |
|
161 | - $id = spl_object_hash($node); |
|
162 | - $node->_parent = $this; |
|
163 | - $this->_children[$id] = $node; |
|
164 | - return $this; |
|
165 | - } |
|
153 | + /** |
|
154 | + * Add child node. |
|
155 | + * |
|
156 | + * @param PolicyNode $node |
|
157 | + * @return self |
|
158 | + */ |
|
159 | + public function addChild(PolicyNode $node) |
|
160 | + { |
|
161 | + $id = spl_object_hash($node); |
|
162 | + $node->_parent = $this; |
|
163 | + $this->_children[$id] = $node; |
|
164 | + return $this; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Get the child nodes. |
|
169 | - * |
|
170 | - * @return PolicyNode[] |
|
171 | - */ |
|
172 | - public function children() |
|
173 | - { |
|
174 | - return array_values($this->_children); |
|
175 | - } |
|
167 | + /** |
|
168 | + * Get the child nodes. |
|
169 | + * |
|
170 | + * @return PolicyNode[] |
|
171 | + */ |
|
172 | + public function children() |
|
173 | + { |
|
174 | + return array_values($this->_children); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Remove this node from the tree. |
|
179 | - * |
|
180 | - * @return self The removed node |
|
181 | - */ |
|
182 | - public function remove() |
|
183 | - { |
|
184 | - if ($this->_parent) { |
|
185 | - $id = spl_object_hash($this); |
|
186 | - unset($this->_parent->_children[$id]); |
|
187 | - unset($this->_parent); |
|
188 | - } |
|
189 | - return $this; |
|
190 | - } |
|
177 | + /** |
|
178 | + * Remove this node from the tree. |
|
179 | + * |
|
180 | + * @return self The removed node |
|
181 | + */ |
|
182 | + public function remove() |
|
183 | + { |
|
184 | + if ($this->_parent) { |
|
185 | + $id = spl_object_hash($this); |
|
186 | + unset($this->_parent->_children[$id]); |
|
187 | + unset($this->_parent); |
|
188 | + } |
|
189 | + return $this; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Check whether node has a parent. |
|
194 | - * |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function hasParent() |
|
198 | - { |
|
199 | - return isset($this->_parent); |
|
200 | - } |
|
192 | + /** |
|
193 | + * Check whether node has a parent. |
|
194 | + * |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function hasParent() |
|
198 | + { |
|
199 | + return isset($this->_parent); |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Get the parent node. |
|
204 | - * |
|
205 | - * @return PolicyNode|null |
|
206 | - */ |
|
207 | - public function parent() |
|
208 | - { |
|
209 | - return $this->_parent; |
|
210 | - } |
|
202 | + /** |
|
203 | + * Get the parent node. |
|
204 | + * |
|
205 | + * @return PolicyNode|null |
|
206 | + */ |
|
207 | + public function parent() |
|
208 | + { |
|
209 | + return $this->_parent; |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * Get chain of parent nodes from this node's parent to the root node. |
|
214 | - * |
|
215 | - * @return PolicyNode[] |
|
216 | - */ |
|
217 | - public function parents() |
|
218 | - { |
|
219 | - if (!$this->_parent) { |
|
220 | - return array(); |
|
221 | - } |
|
222 | - $nodes = $this->_parent->parents(); |
|
223 | - $nodes[] = $this->_parent; |
|
224 | - return array_reverse($nodes); |
|
225 | - } |
|
212 | + /** |
|
213 | + * Get chain of parent nodes from this node's parent to the root node. |
|
214 | + * |
|
215 | + * @return PolicyNode[] |
|
216 | + */ |
|
217 | + public function parents() |
|
218 | + { |
|
219 | + if (!$this->_parent) { |
|
220 | + return array(); |
|
221 | + } |
|
222 | + $nodes = $this->_parent->parents(); |
|
223 | + $nodes[] = $this->_parent; |
|
224 | + return array_reverse($nodes); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * Walk tree from this node, applying a callback for each node. |
|
229 | - * |
|
230 | - * Nodes are traversed depth-first and callback shall be applied post-order. |
|
231 | - * |
|
232 | - * @param callable $fn |
|
233 | - */ |
|
234 | - public function walkNodes(callable $fn) |
|
235 | - { |
|
236 | - foreach ($this->_children as $node) { |
|
237 | - $node->walkNodes($fn); |
|
238 | - } |
|
239 | - $fn($this); |
|
240 | - } |
|
227 | + /** |
|
228 | + * Walk tree from this node, applying a callback for each node. |
|
229 | + * |
|
230 | + * Nodes are traversed depth-first and callback shall be applied post-order. |
|
231 | + * |
|
232 | + * @param callable $fn |
|
233 | + */ |
|
234 | + public function walkNodes(callable $fn) |
|
235 | + { |
|
236 | + foreach ($this->_children as $node) { |
|
237 | + $node->walkNodes($fn); |
|
238 | + } |
|
239 | + $fn($this); |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * Get the total number of nodes in a tree. |
|
244 | - * |
|
245 | - * @return int |
|
246 | - */ |
|
247 | - public function nodeCount() |
|
248 | - { |
|
249 | - $c = 1; |
|
250 | - foreach ($this->_children as $child) { |
|
251 | - $c += $child->nodeCount(); |
|
252 | - } |
|
253 | - return $c; |
|
254 | - } |
|
242 | + /** |
|
243 | + * Get the total number of nodes in a tree. |
|
244 | + * |
|
245 | + * @return int |
|
246 | + */ |
|
247 | + public function nodeCount() |
|
248 | + { |
|
249 | + $c = 1; |
|
250 | + foreach ($this->_children as $child) { |
|
251 | + $c += $child->nodeCount(); |
|
252 | + } |
|
253 | + return $c; |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * Get the number of child nodes. |
|
258 | - * |
|
259 | - * @see \Countable::count() |
|
260 | - */ |
|
261 | - public function count() |
|
262 | - { |
|
263 | - return count($this->_children); |
|
264 | - } |
|
256 | + /** |
|
257 | + * Get the number of child nodes. |
|
258 | + * |
|
259 | + * @see \Countable::count() |
|
260 | + */ |
|
261 | + public function count() |
|
262 | + { |
|
263 | + return count($this->_children); |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Get iterator for the child nodes. |
|
268 | - * |
|
269 | - * @see \IteratorAggregate::getIterator() |
|
270 | - */ |
|
271 | - public function getIterator() |
|
272 | - { |
|
273 | - return new \ArrayIterator($this->_children); |
|
274 | - } |
|
266 | + /** |
|
267 | + * Get iterator for the child nodes. |
|
268 | + * |
|
269 | + * @see \IteratorAggregate::getIterator() |
|
270 | + */ |
|
271 | + public function getIterator() |
|
272 | + { |
|
273 | + return new \ArrayIterator($this->_children); |
|
274 | + } |
|
275 | 275 | } |
@@ -21,171 +21,171 @@ |
||
21 | 21 | */ |
22 | 22 | class CertificationPath implements \Countable, \IteratorAggregate |
23 | 23 | { |
24 | - /** |
|
25 | - * Certification path. |
|
26 | - * |
|
27 | - * @var Certificate[] $_certificates |
|
28 | - */ |
|
29 | - protected $_certificates; |
|
24 | + /** |
|
25 | + * Certification path. |
|
26 | + * |
|
27 | + * @var Certificate[] $_certificates |
|
28 | + */ |
|
29 | + protected $_certificates; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor. |
|
33 | - * |
|
34 | - * @param Certificate ...$certificates Certificates from the trust anchor |
|
35 | - * to the target end-entity certificate |
|
36 | - */ |
|
37 | - public function __construct(Certificate ...$certificates) |
|
38 | - { |
|
39 | - $this->_certificates = $certificates; |
|
40 | - } |
|
31 | + /** |
|
32 | + * Constructor. |
|
33 | + * |
|
34 | + * @param Certificate ...$certificates Certificates from the trust anchor |
|
35 | + * to the target end-entity certificate |
|
36 | + */ |
|
37 | + public function __construct(Certificate ...$certificates) |
|
38 | + { |
|
39 | + $this->_certificates = $certificates; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Initialize from a certificate chain. |
|
44 | - * |
|
45 | - * @param CertificateChain $chain |
|
46 | - * @return self |
|
47 | - */ |
|
48 | - public static function fromCertificateChain(CertificateChain $chain) |
|
49 | - { |
|
50 | - return new self(...array_reverse($chain->certificates(), false)); |
|
51 | - } |
|
42 | + /** |
|
43 | + * Initialize from a certificate chain. |
|
44 | + * |
|
45 | + * @param CertificateChain $chain |
|
46 | + * @return self |
|
47 | + */ |
|
48 | + public static function fromCertificateChain(CertificateChain $chain) |
|
49 | + { |
|
50 | + return new self(...array_reverse($chain->certificates(), false)); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Build certification path to given target. |
|
55 | - * |
|
56 | - * @param Certificate $target Target end-entity certificate |
|
57 | - * @param CertificateBundle $trust_anchors List of trust anchors |
|
58 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
59 | - * certificates |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - public static function toTarget(Certificate $target, |
|
63 | - CertificateBundle $trust_anchors, CertificateBundle $intermediate = null) |
|
64 | - { |
|
65 | - $builder = new CertificationPathBuilder($trust_anchors); |
|
66 | - return $builder->shortestPathToTarget($target, $intermediate); |
|
67 | - } |
|
53 | + /** |
|
54 | + * Build certification path to given target. |
|
55 | + * |
|
56 | + * @param Certificate $target Target end-entity certificate |
|
57 | + * @param CertificateBundle $trust_anchors List of trust anchors |
|
58 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
59 | + * certificates |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + public static function toTarget(Certificate $target, |
|
63 | + CertificateBundle $trust_anchors, CertificateBundle $intermediate = null) |
|
64 | + { |
|
65 | + $builder = new CertificationPathBuilder($trust_anchors); |
|
66 | + return $builder->shortestPathToTarget($target, $intermediate); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Build certification path from given trust anchor to target certificate, |
|
71 | - * using intermediate certificates from given bundle. |
|
72 | - * |
|
73 | - * @param Certificate $trust_anchor Trust anchor certificate |
|
74 | - * @param Certificate $target Target end-entity certificate |
|
75 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
76 | - * certificates |
|
77 | - * @return self |
|
78 | - */ |
|
79 | - public static function fromTrustAnchorToTarget(Certificate $trust_anchor, |
|
80 | - Certificate $target, CertificateBundle $intermediate = null) |
|
81 | - { |
|
82 | - return self::toTarget($target, new CertificateBundle($trust_anchor), |
|
83 | - $intermediate); |
|
84 | - } |
|
69 | + /** |
|
70 | + * Build certification path from given trust anchor to target certificate, |
|
71 | + * using intermediate certificates from given bundle. |
|
72 | + * |
|
73 | + * @param Certificate $trust_anchor Trust anchor certificate |
|
74 | + * @param Certificate $target Target end-entity certificate |
|
75 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
76 | + * certificates |
|
77 | + * @return self |
|
78 | + */ |
|
79 | + public static function fromTrustAnchorToTarget(Certificate $trust_anchor, |
|
80 | + Certificate $target, CertificateBundle $intermediate = null) |
|
81 | + { |
|
82 | + return self::toTarget($target, new CertificateBundle($trust_anchor), |
|
83 | + $intermediate); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get certificates. |
|
88 | - * |
|
89 | - * @return Certificate[] |
|
90 | - */ |
|
91 | - public function certificates() |
|
92 | - { |
|
93 | - return $this->_certificates; |
|
94 | - } |
|
86 | + /** |
|
87 | + * Get certificates. |
|
88 | + * |
|
89 | + * @return Certificate[] |
|
90 | + */ |
|
91 | + public function certificates() |
|
92 | + { |
|
93 | + return $this->_certificates; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Get the trust anchor certificate from the path. |
|
98 | - * |
|
99 | - * @throws \LogicException If path is empty |
|
100 | - * @return Certificate |
|
101 | - */ |
|
102 | - public function trustAnchorCertificate() |
|
103 | - { |
|
104 | - if (!count($this->_certificates)) { |
|
105 | - throw new \LogicException("No certificates."); |
|
106 | - } |
|
107 | - return $this->_certificates[0]; |
|
108 | - } |
|
96 | + /** |
|
97 | + * Get the trust anchor certificate from the path. |
|
98 | + * |
|
99 | + * @throws \LogicException If path is empty |
|
100 | + * @return Certificate |
|
101 | + */ |
|
102 | + public function trustAnchorCertificate() |
|
103 | + { |
|
104 | + if (!count($this->_certificates)) { |
|
105 | + throw new \LogicException("No certificates."); |
|
106 | + } |
|
107 | + return $this->_certificates[0]; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Get the end-entity certificate from the path. |
|
112 | - * |
|
113 | - * @throws \LogicException If path is empty |
|
114 | - * @return Certificate |
|
115 | - */ |
|
116 | - public function endEntityCertificate() |
|
117 | - { |
|
118 | - if (!count($this->_certificates)) { |
|
119 | - throw new \LogicException("No certificates."); |
|
120 | - } |
|
121 | - return $this->_certificates[count($this->_certificates) - 1]; |
|
122 | - } |
|
110 | + /** |
|
111 | + * Get the end-entity certificate from the path. |
|
112 | + * |
|
113 | + * @throws \LogicException If path is empty |
|
114 | + * @return Certificate |
|
115 | + */ |
|
116 | + public function endEntityCertificate() |
|
117 | + { |
|
118 | + if (!count($this->_certificates)) { |
|
119 | + throw new \LogicException("No certificates."); |
|
120 | + } |
|
121 | + return $this->_certificates[count($this->_certificates) - 1]; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Get certification path as a certificate chain. |
|
126 | - * |
|
127 | - * @return CertificateChain |
|
128 | - */ |
|
129 | - public function certificateChain() |
|
130 | - { |
|
131 | - return new CertificateChain( |
|
132 | - ...array_reverse($this->_certificates, false)); |
|
133 | - } |
|
124 | + /** |
|
125 | + * Get certification path as a certificate chain. |
|
126 | + * |
|
127 | + * @return CertificateChain |
|
128 | + */ |
|
129 | + public function certificateChain() |
|
130 | + { |
|
131 | + return new CertificateChain( |
|
132 | + ...array_reverse($this->_certificates, false)); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Check whether certification path starts with one ore more given |
|
137 | - * certificates in parameter order. |
|
138 | - * |
|
139 | - * @param Certificate ...$certs Certificates |
|
140 | - * @return true |
|
141 | - */ |
|
142 | - public function startsWith(Certificate ...$certs) |
|
143 | - { |
|
144 | - $n = count($certs); |
|
145 | - if ($n > count($this->_certificates)) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - for ($i = 0; $i < $n; ++$i) { |
|
149 | - if (!$certs[$i]->equals($this->_certificates[$i])) { |
|
150 | - return false; |
|
151 | - } |
|
152 | - } |
|
153 | - return true; |
|
154 | - } |
|
135 | + /** |
|
136 | + * Check whether certification path starts with one ore more given |
|
137 | + * certificates in parameter order. |
|
138 | + * |
|
139 | + * @param Certificate ...$certs Certificates |
|
140 | + * @return true |
|
141 | + */ |
|
142 | + public function startsWith(Certificate ...$certs) |
|
143 | + { |
|
144 | + $n = count($certs); |
|
145 | + if ($n > count($this->_certificates)) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + for ($i = 0; $i < $n; ++$i) { |
|
149 | + if (!$certs[$i]->equals($this->_certificates[$i])) { |
|
150 | + return false; |
|
151 | + } |
|
152 | + } |
|
153 | + return true; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Validate certification path. |
|
158 | - * |
|
159 | - * @param PathValidationConfig $config |
|
160 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
161 | - * @throws Exception\PathValidationException |
|
162 | - * @return PathValidation\PathValidationResult |
|
163 | - */ |
|
164 | - public function validate(PathValidationConfig $config, Crypto $crypto = null) |
|
165 | - { |
|
166 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
167 | - $validator = new PathValidator($crypto, $config, ...$this->_certificates); |
|
168 | - return $validator->validate(); |
|
169 | - } |
|
156 | + /** |
|
157 | + * Validate certification path. |
|
158 | + * |
|
159 | + * @param PathValidationConfig $config |
|
160 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
161 | + * @throws Exception\PathValidationException |
|
162 | + * @return PathValidation\PathValidationResult |
|
163 | + */ |
|
164 | + public function validate(PathValidationConfig $config, Crypto $crypto = null) |
|
165 | + { |
|
166 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
167 | + $validator = new PathValidator($crypto, $config, ...$this->_certificates); |
|
168 | + return $validator->validate(); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * |
|
173 | - * @see \Countable::count() |
|
174 | - * @return int |
|
175 | - */ |
|
176 | - public function count() |
|
177 | - { |
|
178 | - return count($this->_certificates); |
|
179 | - } |
|
171 | + /** |
|
172 | + * |
|
173 | + * @see \Countable::count() |
|
174 | + * @return int |
|
175 | + */ |
|
176 | + public function count() |
|
177 | + { |
|
178 | + return count($this->_certificates); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get iterator for certificates. |
|
183 | - * |
|
184 | - * @see \IteratorAggregate::getIterator() |
|
185 | - * @return \ArrayIterator |
|
186 | - */ |
|
187 | - public function getIterator() |
|
188 | - { |
|
189 | - return new \ArrayIterator($this->_certificates); |
|
190 | - } |
|
181 | + /** |
|
182 | + * Get iterator for certificates. |
|
183 | + * |
|
184 | + * @see \IteratorAggregate::getIterator() |
|
185 | + * @return \ArrayIterator |
|
186 | + */ |
|
187 | + public function getIterator() |
|
188 | + { |
|
189 | + return new \ArrayIterator($this->_certificates); |
|
190 | + } |
|
191 | 191 | } |
@@ -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 | } |
@@ -18,484 +18,484 @@ |
||
18 | 18 | */ |
19 | 19 | class ValidatorState |
20 | 20 | { |
21 | - /** |
|
22 | - * Length of the certification path (n). |
|
23 | - * |
|
24 | - * @var int $_pathLength |
|
25 | - */ |
|
26 | - protected $_pathLength; |
|
27 | - |
|
28 | - /** |
|
29 | - * Current index in the certification path in the range of 1..n (i). |
|
30 | - * |
|
31 | - * @var int $_index |
|
32 | - */ |
|
33 | - protected $_index; |
|
34 | - |
|
35 | - /** |
|
36 | - * Valid policy tree (valid_policy_tree). |
|
37 | - * |
|
38 | - * A tree of certificate policies with their optional qualifiers. |
|
39 | - * Each of the leaves of the tree represents a valid policy at this stage in |
|
40 | - * the certification path validation. |
|
41 | - * Once the tree is set to NULL, policy processing ceases. |
|
42 | - * |
|
43 | - * @var PolicyTree|null $_validPolicyTree |
|
44 | - */ |
|
45 | - protected $_validPolicyTree; |
|
46 | - |
|
47 | - /** |
|
48 | - * Permitted subtrees (permitted_subtrees). |
|
49 | - * |
|
50 | - * A set of root names for each name type defining a set of subtrees within |
|
51 | - * which all subject names in subsequent certificates in the certification |
|
52 | - * path must fall. |
|
53 | - * |
|
54 | - * @var mixed $_permittedSubtrees |
|
55 | - */ |
|
56 | - protected $_permittedSubtrees; |
|
57 | - |
|
58 | - /** |
|
59 | - * Excluded subtrees (excluded_subtrees). |
|
60 | - * |
|
61 | - * A set of root names for each name type defining a set of subtrees within |
|
62 | - * which no subject name in subsequent certificates in the certification |
|
63 | - * path may fall. |
|
64 | - * |
|
65 | - * @var mixed $_excludedSubtrees |
|
66 | - */ |
|
67 | - protected $_excludedSubtrees; |
|
68 | - |
|
69 | - /** |
|
70 | - * Explicit policy (explicit_policy). |
|
71 | - * |
|
72 | - * An integer that indicates if a non-NULL valid_policy_tree is required. |
|
73 | - * |
|
74 | - * @var int $_explicitPolicy |
|
75 | - */ |
|
76 | - protected $_explicitPolicy; |
|
77 | - |
|
78 | - /** |
|
79 | - * Inhibit anyPolicy (inhibit_anyPolicy). |
|
80 | - * |
|
81 | - * An integer that indicates whether the anyPolicy policy identifier is |
|
82 | - * considered a match. |
|
83 | - * |
|
84 | - * @var int $_inhibitAnyPolicy |
|
85 | - */ |
|
86 | - protected $_inhibitAnyPolicy; |
|
87 | - |
|
88 | - /** |
|
89 | - * Policy mapping (policy_mapping). |
|
90 | - * |
|
91 | - * An integer that indicates if policy mapping is permitted. |
|
92 | - * |
|
93 | - * @var int $_policyMapping |
|
94 | - */ |
|
95 | - protected $_policyMapping; |
|
96 | - |
|
97 | - /** |
|
98 | - * Working public key algorithm (working_public_key_algorithm). |
|
99 | - * |
|
100 | - * The digital signature algorithm used to verify the signature of a |
|
101 | - * certificate. |
|
102 | - * |
|
103 | - * @var AlgorithmIdentifierType $_workingPublicKeyAlgorithm |
|
104 | - */ |
|
105 | - protected $_workingPublicKeyAlgorithm; |
|
106 | - |
|
107 | - /** |
|
108 | - * Working public key (working_public_key). |
|
109 | - * |
|
110 | - * The public key used to verify the signature of a certificate. |
|
111 | - * |
|
112 | - * @var PublicKeyInfo $_workingPublicKey |
|
113 | - */ |
|
114 | - protected $_workingPublicKey; |
|
115 | - |
|
116 | - /** |
|
117 | - * Working public key parameters (working_public_key_parameters). |
|
118 | - * |
|
119 | - * Parameters associated with the current public key that may be required to |
|
120 | - * verify a signature. |
|
121 | - * |
|
122 | - * @var Element|null $_workingPublicKeyParameters |
|
123 | - */ |
|
124 | - protected $_workingPublicKeyParameters; |
|
125 | - |
|
126 | - /** |
|
127 | - * Working issuer name (working_issuer_name). |
|
128 | - * |
|
129 | - * The issuer distinguished name expected in the next certificate in the |
|
130 | - * chain. |
|
131 | - * |
|
132 | - * @var Name $_workingIssuerName |
|
133 | - */ |
|
134 | - protected $_workingIssuerName; |
|
135 | - |
|
136 | - /** |
|
137 | - * Maximum certification path length (max_path_length). |
|
138 | - * |
|
139 | - * @var int $_maxPathLength |
|
140 | - */ |
|
141 | - protected $_maxPathLength; |
|
142 | - |
|
143 | - /** |
|
144 | - * Constructor. |
|
145 | - */ |
|
146 | - protected function __construct() |
|
147 | - { |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Initialize variables according to RFC 5280 6.1.2. |
|
152 | - * |
|
153 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.2 |
|
154 | - * @param PathValidationConfig $config |
|
155 | - * @param Certificate $trust_anchor Trust anchor certificate |
|
156 | - * @param int $n Number of certificates in the certification path |
|
157 | - * @return self |
|
158 | - */ |
|
159 | - public static function initialize(PathValidationConfig $config, |
|
160 | - Certificate $trust_anchor, $n) |
|
161 | - { |
|
162 | - $state = new self(); |
|
163 | - $state->_pathLength = $n; |
|
164 | - $state->_index = 1; |
|
165 | - $state->_validPolicyTree = new PolicyTree(PolicyNode::anyPolicyNode()); |
|
166 | - $state->_permittedSubtrees = null; |
|
167 | - $state->_excludedSubtrees = null; |
|
168 | - $state->_explicitPolicy = $config->explicitPolicy() ? 0 : $n + 1; |
|
169 | - $state->_inhibitAnyPolicy = $config->anyPolicyInhibit() ? 0 : $n + 1; |
|
170 | - $state->_policyMapping = $config->policyMappingInhibit() ? 0 : $n + 1; |
|
171 | - $state->_workingPublicKeyAlgorithm = $trust_anchor->signatureAlgorithm(); |
|
172 | - $tbsCert = $trust_anchor->tbsCertificate(); |
|
173 | - $state->_workingPublicKey = $tbsCert->subjectPublicKeyInfo(); |
|
174 | - $state->_workingPublicKeyParameters = self::getAlgorithmParameters( |
|
175 | - $state->_workingPublicKey->algorithmIdentifier()); |
|
176 | - $state->_workingIssuerName = $tbsCert->issuer(); |
|
177 | - $state->_maxPathLength = $config->maxLength(); |
|
178 | - return $state; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get self with current certification path index set. |
|
183 | - * |
|
184 | - * @param int $index |
|
185 | - * @return self |
|
186 | - */ |
|
187 | - public function withIndex($index) |
|
188 | - { |
|
189 | - $state = clone $this; |
|
190 | - $state->_index = $index; |
|
191 | - return $state; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get self with valid_policy_tree. |
|
196 | - * |
|
197 | - * @param PolicyTree $policy_tree |
|
198 | - * @return self |
|
199 | - */ |
|
200 | - public function withValidPolicyTree(PolicyTree $policy_tree) |
|
201 | - { |
|
202 | - $state = clone $this; |
|
203 | - $state->_validPolicyTree = $policy_tree; |
|
204 | - return $state; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get self with valid_policy_tree set to null. |
|
209 | - * |
|
210 | - * @return self |
|
211 | - */ |
|
212 | - public function withoutValidPolicyTree() |
|
213 | - { |
|
214 | - $state = clone $this; |
|
215 | - $state->_validPolicyTree = null; |
|
216 | - return $state; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Get self with explicit_policy. |
|
221 | - * |
|
222 | - * @param int $num |
|
223 | - * @return self |
|
224 | - */ |
|
225 | - public function withExplicitPolicy($num) |
|
226 | - { |
|
227 | - $state = clone $this; |
|
228 | - $state->_explicitPolicy = $num; |
|
229 | - return $state; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Get self with inhibit_anyPolicy. |
|
234 | - * |
|
235 | - * @param int $num |
|
236 | - * @return self |
|
237 | - */ |
|
238 | - public function withInhibitAnyPolicy($num) |
|
239 | - { |
|
240 | - $state = clone $this; |
|
241 | - $state->_inhibitAnyPolicy = $num; |
|
242 | - return $state; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Get self with policy_mapping. |
|
247 | - * |
|
248 | - * @param int $num |
|
249 | - * @return self |
|
250 | - */ |
|
251 | - public function withPolicyMapping($num) |
|
252 | - { |
|
253 | - $state = clone $this; |
|
254 | - $state->_policyMapping = $num; |
|
255 | - return $state; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Get self with working_public_key_algorithm. |
|
260 | - * |
|
261 | - * @param AlgorithmIdentifierType $algo |
|
262 | - * @return self |
|
263 | - */ |
|
264 | - public function withWorkingPublicKeyAlgorithm(AlgorithmIdentifierType $algo) |
|
265 | - { |
|
266 | - $state = clone $this; |
|
267 | - $state->_workingPublicKeyAlgorithm = $algo; |
|
268 | - return $state; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Get self with working_public_key. |
|
273 | - * |
|
274 | - * @param PublicKeyInfo $pubkey_info |
|
275 | - * @return self |
|
276 | - */ |
|
277 | - public function withWorkingPublicKey(PublicKeyInfo $pubkey_info) |
|
278 | - { |
|
279 | - $state = clone $this; |
|
280 | - $state->_workingPublicKey = $pubkey_info; |
|
281 | - return $state; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Get self with working_public_key_parameters. |
|
286 | - * |
|
287 | - * @param Element|null $params |
|
288 | - * @return self |
|
289 | - */ |
|
290 | - public function withWorkingPublicKeyParameters(Element $params = null) |
|
291 | - { |
|
292 | - $state = clone $this; |
|
293 | - $state->_workingPublicKeyParameters = $params; |
|
294 | - return $state; |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get self with working_issuer_name. |
|
299 | - * |
|
300 | - * @param Name $issuer |
|
301 | - * @return self |
|
302 | - */ |
|
303 | - public function withWorkingIssuerName(Name $issuer) |
|
304 | - { |
|
305 | - $state = clone $this; |
|
306 | - $state->_workingIssuerName = $issuer; |
|
307 | - return $state; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get self with max_path_length. |
|
312 | - * |
|
313 | - * @param int $length |
|
314 | - * @return self |
|
315 | - */ |
|
316 | - public function withMaxPathLength($length) |
|
317 | - { |
|
318 | - $state = clone $this; |
|
319 | - $state->_maxPathLength = $length; |
|
320 | - return $state; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Get the certification path length (n). |
|
325 | - * |
|
326 | - * @return int |
|
327 | - */ |
|
328 | - public function pathLength() |
|
329 | - { |
|
330 | - return $this->_pathLength; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Get the current index in certification path in the range of 1..n. |
|
335 | - * |
|
336 | - * @return int |
|
337 | - */ |
|
338 | - public function index() |
|
339 | - { |
|
340 | - return $this->_index; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Check whether valid_policy_tree is present. |
|
345 | - * |
|
346 | - * @return bool |
|
347 | - */ |
|
348 | - public function hasValidPolicyTree() |
|
349 | - { |
|
350 | - return isset($this->_validPolicyTree); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Get valid_policy_tree. |
|
355 | - * |
|
356 | - * @throws \LogicException |
|
357 | - * @return PolicyTree |
|
358 | - */ |
|
359 | - public function validPolicyTree() |
|
360 | - { |
|
361 | - if (!$this->hasValidPolicyTree()) { |
|
362 | - throw new \LogicException("valid_policy_tree not set."); |
|
363 | - } |
|
364 | - return $this->_validPolicyTree; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Get permitted_subtrees. |
|
369 | - * |
|
370 | - * @return mixed |
|
371 | - */ |
|
372 | - public function permittedSubtrees() |
|
373 | - { |
|
374 | - return $this->_permittedSubtrees; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Get excluded_subtrees. |
|
379 | - * |
|
380 | - * @return mixed |
|
381 | - */ |
|
382 | - public function excludedSubtrees() |
|
383 | - { |
|
384 | - return $this->_excludedSubtrees; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Get explicit_policy. |
|
389 | - * |
|
390 | - * @return int |
|
391 | - */ |
|
392 | - public function explicitPolicy() |
|
393 | - { |
|
394 | - return $this->_explicitPolicy; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Get inhibit_anyPolicy. |
|
399 | - * |
|
400 | - * @return int |
|
401 | - */ |
|
402 | - public function inhibitAnyPolicy() |
|
403 | - { |
|
404 | - return $this->_inhibitAnyPolicy; |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Get policy_mapping. |
|
409 | - * |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function policyMapping() |
|
413 | - { |
|
414 | - return $this->_policyMapping; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Get working_public_key_algorithm. |
|
419 | - * |
|
420 | - * @return AlgorithmIdentifierType |
|
421 | - */ |
|
422 | - public function workingPublicKeyAlgorithm() |
|
423 | - { |
|
424 | - return $this->_workingPublicKeyAlgorithm; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Get working_public_key. |
|
429 | - * |
|
430 | - * @return PublicKeyInfo |
|
431 | - */ |
|
432 | - public function workingPublicKey() |
|
433 | - { |
|
434 | - return $this->_workingPublicKey; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Get working_public_key_parameters. |
|
439 | - * |
|
440 | - * @return Element|null |
|
441 | - */ |
|
442 | - public function workingPublicKeyParameters() |
|
443 | - { |
|
444 | - return $this->_workingPublicKeyParameters; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Get working_issuer_name. |
|
449 | - * |
|
450 | - * @return Name |
|
451 | - */ |
|
452 | - public function workingIssuerName() |
|
453 | - { |
|
454 | - return $this->_workingIssuerName; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Get maximum certification path length. |
|
459 | - * |
|
460 | - * @return int |
|
461 | - */ |
|
462 | - public function maxPathLength() |
|
463 | - { |
|
464 | - return $this->_maxPathLength; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Check whether processing the final certificate of the certification path. |
|
469 | - * |
|
470 | - * @return bool |
|
471 | - */ |
|
472 | - public function isFinal() |
|
473 | - { |
|
474 | - return $this->_index == $this->_pathLength; |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Get the path validation result. |
|
479 | - * |
|
480 | - * @param Certificate[] $certificates Certificates in a certification path |
|
481 | - * @return PathValidationResult |
|
482 | - */ |
|
483 | - public function getResult(array $certificates) |
|
484 | - { |
|
485 | - return new PathValidationResult($certificates, $this->_validPolicyTree, |
|
486 | - $this->_workingPublicKey, $this->_workingPublicKeyAlgorithm, |
|
487 | - $this->_workingPublicKeyParameters); |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Get ASN.1 parameters from algorithm identifier. |
|
492 | - * |
|
493 | - * @param AlgorithmIdentifierType $algo |
|
494 | - * @return Element|null ASN.1 element or null if parameters are omitted |
|
495 | - */ |
|
496 | - public static function getAlgorithmParameters(AlgorithmIdentifierType $algo) |
|
497 | - { |
|
498 | - $seq = $algo->toASN1(); |
|
499 | - return $seq->has(1) ? $seq->at(1)->asElement() : null; |
|
500 | - } |
|
21 | + /** |
|
22 | + * Length of the certification path (n). |
|
23 | + * |
|
24 | + * @var int $_pathLength |
|
25 | + */ |
|
26 | + protected $_pathLength; |
|
27 | + |
|
28 | + /** |
|
29 | + * Current index in the certification path in the range of 1..n (i). |
|
30 | + * |
|
31 | + * @var int $_index |
|
32 | + */ |
|
33 | + protected $_index; |
|
34 | + |
|
35 | + /** |
|
36 | + * Valid policy tree (valid_policy_tree). |
|
37 | + * |
|
38 | + * A tree of certificate policies with their optional qualifiers. |
|
39 | + * Each of the leaves of the tree represents a valid policy at this stage in |
|
40 | + * the certification path validation. |
|
41 | + * Once the tree is set to NULL, policy processing ceases. |
|
42 | + * |
|
43 | + * @var PolicyTree|null $_validPolicyTree |
|
44 | + */ |
|
45 | + protected $_validPolicyTree; |
|
46 | + |
|
47 | + /** |
|
48 | + * Permitted subtrees (permitted_subtrees). |
|
49 | + * |
|
50 | + * A set of root names for each name type defining a set of subtrees within |
|
51 | + * which all subject names in subsequent certificates in the certification |
|
52 | + * path must fall. |
|
53 | + * |
|
54 | + * @var mixed $_permittedSubtrees |
|
55 | + */ |
|
56 | + protected $_permittedSubtrees; |
|
57 | + |
|
58 | + /** |
|
59 | + * Excluded subtrees (excluded_subtrees). |
|
60 | + * |
|
61 | + * A set of root names for each name type defining a set of subtrees within |
|
62 | + * which no subject name in subsequent certificates in the certification |
|
63 | + * path may fall. |
|
64 | + * |
|
65 | + * @var mixed $_excludedSubtrees |
|
66 | + */ |
|
67 | + protected $_excludedSubtrees; |
|
68 | + |
|
69 | + /** |
|
70 | + * Explicit policy (explicit_policy). |
|
71 | + * |
|
72 | + * An integer that indicates if a non-NULL valid_policy_tree is required. |
|
73 | + * |
|
74 | + * @var int $_explicitPolicy |
|
75 | + */ |
|
76 | + protected $_explicitPolicy; |
|
77 | + |
|
78 | + /** |
|
79 | + * Inhibit anyPolicy (inhibit_anyPolicy). |
|
80 | + * |
|
81 | + * An integer that indicates whether the anyPolicy policy identifier is |
|
82 | + * considered a match. |
|
83 | + * |
|
84 | + * @var int $_inhibitAnyPolicy |
|
85 | + */ |
|
86 | + protected $_inhibitAnyPolicy; |
|
87 | + |
|
88 | + /** |
|
89 | + * Policy mapping (policy_mapping). |
|
90 | + * |
|
91 | + * An integer that indicates if policy mapping is permitted. |
|
92 | + * |
|
93 | + * @var int $_policyMapping |
|
94 | + */ |
|
95 | + protected $_policyMapping; |
|
96 | + |
|
97 | + /** |
|
98 | + * Working public key algorithm (working_public_key_algorithm). |
|
99 | + * |
|
100 | + * The digital signature algorithm used to verify the signature of a |
|
101 | + * certificate. |
|
102 | + * |
|
103 | + * @var AlgorithmIdentifierType $_workingPublicKeyAlgorithm |
|
104 | + */ |
|
105 | + protected $_workingPublicKeyAlgorithm; |
|
106 | + |
|
107 | + /** |
|
108 | + * Working public key (working_public_key). |
|
109 | + * |
|
110 | + * The public key used to verify the signature of a certificate. |
|
111 | + * |
|
112 | + * @var PublicKeyInfo $_workingPublicKey |
|
113 | + */ |
|
114 | + protected $_workingPublicKey; |
|
115 | + |
|
116 | + /** |
|
117 | + * Working public key parameters (working_public_key_parameters). |
|
118 | + * |
|
119 | + * Parameters associated with the current public key that may be required to |
|
120 | + * verify a signature. |
|
121 | + * |
|
122 | + * @var Element|null $_workingPublicKeyParameters |
|
123 | + */ |
|
124 | + protected $_workingPublicKeyParameters; |
|
125 | + |
|
126 | + /** |
|
127 | + * Working issuer name (working_issuer_name). |
|
128 | + * |
|
129 | + * The issuer distinguished name expected in the next certificate in the |
|
130 | + * chain. |
|
131 | + * |
|
132 | + * @var Name $_workingIssuerName |
|
133 | + */ |
|
134 | + protected $_workingIssuerName; |
|
135 | + |
|
136 | + /** |
|
137 | + * Maximum certification path length (max_path_length). |
|
138 | + * |
|
139 | + * @var int $_maxPathLength |
|
140 | + */ |
|
141 | + protected $_maxPathLength; |
|
142 | + |
|
143 | + /** |
|
144 | + * Constructor. |
|
145 | + */ |
|
146 | + protected function __construct() |
|
147 | + { |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Initialize variables according to RFC 5280 6.1.2. |
|
152 | + * |
|
153 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.2 |
|
154 | + * @param PathValidationConfig $config |
|
155 | + * @param Certificate $trust_anchor Trust anchor certificate |
|
156 | + * @param int $n Number of certificates in the certification path |
|
157 | + * @return self |
|
158 | + */ |
|
159 | + public static function initialize(PathValidationConfig $config, |
|
160 | + Certificate $trust_anchor, $n) |
|
161 | + { |
|
162 | + $state = new self(); |
|
163 | + $state->_pathLength = $n; |
|
164 | + $state->_index = 1; |
|
165 | + $state->_validPolicyTree = new PolicyTree(PolicyNode::anyPolicyNode()); |
|
166 | + $state->_permittedSubtrees = null; |
|
167 | + $state->_excludedSubtrees = null; |
|
168 | + $state->_explicitPolicy = $config->explicitPolicy() ? 0 : $n + 1; |
|
169 | + $state->_inhibitAnyPolicy = $config->anyPolicyInhibit() ? 0 : $n + 1; |
|
170 | + $state->_policyMapping = $config->policyMappingInhibit() ? 0 : $n + 1; |
|
171 | + $state->_workingPublicKeyAlgorithm = $trust_anchor->signatureAlgorithm(); |
|
172 | + $tbsCert = $trust_anchor->tbsCertificate(); |
|
173 | + $state->_workingPublicKey = $tbsCert->subjectPublicKeyInfo(); |
|
174 | + $state->_workingPublicKeyParameters = self::getAlgorithmParameters( |
|
175 | + $state->_workingPublicKey->algorithmIdentifier()); |
|
176 | + $state->_workingIssuerName = $tbsCert->issuer(); |
|
177 | + $state->_maxPathLength = $config->maxLength(); |
|
178 | + return $state; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get self with current certification path index set. |
|
183 | + * |
|
184 | + * @param int $index |
|
185 | + * @return self |
|
186 | + */ |
|
187 | + public function withIndex($index) |
|
188 | + { |
|
189 | + $state = clone $this; |
|
190 | + $state->_index = $index; |
|
191 | + return $state; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get self with valid_policy_tree. |
|
196 | + * |
|
197 | + * @param PolicyTree $policy_tree |
|
198 | + * @return self |
|
199 | + */ |
|
200 | + public function withValidPolicyTree(PolicyTree $policy_tree) |
|
201 | + { |
|
202 | + $state = clone $this; |
|
203 | + $state->_validPolicyTree = $policy_tree; |
|
204 | + return $state; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get self with valid_policy_tree set to null. |
|
209 | + * |
|
210 | + * @return self |
|
211 | + */ |
|
212 | + public function withoutValidPolicyTree() |
|
213 | + { |
|
214 | + $state = clone $this; |
|
215 | + $state->_validPolicyTree = null; |
|
216 | + return $state; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Get self with explicit_policy. |
|
221 | + * |
|
222 | + * @param int $num |
|
223 | + * @return self |
|
224 | + */ |
|
225 | + public function withExplicitPolicy($num) |
|
226 | + { |
|
227 | + $state = clone $this; |
|
228 | + $state->_explicitPolicy = $num; |
|
229 | + return $state; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Get self with inhibit_anyPolicy. |
|
234 | + * |
|
235 | + * @param int $num |
|
236 | + * @return self |
|
237 | + */ |
|
238 | + public function withInhibitAnyPolicy($num) |
|
239 | + { |
|
240 | + $state = clone $this; |
|
241 | + $state->_inhibitAnyPolicy = $num; |
|
242 | + return $state; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Get self with policy_mapping. |
|
247 | + * |
|
248 | + * @param int $num |
|
249 | + * @return self |
|
250 | + */ |
|
251 | + public function withPolicyMapping($num) |
|
252 | + { |
|
253 | + $state = clone $this; |
|
254 | + $state->_policyMapping = $num; |
|
255 | + return $state; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Get self with working_public_key_algorithm. |
|
260 | + * |
|
261 | + * @param AlgorithmIdentifierType $algo |
|
262 | + * @return self |
|
263 | + */ |
|
264 | + public function withWorkingPublicKeyAlgorithm(AlgorithmIdentifierType $algo) |
|
265 | + { |
|
266 | + $state = clone $this; |
|
267 | + $state->_workingPublicKeyAlgorithm = $algo; |
|
268 | + return $state; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Get self with working_public_key. |
|
273 | + * |
|
274 | + * @param PublicKeyInfo $pubkey_info |
|
275 | + * @return self |
|
276 | + */ |
|
277 | + public function withWorkingPublicKey(PublicKeyInfo $pubkey_info) |
|
278 | + { |
|
279 | + $state = clone $this; |
|
280 | + $state->_workingPublicKey = $pubkey_info; |
|
281 | + return $state; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Get self with working_public_key_parameters. |
|
286 | + * |
|
287 | + * @param Element|null $params |
|
288 | + * @return self |
|
289 | + */ |
|
290 | + public function withWorkingPublicKeyParameters(Element $params = null) |
|
291 | + { |
|
292 | + $state = clone $this; |
|
293 | + $state->_workingPublicKeyParameters = $params; |
|
294 | + return $state; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get self with working_issuer_name. |
|
299 | + * |
|
300 | + * @param Name $issuer |
|
301 | + * @return self |
|
302 | + */ |
|
303 | + public function withWorkingIssuerName(Name $issuer) |
|
304 | + { |
|
305 | + $state = clone $this; |
|
306 | + $state->_workingIssuerName = $issuer; |
|
307 | + return $state; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get self with max_path_length. |
|
312 | + * |
|
313 | + * @param int $length |
|
314 | + * @return self |
|
315 | + */ |
|
316 | + public function withMaxPathLength($length) |
|
317 | + { |
|
318 | + $state = clone $this; |
|
319 | + $state->_maxPathLength = $length; |
|
320 | + return $state; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Get the certification path length (n). |
|
325 | + * |
|
326 | + * @return int |
|
327 | + */ |
|
328 | + public function pathLength() |
|
329 | + { |
|
330 | + return $this->_pathLength; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Get the current index in certification path in the range of 1..n. |
|
335 | + * |
|
336 | + * @return int |
|
337 | + */ |
|
338 | + public function index() |
|
339 | + { |
|
340 | + return $this->_index; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Check whether valid_policy_tree is present. |
|
345 | + * |
|
346 | + * @return bool |
|
347 | + */ |
|
348 | + public function hasValidPolicyTree() |
|
349 | + { |
|
350 | + return isset($this->_validPolicyTree); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Get valid_policy_tree. |
|
355 | + * |
|
356 | + * @throws \LogicException |
|
357 | + * @return PolicyTree |
|
358 | + */ |
|
359 | + public function validPolicyTree() |
|
360 | + { |
|
361 | + if (!$this->hasValidPolicyTree()) { |
|
362 | + throw new \LogicException("valid_policy_tree not set."); |
|
363 | + } |
|
364 | + return $this->_validPolicyTree; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Get permitted_subtrees. |
|
369 | + * |
|
370 | + * @return mixed |
|
371 | + */ |
|
372 | + public function permittedSubtrees() |
|
373 | + { |
|
374 | + return $this->_permittedSubtrees; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Get excluded_subtrees. |
|
379 | + * |
|
380 | + * @return mixed |
|
381 | + */ |
|
382 | + public function excludedSubtrees() |
|
383 | + { |
|
384 | + return $this->_excludedSubtrees; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Get explicit_policy. |
|
389 | + * |
|
390 | + * @return int |
|
391 | + */ |
|
392 | + public function explicitPolicy() |
|
393 | + { |
|
394 | + return $this->_explicitPolicy; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Get inhibit_anyPolicy. |
|
399 | + * |
|
400 | + * @return int |
|
401 | + */ |
|
402 | + public function inhibitAnyPolicy() |
|
403 | + { |
|
404 | + return $this->_inhibitAnyPolicy; |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Get policy_mapping. |
|
409 | + * |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function policyMapping() |
|
413 | + { |
|
414 | + return $this->_policyMapping; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Get working_public_key_algorithm. |
|
419 | + * |
|
420 | + * @return AlgorithmIdentifierType |
|
421 | + */ |
|
422 | + public function workingPublicKeyAlgorithm() |
|
423 | + { |
|
424 | + return $this->_workingPublicKeyAlgorithm; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Get working_public_key. |
|
429 | + * |
|
430 | + * @return PublicKeyInfo |
|
431 | + */ |
|
432 | + public function workingPublicKey() |
|
433 | + { |
|
434 | + return $this->_workingPublicKey; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Get working_public_key_parameters. |
|
439 | + * |
|
440 | + * @return Element|null |
|
441 | + */ |
|
442 | + public function workingPublicKeyParameters() |
|
443 | + { |
|
444 | + return $this->_workingPublicKeyParameters; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Get working_issuer_name. |
|
449 | + * |
|
450 | + * @return Name |
|
451 | + */ |
|
452 | + public function workingIssuerName() |
|
453 | + { |
|
454 | + return $this->_workingIssuerName; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Get maximum certification path length. |
|
459 | + * |
|
460 | + * @return int |
|
461 | + */ |
|
462 | + public function maxPathLength() |
|
463 | + { |
|
464 | + return $this->_maxPathLength; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Check whether processing the final certificate of the certification path. |
|
469 | + * |
|
470 | + * @return bool |
|
471 | + */ |
|
472 | + public function isFinal() |
|
473 | + { |
|
474 | + return $this->_index == $this->_pathLength; |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Get the path validation result. |
|
479 | + * |
|
480 | + * @param Certificate[] $certificates Certificates in a certification path |
|
481 | + * @return PathValidationResult |
|
482 | + */ |
|
483 | + public function getResult(array $certificates) |
|
484 | + { |
|
485 | + return new PathValidationResult($certificates, $this->_validPolicyTree, |
|
486 | + $this->_workingPublicKey, $this->_workingPublicKeyAlgorithm, |
|
487 | + $this->_workingPublicKeyParameters); |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Get ASN.1 parameters from algorithm identifier. |
|
492 | + * |
|
493 | + * @param AlgorithmIdentifierType $algo |
|
494 | + * @return Element|null ASN.1 element or null if parameters are omitted |
|
495 | + */ |
|
496 | + public static function getAlgorithmParameters(AlgorithmIdentifierType $algo) |
|
497 | + { |
|
498 | + $seq = $algo->toASN1(); |
|
499 | + return $seq->has(1) ? $seq->at(1)->asElement() : null; |
|
500 | + } |
|
501 | 501 | } |
@@ -13,85 +13,85 @@ |
||
13 | 13 | */ |
14 | 14 | class PathValidationResult |
15 | 15 | { |
16 | - /** |
|
17 | - * Certificates in a certification path. |
|
18 | - * |
|
19 | - * @var \X509\Certificate\Certificate[] $_certificates |
|
20 | - */ |
|
21 | - protected $_certificates; |
|
16 | + /** |
|
17 | + * Certificates in a certification path. |
|
18 | + * |
|
19 | + * @var \X509\Certificate\Certificate[] $_certificates |
|
20 | + */ |
|
21 | + protected $_certificates; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Valid policy tree. |
|
25 | - * |
|
26 | - * @var \X509\CertificationPath\Policy\PolicyTree|null $_policyTree |
|
27 | - */ |
|
28 | - protected $_policyTree; |
|
23 | + /** |
|
24 | + * Valid policy tree. |
|
25 | + * |
|
26 | + * @var \X509\CertificationPath\Policy\PolicyTree|null $_policyTree |
|
27 | + */ |
|
28 | + protected $_policyTree; |
|
29 | 29 | |
30 | - /** |
|
31 | - * End-entity certificate's public key. |
|
32 | - * |
|
33 | - * @var PublicKeyInfo |
|
34 | - */ |
|
35 | - protected $_publicKeyInfo; |
|
30 | + /** |
|
31 | + * End-entity certificate's public key. |
|
32 | + * |
|
33 | + * @var PublicKeyInfo |
|
34 | + */ |
|
35 | + protected $_publicKeyInfo; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Public key algorithm. |
|
39 | - * |
|
40 | - * @var AlgorithmIdentifierType |
|
41 | - */ |
|
42 | - protected $_publicKeyAlgo; |
|
37 | + /** |
|
38 | + * Public key algorithm. |
|
39 | + * |
|
40 | + * @var AlgorithmIdentifierType |
|
41 | + */ |
|
42 | + protected $_publicKeyAlgo; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Public key parameters. |
|
46 | - * |
|
47 | - * @var Element|null $_publicKeyParameters |
|
48 | - */ |
|
49 | - protected $_publicKeyParameters; |
|
44 | + /** |
|
45 | + * Public key parameters. |
|
46 | + * |
|
47 | + * @var Element|null $_publicKeyParameters |
|
48 | + */ |
|
49 | + protected $_publicKeyParameters; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Constructor. |
|
53 | - * |
|
54 | - * @param \X509\Certificate\Certificate[] $certificates Certificates in a |
|
55 | - * certification path |
|
56 | - * @param \X509\CertificationPath\Policy\PolicyTree|null $policy_tree Valid |
|
57 | - * policy tree |
|
58 | - * @param PublicKeyInfo $pubkey_info Public key of the end-entity |
|
59 | - * certificate |
|
60 | - * @param AlgorithmIdentifierType $algo Public key algorithm of the |
|
61 | - * end-entity certificate |
|
62 | - * @param Element|null $params Algorithm parameters |
|
63 | - */ |
|
64 | - public function __construct(array $certificates, $policy_tree, |
|
65 | - PublicKeyInfo $pubkey_info, AlgorithmIdentifierType $algo, |
|
66 | - Element $params = null) |
|
67 | - { |
|
68 | - $this->_certificates = array_values($certificates); |
|
69 | - $this->_policyTree = $policy_tree; |
|
70 | - $this->_publicKeyInfo = $pubkey_info; |
|
71 | - $this->_publicKeyAlgo = $algo; |
|
72 | - $this->_publicKeyParameters = $params; |
|
73 | - } |
|
51 | + /** |
|
52 | + * Constructor. |
|
53 | + * |
|
54 | + * @param \X509\Certificate\Certificate[] $certificates Certificates in a |
|
55 | + * certification path |
|
56 | + * @param \X509\CertificationPath\Policy\PolicyTree|null $policy_tree Valid |
|
57 | + * policy tree |
|
58 | + * @param PublicKeyInfo $pubkey_info Public key of the end-entity |
|
59 | + * certificate |
|
60 | + * @param AlgorithmIdentifierType $algo Public key algorithm of the |
|
61 | + * end-entity certificate |
|
62 | + * @param Element|null $params Algorithm parameters |
|
63 | + */ |
|
64 | + public function __construct(array $certificates, $policy_tree, |
|
65 | + PublicKeyInfo $pubkey_info, AlgorithmIdentifierType $algo, |
|
66 | + Element $params = null) |
|
67 | + { |
|
68 | + $this->_certificates = array_values($certificates); |
|
69 | + $this->_policyTree = $policy_tree; |
|
70 | + $this->_publicKeyInfo = $pubkey_info; |
|
71 | + $this->_publicKeyAlgo = $algo; |
|
72 | + $this->_publicKeyParameters = $params; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get end-entity certificate. |
|
77 | - * |
|
78 | - * @return \X509\Certificate\Certificate |
|
79 | - */ |
|
80 | - public function certificate() |
|
81 | - { |
|
82 | - return $this->_certificates[count($this->_certificates) - 1]; |
|
83 | - } |
|
75 | + /** |
|
76 | + * Get end-entity certificate. |
|
77 | + * |
|
78 | + * @return \X509\Certificate\Certificate |
|
79 | + */ |
|
80 | + public function certificate() |
|
81 | + { |
|
82 | + return $this->_certificates[count($this->_certificates) - 1]; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Get certificate policies of the end-entity certificate. |
|
87 | - * |
|
88 | - * @return \X509\Certificate\Extension\CertificatePolicy\PolicyInformation[] |
|
89 | - */ |
|
90 | - public function policies() |
|
91 | - { |
|
92 | - if (!$this->_policyTree) { |
|
93 | - return array(); |
|
94 | - } |
|
95 | - return $this->_policyTree->policiesAtDepth(count($this->_certificates)); |
|
96 | - } |
|
85 | + /** |
|
86 | + * Get certificate policies of the end-entity certificate. |
|
87 | + * |
|
88 | + * @return \X509\Certificate\Extension\CertificatePolicy\PolicyInformation[] |
|
89 | + */ |
|
90 | + public function policies() |
|
91 | + { |
|
92 | + if (!$this->_policyTree) { |
|
93 | + return array(); |
|
94 | + } |
|
95 | + return $this->_policyTree->policiesAtDepth(count($this->_certificates)); |
|
96 | + } |
|
97 | 97 | } |
@@ -14,137 +14,137 @@ |
||
14 | 14 | */ |
15 | 15 | class CertificationPathBuilder |
16 | 16 | { |
17 | - /** |
|
18 | - * Trust anchors. |
|
19 | - * |
|
20 | - * @var CertificateBundle |
|
21 | - */ |
|
22 | - protected $_trustList; |
|
17 | + /** |
|
18 | + * Trust anchors. |
|
19 | + * |
|
20 | + * @var CertificateBundle |
|
21 | + */ |
|
22 | + protected $_trustList; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - * |
|
27 | - * @param CertificateBundle $trust_list List of trust anchors |
|
28 | - */ |
|
29 | - public function __construct(CertificateBundle $trust_list) |
|
30 | - { |
|
31 | - $this->_trustList = $trust_list; |
|
32 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + * |
|
27 | + * @param CertificateBundle $trust_list List of trust anchors |
|
28 | + */ |
|
29 | + public function __construct(CertificateBundle $trust_list) |
|
30 | + { |
|
31 | + $this->_trustList = $trust_list; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get all certification paths to given target certificate from |
|
36 | - * any trust anchor. |
|
37 | - * |
|
38 | - * @param Certificate $target Target certificate |
|
39 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
40 | - * certificates |
|
41 | - * @return CertificationPath[] |
|
42 | - */ |
|
43 | - public function allPathsToTarget(Certificate $target, |
|
44 | - CertificateBundle $intermediate = null) |
|
45 | - { |
|
46 | - $paths = $this->_resolvePathsToTarget($target, $intermediate); |
|
47 | - // map paths to CertificationPath objects |
|
48 | - return array_map( |
|
49 | - function ($certs) { |
|
50 | - return new CertificationPath(...$certs); |
|
51 | - }, $paths); |
|
52 | - } |
|
34 | + /** |
|
35 | + * Get all certification paths to given target certificate from |
|
36 | + * any trust anchor. |
|
37 | + * |
|
38 | + * @param Certificate $target Target certificate |
|
39 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
40 | + * certificates |
|
41 | + * @return CertificationPath[] |
|
42 | + */ |
|
43 | + public function allPathsToTarget(Certificate $target, |
|
44 | + CertificateBundle $intermediate = null) |
|
45 | + { |
|
46 | + $paths = $this->_resolvePathsToTarget($target, $intermediate); |
|
47 | + // map paths to CertificationPath objects |
|
48 | + return array_map( |
|
49 | + function ($certs) { |
|
50 | + return new CertificationPath(...$certs); |
|
51 | + }, $paths); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Resolve all possible certification paths from any trust anchor to |
|
56 | - * the target certificate, using optional intermediate certificates. |
|
57 | - * |
|
58 | - * Helper method for allPathsToTarget to be called recursively. |
|
59 | - * |
|
60 | - * @todo Implement loop detection |
|
61 | - * @param Certificate $target |
|
62 | - * @param CertificateBundle $intermediate |
|
63 | - * @return array[] Array of arrays containing path certificates |
|
64 | - */ |
|
65 | - private function _resolvePathsToTarget(Certificate $target, |
|
66 | - CertificateBundle $intermediate = null) |
|
67 | - { |
|
68 | - // array of possible paths |
|
69 | - $paths = array(); |
|
70 | - // signed by certificate in the trust list |
|
71 | - foreach ($this->_findIssuers($target, $this->_trustList) as $issuer) { |
|
72 | - // if target is self-signed, path consists of only |
|
73 | - // the target certificate |
|
74 | - if ($target->equals($issuer)) { |
|
75 | - $paths[] = array($target); |
|
76 | - } else { |
|
77 | - $paths[] = array($issuer, $target); |
|
78 | - } |
|
79 | - } |
|
80 | - if (isset($intermediate)) { |
|
81 | - // signed by intermediate certificate |
|
82 | - foreach ($this->_findIssuers($target, $intermediate) as $issuer) { |
|
83 | - // intermediate certificate must not be self-signed |
|
84 | - if ($issuer->isSelfIssued()) { |
|
85 | - continue; |
|
86 | - } |
|
87 | - // resolve paths to issuer |
|
88 | - $subpaths = $this->_resolvePathsToTarget($issuer, $intermediate); |
|
89 | - foreach ($subpaths as $path) { |
|
90 | - $paths[] = array_merge($path, array($target)); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - return $paths; |
|
95 | - } |
|
54 | + /** |
|
55 | + * Resolve all possible certification paths from any trust anchor to |
|
56 | + * the target certificate, using optional intermediate certificates. |
|
57 | + * |
|
58 | + * Helper method for allPathsToTarget to be called recursively. |
|
59 | + * |
|
60 | + * @todo Implement loop detection |
|
61 | + * @param Certificate $target |
|
62 | + * @param CertificateBundle $intermediate |
|
63 | + * @return array[] Array of arrays containing path certificates |
|
64 | + */ |
|
65 | + private function _resolvePathsToTarget(Certificate $target, |
|
66 | + CertificateBundle $intermediate = null) |
|
67 | + { |
|
68 | + // array of possible paths |
|
69 | + $paths = array(); |
|
70 | + // signed by certificate in the trust list |
|
71 | + foreach ($this->_findIssuers($target, $this->_trustList) as $issuer) { |
|
72 | + // if target is self-signed, path consists of only |
|
73 | + // the target certificate |
|
74 | + if ($target->equals($issuer)) { |
|
75 | + $paths[] = array($target); |
|
76 | + } else { |
|
77 | + $paths[] = array($issuer, $target); |
|
78 | + } |
|
79 | + } |
|
80 | + if (isset($intermediate)) { |
|
81 | + // signed by intermediate certificate |
|
82 | + foreach ($this->_findIssuers($target, $intermediate) as $issuer) { |
|
83 | + // intermediate certificate must not be self-signed |
|
84 | + if ($issuer->isSelfIssued()) { |
|
85 | + continue; |
|
86 | + } |
|
87 | + // resolve paths to issuer |
|
88 | + $subpaths = $this->_resolvePathsToTarget($issuer, $intermediate); |
|
89 | + foreach ($subpaths as $path) { |
|
90 | + $paths[] = array_merge($path, array($target)); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + return $paths; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Get shortest path to given target certificate from any trust anchor. |
|
99 | - * |
|
100 | - * @param Certificate $target Target certificate |
|
101 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
102 | - * certificates |
|
103 | - * @throws PathBuildingException |
|
104 | - * @return CertificationPath |
|
105 | - */ |
|
106 | - public function shortestPathToTarget(Certificate $target, |
|
107 | - CertificateBundle $intermediate = null) |
|
108 | - { |
|
109 | - $paths = $this->allPathsToTarget($target, $intermediate); |
|
110 | - if (!count($paths)) { |
|
111 | - throw new PathBuildingException("No certification paths."); |
|
112 | - } |
|
113 | - usort($paths, |
|
114 | - function ($a, $b) { |
|
115 | - return count($a) < count($b) ? -1 : 1; |
|
116 | - }); |
|
117 | - return reset($paths); |
|
118 | - } |
|
97 | + /** |
|
98 | + * Get shortest path to given target certificate from any trust anchor. |
|
99 | + * |
|
100 | + * @param Certificate $target Target certificate |
|
101 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
102 | + * certificates |
|
103 | + * @throws PathBuildingException |
|
104 | + * @return CertificationPath |
|
105 | + */ |
|
106 | + public function shortestPathToTarget(Certificate $target, |
|
107 | + CertificateBundle $intermediate = null) |
|
108 | + { |
|
109 | + $paths = $this->allPathsToTarget($target, $intermediate); |
|
110 | + if (!count($paths)) { |
|
111 | + throw new PathBuildingException("No certification paths."); |
|
112 | + } |
|
113 | + usort($paths, |
|
114 | + function ($a, $b) { |
|
115 | + return count($a) < count($b) ? -1 : 1; |
|
116 | + }); |
|
117 | + return reset($paths); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Find all issuers of the target certificate from a given bundle. |
|
122 | - * |
|
123 | - * @param Certificate $target Target certificate |
|
124 | - * @param CertificateBundle $bundle Certificates to search |
|
125 | - * @return Certificate[] |
|
126 | - */ |
|
127 | - protected function _findIssuers(Certificate $target, |
|
128 | - CertificateBundle $bundle) |
|
129 | - { |
|
130 | - $issuers = array(); |
|
131 | - $issuer_name = $target->tbsCertificate()->issuer(); |
|
132 | - $extensions = $target->tbsCertificate()->extensions(); |
|
133 | - // find by authority key identifier |
|
134 | - if ($extensions->hasAuthorityKeyIdentifier()) { |
|
135 | - $ext = $extensions->authorityKeyIdentifier(); |
|
136 | - if ($ext->hasKeyIdentifier()) { |
|
137 | - foreach ($bundle->allBySubjectKeyIdentifier( |
|
138 | - $ext->keyIdentifier()) as $issuer) { |
|
139 | - // check that issuer name matches |
|
140 | - if ($issuer->tbsCertificate() |
|
141 | - ->subject() |
|
142 | - ->equals($issuer_name)) { |
|
143 | - $issuers[] = $issuer; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - return $issuers; |
|
149 | - } |
|
120 | + /** |
|
121 | + * Find all issuers of the target certificate from a given bundle. |
|
122 | + * |
|
123 | + * @param Certificate $target Target certificate |
|
124 | + * @param CertificateBundle $bundle Certificates to search |
|
125 | + * @return Certificate[] |
|
126 | + */ |
|
127 | + protected function _findIssuers(Certificate $target, |
|
128 | + CertificateBundle $bundle) |
|
129 | + { |
|
130 | + $issuers = array(); |
|
131 | + $issuer_name = $target->tbsCertificate()->issuer(); |
|
132 | + $extensions = $target->tbsCertificate()->extensions(); |
|
133 | + // find by authority key identifier |
|
134 | + if ($extensions->hasAuthorityKeyIdentifier()) { |
|
135 | + $ext = $extensions->authorityKeyIdentifier(); |
|
136 | + if ($ext->hasKeyIdentifier()) { |
|
137 | + foreach ($bundle->allBySubjectKeyIdentifier( |
|
138 | + $ext->keyIdentifier()) as $issuer) { |
|
139 | + // check that issuer name matches |
|
140 | + if ($issuer->tbsCertificate() |
|
141 | + ->subject() |
|
142 | + ->equals($issuer_name)) { |
|
143 | + $issuers[] = $issuer; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + return $issuers; |
|
149 | + } |
|
150 | 150 | } |