@@ -19,139 +19,139 @@ |
||
19 | 19 | * @link https://tools.ietf.org/html/rfc5755#section-4.3.2 |
20 | 20 | */ |
21 | 21 | class TargetInformationExtension extends Extension implements |
22 | - \Countable, |
|
23 | - \IteratorAggregate |
|
22 | + \Countable, |
|
23 | + \IteratorAggregate |
|
24 | 24 | { |
25 | - /** |
|
26 | - * Targets elements. |
|
27 | - * |
|
28 | - * @var Targets[] $_targets |
|
29 | - */ |
|
30 | - protected $_targets; |
|
25 | + /** |
|
26 | + * Targets elements. |
|
27 | + * |
|
28 | + * @var Targets[] $_targets |
|
29 | + */ |
|
30 | + protected $_targets; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Targets[] merged to single Targets. |
|
34 | - * |
|
35 | - * @var Targets|null |
|
36 | - */ |
|
37 | - private $_merged; |
|
32 | + /** |
|
33 | + * Targets[] merged to single Targets. |
|
34 | + * |
|
35 | + * @var Targets|null |
|
36 | + */ |
|
37 | + private $_merged; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor. |
|
41 | - * |
|
42 | - * @param bool $critical |
|
43 | - * @param Targets[] $targets |
|
44 | - */ |
|
45 | - public function __construct(bool $critical, Targets ...$targets) |
|
46 | - { |
|
47 | - parent::__construct(self::OID_TARGET_INFORMATION, $critical); |
|
48 | - $this->_targets = $targets; |
|
49 | - } |
|
39 | + /** |
|
40 | + * Constructor. |
|
41 | + * |
|
42 | + * @param bool $critical |
|
43 | + * @param Targets[] $targets |
|
44 | + */ |
|
45 | + public function __construct(bool $critical, Targets ...$targets) |
|
46 | + { |
|
47 | + parent::__construct(self::OID_TARGET_INFORMATION, $critical); |
|
48 | + $this->_targets = $targets; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Initialize from one or more Target objects. |
|
53 | - * |
|
54 | - * Extension criticality shall be set to true as specified by RFC 5755. |
|
55 | - * |
|
56 | - * @param Target[] $target |
|
57 | - * @return TargetInformationExtension |
|
58 | - */ |
|
59 | - public static function fromTargets(Target ...$target): self |
|
60 | - { |
|
61 | - return new self(true, new Targets(...$target)); |
|
62 | - } |
|
51 | + /** |
|
52 | + * Initialize from one or more Target objects. |
|
53 | + * |
|
54 | + * Extension criticality shall be set to true as specified by RFC 5755. |
|
55 | + * |
|
56 | + * @param Target[] $target |
|
57 | + * @return TargetInformationExtension |
|
58 | + */ |
|
59 | + public static function fromTargets(Target ...$target): self |
|
60 | + { |
|
61 | + return new self(true, new Targets(...$target)); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Reset internal state on clone. |
|
66 | - */ |
|
67 | - public function __clone() |
|
68 | - { |
|
69 | - $this->_merged = null; |
|
70 | - } |
|
64 | + /** |
|
65 | + * Reset internal state on clone. |
|
66 | + */ |
|
67 | + public function __clone() |
|
68 | + { |
|
69 | + $this->_merged = null; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * |
|
74 | - * {@inheritdoc} |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - protected static function _fromDER(string $data, bool $critical): self |
|
78 | - { |
|
79 | - $targets = array_map( |
|
80 | - function (UnspecifiedType $el) { |
|
81 | - return Targets::fromASN1($el->asSequence()); |
|
82 | - }, Sequence::fromDER($data)->elements()); |
|
83 | - return new self($critical, ...$targets); |
|
84 | - } |
|
72 | + /** |
|
73 | + * |
|
74 | + * {@inheritdoc} |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + protected static function _fromDER(string $data, bool $critical): self |
|
78 | + { |
|
79 | + $targets = array_map( |
|
80 | + function (UnspecifiedType $el) { |
|
81 | + return Targets::fromASN1($el->asSequence()); |
|
82 | + }, Sequence::fromDER($data)->elements()); |
|
83 | + return new self($critical, ...$targets); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get all targets. |
|
88 | - * |
|
89 | - * @return Targets |
|
90 | - */ |
|
91 | - public function targets(): Targets |
|
92 | - { |
|
93 | - if (!isset($this->_merged)) { |
|
94 | - $a = array(); |
|
95 | - foreach ($this->_targets as $targets) { |
|
96 | - $a = array_merge($a, $targets->all()); |
|
97 | - } |
|
98 | - $this->_merged = new Targets(...$a); |
|
99 | - } |
|
100 | - return $this->_merged; |
|
101 | - } |
|
86 | + /** |
|
87 | + * Get all targets. |
|
88 | + * |
|
89 | + * @return Targets |
|
90 | + */ |
|
91 | + public function targets(): Targets |
|
92 | + { |
|
93 | + if (!isset($this->_merged)) { |
|
94 | + $a = array(); |
|
95 | + foreach ($this->_targets as $targets) { |
|
96 | + $a = array_merge($a, $targets->all()); |
|
97 | + } |
|
98 | + $this->_merged = new Targets(...$a); |
|
99 | + } |
|
100 | + return $this->_merged; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Get all name targets. |
|
105 | - * |
|
106 | - * @return Target[] |
|
107 | - */ |
|
108 | - public function names(): array |
|
109 | - { |
|
110 | - return $this->targets()->nameTargets(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * Get all name targets. |
|
105 | + * |
|
106 | + * @return Target[] |
|
107 | + */ |
|
108 | + public function names(): array |
|
109 | + { |
|
110 | + return $this->targets()->nameTargets(); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get all group targets. |
|
115 | - * |
|
116 | - * @return Target[] |
|
117 | - */ |
|
118 | - public function groups(): array |
|
119 | - { |
|
120 | - return $this->targets()->groupTargets(); |
|
121 | - } |
|
113 | + /** |
|
114 | + * Get all group targets. |
|
115 | + * |
|
116 | + * @return Target[] |
|
117 | + */ |
|
118 | + public function groups(): array |
|
119 | + { |
|
120 | + return $this->targets()->groupTargets(); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * |
|
125 | - * @see \X509\Certificate\Extension\Extension::_valueASN1() |
|
126 | - * @return Sequence |
|
127 | - */ |
|
128 | - protected function _valueASN1(): Sequence |
|
129 | - { |
|
130 | - $elements = array_map( |
|
131 | - function (Targets $targets) { |
|
132 | - return $targets->toASN1(); |
|
133 | - }, $this->_targets); |
|
134 | - return new Sequence(...$elements); |
|
135 | - } |
|
123 | + /** |
|
124 | + * |
|
125 | + * @see \X509\Certificate\Extension\Extension::_valueASN1() |
|
126 | + * @return Sequence |
|
127 | + */ |
|
128 | + protected function _valueASN1(): Sequence |
|
129 | + { |
|
130 | + $elements = array_map( |
|
131 | + function (Targets $targets) { |
|
132 | + return $targets->toASN1(); |
|
133 | + }, $this->_targets); |
|
134 | + return new Sequence(...$elements); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * |
|
139 | - * @see \Countable::count() |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function count(): int |
|
143 | - { |
|
144 | - return count($this->targets()); |
|
145 | - } |
|
137 | + /** |
|
138 | + * |
|
139 | + * @see \Countable::count() |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function count(): int |
|
143 | + { |
|
144 | + return count($this->targets()); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Get iterator for targets. |
|
149 | - * |
|
150 | - * @see \IteratorAggregate::getIterator() |
|
151 | - * @return \ArrayIterator |
|
152 | - */ |
|
153 | - public function getIterator(): \ArrayIterator |
|
154 | - { |
|
155 | - return new \ArrayIterator($this->targets()->all()); |
|
156 | - } |
|
147 | + /** |
|
148 | + * Get iterator for targets. |
|
149 | + * |
|
150 | + * @see \IteratorAggregate::getIterator() |
|
151 | + * @return \ArrayIterator |
|
152 | + */ |
|
153 | + public function getIterator(): \ArrayIterator |
|
154 | + { |
|
155 | + return new \ArrayIterator($this->targets()->all()); |
|
156 | + } |
|
157 | 157 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | protected static function _fromDER(string $data, bool $critical): self |
78 | 78 | { |
79 | 79 | $targets = array_map( |
80 | - function (UnspecifiedType $el) { |
|
80 | + function(UnspecifiedType $el) { |
|
81 | 81 | return Targets::fromASN1($el->asSequence()); |
82 | 82 | }, Sequence::fromDER($data)->elements()); |
83 | 83 | return new self($critical, ...$targets); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | protected function _valueASN1(): Sequence |
129 | 129 | { |
130 | 130 | $elements = array_map( |
131 | - function (Targets $targets) { |
|
131 | + function(Targets $targets) { |
|
132 | 132 | return $targets->toASN1(); |
133 | 133 | }, $this->_targets); |
134 | 134 | return new Sequence(...$elements); |
@@ -14,265 +14,265 @@ |
||
14 | 14 | */ |
15 | 15 | class PolicyNode implements \IteratorAggregate, \Countable |
16 | 16 | { |
17 | - /** |
|
18 | - * Policy OID. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_validPolicy; |
|
17 | + /** |
|
18 | + * Policy OID. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_validPolicy; |
|
23 | 23 | |
24 | - /** |
|
25 | - * List of qualifiers. |
|
26 | - * |
|
27 | - * @var \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
28 | - */ |
|
29 | - protected $_qualifiers; |
|
24 | + /** |
|
25 | + * List of qualifiers. |
|
26 | + * |
|
27 | + * @var \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
28 | + */ |
|
29 | + protected $_qualifiers; |
|
30 | 30 | |
31 | - /** |
|
32 | - * List of expected policy OIDs. |
|
33 | - * |
|
34 | - * @var string[] |
|
35 | - */ |
|
36 | - protected $_expectedPolicies; |
|
31 | + /** |
|
32 | + * List of expected policy OIDs. |
|
33 | + * |
|
34 | + * @var string[] |
|
35 | + */ |
|
36 | + protected $_expectedPolicies; |
|
37 | 37 | |
38 | - /** |
|
39 | - * List of child nodes. |
|
40 | - * |
|
41 | - * @var PolicyNode[] |
|
42 | - */ |
|
43 | - protected $_children; |
|
38 | + /** |
|
39 | + * List of child nodes. |
|
40 | + * |
|
41 | + * @var PolicyNode[] |
|
42 | + */ |
|
43 | + protected $_children; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Reference to the parent node. |
|
47 | - * |
|
48 | - * @var PolicyNode|null |
|
49 | - */ |
|
50 | - protected $_parent; |
|
45 | + /** |
|
46 | + * Reference to the parent node. |
|
47 | + * |
|
48 | + * @var PolicyNode|null |
|
49 | + */ |
|
50 | + protected $_parent; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Constructor. |
|
54 | - * |
|
55 | - * @param string $valid_policy Policy OID |
|
56 | - * @param \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] $qualifiers |
|
57 | - * @param string[] $expected_policies |
|
58 | - */ |
|
59 | - public function __construct(string $valid_policy, array $qualifiers, |
|
60 | - array $expected_policies) |
|
61 | - { |
|
62 | - $this->_validPolicy = $valid_policy; |
|
63 | - $this->_qualifiers = $qualifiers; |
|
64 | - $this->_expectedPolicies = $expected_policies; |
|
65 | - $this->_children = array(); |
|
66 | - } |
|
52 | + /** |
|
53 | + * Constructor. |
|
54 | + * |
|
55 | + * @param string $valid_policy Policy OID |
|
56 | + * @param \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] $qualifiers |
|
57 | + * @param string[] $expected_policies |
|
58 | + */ |
|
59 | + public function __construct(string $valid_policy, array $qualifiers, |
|
60 | + array $expected_policies) |
|
61 | + { |
|
62 | + $this->_validPolicy = $valid_policy; |
|
63 | + $this->_qualifiers = $qualifiers; |
|
64 | + $this->_expectedPolicies = $expected_policies; |
|
65 | + $this->_children = array(); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Create initial node for the policy tree. |
|
70 | - * |
|
71 | - * @return self |
|
72 | - */ |
|
73 | - public static function anyPolicyNode(): self |
|
74 | - { |
|
75 | - return new self(PolicyInformation::OID_ANY_POLICY, array(), |
|
76 | - array(PolicyInformation::OID_ANY_POLICY)); |
|
77 | - } |
|
68 | + /** |
|
69 | + * Create initial node for the policy tree. |
|
70 | + * |
|
71 | + * @return self |
|
72 | + */ |
|
73 | + public static function anyPolicyNode(): self |
|
74 | + { |
|
75 | + return new self(PolicyInformation::OID_ANY_POLICY, array(), |
|
76 | + array(PolicyInformation::OID_ANY_POLICY)); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Get the valid policy OID. |
|
81 | - * |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function validPolicy(): string |
|
85 | - { |
|
86 | - return $this->_validPolicy; |
|
87 | - } |
|
79 | + /** |
|
80 | + * Get the valid policy OID. |
|
81 | + * |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function validPolicy(): string |
|
85 | + { |
|
86 | + return $this->_validPolicy; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Check whether node has anyPolicy as a valid policy. |
|
91 | - * |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - public function isAnyPolicy(): bool |
|
95 | - { |
|
96 | - return PolicyInformation::OID_ANY_POLICY == $this->_validPolicy; |
|
97 | - } |
|
89 | + /** |
|
90 | + * Check whether node has anyPolicy as a valid policy. |
|
91 | + * |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + public function isAnyPolicy(): bool |
|
95 | + { |
|
96 | + return PolicyInformation::OID_ANY_POLICY == $this->_validPolicy; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get the qualifier set. |
|
101 | - * |
|
102 | - * @return \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
103 | - */ |
|
104 | - public function qualifiers(): array |
|
105 | - { |
|
106 | - return $this->_qualifiers; |
|
107 | - } |
|
99 | + /** |
|
100 | + * Get the qualifier set. |
|
101 | + * |
|
102 | + * @return \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
103 | + */ |
|
104 | + public function qualifiers(): array |
|
105 | + { |
|
106 | + return $this->_qualifiers; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Check whether node has OID as an expected policy. |
|
111 | - * |
|
112 | - * @param string $oid |
|
113 | - * @return boolean |
|
114 | - */ |
|
115 | - public function hasExpectedPolicy(string $oid): bool |
|
116 | - { |
|
117 | - return in_array($oid, $this->_expectedPolicies); |
|
118 | - } |
|
109 | + /** |
|
110 | + * Check whether node has OID as an expected policy. |
|
111 | + * |
|
112 | + * @param string $oid |
|
113 | + * @return boolean |
|
114 | + */ |
|
115 | + public function hasExpectedPolicy(string $oid): bool |
|
116 | + { |
|
117 | + return in_array($oid, $this->_expectedPolicies); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Get the expected policy set. |
|
122 | - * |
|
123 | - * @return string[] |
|
124 | - */ |
|
125 | - public function expectedPolicies(): array |
|
126 | - { |
|
127 | - return $this->_expectedPolicies; |
|
128 | - } |
|
120 | + /** |
|
121 | + * Get the expected policy set. |
|
122 | + * |
|
123 | + * @return string[] |
|
124 | + */ |
|
125 | + public function expectedPolicies(): array |
|
126 | + { |
|
127 | + return $this->_expectedPolicies; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Set expected policies. |
|
132 | - * |
|
133 | - * @param string ...$oids Policy OIDs |
|
134 | - */ |
|
135 | - public function setExpectedPolicies(string ...$oids) |
|
136 | - { |
|
137 | - $this->_expectedPolicies = $oids; |
|
138 | - } |
|
130 | + /** |
|
131 | + * Set expected policies. |
|
132 | + * |
|
133 | + * @param string ...$oids Policy OIDs |
|
134 | + */ |
|
135 | + public function setExpectedPolicies(string ...$oids) |
|
136 | + { |
|
137 | + $this->_expectedPolicies = $oids; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Check whether node has a child node with given valid policy OID. |
|
142 | - * |
|
143 | - * @param string $oid |
|
144 | - * @return boolean |
|
145 | - */ |
|
146 | - public function hasChildWithValidPolicy(string $oid): bool |
|
147 | - { |
|
148 | - foreach ($this->_children as $node) { |
|
149 | - if ($node->validPolicy() == $oid) { |
|
150 | - return true; |
|
151 | - } |
|
152 | - } |
|
153 | - return false; |
|
154 | - } |
|
140 | + /** |
|
141 | + * Check whether node has a child node with given valid policy OID. |
|
142 | + * |
|
143 | + * @param string $oid |
|
144 | + * @return boolean |
|
145 | + */ |
|
146 | + public function hasChildWithValidPolicy(string $oid): bool |
|
147 | + { |
|
148 | + foreach ($this->_children as $node) { |
|
149 | + if ($node->validPolicy() == $oid) { |
|
150 | + return true; |
|
151 | + } |
|
152 | + } |
|
153 | + return false; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Add child node. |
|
158 | - * |
|
159 | - * @param PolicyNode $node |
|
160 | - * @return self |
|
161 | - */ |
|
162 | - public function addChild(PolicyNode $node): self |
|
163 | - { |
|
164 | - $id = spl_object_hash($node); |
|
165 | - $node->_parent = $this; |
|
166 | - $this->_children[$id] = $node; |
|
167 | - return $this; |
|
168 | - } |
|
156 | + /** |
|
157 | + * Add child node. |
|
158 | + * |
|
159 | + * @param PolicyNode $node |
|
160 | + * @return self |
|
161 | + */ |
|
162 | + public function addChild(PolicyNode $node): self |
|
163 | + { |
|
164 | + $id = spl_object_hash($node); |
|
165 | + $node->_parent = $this; |
|
166 | + $this->_children[$id] = $node; |
|
167 | + return $this; |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Get the child nodes. |
|
172 | - * |
|
173 | - * @return PolicyNode[] |
|
174 | - */ |
|
175 | - public function children(): array |
|
176 | - { |
|
177 | - return array_values($this->_children); |
|
178 | - } |
|
170 | + /** |
|
171 | + * Get the child nodes. |
|
172 | + * |
|
173 | + * @return PolicyNode[] |
|
174 | + */ |
|
175 | + public function children(): array |
|
176 | + { |
|
177 | + return array_values($this->_children); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Remove this node from the tree. |
|
182 | - * |
|
183 | - * @return self The removed node |
|
184 | - */ |
|
185 | - public function remove(): self |
|
186 | - { |
|
187 | - if ($this->_parent) { |
|
188 | - $id = spl_object_hash($this); |
|
189 | - unset($this->_parent->_children[$id]); |
|
190 | - unset($this->_parent); |
|
191 | - } |
|
192 | - return $this; |
|
193 | - } |
|
180 | + /** |
|
181 | + * Remove this node from the tree. |
|
182 | + * |
|
183 | + * @return self The removed node |
|
184 | + */ |
|
185 | + public function remove(): self |
|
186 | + { |
|
187 | + if ($this->_parent) { |
|
188 | + $id = spl_object_hash($this); |
|
189 | + unset($this->_parent->_children[$id]); |
|
190 | + unset($this->_parent); |
|
191 | + } |
|
192 | + return $this; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * Check whether node has a parent. |
|
197 | - * |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function hasParent(): bool |
|
201 | - { |
|
202 | - return isset($this->_parent); |
|
203 | - } |
|
195 | + /** |
|
196 | + * Check whether node has a parent. |
|
197 | + * |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function hasParent(): bool |
|
201 | + { |
|
202 | + return isset($this->_parent); |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Get the parent node. |
|
207 | - * |
|
208 | - * @return PolicyNode|null |
|
209 | - */ |
|
210 | - public function parent() |
|
211 | - { |
|
212 | - return $this->_parent; |
|
213 | - } |
|
205 | + /** |
|
206 | + * Get the parent node. |
|
207 | + * |
|
208 | + * @return PolicyNode|null |
|
209 | + */ |
|
210 | + public function parent() |
|
211 | + { |
|
212 | + return $this->_parent; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Get chain of parent nodes from this node's parent to the root node. |
|
217 | - * |
|
218 | - * @return PolicyNode[] |
|
219 | - */ |
|
220 | - public function parents(): array |
|
221 | - { |
|
222 | - if (!$this->_parent) { |
|
223 | - return array(); |
|
224 | - } |
|
225 | - $nodes = $this->_parent->parents(); |
|
226 | - $nodes[] = $this->_parent; |
|
227 | - return array_reverse($nodes); |
|
228 | - } |
|
215 | + /** |
|
216 | + * Get chain of parent nodes from this node's parent to the root node. |
|
217 | + * |
|
218 | + * @return PolicyNode[] |
|
219 | + */ |
|
220 | + public function parents(): array |
|
221 | + { |
|
222 | + if (!$this->_parent) { |
|
223 | + return array(); |
|
224 | + } |
|
225 | + $nodes = $this->_parent->parents(); |
|
226 | + $nodes[] = $this->_parent; |
|
227 | + return array_reverse($nodes); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Walk tree from this node, applying a callback for each node. |
|
232 | - * |
|
233 | - * Nodes are traversed depth-first and callback shall be applied post-order. |
|
234 | - * |
|
235 | - * @param callable $fn |
|
236 | - */ |
|
237 | - public function walkNodes(callable $fn) |
|
238 | - { |
|
239 | - foreach ($this->_children as $node) { |
|
240 | - $node->walkNodes($fn); |
|
241 | - } |
|
242 | - $fn($this); |
|
243 | - } |
|
230 | + /** |
|
231 | + * Walk tree from this node, applying a callback for each node. |
|
232 | + * |
|
233 | + * Nodes are traversed depth-first and callback shall be applied post-order. |
|
234 | + * |
|
235 | + * @param callable $fn |
|
236 | + */ |
|
237 | + public function walkNodes(callable $fn) |
|
238 | + { |
|
239 | + foreach ($this->_children as $node) { |
|
240 | + $node->walkNodes($fn); |
|
241 | + } |
|
242 | + $fn($this); |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Get the total number of nodes in a tree. |
|
247 | - * |
|
248 | - * @return int |
|
249 | - */ |
|
250 | - public function nodeCount(): int |
|
251 | - { |
|
252 | - $c = 1; |
|
253 | - foreach ($this->_children as $child) { |
|
254 | - $c += $child->nodeCount(); |
|
255 | - } |
|
256 | - return $c; |
|
257 | - } |
|
245 | + /** |
|
246 | + * Get the total number of nodes in a tree. |
|
247 | + * |
|
248 | + * @return int |
|
249 | + */ |
|
250 | + public function nodeCount(): int |
|
251 | + { |
|
252 | + $c = 1; |
|
253 | + foreach ($this->_children as $child) { |
|
254 | + $c += $child->nodeCount(); |
|
255 | + } |
|
256 | + return $c; |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Get the number of child nodes. |
|
261 | - * |
|
262 | - * @see \Countable::count() |
|
263 | - */ |
|
264 | - public function count(): int |
|
265 | - { |
|
266 | - return count($this->_children); |
|
267 | - } |
|
259 | + /** |
|
260 | + * Get the number of child nodes. |
|
261 | + * |
|
262 | + * @see \Countable::count() |
|
263 | + */ |
|
264 | + public function count(): int |
|
265 | + { |
|
266 | + return count($this->_children); |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * Get iterator for the child nodes. |
|
271 | - * |
|
272 | - * @see \IteratorAggregate::getIterator() |
|
273 | - */ |
|
274 | - public function getIterator(): \ArrayIterator |
|
275 | - { |
|
276 | - return new \ArrayIterator($this->_children); |
|
277 | - } |
|
269 | + /** |
|
270 | + * Get iterator for the child nodes. |
|
271 | + * |
|
272 | + * @see \IteratorAggregate::getIterator() |
|
273 | + */ |
|
274 | + public function getIterator(): \ArrayIterator |
|
275 | + { |
|
276 | + return new \ArrayIterator($this->_children); |
|
277 | + } |
|
278 | 278 | } |
@@ -10,411 +10,411 @@ |
||
10 | 10 | |
11 | 11 | class PolicyTree |
12 | 12 | { |
13 | - /** |
|
14 | - * Root node at depth zero. |
|
15 | - * |
|
16 | - * @var PolicyNode|null |
|
17 | - */ |
|
18 | - protected $_root; |
|
13 | + /** |
|
14 | + * Root node at depth zero. |
|
15 | + * |
|
16 | + * @var PolicyNode|null |
|
17 | + */ |
|
18 | + protected $_root; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Constructor. |
|
22 | - * |
|
23 | - * @param PolicyNode $root Initial root node |
|
24 | - */ |
|
25 | - public function __construct(PolicyNode $root) |
|
26 | - { |
|
27 | - $this->_root = $root; |
|
28 | - } |
|
20 | + /** |
|
21 | + * Constructor. |
|
22 | + * |
|
23 | + * @param PolicyNode $root Initial root node |
|
24 | + */ |
|
25 | + public function __construct(PolicyNode $root) |
|
26 | + { |
|
27 | + $this->_root = $root; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Process policy information from the certificate. |
|
32 | - * |
|
33 | - * Certificate policies extension must be present. |
|
34 | - * |
|
35 | - * @param ValidatorState $state |
|
36 | - * @param Certificate $cert |
|
37 | - * @return ValidatorState |
|
38 | - */ |
|
39 | - public function processPolicies(ValidatorState $state, Certificate $cert): ValidatorState |
|
40 | - { |
|
41 | - $policies = $cert->tbsCertificate() |
|
42 | - ->extensions() |
|
43 | - ->certificatePolicies(); |
|
44 | - $tree = clone $this; |
|
45 | - // (d.1) for each policy P not equal to anyPolicy |
|
46 | - foreach ($policies as $policy) { |
|
47 | - if ($policy->isAnyPolicy()) { |
|
48 | - $tree->_processAnyPolicy($policy, $cert, $state); |
|
49 | - } else { |
|
50 | - $tree->_processPolicy($policy, $state); |
|
51 | - } |
|
52 | - } |
|
53 | - // if whole tree is pruned |
|
54 | - if (!$tree->_pruneTree($state->index() - 1)) { |
|
55 | - return $state->withoutValidPolicyTree(); |
|
56 | - } |
|
57 | - return $state->withValidPolicyTree($tree); |
|
58 | - } |
|
30 | + /** |
|
31 | + * Process policy information from the certificate. |
|
32 | + * |
|
33 | + * Certificate policies extension must be present. |
|
34 | + * |
|
35 | + * @param ValidatorState $state |
|
36 | + * @param Certificate $cert |
|
37 | + * @return ValidatorState |
|
38 | + */ |
|
39 | + public function processPolicies(ValidatorState $state, Certificate $cert): ValidatorState |
|
40 | + { |
|
41 | + $policies = $cert->tbsCertificate() |
|
42 | + ->extensions() |
|
43 | + ->certificatePolicies(); |
|
44 | + $tree = clone $this; |
|
45 | + // (d.1) for each policy P not equal to anyPolicy |
|
46 | + foreach ($policies as $policy) { |
|
47 | + if ($policy->isAnyPolicy()) { |
|
48 | + $tree->_processAnyPolicy($policy, $cert, $state); |
|
49 | + } else { |
|
50 | + $tree->_processPolicy($policy, $state); |
|
51 | + } |
|
52 | + } |
|
53 | + // if whole tree is pruned |
|
54 | + if (!$tree->_pruneTree($state->index() - 1)) { |
|
55 | + return $state->withoutValidPolicyTree(); |
|
56 | + } |
|
57 | + return $state->withValidPolicyTree($tree); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Process policy mappings from the certificate. |
|
62 | - * |
|
63 | - * @param ValidatorState $state |
|
64 | - * @param Certificate $cert |
|
65 | - * @return ValidatorState |
|
66 | - */ |
|
67 | - public function processMappings(ValidatorState $state, Certificate $cert): ValidatorState |
|
68 | - { |
|
69 | - $tree = clone $this; |
|
70 | - if ($state->policyMapping() > 0) { |
|
71 | - $tree->_applyMappings($cert, $state); |
|
72 | - } else if ($state->policyMapping() == 0) { |
|
73 | - $tree->_deleteMappings($cert, $state); |
|
74 | - } |
|
75 | - // if whole tree is pruned |
|
76 | - if (!$tree->_root) { |
|
77 | - return $state->withoutValidPolicyTree(); |
|
78 | - } |
|
79 | - return $state->withValidPolicyTree($tree); |
|
80 | - } |
|
60 | + /** |
|
61 | + * Process policy mappings from the certificate. |
|
62 | + * |
|
63 | + * @param ValidatorState $state |
|
64 | + * @param Certificate $cert |
|
65 | + * @return ValidatorState |
|
66 | + */ |
|
67 | + public function processMappings(ValidatorState $state, Certificate $cert): ValidatorState |
|
68 | + { |
|
69 | + $tree = clone $this; |
|
70 | + if ($state->policyMapping() > 0) { |
|
71 | + $tree->_applyMappings($cert, $state); |
|
72 | + } else if ($state->policyMapping() == 0) { |
|
73 | + $tree->_deleteMappings($cert, $state); |
|
74 | + } |
|
75 | + // if whole tree is pruned |
|
76 | + if (!$tree->_root) { |
|
77 | + return $state->withoutValidPolicyTree(); |
|
78 | + } |
|
79 | + return $state->withValidPolicyTree($tree); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
|
84 | - * |
|
85 | - * @param ValidatorState $state |
|
86 | - * @param array $policies |
|
87 | - * @return ValidatorState |
|
88 | - */ |
|
89 | - public function calculateIntersection(ValidatorState $state, array $policies): ValidatorState |
|
90 | - { |
|
91 | - $tree = clone $this; |
|
92 | - $valid_policy_node_set = $tree->_validPolicyNodeSet(); |
|
93 | - // 2. If the valid_policy of any node in the valid_policy_node_set |
|
94 | - // is not in the user-initial-policy-set and is not anyPolicy, |
|
95 | - // delete this node and all its children. |
|
96 | - $valid_policy_node_set = array_filter($valid_policy_node_set, |
|
97 | - function (PolicyNode $node) use ($policies) { |
|
98 | - if ($node->isAnyPolicy()) { |
|
99 | - return true; |
|
100 | - } |
|
101 | - if (in_array($node->validPolicy(), $policies)) { |
|
102 | - return true; |
|
103 | - } |
|
104 | - $node->remove(); |
|
105 | - return false; |
|
106 | - }); |
|
107 | - // array of valid policy OIDs |
|
108 | - $valid_policy_set = array_map( |
|
109 | - function (PolicyNode $node) { |
|
110 | - return $node->validPolicy(); |
|
111 | - }, $valid_policy_node_set); |
|
112 | - // 3. If the valid_policy_tree includes a node of depth n with |
|
113 | - // the valid_policy anyPolicy and the user-initial-policy-set |
|
114 | - // is not any-policy |
|
115 | - foreach ($tree->_nodesAtDepth($state->index()) as $node) { |
|
116 | - if ($node->hasParent() && $node->isAnyPolicy()) { |
|
117 | - // a. Set P-Q to the qualifier_set in the node of depth n |
|
118 | - // with valid_policy anyPolicy. |
|
119 | - $pq = $node->qualifiers(); |
|
120 | - // b. For each P-OID in the user-initial-policy-set that is not |
|
121 | - // the valid_policy of a node in the valid_policy_node_set, |
|
122 | - // create a child node whose parent is the node of depth n-1 |
|
123 | - // with the valid_policy anyPolicy. |
|
124 | - $poids = array_diff($policies, $valid_policy_set); |
|
125 | - foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) { |
|
126 | - if ($parent->isAnyPolicy()) { |
|
127 | - // Set the values in the child node as follows: |
|
128 | - // set the valid_policy to P-OID, set the qualifier_set |
|
129 | - // to P-Q, and set the expected_policy_set to {P-OID}. |
|
130 | - foreach ($poids as $poid) { |
|
131 | - $parent->addChild( |
|
132 | - new PolicyNode($poid, $pq, array($poid))); |
|
133 | - } |
|
134 | - break; |
|
135 | - } |
|
136 | - } |
|
137 | - // c. Delete the node of depth n with the |
|
138 | - // valid_policy anyPolicy. |
|
139 | - $node->remove(); |
|
140 | - } |
|
141 | - } |
|
142 | - // 4. If there is a node in the valid_policy_tree of depth n-1 or less |
|
143 | - // without any child nodes, delete that node. Repeat this step until |
|
144 | - // there are no nodes of depth n-1 or less without children. |
|
145 | - if (!$tree->_pruneTree($state->index() - 1)) { |
|
146 | - return $state->withoutValidPolicyTree(); |
|
147 | - } |
|
148 | - return $state->withValidPolicyTree($tree); |
|
149 | - } |
|
82 | + /** |
|
83 | + * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
|
84 | + * |
|
85 | + * @param ValidatorState $state |
|
86 | + * @param array $policies |
|
87 | + * @return ValidatorState |
|
88 | + */ |
|
89 | + public function calculateIntersection(ValidatorState $state, array $policies): ValidatorState |
|
90 | + { |
|
91 | + $tree = clone $this; |
|
92 | + $valid_policy_node_set = $tree->_validPolicyNodeSet(); |
|
93 | + // 2. If the valid_policy of any node in the valid_policy_node_set |
|
94 | + // is not in the user-initial-policy-set and is not anyPolicy, |
|
95 | + // delete this node and all its children. |
|
96 | + $valid_policy_node_set = array_filter($valid_policy_node_set, |
|
97 | + function (PolicyNode $node) use ($policies) { |
|
98 | + if ($node->isAnyPolicy()) { |
|
99 | + return true; |
|
100 | + } |
|
101 | + if (in_array($node->validPolicy(), $policies)) { |
|
102 | + return true; |
|
103 | + } |
|
104 | + $node->remove(); |
|
105 | + return false; |
|
106 | + }); |
|
107 | + // array of valid policy OIDs |
|
108 | + $valid_policy_set = array_map( |
|
109 | + function (PolicyNode $node) { |
|
110 | + return $node->validPolicy(); |
|
111 | + }, $valid_policy_node_set); |
|
112 | + // 3. If the valid_policy_tree includes a node of depth n with |
|
113 | + // the valid_policy anyPolicy and the user-initial-policy-set |
|
114 | + // is not any-policy |
|
115 | + foreach ($tree->_nodesAtDepth($state->index()) as $node) { |
|
116 | + if ($node->hasParent() && $node->isAnyPolicy()) { |
|
117 | + // a. Set P-Q to the qualifier_set in the node of depth n |
|
118 | + // with valid_policy anyPolicy. |
|
119 | + $pq = $node->qualifiers(); |
|
120 | + // b. For each P-OID in the user-initial-policy-set that is not |
|
121 | + // the valid_policy of a node in the valid_policy_node_set, |
|
122 | + // create a child node whose parent is the node of depth n-1 |
|
123 | + // with the valid_policy anyPolicy. |
|
124 | + $poids = array_diff($policies, $valid_policy_set); |
|
125 | + foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) { |
|
126 | + if ($parent->isAnyPolicy()) { |
|
127 | + // Set the values in the child node as follows: |
|
128 | + // set the valid_policy to P-OID, set the qualifier_set |
|
129 | + // to P-Q, and set the expected_policy_set to {P-OID}. |
|
130 | + foreach ($poids as $poid) { |
|
131 | + $parent->addChild( |
|
132 | + new PolicyNode($poid, $pq, array($poid))); |
|
133 | + } |
|
134 | + break; |
|
135 | + } |
|
136 | + } |
|
137 | + // c. Delete the node of depth n with the |
|
138 | + // valid_policy anyPolicy. |
|
139 | + $node->remove(); |
|
140 | + } |
|
141 | + } |
|
142 | + // 4. If there is a node in the valid_policy_tree of depth n-1 or less |
|
143 | + // without any child nodes, delete that node. Repeat this step until |
|
144 | + // there are no nodes of depth n-1 or less without children. |
|
145 | + if (!$tree->_pruneTree($state->index() - 1)) { |
|
146 | + return $state->withoutValidPolicyTree(); |
|
147 | + } |
|
148 | + return $state->withValidPolicyTree($tree); |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Get policies at given policy tree depth. |
|
153 | - * |
|
154 | - * @param int $i Depth in range 1..n |
|
155 | - * @return PolicyInformation[] |
|
156 | - */ |
|
157 | - public function policiesAtDepth(int $i): array |
|
158 | - { |
|
159 | - $policies = array(); |
|
160 | - foreach ($this->_nodesAtDepth($i) as $node) { |
|
161 | - $policies[] = new PolicyInformation($node->validPolicy(), |
|
162 | - ...$node->qualifiers()); |
|
163 | - } |
|
164 | - return $policies; |
|
165 | - } |
|
151 | + /** |
|
152 | + * Get policies at given policy tree depth. |
|
153 | + * |
|
154 | + * @param int $i Depth in range 1..n |
|
155 | + * @return PolicyInformation[] |
|
156 | + */ |
|
157 | + public function policiesAtDepth(int $i): array |
|
158 | + { |
|
159 | + $policies = array(); |
|
160 | + foreach ($this->_nodesAtDepth($i) as $node) { |
|
161 | + $policies[] = new PolicyInformation($node->validPolicy(), |
|
162 | + ...$node->qualifiers()); |
|
163 | + } |
|
164 | + return $policies; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Process single policy information. |
|
169 | - * |
|
170 | - * @param PolicyInformation $policy |
|
171 | - * @param ValidatorState $state |
|
172 | - */ |
|
173 | - protected function _processPolicy(PolicyInformation $policy, |
|
174 | - ValidatorState $state) |
|
175 | - { |
|
176 | - $p_oid = $policy->oid(); |
|
177 | - $i = $state->index(); |
|
178 | - $match_count = 0; |
|
179 | - // (d.1.i) for each node of depth i-1 in the valid_policy_tree... |
|
180 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
181 | - // ...where P-OID is in the expected_policy_set |
|
182 | - if ($node->hasExpectedPolicy($p_oid)) { |
|
183 | - $node->addChild( |
|
184 | - new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid))); |
|
185 | - ++$match_count; |
|
186 | - } |
|
187 | - } |
|
188 | - // (d.1.ii) if there was no match in step (i)... |
|
189 | - if (!$match_count) { |
|
190 | - // ...and the valid_policy_tree includes a node of depth i-1 with |
|
191 | - // the valid_policy anyPolicy |
|
192 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
193 | - if ($node->isAnyPolicy()) { |
|
194 | - $node->addChild( |
|
195 | - new PolicyNode($p_oid, $policy->qualifiers(), |
|
196 | - array($p_oid))); |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
167 | + /** |
|
168 | + * Process single policy information. |
|
169 | + * |
|
170 | + * @param PolicyInformation $policy |
|
171 | + * @param ValidatorState $state |
|
172 | + */ |
|
173 | + protected function _processPolicy(PolicyInformation $policy, |
|
174 | + ValidatorState $state) |
|
175 | + { |
|
176 | + $p_oid = $policy->oid(); |
|
177 | + $i = $state->index(); |
|
178 | + $match_count = 0; |
|
179 | + // (d.1.i) for each node of depth i-1 in the valid_policy_tree... |
|
180 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
181 | + // ...where P-OID is in the expected_policy_set |
|
182 | + if ($node->hasExpectedPolicy($p_oid)) { |
|
183 | + $node->addChild( |
|
184 | + new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid))); |
|
185 | + ++$match_count; |
|
186 | + } |
|
187 | + } |
|
188 | + // (d.1.ii) if there was no match in step (i)... |
|
189 | + if (!$match_count) { |
|
190 | + // ...and the valid_policy_tree includes a node of depth i-1 with |
|
191 | + // the valid_policy anyPolicy |
|
192 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
193 | + if ($node->isAnyPolicy()) { |
|
194 | + $node->addChild( |
|
195 | + new PolicyNode($p_oid, $policy->qualifiers(), |
|
196 | + array($p_oid))); |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Process anyPolicy policy information. |
|
204 | - * |
|
205 | - * @param PolicyInformation $policy |
|
206 | - * @param Certificate $cert |
|
207 | - * @param ValidatorState $state |
|
208 | - */ |
|
209 | - protected function _processAnyPolicy(PolicyInformation $policy, |
|
210 | - Certificate $cert, ValidatorState $state) |
|
211 | - { |
|
212 | - $i = $state->index(); |
|
213 | - // if (a) inhibit_anyPolicy is greater than 0 or |
|
214 | - // (b) i<n and the certificate is self-issued |
|
215 | - if (!($state->inhibitAnyPolicy() > 0 || |
|
216 | - ($i < $state->pathLength() && $cert->isSelfIssued()))) { |
|
217 | - return; |
|
218 | - } |
|
219 | - // for each node in the valid_policy_tree of depth i-1 |
|
220 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
221 | - // for each value in the expected_policy_set |
|
222 | - foreach ($node->expectedPolicies() as $p_oid) { |
|
223 | - // that does not appear in a child node |
|
224 | - if (!$node->hasChildWithValidPolicy($p_oid)) { |
|
225 | - $node->addChild( |
|
226 | - new PolicyNode($p_oid, $policy->qualifiers(), |
|
227 | - array($p_oid))); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
202 | + /** |
|
203 | + * Process anyPolicy policy information. |
|
204 | + * |
|
205 | + * @param PolicyInformation $policy |
|
206 | + * @param Certificate $cert |
|
207 | + * @param ValidatorState $state |
|
208 | + */ |
|
209 | + protected function _processAnyPolicy(PolicyInformation $policy, |
|
210 | + Certificate $cert, ValidatorState $state) |
|
211 | + { |
|
212 | + $i = $state->index(); |
|
213 | + // if (a) inhibit_anyPolicy is greater than 0 or |
|
214 | + // (b) i<n and the certificate is self-issued |
|
215 | + if (!($state->inhibitAnyPolicy() > 0 || |
|
216 | + ($i < $state->pathLength() && $cert->isSelfIssued()))) { |
|
217 | + return; |
|
218 | + } |
|
219 | + // for each node in the valid_policy_tree of depth i-1 |
|
220 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
221 | + // for each value in the expected_policy_set |
|
222 | + foreach ($node->expectedPolicies() as $p_oid) { |
|
223 | + // that does not appear in a child node |
|
224 | + if (!$node->hasChildWithValidPolicy($p_oid)) { |
|
225 | + $node->addChild( |
|
226 | + new PolicyNode($p_oid, $policy->qualifiers(), |
|
227 | + array($p_oid))); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Apply policy mappings to the policy tree. |
|
235 | - * |
|
236 | - * @param Certificate $cert |
|
237 | - * @param ValidatorState $state |
|
238 | - */ |
|
239 | - protected function _applyMappings(Certificate $cert, ValidatorState $state) |
|
240 | - { |
|
241 | - $policy_mappings = $cert->tbsCertificate() |
|
242 | - ->extensions() |
|
243 | - ->policyMappings(); |
|
244 | - // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i... |
|
245 | - foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) { |
|
246 | - $match_count = 0; |
|
247 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
248 | - // ...where ID-P is the valid_policy |
|
249 | - if ($node->validPolicy() == $idp) { |
|
250 | - // set expected_policy_set to the set of subjectDomainPolicy |
|
251 | - // values that are specified as equivalent to ID-P by |
|
252 | - // the policy mappings extension |
|
253 | - $node->setExpectedPolicies(...$sdps); |
|
254 | - ++$match_count; |
|
255 | - } |
|
256 | - } |
|
257 | - // if no node of depth i in the valid_policy_tree has |
|
258 | - // a valid_policy of ID-P... |
|
259 | - if (!$match_count) { |
|
260 | - $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps); |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
233 | + /** |
|
234 | + * Apply policy mappings to the policy tree. |
|
235 | + * |
|
236 | + * @param Certificate $cert |
|
237 | + * @param ValidatorState $state |
|
238 | + */ |
|
239 | + protected function _applyMappings(Certificate $cert, ValidatorState $state) |
|
240 | + { |
|
241 | + $policy_mappings = $cert->tbsCertificate() |
|
242 | + ->extensions() |
|
243 | + ->policyMappings(); |
|
244 | + // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i... |
|
245 | + foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) { |
|
246 | + $match_count = 0; |
|
247 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
248 | + // ...where ID-P is the valid_policy |
|
249 | + if ($node->validPolicy() == $idp) { |
|
250 | + // set expected_policy_set to the set of subjectDomainPolicy |
|
251 | + // values that are specified as equivalent to ID-P by |
|
252 | + // the policy mappings extension |
|
253 | + $node->setExpectedPolicies(...$sdps); |
|
254 | + ++$match_count; |
|
255 | + } |
|
256 | + } |
|
257 | + // if no node of depth i in the valid_policy_tree has |
|
258 | + // a valid_policy of ID-P... |
|
259 | + if (!$match_count) { |
|
260 | + $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps); |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1). |
|
267 | - * |
|
268 | - * @param Certificate $cert |
|
269 | - * @param ValidatorState $state |
|
270 | - * @param string $idp OID of the issuer domain policy |
|
271 | - * @param array $sdps Array of subject domain policy OIDs |
|
272 | - */ |
|
273 | - protected function _applyAnyPolicyMapping(Certificate $cert, |
|
274 | - ValidatorState $state, $idp, array $sdps) |
|
275 | - { |
|
276 | - // (6.1.4. b.1.) ...but there is a node of depth i with |
|
277 | - // a valid_policy of anyPolicy |
|
278 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
279 | - if ($node->isAnyPolicy()) { |
|
280 | - // then generate a child node of the node of depth i-1 |
|
281 | - // that has a valid_policy of anyPolicy as follows... |
|
282 | - foreach ($this->_nodesAtDepth($state->index() - 1) as $node) { |
|
283 | - if ($node->isAnyPolicy()) { |
|
284 | - // try to fetch qualifiers of anyPolicy certificate policy |
|
285 | - $qualifiers = array(); |
|
286 | - try { |
|
287 | - $qualifiers = $cert->tbsCertificate() |
|
288 | - ->extensions() |
|
289 | - ->certificatePolicies() |
|
290 | - ->anyPolicy() |
|
291 | - ->qualifiers(); |
|
292 | - } catch (\LogicException $e) { |
|
293 | - // if there's no policies or no qualifiers |
|
294 | - } |
|
295 | - $node->addChild( |
|
296 | - new PolicyNode($idp, $qualifiers, $sdps)); |
|
297 | - // bail after first anyPolicy has been processed |
|
298 | - break; |
|
299 | - } |
|
300 | - } |
|
301 | - // bail after first anyPolicy has been processed |
|
302 | - break; |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
265 | + /** |
|
266 | + * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1). |
|
267 | + * |
|
268 | + * @param Certificate $cert |
|
269 | + * @param ValidatorState $state |
|
270 | + * @param string $idp OID of the issuer domain policy |
|
271 | + * @param array $sdps Array of subject domain policy OIDs |
|
272 | + */ |
|
273 | + protected function _applyAnyPolicyMapping(Certificate $cert, |
|
274 | + ValidatorState $state, $idp, array $sdps) |
|
275 | + { |
|
276 | + // (6.1.4. b.1.) ...but there is a node of depth i with |
|
277 | + // a valid_policy of anyPolicy |
|
278 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
279 | + if ($node->isAnyPolicy()) { |
|
280 | + // then generate a child node of the node of depth i-1 |
|
281 | + // that has a valid_policy of anyPolicy as follows... |
|
282 | + foreach ($this->_nodesAtDepth($state->index() - 1) as $node) { |
|
283 | + if ($node->isAnyPolicy()) { |
|
284 | + // try to fetch qualifiers of anyPolicy certificate policy |
|
285 | + $qualifiers = array(); |
|
286 | + try { |
|
287 | + $qualifiers = $cert->tbsCertificate() |
|
288 | + ->extensions() |
|
289 | + ->certificatePolicies() |
|
290 | + ->anyPolicy() |
|
291 | + ->qualifiers(); |
|
292 | + } catch (\LogicException $e) { |
|
293 | + // if there's no policies or no qualifiers |
|
294 | + } |
|
295 | + $node->addChild( |
|
296 | + new PolicyNode($idp, $qualifiers, $sdps)); |
|
297 | + // bail after first anyPolicy has been processed |
|
298 | + break; |
|
299 | + } |
|
300 | + } |
|
301 | + // bail after first anyPolicy has been processed |
|
302 | + break; |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * Delete nodes as specified in 6.1.4 (b)(2). |
|
309 | - * |
|
310 | - * @param Certificate $cert |
|
311 | - * @param ValidatorState $state |
|
312 | - */ |
|
313 | - protected function _deleteMappings(Certificate $cert, ValidatorState $state) |
|
314 | - { |
|
315 | - $idps = $cert->tbsCertificate() |
|
316 | - ->extensions() |
|
317 | - ->policyMappings() |
|
318 | - ->issuerDomainPolicies(); |
|
319 | - // delete each node of depth i in the valid_policy_tree |
|
320 | - // where ID-P is the valid_policy |
|
321 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
322 | - if (in_array($node->validPolicy(), $idps)) { |
|
323 | - $node->remove(); |
|
324 | - } |
|
325 | - } |
|
326 | - $this->_pruneTree($state->index() - 1); |
|
327 | - } |
|
307 | + /** |
|
308 | + * Delete nodes as specified in 6.1.4 (b)(2). |
|
309 | + * |
|
310 | + * @param Certificate $cert |
|
311 | + * @param ValidatorState $state |
|
312 | + */ |
|
313 | + protected function _deleteMappings(Certificate $cert, ValidatorState $state) |
|
314 | + { |
|
315 | + $idps = $cert->tbsCertificate() |
|
316 | + ->extensions() |
|
317 | + ->policyMappings() |
|
318 | + ->issuerDomainPolicies(); |
|
319 | + // delete each node of depth i in the valid_policy_tree |
|
320 | + // where ID-P is the valid_policy |
|
321 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
322 | + if (in_array($node->validPolicy(), $idps)) { |
|
323 | + $node->remove(); |
|
324 | + } |
|
325 | + } |
|
326 | + $this->_pruneTree($state->index() - 1); |
|
327 | + } |
|
328 | 328 | |
329 | - /** |
|
330 | - * Prune tree starting from given depth. |
|
331 | - * |
|
332 | - * @param int $depth |
|
333 | - * @return int The number of nodes left in a tree |
|
334 | - */ |
|
335 | - protected function _pruneTree(int $depth): int |
|
336 | - { |
|
337 | - for ($i = $depth; $i > 0; --$i) { |
|
338 | - foreach ($this->_nodesAtDepth($i) as $node) { |
|
339 | - if (!count($node)) { |
|
340 | - $node->remove(); |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - // if root has no children left |
|
345 | - if (!count($this->_root)) { |
|
346 | - $this->_root = null; |
|
347 | - return 0; |
|
348 | - } |
|
349 | - return $this->_root->nodeCount(); |
|
350 | - } |
|
329 | + /** |
|
330 | + * Prune tree starting from given depth. |
|
331 | + * |
|
332 | + * @param int $depth |
|
333 | + * @return int The number of nodes left in a tree |
|
334 | + */ |
|
335 | + protected function _pruneTree(int $depth): int |
|
336 | + { |
|
337 | + for ($i = $depth; $i > 0; --$i) { |
|
338 | + foreach ($this->_nodesAtDepth($i) as $node) { |
|
339 | + if (!count($node)) { |
|
340 | + $node->remove(); |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + // if root has no children left |
|
345 | + if (!count($this->_root)) { |
|
346 | + $this->_root = null; |
|
347 | + return 0; |
|
348 | + } |
|
349 | + return $this->_root->nodeCount(); |
|
350 | + } |
|
351 | 351 | |
352 | - /** |
|
353 | - * Get all nodes at given depth. |
|
354 | - * |
|
355 | - * @param int $i |
|
356 | - * @return PolicyNode[] |
|
357 | - */ |
|
358 | - protected function _nodesAtDepth(int $i): array |
|
359 | - { |
|
360 | - if (!$this->_root) { |
|
361 | - return array(); |
|
362 | - } |
|
363 | - $depth = 0; |
|
364 | - $nodes = array($this->_root); |
|
365 | - while ($depth < $i) { |
|
366 | - $nodes = self::_gatherChildren(...$nodes); |
|
367 | - if (!count($nodes)) { |
|
368 | - break; |
|
369 | - } |
|
370 | - ++$depth; |
|
371 | - } |
|
372 | - return $nodes; |
|
373 | - } |
|
352 | + /** |
|
353 | + * Get all nodes at given depth. |
|
354 | + * |
|
355 | + * @param int $i |
|
356 | + * @return PolicyNode[] |
|
357 | + */ |
|
358 | + protected function _nodesAtDepth(int $i): array |
|
359 | + { |
|
360 | + if (!$this->_root) { |
|
361 | + return array(); |
|
362 | + } |
|
363 | + $depth = 0; |
|
364 | + $nodes = array($this->_root); |
|
365 | + while ($depth < $i) { |
|
366 | + $nodes = self::_gatherChildren(...$nodes); |
|
367 | + if (!count($nodes)) { |
|
368 | + break; |
|
369 | + } |
|
370 | + ++$depth; |
|
371 | + } |
|
372 | + return $nodes; |
|
373 | + } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1. |
|
377 | - * |
|
378 | - * @return PolicyNode[] |
|
379 | - */ |
|
380 | - protected function _validPolicyNodeSet(): array |
|
381 | - { |
|
382 | - // 1. Determine the set of policy nodes whose parent nodes have |
|
383 | - // a valid_policy of anyPolicy. This is the valid_policy_node_set. |
|
384 | - $set = array(); |
|
385 | - if (!$this->_root) { |
|
386 | - return $set; |
|
387 | - } |
|
388 | - // for each node in a tree |
|
389 | - $this->_root->walkNodes( |
|
390 | - function (PolicyNode $node) use (&$set) { |
|
391 | - $parents = $node->parents(); |
|
392 | - // node has parents |
|
393 | - if (count($parents)) { |
|
394 | - // check that each ancestor is an anyPolicy node |
|
395 | - foreach ($parents as $ancestor) { |
|
396 | - if (!$ancestor->isAnyPolicy()) { |
|
397 | - return; |
|
398 | - } |
|
399 | - } |
|
400 | - $set[] = $node; |
|
401 | - } |
|
402 | - }); |
|
403 | - return $set; |
|
404 | - } |
|
375 | + /** |
|
376 | + * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1. |
|
377 | + * |
|
378 | + * @return PolicyNode[] |
|
379 | + */ |
|
380 | + protected function _validPolicyNodeSet(): array |
|
381 | + { |
|
382 | + // 1. Determine the set of policy nodes whose parent nodes have |
|
383 | + // a valid_policy of anyPolicy. This is the valid_policy_node_set. |
|
384 | + $set = array(); |
|
385 | + if (!$this->_root) { |
|
386 | + return $set; |
|
387 | + } |
|
388 | + // for each node in a tree |
|
389 | + $this->_root->walkNodes( |
|
390 | + function (PolicyNode $node) use (&$set) { |
|
391 | + $parents = $node->parents(); |
|
392 | + // node has parents |
|
393 | + if (count($parents)) { |
|
394 | + // check that each ancestor is an anyPolicy node |
|
395 | + foreach ($parents as $ancestor) { |
|
396 | + if (!$ancestor->isAnyPolicy()) { |
|
397 | + return; |
|
398 | + } |
|
399 | + } |
|
400 | + $set[] = $node; |
|
401 | + } |
|
402 | + }); |
|
403 | + return $set; |
|
404 | + } |
|
405 | 405 | |
406 | - /** |
|
407 | - * Gather all children of given nodes to a flattened array. |
|
408 | - * |
|
409 | - * @param PolicyNode ...$nodes |
|
410 | - * @return PolicyNode[] |
|
411 | - */ |
|
412 | - private static function _gatherChildren(PolicyNode ...$nodes): array |
|
413 | - { |
|
414 | - $children = array(); |
|
415 | - foreach ($nodes as $node) { |
|
416 | - $children = array_merge($children, $node->children()); |
|
417 | - } |
|
418 | - return $children; |
|
419 | - } |
|
406 | + /** |
|
407 | + * Gather all children of given nodes to a flattened array. |
|
408 | + * |
|
409 | + * @param PolicyNode ...$nodes |
|
410 | + * @return PolicyNode[] |
|
411 | + */ |
|
412 | + private static function _gatherChildren(PolicyNode ...$nodes): array |
|
413 | + { |
|
414 | + $children = array(); |
|
415 | + foreach ($nodes as $node) { |
|
416 | + $children = array_merge($children, $node->children()); |
|
417 | + } |
|
418 | + return $children; |
|
419 | + } |
|
420 | 420 | } |
@@ -23,171 +23,171 @@ |
||
23 | 23 | */ |
24 | 24 | class CertificationPath implements \Countable, \IteratorAggregate |
25 | 25 | { |
26 | - /** |
|
27 | - * Certification path. |
|
28 | - * |
|
29 | - * @var Certificate[] $_certificates |
|
30 | - */ |
|
31 | - protected $_certificates; |
|
26 | + /** |
|
27 | + * Certification path. |
|
28 | + * |
|
29 | + * @var Certificate[] $_certificates |
|
30 | + */ |
|
31 | + protected $_certificates; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor. |
|
35 | - * |
|
36 | - * @param Certificate ...$certificates Certificates from the trust anchor |
|
37 | - * to the target end-entity certificate |
|
38 | - */ |
|
39 | - public function __construct(Certificate ...$certificates) |
|
40 | - { |
|
41 | - $this->_certificates = $certificates; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + * |
|
36 | + * @param Certificate ...$certificates Certificates from the trust anchor |
|
37 | + * to the target end-entity certificate |
|
38 | + */ |
|
39 | + public function __construct(Certificate ...$certificates) |
|
40 | + { |
|
41 | + $this->_certificates = $certificates; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Initialize from a certificate chain. |
|
46 | - * |
|
47 | - * @param CertificateChain $chain |
|
48 | - * @return self |
|
49 | - */ |
|
50 | - public static function fromCertificateChain(CertificateChain $chain): self |
|
51 | - { |
|
52 | - return new self(...array_reverse($chain->certificates(), false)); |
|
53 | - } |
|
44 | + /** |
|
45 | + * Initialize from a certificate chain. |
|
46 | + * |
|
47 | + * @param CertificateChain $chain |
|
48 | + * @return self |
|
49 | + */ |
|
50 | + public static function fromCertificateChain(CertificateChain $chain): self |
|
51 | + { |
|
52 | + return new self(...array_reverse($chain->certificates(), false)); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Build certification path to given target. |
|
57 | - * |
|
58 | - * @param Certificate $target Target end-entity certificate |
|
59 | - * @param CertificateBundle $trust_anchors List of trust anchors |
|
60 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
61 | - * certificates |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public static function toTarget(Certificate $target, |
|
65 | - CertificateBundle $trust_anchors, CertificateBundle $intermediate = null): self |
|
66 | - { |
|
67 | - $builder = new CertificationPathBuilder($trust_anchors); |
|
68 | - return $builder->shortestPathToTarget($target, $intermediate); |
|
69 | - } |
|
55 | + /** |
|
56 | + * Build certification path to given target. |
|
57 | + * |
|
58 | + * @param Certificate $target Target end-entity certificate |
|
59 | + * @param CertificateBundle $trust_anchors List of trust anchors |
|
60 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
61 | + * certificates |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public static function toTarget(Certificate $target, |
|
65 | + CertificateBundle $trust_anchors, CertificateBundle $intermediate = null): self |
|
66 | + { |
|
67 | + $builder = new CertificationPathBuilder($trust_anchors); |
|
68 | + return $builder->shortestPathToTarget($target, $intermediate); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Build certification path from given trust anchor to target certificate, |
|
73 | - * using intermediate certificates from given bundle. |
|
74 | - * |
|
75 | - * @param Certificate $trust_anchor Trust anchor certificate |
|
76 | - * @param Certificate $target Target end-entity certificate |
|
77 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
78 | - * certificates |
|
79 | - * @return self |
|
80 | - */ |
|
81 | - public static function fromTrustAnchorToTarget(Certificate $trust_anchor, |
|
82 | - Certificate $target, CertificateBundle $intermediate = null): self |
|
83 | - { |
|
84 | - return self::toTarget($target, new CertificateBundle($trust_anchor), |
|
85 | - $intermediate); |
|
86 | - } |
|
71 | + /** |
|
72 | + * Build certification path from given trust anchor to target certificate, |
|
73 | + * using intermediate certificates from given bundle. |
|
74 | + * |
|
75 | + * @param Certificate $trust_anchor Trust anchor certificate |
|
76 | + * @param Certificate $target Target end-entity certificate |
|
77 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
78 | + * certificates |
|
79 | + * @return self |
|
80 | + */ |
|
81 | + public static function fromTrustAnchorToTarget(Certificate $trust_anchor, |
|
82 | + Certificate $target, CertificateBundle $intermediate = null): self |
|
83 | + { |
|
84 | + return self::toTarget($target, new CertificateBundle($trust_anchor), |
|
85 | + $intermediate); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get certificates. |
|
90 | - * |
|
91 | - * @return Certificate[] |
|
92 | - */ |
|
93 | - public function certificates(): array |
|
94 | - { |
|
95 | - return $this->_certificates; |
|
96 | - } |
|
88 | + /** |
|
89 | + * Get certificates. |
|
90 | + * |
|
91 | + * @return Certificate[] |
|
92 | + */ |
|
93 | + public function certificates(): array |
|
94 | + { |
|
95 | + return $this->_certificates; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get the trust anchor certificate from the path. |
|
100 | - * |
|
101 | - * @throws \LogicException If path is empty |
|
102 | - * @return Certificate |
|
103 | - */ |
|
104 | - public function trustAnchorCertificate(): Certificate |
|
105 | - { |
|
106 | - if (!count($this->_certificates)) { |
|
107 | - throw new \LogicException("No certificates."); |
|
108 | - } |
|
109 | - return $this->_certificates[0]; |
|
110 | - } |
|
98 | + /** |
|
99 | + * Get the trust anchor certificate from the path. |
|
100 | + * |
|
101 | + * @throws \LogicException If path is empty |
|
102 | + * @return Certificate |
|
103 | + */ |
|
104 | + public function trustAnchorCertificate(): Certificate |
|
105 | + { |
|
106 | + if (!count($this->_certificates)) { |
|
107 | + throw new \LogicException("No certificates."); |
|
108 | + } |
|
109 | + return $this->_certificates[0]; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Get the end-entity certificate from the path. |
|
114 | - * |
|
115 | - * @throws \LogicException If path is empty |
|
116 | - * @return Certificate |
|
117 | - */ |
|
118 | - public function endEntityCertificate(): Certificate |
|
119 | - { |
|
120 | - if (!count($this->_certificates)) { |
|
121 | - throw new \LogicException("No certificates."); |
|
122 | - } |
|
123 | - return $this->_certificates[count($this->_certificates) - 1]; |
|
124 | - } |
|
112 | + /** |
|
113 | + * Get the end-entity certificate from the path. |
|
114 | + * |
|
115 | + * @throws \LogicException If path is empty |
|
116 | + * @return Certificate |
|
117 | + */ |
|
118 | + public function endEntityCertificate(): Certificate |
|
119 | + { |
|
120 | + if (!count($this->_certificates)) { |
|
121 | + throw new \LogicException("No certificates."); |
|
122 | + } |
|
123 | + return $this->_certificates[count($this->_certificates) - 1]; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Get certification path as a certificate chain. |
|
128 | - * |
|
129 | - * @return CertificateChain |
|
130 | - */ |
|
131 | - public function certificateChain(): CertificateChain |
|
132 | - { |
|
133 | - return new CertificateChain( |
|
134 | - ...array_reverse($this->_certificates, false)); |
|
135 | - } |
|
126 | + /** |
|
127 | + * Get certification path as a certificate chain. |
|
128 | + * |
|
129 | + * @return CertificateChain |
|
130 | + */ |
|
131 | + public function certificateChain(): CertificateChain |
|
132 | + { |
|
133 | + return new CertificateChain( |
|
134 | + ...array_reverse($this->_certificates, false)); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Check whether certification path starts with one ore more given |
|
139 | - * certificates in parameter order. |
|
140 | - * |
|
141 | - * @param Certificate ...$certs Certificates |
|
142 | - * @return true |
|
143 | - */ |
|
144 | - public function startsWith(Certificate ...$certs): bool |
|
145 | - { |
|
146 | - $n = count($certs); |
|
147 | - if ($n > count($this->_certificates)) { |
|
148 | - return false; |
|
149 | - } |
|
150 | - for ($i = 0; $i < $n; ++$i) { |
|
151 | - if (!$certs[$i]->equals($this->_certificates[$i])) { |
|
152 | - return false; |
|
153 | - } |
|
154 | - } |
|
155 | - return true; |
|
156 | - } |
|
137 | + /** |
|
138 | + * Check whether certification path starts with one ore more given |
|
139 | + * certificates in parameter order. |
|
140 | + * |
|
141 | + * @param Certificate ...$certs Certificates |
|
142 | + * @return true |
|
143 | + */ |
|
144 | + public function startsWith(Certificate ...$certs): bool |
|
145 | + { |
|
146 | + $n = count($certs); |
|
147 | + if ($n > count($this->_certificates)) { |
|
148 | + return false; |
|
149 | + } |
|
150 | + for ($i = 0; $i < $n; ++$i) { |
|
151 | + if (!$certs[$i]->equals($this->_certificates[$i])) { |
|
152 | + return false; |
|
153 | + } |
|
154 | + } |
|
155 | + return true; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Validate certification path. |
|
160 | - * |
|
161 | - * @param PathValidationConfig $config |
|
162 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
163 | - * @throws Exception\PathValidationException |
|
164 | - * @return PathValidation\PathValidationResult |
|
165 | - */ |
|
166 | - public function validate(PathValidationConfig $config, Crypto $crypto = null): PathValidation\PathValidationResult |
|
167 | - { |
|
168 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
169 | - $validator = new PathValidator($crypto, $config, ...$this->_certificates); |
|
170 | - return $validator->validate(); |
|
171 | - } |
|
158 | + /** |
|
159 | + * Validate certification path. |
|
160 | + * |
|
161 | + * @param PathValidationConfig $config |
|
162 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
163 | + * @throws Exception\PathValidationException |
|
164 | + * @return PathValidation\PathValidationResult |
|
165 | + */ |
|
166 | + public function validate(PathValidationConfig $config, Crypto $crypto = null): PathValidation\PathValidationResult |
|
167 | + { |
|
168 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
169 | + $validator = new PathValidator($crypto, $config, ...$this->_certificates); |
|
170 | + return $validator->validate(); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * |
|
175 | - * @see \Countable::count() |
|
176 | - * @return int |
|
177 | - */ |
|
178 | - public function count(): int |
|
179 | - { |
|
180 | - return count($this->_certificates); |
|
181 | - } |
|
173 | + /** |
|
174 | + * |
|
175 | + * @see \Countable::count() |
|
176 | + * @return int |
|
177 | + */ |
|
178 | + public function count(): int |
|
179 | + { |
|
180 | + return count($this->_certificates); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Get iterator for certificates. |
|
185 | - * |
|
186 | - * @see \IteratorAggregate::getIterator() |
|
187 | - * @return \ArrayIterator |
|
188 | - */ |
|
189 | - public function getIterator(): \ArrayIterator |
|
190 | - { |
|
191 | - return new \ArrayIterator($this->_certificates); |
|
192 | - } |
|
183 | + /** |
|
184 | + * Get iterator for certificates. |
|
185 | + * |
|
186 | + * @see \IteratorAggregate::getIterator() |
|
187 | + * @return \ArrayIterator |
|
188 | + */ |
|
189 | + public function getIterator(): \ArrayIterator |
|
190 | + { |
|
191 | + return new \ArrayIterator($this->_certificates); |
|
192 | + } |
|
193 | 193 | } |
@@ -14,274 +14,274 @@ |
||
14 | 14 | */ |
15 | 15 | class PathValidationConfig |
16 | 16 | { |
17 | - /** |
|
18 | - * Maximum allowed certification path length. |
|
19 | - * |
|
20 | - * @var int $_maxLength |
|
21 | - */ |
|
22 | - protected $_maxLength; |
|
17 | + /** |
|
18 | + * Maximum allowed certification path length. |
|
19 | + * |
|
20 | + * @var int $_maxLength |
|
21 | + */ |
|
22 | + protected $_maxLength; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Reference time. |
|
26 | - * |
|
27 | - * @var \DateTimeImmutable $_dateTime |
|
28 | - */ |
|
29 | - protected $_dateTime; |
|
24 | + /** |
|
25 | + * Reference time. |
|
26 | + * |
|
27 | + * @var \DateTimeImmutable $_dateTime |
|
28 | + */ |
|
29 | + protected $_dateTime; |
|
30 | 30 | |
31 | - /** |
|
32 | - * List of acceptable policy identifiers. |
|
33 | - * |
|
34 | - * @var string[] $_policySet |
|
35 | - */ |
|
36 | - protected $_policySet; |
|
31 | + /** |
|
32 | + * List of acceptable policy identifiers. |
|
33 | + * |
|
34 | + * @var string[] $_policySet |
|
35 | + */ |
|
36 | + protected $_policySet; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Trust anchor certificate. |
|
40 | - * |
|
41 | - * If not set, path validation uses the first certificate of the path. |
|
42 | - * |
|
43 | - * @var Certificate|null $_trustAnchor |
|
44 | - */ |
|
45 | - protected $_trustAnchor; |
|
38 | + /** |
|
39 | + * Trust anchor certificate. |
|
40 | + * |
|
41 | + * If not set, path validation uses the first certificate of the path. |
|
42 | + * |
|
43 | + * @var Certificate|null $_trustAnchor |
|
44 | + */ |
|
45 | + protected $_trustAnchor; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Whether policy mapping in inhibited. |
|
49 | - * |
|
50 | - * Setting this to true disallows policy mapping. |
|
51 | - * |
|
52 | - * @var bool $_policyMappingInhibit |
|
53 | - */ |
|
54 | - protected $_policyMappingInhibit; |
|
47 | + /** |
|
48 | + * Whether policy mapping in inhibited. |
|
49 | + * |
|
50 | + * Setting this to true disallows policy mapping. |
|
51 | + * |
|
52 | + * @var bool $_policyMappingInhibit |
|
53 | + */ |
|
54 | + protected $_policyMappingInhibit; |
|
55 | 55 | |
56 | - /** |
|
57 | - * Whether the path must be valid for at least one policy in the |
|
58 | - * initial policy set. |
|
59 | - * |
|
60 | - * @var bool $_explicitPolicy |
|
61 | - */ |
|
62 | - protected $_explicitPolicy; |
|
56 | + /** |
|
57 | + * Whether the path must be valid for at least one policy in the |
|
58 | + * initial policy set. |
|
59 | + * |
|
60 | + * @var bool $_explicitPolicy |
|
61 | + */ |
|
62 | + protected $_explicitPolicy; |
|
63 | 63 | |
64 | - /** |
|
65 | - * Whether anyPolicy OID processing should be inhibited. |
|
66 | - * |
|
67 | - * Setting this to true disallows the usage of anyPolicy. |
|
68 | - * |
|
69 | - * @var bool $_anyPolicyInhibit |
|
70 | - */ |
|
71 | - protected $_anyPolicyInhibit; |
|
64 | + /** |
|
65 | + * Whether anyPolicy OID processing should be inhibited. |
|
66 | + * |
|
67 | + * Setting this to true disallows the usage of anyPolicy. |
|
68 | + * |
|
69 | + * @var bool $_anyPolicyInhibit |
|
70 | + */ |
|
71 | + protected $_anyPolicyInhibit; |
|
72 | 72 | |
73 | - /** |
|
74 | - * |
|
75 | - * @todo Implement |
|
76 | - * @var mixed $_permittedSubtrees |
|
77 | - */ |
|
78 | - protected $_permittedSubtrees; |
|
73 | + /** |
|
74 | + * |
|
75 | + * @todo Implement |
|
76 | + * @var mixed $_permittedSubtrees |
|
77 | + */ |
|
78 | + protected $_permittedSubtrees; |
|
79 | 79 | |
80 | - /** |
|
81 | - * |
|
82 | - * @todo Implement |
|
83 | - * @var mixed $_excludedSubtrees |
|
84 | - */ |
|
85 | - protected $_excludedSubtrees; |
|
80 | + /** |
|
81 | + * |
|
82 | + * @todo Implement |
|
83 | + * @var mixed $_excludedSubtrees |
|
84 | + */ |
|
85 | + protected $_excludedSubtrees; |
|
86 | 86 | |
87 | - /** |
|
88 | - * Constructor. |
|
89 | - * |
|
90 | - * @param \DateTimeImmutable $dt Reference date and time |
|
91 | - * @param int $max_length Maximum certification path length |
|
92 | - */ |
|
93 | - public function __construct(\DateTimeImmutable $dt, int $max_length) |
|
94 | - { |
|
95 | - $this->_dateTime = $dt; |
|
96 | - $this->_maxLength = (int) $max_length; |
|
97 | - $this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY); |
|
98 | - $this->_policyMappingInhibit = false; |
|
99 | - $this->_explicitPolicy = false; |
|
100 | - $this->_anyPolicyInhibit = false; |
|
101 | - } |
|
87 | + /** |
|
88 | + * Constructor. |
|
89 | + * |
|
90 | + * @param \DateTimeImmutable $dt Reference date and time |
|
91 | + * @param int $max_length Maximum certification path length |
|
92 | + */ |
|
93 | + public function __construct(\DateTimeImmutable $dt, int $max_length) |
|
94 | + { |
|
95 | + $this->_dateTime = $dt; |
|
96 | + $this->_maxLength = (int) $max_length; |
|
97 | + $this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY); |
|
98 | + $this->_policyMappingInhibit = false; |
|
99 | + $this->_explicitPolicy = false; |
|
100 | + $this->_anyPolicyInhibit = false; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Get default configuration. |
|
105 | - * |
|
106 | - * @return self |
|
107 | - */ |
|
108 | - public static function defaultConfig(): self |
|
109 | - { |
|
110 | - return new self(new \DateTimeImmutable(), 3); |
|
111 | - } |
|
103 | + /** |
|
104 | + * Get default configuration. |
|
105 | + * |
|
106 | + * @return self |
|
107 | + */ |
|
108 | + public static function defaultConfig(): self |
|
109 | + { |
|
110 | + return new self(new \DateTimeImmutable(), 3); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get self with maximum path length. |
|
115 | - * |
|
116 | - * @param int $length |
|
117 | - * @return self |
|
118 | - */ |
|
119 | - public function withMaxLength(int $length): self |
|
120 | - { |
|
121 | - $obj = clone $this; |
|
122 | - $obj->_maxLength = $length; |
|
123 | - return $obj; |
|
124 | - } |
|
113 | + /** |
|
114 | + * Get self with maximum path length. |
|
115 | + * |
|
116 | + * @param int $length |
|
117 | + * @return self |
|
118 | + */ |
|
119 | + public function withMaxLength(int $length): self |
|
120 | + { |
|
121 | + $obj = clone $this; |
|
122 | + $obj->_maxLength = $length; |
|
123 | + return $obj; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Get self with reference date and time. |
|
128 | - * |
|
129 | - * @param \DateTimeImmutable $dt |
|
130 | - * @return self |
|
131 | - */ |
|
132 | - public function withDateTime(\DateTimeImmutable $dt): self |
|
133 | - { |
|
134 | - $obj = clone $this; |
|
135 | - $obj->_dateTime = $dt; |
|
136 | - return $obj; |
|
137 | - } |
|
126 | + /** |
|
127 | + * Get self with reference date and time. |
|
128 | + * |
|
129 | + * @param \DateTimeImmutable $dt |
|
130 | + * @return self |
|
131 | + */ |
|
132 | + public function withDateTime(\DateTimeImmutable $dt): self |
|
133 | + { |
|
134 | + $obj = clone $this; |
|
135 | + $obj->_dateTime = $dt; |
|
136 | + return $obj; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Get self with trust anchor certificate. |
|
141 | - * |
|
142 | - * @param Certificate $ca |
|
143 | - * @return self |
|
144 | - */ |
|
145 | - public function withTrustAnchor(Certificate $ca): self |
|
146 | - { |
|
147 | - $obj = clone $this; |
|
148 | - $obj->_trustAnchor = $ca; |
|
149 | - return $obj; |
|
150 | - } |
|
139 | + /** |
|
140 | + * Get self with trust anchor certificate. |
|
141 | + * |
|
142 | + * @param Certificate $ca |
|
143 | + * @return self |
|
144 | + */ |
|
145 | + public function withTrustAnchor(Certificate $ca): self |
|
146 | + { |
|
147 | + $obj = clone $this; |
|
148 | + $obj->_trustAnchor = $ca; |
|
149 | + return $obj; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Get self with initial-policy-mapping-inhibit set. |
|
154 | - * |
|
155 | - * @param bool $flag |
|
156 | - * @return self |
|
157 | - */ |
|
158 | - public function withPolicyMappingInhibit(bool $flag): self |
|
159 | - { |
|
160 | - $obj = clone $this; |
|
161 | - $obj->_policyMappingInhibit = $flag; |
|
162 | - return $obj; |
|
163 | - } |
|
152 | + /** |
|
153 | + * Get self with initial-policy-mapping-inhibit set. |
|
154 | + * |
|
155 | + * @param bool $flag |
|
156 | + * @return self |
|
157 | + */ |
|
158 | + public function withPolicyMappingInhibit(bool $flag): self |
|
159 | + { |
|
160 | + $obj = clone $this; |
|
161 | + $obj->_policyMappingInhibit = $flag; |
|
162 | + return $obj; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Get self with initial-explicit-policy set. |
|
167 | - * |
|
168 | - * @param bool $flag |
|
169 | - * @return self |
|
170 | - */ |
|
171 | - public function withExplicitPolicy(bool $flag): self |
|
172 | - { |
|
173 | - $obj = clone $this; |
|
174 | - $obj->_explicitPolicy = $flag; |
|
175 | - return $obj; |
|
176 | - } |
|
165 | + /** |
|
166 | + * Get self with initial-explicit-policy set. |
|
167 | + * |
|
168 | + * @param bool $flag |
|
169 | + * @return self |
|
170 | + */ |
|
171 | + public function withExplicitPolicy(bool $flag): self |
|
172 | + { |
|
173 | + $obj = clone $this; |
|
174 | + $obj->_explicitPolicy = $flag; |
|
175 | + return $obj; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Get self with initial-any-policy-inhibit set. |
|
180 | - * |
|
181 | - * @param bool $flag |
|
182 | - * @return self |
|
183 | - */ |
|
184 | - public function withAnyPolicyInhibit(bool $flag): self |
|
185 | - { |
|
186 | - $obj = clone $this; |
|
187 | - $obj->_anyPolicyInhibit = $flag; |
|
188 | - return $obj; |
|
189 | - } |
|
178 | + /** |
|
179 | + * Get self with initial-any-policy-inhibit set. |
|
180 | + * |
|
181 | + * @param bool $flag |
|
182 | + * @return self |
|
183 | + */ |
|
184 | + public function withAnyPolicyInhibit(bool $flag): self |
|
185 | + { |
|
186 | + $obj = clone $this; |
|
187 | + $obj->_anyPolicyInhibit = $flag; |
|
188 | + return $obj; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Get self with user-initial-policy-set set to policy OIDs. |
|
193 | - * |
|
194 | - * @param string ...$policies List of policy OIDs |
|
195 | - * @return self |
|
196 | - */ |
|
197 | - public function withPolicySet(string ...$policies): self |
|
198 | - { |
|
199 | - $obj = clone $this; |
|
200 | - $obj->_policySet = $policies; |
|
201 | - return $obj; |
|
202 | - } |
|
191 | + /** |
|
192 | + * Get self with user-initial-policy-set set to policy OIDs. |
|
193 | + * |
|
194 | + * @param string ...$policies List of policy OIDs |
|
195 | + * @return self |
|
196 | + */ |
|
197 | + public function withPolicySet(string ...$policies): self |
|
198 | + { |
|
199 | + $obj = clone $this; |
|
200 | + $obj->_policySet = $policies; |
|
201 | + return $obj; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Get maximum certification path length. |
|
206 | - * |
|
207 | - * @return int |
|
208 | - */ |
|
209 | - public function maxLength(): int |
|
210 | - { |
|
211 | - return $this->_maxLength; |
|
212 | - } |
|
204 | + /** |
|
205 | + * Get maximum certification path length. |
|
206 | + * |
|
207 | + * @return int |
|
208 | + */ |
|
209 | + public function maxLength(): int |
|
210 | + { |
|
211 | + return $this->_maxLength; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Get reference date and time. |
|
216 | - * |
|
217 | - * @return \DateTimeImmutable |
|
218 | - */ |
|
219 | - public function dateTime(): \DateTimeImmutable |
|
220 | - { |
|
221 | - return $this->_dateTime; |
|
222 | - } |
|
214 | + /** |
|
215 | + * Get reference date and time. |
|
216 | + * |
|
217 | + * @return \DateTimeImmutable |
|
218 | + */ |
|
219 | + public function dateTime(): \DateTimeImmutable |
|
220 | + { |
|
221 | + return $this->_dateTime; |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Get user-initial-policy-set. |
|
226 | - * |
|
227 | - * @return string[] Array of OID's |
|
228 | - */ |
|
229 | - public function policySet(): array |
|
230 | - { |
|
231 | - return $this->_policySet; |
|
232 | - } |
|
224 | + /** |
|
225 | + * Get user-initial-policy-set. |
|
226 | + * |
|
227 | + * @return string[] Array of OID's |
|
228 | + */ |
|
229 | + public function policySet(): array |
|
230 | + { |
|
231 | + return $this->_policySet; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * Check whether trust anchor certificate is set. |
|
236 | - * |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function hasTrustAnchor(): bool |
|
240 | - { |
|
241 | - return isset($this->_trustAnchor); |
|
242 | - } |
|
234 | + /** |
|
235 | + * Check whether trust anchor certificate is set. |
|
236 | + * |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function hasTrustAnchor(): bool |
|
240 | + { |
|
241 | + return isset($this->_trustAnchor); |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * Get trust anchor certificate. |
|
246 | - * |
|
247 | - * @throws \LogicException |
|
248 | - * @return Certificate |
|
249 | - */ |
|
250 | - public function trustAnchor(): Certificate |
|
251 | - { |
|
252 | - if (!$this->hasTrustAnchor()) { |
|
253 | - throw new \LogicException("No trust anchor."); |
|
254 | - } |
|
255 | - return $this->_trustAnchor; |
|
256 | - } |
|
244 | + /** |
|
245 | + * Get trust anchor certificate. |
|
246 | + * |
|
247 | + * @throws \LogicException |
|
248 | + * @return Certificate |
|
249 | + */ |
|
250 | + public function trustAnchor(): Certificate |
|
251 | + { |
|
252 | + if (!$this->hasTrustAnchor()) { |
|
253 | + throw new \LogicException("No trust anchor."); |
|
254 | + } |
|
255 | + return $this->_trustAnchor; |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Get initial-policy-mapping-inhibit. |
|
260 | - * |
|
261 | - * @return bool |
|
262 | - */ |
|
263 | - public function policyMappingInhibit(): bool |
|
264 | - { |
|
265 | - return $this->_policyMappingInhibit; |
|
266 | - } |
|
258 | + /** |
|
259 | + * Get initial-policy-mapping-inhibit. |
|
260 | + * |
|
261 | + * @return bool |
|
262 | + */ |
|
263 | + public function policyMappingInhibit(): bool |
|
264 | + { |
|
265 | + return $this->_policyMappingInhibit; |
|
266 | + } |
|
267 | 267 | |
268 | - /** |
|
269 | - * Get initial-explicit-policy. |
|
270 | - * |
|
271 | - * @return bool |
|
272 | - */ |
|
273 | - public function explicitPolicy(): bool |
|
274 | - { |
|
275 | - return $this->_explicitPolicy; |
|
276 | - } |
|
268 | + /** |
|
269 | + * Get initial-explicit-policy. |
|
270 | + * |
|
271 | + * @return bool |
|
272 | + */ |
|
273 | + public function explicitPolicy(): bool |
|
274 | + { |
|
275 | + return $this->_explicitPolicy; |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Get initial-any-policy-inhibit. |
|
280 | - * |
|
281 | - * @return bool |
|
282 | - */ |
|
283 | - public function anyPolicyInhibit(): bool |
|
284 | - { |
|
285 | - return $this->_anyPolicyInhibit; |
|
286 | - } |
|
278 | + /** |
|
279 | + * Get initial-any-policy-inhibit. |
|
280 | + * |
|
281 | + * @return bool |
|
282 | + */ |
|
283 | + public function anyPolicyInhibit(): bool |
|
284 | + { |
|
285 | + return $this->_anyPolicyInhibit; |
|
286 | + } |
|
287 | 287 | } |
@@ -20,484 +20,484 @@ |
||
20 | 20 | */ |
21 | 21 | class ValidatorState |
22 | 22 | { |
23 | - /** |
|
24 | - * Length of the certification path (n). |
|
25 | - * |
|
26 | - * @var int $_pathLength |
|
27 | - */ |
|
28 | - protected $_pathLength; |
|
29 | - |
|
30 | - /** |
|
31 | - * Current index in the certification path in the range of 1..n (i). |
|
32 | - * |
|
33 | - * @var int $_index |
|
34 | - */ |
|
35 | - protected $_index; |
|
36 | - |
|
37 | - /** |
|
38 | - * Valid policy tree (valid_policy_tree). |
|
39 | - * |
|
40 | - * A tree of certificate policies with their optional qualifiers. |
|
41 | - * Each of the leaves of the tree represents a valid policy at this stage in |
|
42 | - * the certification path validation. |
|
43 | - * Once the tree is set to NULL, policy processing ceases. |
|
44 | - * |
|
45 | - * @var PolicyTree|null $_validPolicyTree |
|
46 | - */ |
|
47 | - protected $_validPolicyTree; |
|
48 | - |
|
49 | - /** |
|
50 | - * Permitted subtrees (permitted_subtrees). |
|
51 | - * |
|
52 | - * A set of root names for each name type defining a set of subtrees within |
|
53 | - * which all subject names in subsequent certificates in the certification |
|
54 | - * path must fall. |
|
55 | - * |
|
56 | - * @var mixed $_permittedSubtrees |
|
57 | - */ |
|
58 | - protected $_permittedSubtrees; |
|
59 | - |
|
60 | - /** |
|
61 | - * Excluded subtrees (excluded_subtrees). |
|
62 | - * |
|
63 | - * A set of root names for each name type defining a set of subtrees within |
|
64 | - * which no subject name in subsequent certificates in the certification |
|
65 | - * path may fall. |
|
66 | - * |
|
67 | - * @var mixed $_excludedSubtrees |
|
68 | - */ |
|
69 | - protected $_excludedSubtrees; |
|
70 | - |
|
71 | - /** |
|
72 | - * Explicit policy (explicit_policy). |
|
73 | - * |
|
74 | - * An integer that indicates if a non-NULL valid_policy_tree is required. |
|
75 | - * |
|
76 | - * @var int $_explicitPolicy |
|
77 | - */ |
|
78 | - protected $_explicitPolicy; |
|
79 | - |
|
80 | - /** |
|
81 | - * Inhibit anyPolicy (inhibit_anyPolicy). |
|
82 | - * |
|
83 | - * An integer that indicates whether the anyPolicy policy identifier is |
|
84 | - * considered a match. |
|
85 | - * |
|
86 | - * @var int $_inhibitAnyPolicy |
|
87 | - */ |
|
88 | - protected $_inhibitAnyPolicy; |
|
89 | - |
|
90 | - /** |
|
91 | - * Policy mapping (policy_mapping). |
|
92 | - * |
|
93 | - * An integer that indicates if policy mapping is permitted. |
|
94 | - * |
|
95 | - * @var int $_policyMapping |
|
96 | - */ |
|
97 | - protected $_policyMapping; |
|
98 | - |
|
99 | - /** |
|
100 | - * Working public key algorithm (working_public_key_algorithm). |
|
101 | - * |
|
102 | - * The digital signature algorithm used to verify the signature of a |
|
103 | - * certificate. |
|
104 | - * |
|
105 | - * @var AlgorithmIdentifierType $_workingPublicKeyAlgorithm |
|
106 | - */ |
|
107 | - protected $_workingPublicKeyAlgorithm; |
|
108 | - |
|
109 | - /** |
|
110 | - * Working public key (working_public_key). |
|
111 | - * |
|
112 | - * The public key used to verify the signature of a certificate. |
|
113 | - * |
|
114 | - * @var PublicKeyInfo $_workingPublicKey |
|
115 | - */ |
|
116 | - protected $_workingPublicKey; |
|
117 | - |
|
118 | - /** |
|
119 | - * Working public key parameters (working_public_key_parameters). |
|
120 | - * |
|
121 | - * Parameters associated with the current public key that may be required to |
|
122 | - * verify a signature. |
|
123 | - * |
|
124 | - * @var Element|null $_workingPublicKeyParameters |
|
125 | - */ |
|
126 | - protected $_workingPublicKeyParameters; |
|
127 | - |
|
128 | - /** |
|
129 | - * Working issuer name (working_issuer_name). |
|
130 | - * |
|
131 | - * The issuer distinguished name expected in the next certificate in the |
|
132 | - * chain. |
|
133 | - * |
|
134 | - * @var Name $_workingIssuerName |
|
135 | - */ |
|
136 | - protected $_workingIssuerName; |
|
137 | - |
|
138 | - /** |
|
139 | - * Maximum certification path length (max_path_length). |
|
140 | - * |
|
141 | - * @var int $_maxPathLength |
|
142 | - */ |
|
143 | - protected $_maxPathLength; |
|
144 | - |
|
145 | - /** |
|
146 | - * Constructor. |
|
147 | - */ |
|
148 | - protected function __construct() |
|
149 | - { |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Initialize variables according to RFC 5280 6.1.2. |
|
154 | - * |
|
155 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.2 |
|
156 | - * @param PathValidationConfig $config |
|
157 | - * @param Certificate $trust_anchor Trust anchor certificate |
|
158 | - * @param int $n Number of certificates in the certification path |
|
159 | - * @return self |
|
160 | - */ |
|
161 | - public static function initialize(PathValidationConfig $config, |
|
162 | - Certificate $trust_anchor, $n) |
|
163 | - { |
|
164 | - $state = new self(); |
|
165 | - $state->_pathLength = $n; |
|
166 | - $state->_index = 1; |
|
167 | - $state->_validPolicyTree = new PolicyTree(PolicyNode::anyPolicyNode()); |
|
168 | - $state->_permittedSubtrees = null; |
|
169 | - $state->_excludedSubtrees = null; |
|
170 | - $state->_explicitPolicy = $config->explicitPolicy() ? 0 : $n + 1; |
|
171 | - $state->_inhibitAnyPolicy = $config->anyPolicyInhibit() ? 0 : $n + 1; |
|
172 | - $state->_policyMapping = $config->policyMappingInhibit() ? 0 : $n + 1; |
|
173 | - $state->_workingPublicKeyAlgorithm = $trust_anchor->signatureAlgorithm(); |
|
174 | - $tbsCert = $trust_anchor->tbsCertificate(); |
|
175 | - $state->_workingPublicKey = $tbsCert->subjectPublicKeyInfo(); |
|
176 | - $state->_workingPublicKeyParameters = self::getAlgorithmParameters( |
|
177 | - $state->_workingPublicKey->algorithmIdentifier()); |
|
178 | - $state->_workingIssuerName = $tbsCert->issuer(); |
|
179 | - $state->_maxPathLength = $config->maxLength(); |
|
180 | - return $state; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Get self with current certification path index set. |
|
185 | - * |
|
186 | - * @param int $index |
|
187 | - * @return self |
|
188 | - */ |
|
189 | - public function withIndex(int $index): self |
|
190 | - { |
|
191 | - $state = clone $this; |
|
192 | - $state->_index = $index; |
|
193 | - return $state; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Get self with valid_policy_tree. |
|
198 | - * |
|
199 | - * @param PolicyTree $policy_tree |
|
200 | - * @return self |
|
201 | - */ |
|
202 | - public function withValidPolicyTree(PolicyTree $policy_tree): self |
|
203 | - { |
|
204 | - $state = clone $this; |
|
205 | - $state->_validPolicyTree = $policy_tree; |
|
206 | - return $state; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Get self with valid_policy_tree set to null. |
|
211 | - * |
|
212 | - * @return self |
|
213 | - */ |
|
214 | - public function withoutValidPolicyTree(): self |
|
215 | - { |
|
216 | - $state = clone $this; |
|
217 | - $state->_validPolicyTree = null; |
|
218 | - return $state; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get self with explicit_policy. |
|
223 | - * |
|
224 | - * @param int $num |
|
225 | - * @return self |
|
226 | - */ |
|
227 | - public function withExplicitPolicy(int $num): self |
|
228 | - { |
|
229 | - $state = clone $this; |
|
230 | - $state->_explicitPolicy = $num; |
|
231 | - return $state; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Get self with inhibit_anyPolicy. |
|
236 | - * |
|
237 | - * @param int $num |
|
238 | - * @return self |
|
239 | - */ |
|
240 | - public function withInhibitAnyPolicy(int $num): self |
|
241 | - { |
|
242 | - $state = clone $this; |
|
243 | - $state->_inhibitAnyPolicy = $num; |
|
244 | - return $state; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Get self with policy_mapping. |
|
249 | - * |
|
250 | - * @param int $num |
|
251 | - * @return self |
|
252 | - */ |
|
253 | - public function withPolicyMapping(int $num): self |
|
254 | - { |
|
255 | - $state = clone $this; |
|
256 | - $state->_policyMapping = $num; |
|
257 | - return $state; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Get self with working_public_key_algorithm. |
|
262 | - * |
|
263 | - * @param AlgorithmIdentifierType $algo |
|
264 | - * @return self |
|
265 | - */ |
|
266 | - public function withWorkingPublicKeyAlgorithm(AlgorithmIdentifierType $algo): self |
|
267 | - { |
|
268 | - $state = clone $this; |
|
269 | - $state->_workingPublicKeyAlgorithm = $algo; |
|
270 | - return $state; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Get self with working_public_key. |
|
275 | - * |
|
276 | - * @param PublicKeyInfo $pubkey_info |
|
277 | - * @return self |
|
278 | - */ |
|
279 | - public function withWorkingPublicKey(PublicKeyInfo $pubkey_info): self |
|
280 | - { |
|
281 | - $state = clone $this; |
|
282 | - $state->_workingPublicKey = $pubkey_info; |
|
283 | - return $state; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Get self with working_public_key_parameters. |
|
288 | - * |
|
289 | - * @param Element|null $params |
|
290 | - * @return self |
|
291 | - */ |
|
292 | - public function withWorkingPublicKeyParameters(Element $params = null): self |
|
293 | - { |
|
294 | - $state = clone $this; |
|
295 | - $state->_workingPublicKeyParameters = $params; |
|
296 | - return $state; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Get self with working_issuer_name. |
|
301 | - * |
|
302 | - * @param Name $issuer |
|
303 | - * @return self |
|
304 | - */ |
|
305 | - public function withWorkingIssuerName(Name $issuer): self |
|
306 | - { |
|
307 | - $state = clone $this; |
|
308 | - $state->_workingIssuerName = $issuer; |
|
309 | - return $state; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Get self with max_path_length. |
|
314 | - * |
|
315 | - * @param int $length |
|
316 | - * @return self |
|
317 | - */ |
|
318 | - public function withMaxPathLength(int $length): self |
|
319 | - { |
|
320 | - $state = clone $this; |
|
321 | - $state->_maxPathLength = $length; |
|
322 | - return $state; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Get the certification path length (n). |
|
327 | - * |
|
328 | - * @return int |
|
329 | - */ |
|
330 | - public function pathLength(): int |
|
331 | - { |
|
332 | - return $this->_pathLength; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Get the current index in certification path in the range of 1..n. |
|
337 | - * |
|
338 | - * @return int |
|
339 | - */ |
|
340 | - public function index(): int |
|
341 | - { |
|
342 | - return $this->_index; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Check whether valid_policy_tree is present. |
|
347 | - * |
|
348 | - * @return bool |
|
349 | - */ |
|
350 | - public function hasValidPolicyTree(): bool |
|
351 | - { |
|
352 | - return isset($this->_validPolicyTree); |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Get valid_policy_tree. |
|
357 | - * |
|
358 | - * @throws \LogicException |
|
359 | - * @return PolicyTree |
|
360 | - */ |
|
361 | - public function validPolicyTree(): PolicyTree |
|
362 | - { |
|
363 | - if (!$this->hasValidPolicyTree()) { |
|
364 | - throw new \LogicException("valid_policy_tree not set."); |
|
365 | - } |
|
366 | - return $this->_validPolicyTree; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Get permitted_subtrees. |
|
371 | - * |
|
372 | - * @return mixed |
|
373 | - */ |
|
374 | - public function permittedSubtrees() |
|
375 | - { |
|
376 | - return $this->_permittedSubtrees; |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Get excluded_subtrees. |
|
381 | - * |
|
382 | - * @return mixed |
|
383 | - */ |
|
384 | - public function excludedSubtrees() |
|
385 | - { |
|
386 | - return $this->_excludedSubtrees; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Get explicit_policy. |
|
391 | - * |
|
392 | - * @return int |
|
393 | - */ |
|
394 | - public function explicitPolicy(): int |
|
395 | - { |
|
396 | - return $this->_explicitPolicy; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Get inhibit_anyPolicy. |
|
401 | - * |
|
402 | - * @return int |
|
403 | - */ |
|
404 | - public function inhibitAnyPolicy(): int |
|
405 | - { |
|
406 | - return $this->_inhibitAnyPolicy; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Get policy_mapping. |
|
411 | - * |
|
412 | - * @return int |
|
413 | - */ |
|
414 | - public function policyMapping(): int |
|
415 | - { |
|
416 | - return $this->_policyMapping; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Get working_public_key_algorithm. |
|
421 | - * |
|
422 | - * @return AlgorithmIdentifierType |
|
423 | - */ |
|
424 | - public function workingPublicKeyAlgorithm(): AlgorithmIdentifierType |
|
425 | - { |
|
426 | - return $this->_workingPublicKeyAlgorithm; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Get working_public_key. |
|
431 | - * |
|
432 | - * @return PublicKeyInfo |
|
433 | - */ |
|
434 | - public function workingPublicKey(): PublicKeyInfo |
|
435 | - { |
|
436 | - return $this->_workingPublicKey; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Get working_public_key_parameters. |
|
441 | - * |
|
442 | - * @return Element|null |
|
443 | - */ |
|
444 | - public function workingPublicKeyParameters() |
|
445 | - { |
|
446 | - return $this->_workingPublicKeyParameters; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Get working_issuer_name. |
|
451 | - * |
|
452 | - * @return Name |
|
453 | - */ |
|
454 | - public function workingIssuerName(): Name |
|
455 | - { |
|
456 | - return $this->_workingIssuerName; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get maximum certification path length. |
|
461 | - * |
|
462 | - * @return int |
|
463 | - */ |
|
464 | - public function maxPathLength(): int |
|
465 | - { |
|
466 | - return $this->_maxPathLength; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Check whether processing the final certificate of the certification path. |
|
471 | - * |
|
472 | - * @return bool |
|
473 | - */ |
|
474 | - public function isFinal(): bool |
|
475 | - { |
|
476 | - return $this->_index == $this->_pathLength; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Get the path validation result. |
|
481 | - * |
|
482 | - * @param Certificate[] $certificates Certificates in a certification path |
|
483 | - * @return PathValidationResult |
|
484 | - */ |
|
485 | - public function getResult(array $certificates): PathValidationResult |
|
486 | - { |
|
487 | - return new PathValidationResult($certificates, $this->_validPolicyTree, |
|
488 | - $this->_workingPublicKey, $this->_workingPublicKeyAlgorithm, |
|
489 | - $this->_workingPublicKeyParameters); |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * Get ASN.1 parameters from algorithm identifier. |
|
494 | - * |
|
495 | - * @param AlgorithmIdentifierType $algo |
|
496 | - * @return Element|null ASN.1 element or null if parameters are omitted |
|
497 | - */ |
|
498 | - public static function getAlgorithmParameters(AlgorithmIdentifierType $algo) |
|
499 | - { |
|
500 | - $seq = $algo->toASN1(); |
|
501 | - return $seq->has(1) ? $seq->at(1)->asElement() : null; |
|
502 | - } |
|
23 | + /** |
|
24 | + * Length of the certification path (n). |
|
25 | + * |
|
26 | + * @var int $_pathLength |
|
27 | + */ |
|
28 | + protected $_pathLength; |
|
29 | + |
|
30 | + /** |
|
31 | + * Current index in the certification path in the range of 1..n (i). |
|
32 | + * |
|
33 | + * @var int $_index |
|
34 | + */ |
|
35 | + protected $_index; |
|
36 | + |
|
37 | + /** |
|
38 | + * Valid policy tree (valid_policy_tree). |
|
39 | + * |
|
40 | + * A tree of certificate policies with their optional qualifiers. |
|
41 | + * Each of the leaves of the tree represents a valid policy at this stage in |
|
42 | + * the certification path validation. |
|
43 | + * Once the tree is set to NULL, policy processing ceases. |
|
44 | + * |
|
45 | + * @var PolicyTree|null $_validPolicyTree |
|
46 | + */ |
|
47 | + protected $_validPolicyTree; |
|
48 | + |
|
49 | + /** |
|
50 | + * Permitted subtrees (permitted_subtrees). |
|
51 | + * |
|
52 | + * A set of root names for each name type defining a set of subtrees within |
|
53 | + * which all subject names in subsequent certificates in the certification |
|
54 | + * path must fall. |
|
55 | + * |
|
56 | + * @var mixed $_permittedSubtrees |
|
57 | + */ |
|
58 | + protected $_permittedSubtrees; |
|
59 | + |
|
60 | + /** |
|
61 | + * Excluded subtrees (excluded_subtrees). |
|
62 | + * |
|
63 | + * A set of root names for each name type defining a set of subtrees within |
|
64 | + * which no subject name in subsequent certificates in the certification |
|
65 | + * path may fall. |
|
66 | + * |
|
67 | + * @var mixed $_excludedSubtrees |
|
68 | + */ |
|
69 | + protected $_excludedSubtrees; |
|
70 | + |
|
71 | + /** |
|
72 | + * Explicit policy (explicit_policy). |
|
73 | + * |
|
74 | + * An integer that indicates if a non-NULL valid_policy_tree is required. |
|
75 | + * |
|
76 | + * @var int $_explicitPolicy |
|
77 | + */ |
|
78 | + protected $_explicitPolicy; |
|
79 | + |
|
80 | + /** |
|
81 | + * Inhibit anyPolicy (inhibit_anyPolicy). |
|
82 | + * |
|
83 | + * An integer that indicates whether the anyPolicy policy identifier is |
|
84 | + * considered a match. |
|
85 | + * |
|
86 | + * @var int $_inhibitAnyPolicy |
|
87 | + */ |
|
88 | + protected $_inhibitAnyPolicy; |
|
89 | + |
|
90 | + /** |
|
91 | + * Policy mapping (policy_mapping). |
|
92 | + * |
|
93 | + * An integer that indicates if policy mapping is permitted. |
|
94 | + * |
|
95 | + * @var int $_policyMapping |
|
96 | + */ |
|
97 | + protected $_policyMapping; |
|
98 | + |
|
99 | + /** |
|
100 | + * Working public key algorithm (working_public_key_algorithm). |
|
101 | + * |
|
102 | + * The digital signature algorithm used to verify the signature of a |
|
103 | + * certificate. |
|
104 | + * |
|
105 | + * @var AlgorithmIdentifierType $_workingPublicKeyAlgorithm |
|
106 | + */ |
|
107 | + protected $_workingPublicKeyAlgorithm; |
|
108 | + |
|
109 | + /** |
|
110 | + * Working public key (working_public_key). |
|
111 | + * |
|
112 | + * The public key used to verify the signature of a certificate. |
|
113 | + * |
|
114 | + * @var PublicKeyInfo $_workingPublicKey |
|
115 | + */ |
|
116 | + protected $_workingPublicKey; |
|
117 | + |
|
118 | + /** |
|
119 | + * Working public key parameters (working_public_key_parameters). |
|
120 | + * |
|
121 | + * Parameters associated with the current public key that may be required to |
|
122 | + * verify a signature. |
|
123 | + * |
|
124 | + * @var Element|null $_workingPublicKeyParameters |
|
125 | + */ |
|
126 | + protected $_workingPublicKeyParameters; |
|
127 | + |
|
128 | + /** |
|
129 | + * Working issuer name (working_issuer_name). |
|
130 | + * |
|
131 | + * The issuer distinguished name expected in the next certificate in the |
|
132 | + * chain. |
|
133 | + * |
|
134 | + * @var Name $_workingIssuerName |
|
135 | + */ |
|
136 | + protected $_workingIssuerName; |
|
137 | + |
|
138 | + /** |
|
139 | + * Maximum certification path length (max_path_length). |
|
140 | + * |
|
141 | + * @var int $_maxPathLength |
|
142 | + */ |
|
143 | + protected $_maxPathLength; |
|
144 | + |
|
145 | + /** |
|
146 | + * Constructor. |
|
147 | + */ |
|
148 | + protected function __construct() |
|
149 | + { |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Initialize variables according to RFC 5280 6.1.2. |
|
154 | + * |
|
155 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.2 |
|
156 | + * @param PathValidationConfig $config |
|
157 | + * @param Certificate $trust_anchor Trust anchor certificate |
|
158 | + * @param int $n Number of certificates in the certification path |
|
159 | + * @return self |
|
160 | + */ |
|
161 | + public static function initialize(PathValidationConfig $config, |
|
162 | + Certificate $trust_anchor, $n) |
|
163 | + { |
|
164 | + $state = new self(); |
|
165 | + $state->_pathLength = $n; |
|
166 | + $state->_index = 1; |
|
167 | + $state->_validPolicyTree = new PolicyTree(PolicyNode::anyPolicyNode()); |
|
168 | + $state->_permittedSubtrees = null; |
|
169 | + $state->_excludedSubtrees = null; |
|
170 | + $state->_explicitPolicy = $config->explicitPolicy() ? 0 : $n + 1; |
|
171 | + $state->_inhibitAnyPolicy = $config->anyPolicyInhibit() ? 0 : $n + 1; |
|
172 | + $state->_policyMapping = $config->policyMappingInhibit() ? 0 : $n + 1; |
|
173 | + $state->_workingPublicKeyAlgorithm = $trust_anchor->signatureAlgorithm(); |
|
174 | + $tbsCert = $trust_anchor->tbsCertificate(); |
|
175 | + $state->_workingPublicKey = $tbsCert->subjectPublicKeyInfo(); |
|
176 | + $state->_workingPublicKeyParameters = self::getAlgorithmParameters( |
|
177 | + $state->_workingPublicKey->algorithmIdentifier()); |
|
178 | + $state->_workingIssuerName = $tbsCert->issuer(); |
|
179 | + $state->_maxPathLength = $config->maxLength(); |
|
180 | + return $state; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Get self with current certification path index set. |
|
185 | + * |
|
186 | + * @param int $index |
|
187 | + * @return self |
|
188 | + */ |
|
189 | + public function withIndex(int $index): self |
|
190 | + { |
|
191 | + $state = clone $this; |
|
192 | + $state->_index = $index; |
|
193 | + return $state; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Get self with valid_policy_tree. |
|
198 | + * |
|
199 | + * @param PolicyTree $policy_tree |
|
200 | + * @return self |
|
201 | + */ |
|
202 | + public function withValidPolicyTree(PolicyTree $policy_tree): self |
|
203 | + { |
|
204 | + $state = clone $this; |
|
205 | + $state->_validPolicyTree = $policy_tree; |
|
206 | + return $state; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Get self with valid_policy_tree set to null. |
|
211 | + * |
|
212 | + * @return self |
|
213 | + */ |
|
214 | + public function withoutValidPolicyTree(): self |
|
215 | + { |
|
216 | + $state = clone $this; |
|
217 | + $state->_validPolicyTree = null; |
|
218 | + return $state; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Get self with explicit_policy. |
|
223 | + * |
|
224 | + * @param int $num |
|
225 | + * @return self |
|
226 | + */ |
|
227 | + public function withExplicitPolicy(int $num): self |
|
228 | + { |
|
229 | + $state = clone $this; |
|
230 | + $state->_explicitPolicy = $num; |
|
231 | + return $state; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Get self with inhibit_anyPolicy. |
|
236 | + * |
|
237 | + * @param int $num |
|
238 | + * @return self |
|
239 | + */ |
|
240 | + public function withInhibitAnyPolicy(int $num): self |
|
241 | + { |
|
242 | + $state = clone $this; |
|
243 | + $state->_inhibitAnyPolicy = $num; |
|
244 | + return $state; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Get self with policy_mapping. |
|
249 | + * |
|
250 | + * @param int $num |
|
251 | + * @return self |
|
252 | + */ |
|
253 | + public function withPolicyMapping(int $num): self |
|
254 | + { |
|
255 | + $state = clone $this; |
|
256 | + $state->_policyMapping = $num; |
|
257 | + return $state; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Get self with working_public_key_algorithm. |
|
262 | + * |
|
263 | + * @param AlgorithmIdentifierType $algo |
|
264 | + * @return self |
|
265 | + */ |
|
266 | + public function withWorkingPublicKeyAlgorithm(AlgorithmIdentifierType $algo): self |
|
267 | + { |
|
268 | + $state = clone $this; |
|
269 | + $state->_workingPublicKeyAlgorithm = $algo; |
|
270 | + return $state; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Get self with working_public_key. |
|
275 | + * |
|
276 | + * @param PublicKeyInfo $pubkey_info |
|
277 | + * @return self |
|
278 | + */ |
|
279 | + public function withWorkingPublicKey(PublicKeyInfo $pubkey_info): self |
|
280 | + { |
|
281 | + $state = clone $this; |
|
282 | + $state->_workingPublicKey = $pubkey_info; |
|
283 | + return $state; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Get self with working_public_key_parameters. |
|
288 | + * |
|
289 | + * @param Element|null $params |
|
290 | + * @return self |
|
291 | + */ |
|
292 | + public function withWorkingPublicKeyParameters(Element $params = null): self |
|
293 | + { |
|
294 | + $state = clone $this; |
|
295 | + $state->_workingPublicKeyParameters = $params; |
|
296 | + return $state; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Get self with working_issuer_name. |
|
301 | + * |
|
302 | + * @param Name $issuer |
|
303 | + * @return self |
|
304 | + */ |
|
305 | + public function withWorkingIssuerName(Name $issuer): self |
|
306 | + { |
|
307 | + $state = clone $this; |
|
308 | + $state->_workingIssuerName = $issuer; |
|
309 | + return $state; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Get self with max_path_length. |
|
314 | + * |
|
315 | + * @param int $length |
|
316 | + * @return self |
|
317 | + */ |
|
318 | + public function withMaxPathLength(int $length): self |
|
319 | + { |
|
320 | + $state = clone $this; |
|
321 | + $state->_maxPathLength = $length; |
|
322 | + return $state; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Get the certification path length (n). |
|
327 | + * |
|
328 | + * @return int |
|
329 | + */ |
|
330 | + public function pathLength(): int |
|
331 | + { |
|
332 | + return $this->_pathLength; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Get the current index in certification path in the range of 1..n. |
|
337 | + * |
|
338 | + * @return int |
|
339 | + */ |
|
340 | + public function index(): int |
|
341 | + { |
|
342 | + return $this->_index; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Check whether valid_policy_tree is present. |
|
347 | + * |
|
348 | + * @return bool |
|
349 | + */ |
|
350 | + public function hasValidPolicyTree(): bool |
|
351 | + { |
|
352 | + return isset($this->_validPolicyTree); |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Get valid_policy_tree. |
|
357 | + * |
|
358 | + * @throws \LogicException |
|
359 | + * @return PolicyTree |
|
360 | + */ |
|
361 | + public function validPolicyTree(): PolicyTree |
|
362 | + { |
|
363 | + if (!$this->hasValidPolicyTree()) { |
|
364 | + throw new \LogicException("valid_policy_tree not set."); |
|
365 | + } |
|
366 | + return $this->_validPolicyTree; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Get permitted_subtrees. |
|
371 | + * |
|
372 | + * @return mixed |
|
373 | + */ |
|
374 | + public function permittedSubtrees() |
|
375 | + { |
|
376 | + return $this->_permittedSubtrees; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Get excluded_subtrees. |
|
381 | + * |
|
382 | + * @return mixed |
|
383 | + */ |
|
384 | + public function excludedSubtrees() |
|
385 | + { |
|
386 | + return $this->_excludedSubtrees; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Get explicit_policy. |
|
391 | + * |
|
392 | + * @return int |
|
393 | + */ |
|
394 | + public function explicitPolicy(): int |
|
395 | + { |
|
396 | + return $this->_explicitPolicy; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Get inhibit_anyPolicy. |
|
401 | + * |
|
402 | + * @return int |
|
403 | + */ |
|
404 | + public function inhibitAnyPolicy(): int |
|
405 | + { |
|
406 | + return $this->_inhibitAnyPolicy; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Get policy_mapping. |
|
411 | + * |
|
412 | + * @return int |
|
413 | + */ |
|
414 | + public function policyMapping(): int |
|
415 | + { |
|
416 | + return $this->_policyMapping; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Get working_public_key_algorithm. |
|
421 | + * |
|
422 | + * @return AlgorithmIdentifierType |
|
423 | + */ |
|
424 | + public function workingPublicKeyAlgorithm(): AlgorithmIdentifierType |
|
425 | + { |
|
426 | + return $this->_workingPublicKeyAlgorithm; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Get working_public_key. |
|
431 | + * |
|
432 | + * @return PublicKeyInfo |
|
433 | + */ |
|
434 | + public function workingPublicKey(): PublicKeyInfo |
|
435 | + { |
|
436 | + return $this->_workingPublicKey; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Get working_public_key_parameters. |
|
441 | + * |
|
442 | + * @return Element|null |
|
443 | + */ |
|
444 | + public function workingPublicKeyParameters() |
|
445 | + { |
|
446 | + return $this->_workingPublicKeyParameters; |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * Get working_issuer_name. |
|
451 | + * |
|
452 | + * @return Name |
|
453 | + */ |
|
454 | + public function workingIssuerName(): Name |
|
455 | + { |
|
456 | + return $this->_workingIssuerName; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get maximum certification path length. |
|
461 | + * |
|
462 | + * @return int |
|
463 | + */ |
|
464 | + public function maxPathLength(): int |
|
465 | + { |
|
466 | + return $this->_maxPathLength; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Check whether processing the final certificate of the certification path. |
|
471 | + * |
|
472 | + * @return bool |
|
473 | + */ |
|
474 | + public function isFinal(): bool |
|
475 | + { |
|
476 | + return $this->_index == $this->_pathLength; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Get the path validation result. |
|
481 | + * |
|
482 | + * @param Certificate[] $certificates Certificates in a certification path |
|
483 | + * @return PathValidationResult |
|
484 | + */ |
|
485 | + public function getResult(array $certificates): PathValidationResult |
|
486 | + { |
|
487 | + return new PathValidationResult($certificates, $this->_validPolicyTree, |
|
488 | + $this->_workingPublicKey, $this->_workingPublicKeyAlgorithm, |
|
489 | + $this->_workingPublicKeyParameters); |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * Get ASN.1 parameters from algorithm identifier. |
|
494 | + * |
|
495 | + * @param AlgorithmIdentifierType $algo |
|
496 | + * @return Element|null ASN.1 element or null if parameters are omitted |
|
497 | + */ |
|
498 | + public static function getAlgorithmParameters(AlgorithmIdentifierType $algo) |
|
499 | + { |
|
500 | + $seq = $algo->toASN1(); |
|
501 | + return $seq->has(1) ? $seq->at(1)->asElement() : null; |
|
502 | + } |
|
503 | 503 | } |
@@ -20,92 +20,92 @@ |
||
20 | 20 | */ |
21 | 21 | class ObjectDigestInfo |
22 | 22 | { |
23 | - const TYPE_PUBLIC_KEY = 0; |
|
24 | - const TYPE_PUBLIC_KEY_CERT = 1; |
|
25 | - const TYPE_OTHER_OBJECT_TYPES = 2; |
|
23 | + const TYPE_PUBLIC_KEY = 0; |
|
24 | + const TYPE_PUBLIC_KEY_CERT = 1; |
|
25 | + const TYPE_OTHER_OBJECT_TYPES = 2; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Object type. |
|
29 | - * |
|
30 | - * @var int $_digestedObjectType |
|
31 | - */ |
|
32 | - protected $_digestedObjectType; |
|
27 | + /** |
|
28 | + * Object type. |
|
29 | + * |
|
30 | + * @var int $_digestedObjectType |
|
31 | + */ |
|
32 | + protected $_digestedObjectType; |
|
33 | 33 | |
34 | - /** |
|
35 | - * OID of other object type. |
|
36 | - * |
|
37 | - * @var string|null $_otherObjectTypeID |
|
38 | - */ |
|
39 | - protected $_otherObjectTypeID; |
|
34 | + /** |
|
35 | + * OID of other object type. |
|
36 | + * |
|
37 | + * @var string|null $_otherObjectTypeID |
|
38 | + */ |
|
39 | + protected $_otherObjectTypeID; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Digest algorithm. |
|
43 | - * |
|
44 | - * @var AlgorithmIdentifierType $_digestAlgorithm |
|
45 | - */ |
|
46 | - protected $_digestAlgorithm; |
|
41 | + /** |
|
42 | + * Digest algorithm. |
|
43 | + * |
|
44 | + * @var AlgorithmIdentifierType $_digestAlgorithm |
|
45 | + */ |
|
46 | + protected $_digestAlgorithm; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Object digest. |
|
50 | - * |
|
51 | - * @var BitString $_objectDigest |
|
52 | - */ |
|
53 | - protected $_objectDigest; |
|
48 | + /** |
|
49 | + * Object digest. |
|
50 | + * |
|
51 | + * @var BitString $_objectDigest |
|
52 | + */ |
|
53 | + protected $_objectDigest; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Constructor. |
|
57 | - * |
|
58 | - * @param int $type |
|
59 | - * @param AlgorithmIdentifierType $algo |
|
60 | - * @param BitString $digest |
|
61 | - */ |
|
62 | - public function __construct(int $type, AlgorithmIdentifierType $algo, |
|
63 | - BitString $digest) |
|
64 | - { |
|
65 | - $this->_digestedObjectType = $type; |
|
66 | - $this->_otherObjectTypeID = null; |
|
67 | - $this->_digestAlgorithm = $algo; |
|
68 | - $this->_objectDigest = $digest; |
|
69 | - } |
|
55 | + /** |
|
56 | + * Constructor. |
|
57 | + * |
|
58 | + * @param int $type |
|
59 | + * @param AlgorithmIdentifierType $algo |
|
60 | + * @param BitString $digest |
|
61 | + */ |
|
62 | + public function __construct(int $type, AlgorithmIdentifierType $algo, |
|
63 | + BitString $digest) |
|
64 | + { |
|
65 | + $this->_digestedObjectType = $type; |
|
66 | + $this->_otherObjectTypeID = null; |
|
67 | + $this->_digestAlgorithm = $algo; |
|
68 | + $this->_objectDigest = $digest; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Initialize from ASN.1. |
|
73 | - * |
|
74 | - * @param Sequence $seq |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - public static function fromASN1(Sequence $seq): self |
|
78 | - { |
|
79 | - $type = $seq->at(0) |
|
80 | - ->asEnumerated() |
|
81 | - ->intNumber(); |
|
82 | - $oid = null; |
|
83 | - $idx = 1; |
|
84 | - if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { |
|
85 | - $oid = $seq->at($idx++) |
|
86 | - ->asObjectIdentifier() |
|
87 | - ->oid(); |
|
88 | - } |
|
89 | - $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); |
|
90 | - $digest = $seq->at($idx)->asBitString(); |
|
91 | - $obj = new self($type, $algo, $digest); |
|
92 | - $obj->_otherObjectTypeID = $oid; |
|
93 | - return $obj; |
|
94 | - } |
|
71 | + /** |
|
72 | + * Initialize from ASN.1. |
|
73 | + * |
|
74 | + * @param Sequence $seq |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + public static function fromASN1(Sequence $seq): self |
|
78 | + { |
|
79 | + $type = $seq->at(0) |
|
80 | + ->asEnumerated() |
|
81 | + ->intNumber(); |
|
82 | + $oid = null; |
|
83 | + $idx = 1; |
|
84 | + if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { |
|
85 | + $oid = $seq->at($idx++) |
|
86 | + ->asObjectIdentifier() |
|
87 | + ->oid(); |
|
88 | + } |
|
89 | + $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); |
|
90 | + $digest = $seq->at($idx)->asBitString(); |
|
91 | + $obj = new self($type, $algo, $digest); |
|
92 | + $obj->_otherObjectTypeID = $oid; |
|
93 | + return $obj; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Generate ASN.1 structure. |
|
98 | - * |
|
99 | - * @return Sequence |
|
100 | - */ |
|
101 | - public function toASN1(): Sequence |
|
102 | - { |
|
103 | - $elements = array(new Enumerated($this->_digestedObjectType)); |
|
104 | - if (isset($this->_otherObjectTypeID)) { |
|
105 | - $elements[] = new ObjectIdentifier($this->_otherObjectTypeID); |
|
106 | - } |
|
107 | - $elements[] = $this->_digestAlgorithm->toASN1(); |
|
108 | - $elements[] = $this->_objectDigest; |
|
109 | - return new Sequence(...$elements); |
|
110 | - } |
|
96 | + /** |
|
97 | + * Generate ASN.1 structure. |
|
98 | + * |
|
99 | + * @return Sequence |
|
100 | + */ |
|
101 | + public function toASN1(): Sequence |
|
102 | + { |
|
103 | + $elements = array(new Enumerated($this->_digestedObjectType)); |
|
104 | + if (isset($this->_otherObjectTypeID)) { |
|
105 | + $elements[] = new ObjectIdentifier($this->_otherObjectTypeID); |
|
106 | + } |
|
107 | + $elements[] = $this->_digestAlgorithm->toASN1(); |
|
108 | + $elements[] = $this->_objectDigest; |
|
109 | + return new Sequence(...$elements); |
|
110 | + } |
|
111 | 111 | } |
@@ -19,144 +19,144 @@ |
||
19 | 19 | */ |
20 | 20 | class V2Form extends AttCertIssuer |
21 | 21 | { |
22 | - /** |
|
23 | - * Issuer name. |
|
24 | - * |
|
25 | - * @var GeneralNames $_issuerName |
|
26 | - */ |
|
27 | - protected $_issuerName; |
|
22 | + /** |
|
23 | + * Issuer name. |
|
24 | + * |
|
25 | + * @var GeneralNames $_issuerName |
|
26 | + */ |
|
27 | + protected $_issuerName; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Issuer PKC's issuer and serial. |
|
31 | - * |
|
32 | - * @var IssuerSerial $_baseCertificateID |
|
33 | - */ |
|
34 | - protected $_baseCertificateID; |
|
29 | + /** |
|
30 | + * Issuer PKC's issuer and serial. |
|
31 | + * |
|
32 | + * @var IssuerSerial $_baseCertificateID |
|
33 | + */ |
|
34 | + protected $_baseCertificateID; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Linked object. |
|
38 | - * |
|
39 | - * @var ObjectDigestInfo $_objectDigestInfo |
|
40 | - */ |
|
41 | - protected $_objectDigestInfo; |
|
36 | + /** |
|
37 | + * Linked object. |
|
38 | + * |
|
39 | + * @var ObjectDigestInfo $_objectDigestInfo |
|
40 | + */ |
|
41 | + protected $_objectDigestInfo; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param GeneralNames|null $names |
|
47 | - */ |
|
48 | - public function __construct(GeneralNames $names = null) |
|
49 | - { |
|
50 | - $this->_issuerName = $names; |
|
51 | - $this->_baseCertificateID = null; |
|
52 | - $this->_objectDigestInfo = null; |
|
53 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param GeneralNames|null $names |
|
47 | + */ |
|
48 | + public function __construct(GeneralNames $names = null) |
|
49 | + { |
|
50 | + $this->_issuerName = $names; |
|
51 | + $this->_baseCertificateID = null; |
|
52 | + $this->_objectDigestInfo = null; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Initialize from ASN.1. |
|
57 | - * |
|
58 | - * @param Sequence $seq |
|
59 | - * @return self |
|
60 | - */ |
|
61 | - public static function fromV2ASN1(Sequence $seq): self |
|
62 | - { |
|
63 | - $issuer = null; |
|
64 | - $cert_id = null; |
|
65 | - $digest_info = null; |
|
66 | - if ($seq->has(0, Element::TYPE_SEQUENCE)) { |
|
67 | - $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
68 | - } |
|
69 | - if ($seq->hasTagged(0)) { |
|
70 | - $cert_id = IssuerSerial::fromASN1( |
|
71 | - $seq->getTagged(0) |
|
72 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
73 | - ->asSequence()); |
|
74 | - } |
|
75 | - if ($seq->hasTagged(1)) { |
|
76 | - $digest_info = ObjectDigestInfo::fromASN1( |
|
77 | - $seq->getTagged(1) |
|
78 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
79 | - ->asSequence()); |
|
80 | - } |
|
81 | - $obj = new self($issuer); |
|
82 | - $obj->_baseCertificateID = $cert_id; |
|
83 | - $obj->_objectDigestInfo = $digest_info; |
|
84 | - return $obj; |
|
85 | - } |
|
55 | + /** |
|
56 | + * Initialize from ASN.1. |
|
57 | + * |
|
58 | + * @param Sequence $seq |
|
59 | + * @return self |
|
60 | + */ |
|
61 | + public static function fromV2ASN1(Sequence $seq): self |
|
62 | + { |
|
63 | + $issuer = null; |
|
64 | + $cert_id = null; |
|
65 | + $digest_info = null; |
|
66 | + if ($seq->has(0, Element::TYPE_SEQUENCE)) { |
|
67 | + $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
68 | + } |
|
69 | + if ($seq->hasTagged(0)) { |
|
70 | + $cert_id = IssuerSerial::fromASN1( |
|
71 | + $seq->getTagged(0) |
|
72 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
73 | + ->asSequence()); |
|
74 | + } |
|
75 | + if ($seq->hasTagged(1)) { |
|
76 | + $digest_info = ObjectDigestInfo::fromASN1( |
|
77 | + $seq->getTagged(1) |
|
78 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
79 | + ->asSequence()); |
|
80 | + } |
|
81 | + $obj = new self($issuer); |
|
82 | + $obj->_baseCertificateID = $cert_id; |
|
83 | + $obj->_objectDigestInfo = $digest_info; |
|
84 | + return $obj; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Check whether issuer name is set. |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function hasIssuerName(): bool |
|
93 | - { |
|
94 | - return isset($this->_issuerName); |
|
95 | - } |
|
87 | + /** |
|
88 | + * Check whether issuer name is set. |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function hasIssuerName(): bool |
|
93 | + { |
|
94 | + return isset($this->_issuerName); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Get issuer name. |
|
99 | - * |
|
100 | - * @throws \LogicException |
|
101 | - * @return GeneralNames |
|
102 | - */ |
|
103 | - public function issuerName(): GeneralNames |
|
104 | - { |
|
105 | - if (!$this->hasIssuerName()) { |
|
106 | - throw new \LogicException("issuerName not set."); |
|
107 | - } |
|
108 | - return $this->_issuerName; |
|
109 | - } |
|
97 | + /** |
|
98 | + * Get issuer name. |
|
99 | + * |
|
100 | + * @throws \LogicException |
|
101 | + * @return GeneralNames |
|
102 | + */ |
|
103 | + public function issuerName(): GeneralNames |
|
104 | + { |
|
105 | + if (!$this->hasIssuerName()) { |
|
106 | + throw new \LogicException("issuerName not set."); |
|
107 | + } |
|
108 | + return $this->_issuerName; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Get DN of the issuer. |
|
113 | - * |
|
114 | - * This is a convenience method conforming to RFC 5755, which states |
|
115 | - * that Issuer must contain only one non-empty distinguished name. |
|
116 | - * |
|
117 | - * @return \X501\ASN1\Name |
|
118 | - */ |
|
119 | - public function name(): Name |
|
120 | - { |
|
121 | - return $this->issuerName()->firstDN(); |
|
122 | - } |
|
111 | + /** |
|
112 | + * Get DN of the issuer. |
|
113 | + * |
|
114 | + * This is a convenience method conforming to RFC 5755, which states |
|
115 | + * that Issuer must contain only one non-empty distinguished name. |
|
116 | + * |
|
117 | + * @return \X501\ASN1\Name |
|
118 | + */ |
|
119 | + public function name(): Name |
|
120 | + { |
|
121 | + return $this->issuerName()->firstDN(); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * |
|
126 | - * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
|
127 | - * @return ImplicitlyTaggedType Tagged Sequence |
|
128 | - */ |
|
129 | - public function toASN1(): TaggedType |
|
130 | - { |
|
131 | - $elements = array(); |
|
132 | - if (isset($this->_issuerName)) { |
|
133 | - $elements[] = $this->_issuerName->toASN1(); |
|
134 | - } |
|
135 | - if (isset($this->_baseCertificateID)) { |
|
136 | - $elements[] = new ImplicitlyTaggedType(0, |
|
137 | - $this->_baseCertificateID->toASN1()); |
|
138 | - } |
|
139 | - if (isset($this->_objectDigestInfo)) { |
|
140 | - $elements[] = new ImplicitlyTaggedType(1, |
|
141 | - $this->_objectDigestInfo->toASN1()); |
|
142 | - } |
|
143 | - return new ImplicitlyTaggedType(0, new Sequence(...$elements)); |
|
144 | - } |
|
124 | + /** |
|
125 | + * |
|
126 | + * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
|
127 | + * @return ImplicitlyTaggedType Tagged Sequence |
|
128 | + */ |
|
129 | + public function toASN1(): TaggedType |
|
130 | + { |
|
131 | + $elements = array(); |
|
132 | + if (isset($this->_issuerName)) { |
|
133 | + $elements[] = $this->_issuerName->toASN1(); |
|
134 | + } |
|
135 | + if (isset($this->_baseCertificateID)) { |
|
136 | + $elements[] = new ImplicitlyTaggedType(0, |
|
137 | + $this->_baseCertificateID->toASN1()); |
|
138 | + } |
|
139 | + if (isset($this->_objectDigestInfo)) { |
|
140 | + $elements[] = new ImplicitlyTaggedType(1, |
|
141 | + $this->_objectDigestInfo->toASN1()); |
|
142 | + } |
|
143 | + return new ImplicitlyTaggedType(0, new Sequence(...$elements)); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * |
|
148 | - * {@inheritdoc} |
|
149 | - * @see \X509\AttributeCertificate\AttCertIssuer::identifiesPKC() |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - public function identifiesPKC(Certificate $cert): bool |
|
153 | - { |
|
154 | - $name = $this->_issuerName->firstDN(); |
|
155 | - if (!$cert->tbsCertificate() |
|
156 | - ->subject() |
|
157 | - ->equals($name)) { |
|
158 | - return false; |
|
159 | - } |
|
160 | - return true; |
|
161 | - } |
|
146 | + /** |
|
147 | + * |
|
148 | + * {@inheritdoc} |
|
149 | + * @see \X509\AttributeCertificate\AttCertIssuer::identifiesPKC() |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + public function identifiesPKC(Certificate $cert): bool |
|
153 | + { |
|
154 | + $name = $this->_issuerName->firstDN(); |
|
155 | + if (!$cert->tbsCertificate() |
|
156 | + ->subject() |
|
157 | + ->equals($name)) { |
|
158 | + return false; |
|
159 | + } |
|
160 | + return true; |
|
161 | + } |
|
162 | 162 | } |
@@ -23,155 +23,155 @@ |
||
23 | 23 | */ |
24 | 24 | class RoleAttributeValue extends AttributeValue |
25 | 25 | { |
26 | - /** |
|
27 | - * Issuing authority. |
|
28 | - * |
|
29 | - * @var GeneralNames $_roleAuthority |
|
30 | - */ |
|
31 | - protected $_roleAuthority; |
|
26 | + /** |
|
27 | + * Issuing authority. |
|
28 | + * |
|
29 | + * @var GeneralNames $_roleAuthority |
|
30 | + */ |
|
31 | + protected $_roleAuthority; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Role name. |
|
35 | - * |
|
36 | - * @var GeneralName $_roleName |
|
37 | - */ |
|
38 | - protected $_roleName; |
|
33 | + /** |
|
34 | + * Role name. |
|
35 | + * |
|
36 | + * @var GeneralName $_roleName |
|
37 | + */ |
|
38 | + protected $_roleName; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param GeneralName $name Role name |
|
44 | - * @param GeneralNames|null $authority Issuing authority |
|
45 | - */ |
|
46 | - public function __construct(GeneralName $name, GeneralNames $authority = null) |
|
47 | - { |
|
48 | - $this->_roleAuthority = $authority; |
|
49 | - $this->_roleName = $name; |
|
50 | - $this->_oid = AttributeType::OID_ROLE; |
|
51 | - } |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param GeneralName $name Role name |
|
44 | + * @param GeneralNames|null $authority Issuing authority |
|
45 | + */ |
|
46 | + public function __construct(GeneralName $name, GeneralNames $authority = null) |
|
47 | + { |
|
48 | + $this->_roleAuthority = $authority; |
|
49 | + $this->_roleName = $name; |
|
50 | + $this->_oid = AttributeType::OID_ROLE; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Initialize from a role string. |
|
55 | - * |
|
56 | - * @param string $role_name Role name in URI format |
|
57 | - * @param GeneralNames|null $authority Issuing authority |
|
58 | - * @return self |
|
59 | - */ |
|
60 | - public static function fromString(string $role_name, |
|
61 | - GeneralNames $authority = null): self |
|
62 | - { |
|
63 | - return new self(new UniformResourceIdentifier($role_name), $authority); |
|
64 | - } |
|
53 | + /** |
|
54 | + * Initialize from a role string. |
|
55 | + * |
|
56 | + * @param string $role_name Role name in URI format |
|
57 | + * @param GeneralNames|null $authority Issuing authority |
|
58 | + * @return self |
|
59 | + */ |
|
60 | + public static function fromString(string $role_name, |
|
61 | + GeneralNames $authority = null): self |
|
62 | + { |
|
63 | + return new self(new UniformResourceIdentifier($role_name), $authority); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * |
|
68 | - * @param UnspecifiedType $el |
|
69 | - * @return self |
|
70 | - */ |
|
71 | - public static function fromASN1(UnspecifiedType $el): self |
|
72 | - { |
|
73 | - $seq = $el->asSequence(); |
|
74 | - $authority = null; |
|
75 | - if ($seq->hasTagged(0)) { |
|
76 | - $authority = GeneralNames::fromASN1( |
|
77 | - $seq->getTagged(0) |
|
78 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
79 | - ->asSequence()); |
|
80 | - } |
|
81 | - $name = GeneralName::fromASN1( |
|
82 | - $seq->getTagged(1) |
|
83 | - ->asExplicit() |
|
84 | - ->asTagged()); |
|
85 | - return new self($name, $authority); |
|
86 | - } |
|
66 | + /** |
|
67 | + * |
|
68 | + * @param UnspecifiedType $el |
|
69 | + * @return self |
|
70 | + */ |
|
71 | + public static function fromASN1(UnspecifiedType $el): self |
|
72 | + { |
|
73 | + $seq = $el->asSequence(); |
|
74 | + $authority = null; |
|
75 | + if ($seq->hasTagged(0)) { |
|
76 | + $authority = GeneralNames::fromASN1( |
|
77 | + $seq->getTagged(0) |
|
78 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
79 | + ->asSequence()); |
|
80 | + } |
|
81 | + $name = GeneralName::fromASN1( |
|
82 | + $seq->getTagged(1) |
|
83 | + ->asExplicit() |
|
84 | + ->asTagged()); |
|
85 | + return new self($name, $authority); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Check whether issuing authority is present. |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function hasRoleAuthority(): bool |
|
94 | - { |
|
95 | - return isset($this->_roleAuthority); |
|
96 | - } |
|
88 | + /** |
|
89 | + * Check whether issuing authority is present. |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function hasRoleAuthority(): bool |
|
94 | + { |
|
95 | + return isset($this->_roleAuthority); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get issuing authority. |
|
100 | - * |
|
101 | - * @throws \LogicException |
|
102 | - * @return GeneralNames |
|
103 | - */ |
|
104 | - public function roleAuthority(): GeneralNames |
|
105 | - { |
|
106 | - if (!$this->hasRoleAuthority()) { |
|
107 | - throw new \LogicException("roleAuthority not set."); |
|
108 | - } |
|
109 | - return $this->_roleAuthority; |
|
110 | - } |
|
98 | + /** |
|
99 | + * Get issuing authority. |
|
100 | + * |
|
101 | + * @throws \LogicException |
|
102 | + * @return GeneralNames |
|
103 | + */ |
|
104 | + public function roleAuthority(): GeneralNames |
|
105 | + { |
|
106 | + if (!$this->hasRoleAuthority()) { |
|
107 | + throw new \LogicException("roleAuthority not set."); |
|
108 | + } |
|
109 | + return $this->_roleAuthority; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Get role name. |
|
114 | - * |
|
115 | - * @return GeneralName |
|
116 | - */ |
|
117 | - public function roleName(): GeneralName |
|
118 | - { |
|
119 | - return $this->_roleName; |
|
120 | - } |
|
112 | + /** |
|
113 | + * Get role name. |
|
114 | + * |
|
115 | + * @return GeneralName |
|
116 | + */ |
|
117 | + public function roleName(): GeneralName |
|
118 | + { |
|
119 | + return $this->_roleName; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * |
|
124 | - * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
125 | - * @return Sequence |
|
126 | - */ |
|
127 | - public function toASN1(): Sequence |
|
128 | - { |
|
129 | - $elements = array(); |
|
130 | - if (isset($this->_roleAuthority)) { |
|
131 | - $elements[] = new ImplicitlyTaggedType(0, |
|
132 | - $this->_roleAuthority->toASN1()); |
|
133 | - } |
|
134 | - $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1()); |
|
135 | - return new Sequence(...$elements); |
|
136 | - } |
|
122 | + /** |
|
123 | + * |
|
124 | + * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
125 | + * @return Sequence |
|
126 | + */ |
|
127 | + public function toASN1(): Sequence |
|
128 | + { |
|
129 | + $elements = array(); |
|
130 | + if (isset($this->_roleAuthority)) { |
|
131 | + $elements[] = new ImplicitlyTaggedType(0, |
|
132 | + $this->_roleAuthority->toASN1()); |
|
133 | + } |
|
134 | + $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1()); |
|
135 | + return new Sequence(...$elements); |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * |
|
140 | - * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function stringValue(): string |
|
144 | - { |
|
145 | - return "#" . bin2hex($this->toASN1()->toDER()); |
|
146 | - } |
|
138 | + /** |
|
139 | + * |
|
140 | + * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function stringValue(): string |
|
144 | + { |
|
145 | + return "#" . bin2hex($this->toASN1()->toDER()); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * |
|
150 | - * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
151 | - * @return BinaryMatch |
|
152 | - */ |
|
153 | - public function equalityMatchingRule(): BinaryMatch |
|
154 | - { |
|
155 | - return new BinaryMatch(); |
|
156 | - } |
|
148 | + /** |
|
149 | + * |
|
150 | + * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
151 | + * @return BinaryMatch |
|
152 | + */ |
|
153 | + public function equalityMatchingRule(): BinaryMatch |
|
154 | + { |
|
155 | + return new BinaryMatch(); |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * |
|
160 | - * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function rfc2253String(): string |
|
164 | - { |
|
165 | - return $this->stringValue(); |
|
166 | - } |
|
158 | + /** |
|
159 | + * |
|
160 | + * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + public function rfc2253String(): string |
|
164 | + { |
|
165 | + return $this->stringValue(); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * |
|
170 | - * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - protected function _transcodedString(): string |
|
174 | - { |
|
175 | - return $this->stringValue(); |
|
176 | - } |
|
168 | + /** |
|
169 | + * |
|
170 | + * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + protected function _transcodedString(): string |
|
174 | + { |
|
175 | + return $this->stringValue(); |
|
176 | + } |
|
177 | 177 | } |