@@ -9,16 +9,16 @@ |
||
9 | 9 | */ |
10 | 10 | class ChargingIdentityAttributeValue extends IetfAttrSyntax |
11 | 11 | { |
12 | - const OID = "1.3.6.1.5.5.7.10.3"; |
|
12 | + const OID = "1.3.6.1.5.5.7.10.3"; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Constructor. |
|
16 | - * |
|
17 | - * @param IetfAttrValue ...$values |
|
18 | - */ |
|
19 | - public function __construct(IetfAttrValue ...$values) |
|
20 | - { |
|
21 | - parent::__construct(...$values); |
|
22 | - $this->_oid = self::OID; |
|
23 | - } |
|
14 | + /** |
|
15 | + * Constructor. |
|
16 | + * |
|
17 | + * @param IetfAttrValue ...$values |
|
18 | + */ |
|
19 | + public function __construct(IetfAttrValue ...$values) |
|
20 | + { |
|
21 | + parent::__construct(...$values); |
|
22 | + $this->_oid = self::OID; |
|
23 | + } |
|
24 | 24 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ++$idx; |
64 | 64 | } |
65 | 65 | $values = array_map( |
66 | - function (UnspecifiedType $el) { |
|
66 | + function(UnspecifiedType $el) { |
|
67 | 67 | return IetfAttrValue::fromASN1($el); |
68 | 68 | }, |
69 | 69 | $seq->at($idx) |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $this->_policyAuthority->toASN1()); |
149 | 149 | } |
150 | 150 | $values = array_map( |
151 | - function (IetfAttrValue $val) { |
|
151 | + function(IetfAttrValue $val) { |
|
152 | 152 | return $val->toASN1(); |
153 | 153 | }, $this->_values); |
154 | 154 | $elements[] = new Sequence(...$values); |
@@ -19,203 +19,203 @@ |
||
19 | 19 | * @link https://tools.ietf.org/html/rfc5755#section-4.4 |
20 | 20 | */ |
21 | 21 | abstract class IetfAttrSyntax extends AttributeValue implements |
22 | - \Countable, |
|
23 | - \IteratorAggregate |
|
22 | + \Countable, |
|
23 | + \IteratorAggregate |
|
24 | 24 | { |
25 | - /** |
|
26 | - * Policy authority. |
|
27 | - * |
|
28 | - * @var GeneralNames|null $_policyAuthority |
|
29 | - */ |
|
30 | - protected $_policyAuthority; |
|
25 | + /** |
|
26 | + * Policy authority. |
|
27 | + * |
|
28 | + * @var GeneralNames|null $_policyAuthority |
|
29 | + */ |
|
30 | + protected $_policyAuthority; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Values. |
|
34 | - * |
|
35 | - * @var IetfAttrValue[] $_values |
|
36 | - */ |
|
37 | - protected $_values; |
|
32 | + /** |
|
33 | + * Values. |
|
34 | + * |
|
35 | + * @var IetfAttrValue[] $_values |
|
36 | + */ |
|
37 | + protected $_values; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor. |
|
41 | - * |
|
42 | - * @param IetfAttrValue ...$values |
|
43 | - */ |
|
44 | - public function __construct(IetfAttrValue ...$values) |
|
45 | - { |
|
46 | - $this->_policyAuthority = null; |
|
47 | - $this->_values = $values; |
|
48 | - } |
|
39 | + /** |
|
40 | + * Constructor. |
|
41 | + * |
|
42 | + * @param IetfAttrValue ...$values |
|
43 | + */ |
|
44 | + public function __construct(IetfAttrValue ...$values) |
|
45 | + { |
|
46 | + $this->_policyAuthority = null; |
|
47 | + $this->_values = $values; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * @param UnspecifiedType $el |
|
53 | - * @return self |
|
54 | - */ |
|
55 | - public static function fromASN1(UnspecifiedType $el): self |
|
56 | - { |
|
57 | - $seq = $el->asSequence(); |
|
58 | - $authority = null; |
|
59 | - $idx = 0; |
|
60 | - if ($seq->hasTagged(0)) { |
|
61 | - $authority = GeneralNames::fromASN1( |
|
62 | - $seq->getTagged(0) |
|
63 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
64 | - ->asSequence()); |
|
65 | - ++$idx; |
|
66 | - } |
|
67 | - $values = array_map( |
|
68 | - function (UnspecifiedType $el) { |
|
69 | - return IetfAttrValue::fromASN1($el); |
|
70 | - }, |
|
71 | - $seq->at($idx) |
|
72 | - ->asSequence() |
|
73 | - ->elements()); |
|
74 | - $obj = new static(...$values); |
|
75 | - $obj->_policyAuthority = $authority; |
|
76 | - return $obj; |
|
77 | - } |
|
50 | + /** |
|
51 | + * |
|
52 | + * @param UnspecifiedType $el |
|
53 | + * @return self |
|
54 | + */ |
|
55 | + public static function fromASN1(UnspecifiedType $el): self |
|
56 | + { |
|
57 | + $seq = $el->asSequence(); |
|
58 | + $authority = null; |
|
59 | + $idx = 0; |
|
60 | + if ($seq->hasTagged(0)) { |
|
61 | + $authority = GeneralNames::fromASN1( |
|
62 | + $seq->getTagged(0) |
|
63 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
64 | + ->asSequence()); |
|
65 | + ++$idx; |
|
66 | + } |
|
67 | + $values = array_map( |
|
68 | + function (UnspecifiedType $el) { |
|
69 | + return IetfAttrValue::fromASN1($el); |
|
70 | + }, |
|
71 | + $seq->at($idx) |
|
72 | + ->asSequence() |
|
73 | + ->elements()); |
|
74 | + $obj = new static(...$values); |
|
75 | + $obj->_policyAuthority = $authority; |
|
76 | + return $obj; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Get self with policy authority. |
|
81 | - * |
|
82 | - * @param GeneralNames $names |
|
83 | - * @return self |
|
84 | - */ |
|
85 | - public function withPolicyAuthority(GeneralNames $names): self |
|
86 | - { |
|
87 | - $obj = clone $this; |
|
88 | - $obj->_policyAuthority = $names; |
|
89 | - return $obj; |
|
90 | - } |
|
79 | + /** |
|
80 | + * Get self with policy authority. |
|
81 | + * |
|
82 | + * @param GeneralNames $names |
|
83 | + * @return self |
|
84 | + */ |
|
85 | + public function withPolicyAuthority(GeneralNames $names): self |
|
86 | + { |
|
87 | + $obj = clone $this; |
|
88 | + $obj->_policyAuthority = $names; |
|
89 | + return $obj; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Check whether policy authority is present. |
|
94 | - * |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasPolicyAuthority(): bool |
|
98 | - { |
|
99 | - return isset($this->_policyAuthority); |
|
100 | - } |
|
92 | + /** |
|
93 | + * Check whether policy authority is present. |
|
94 | + * |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasPolicyAuthority(): bool |
|
98 | + { |
|
99 | + return isset($this->_policyAuthority); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Get policy authority. |
|
104 | - * |
|
105 | - * @throws \LogicException |
|
106 | - * @return GeneralNames |
|
107 | - */ |
|
108 | - public function policyAuthority(): GeneralNames |
|
109 | - { |
|
110 | - if (!$this->hasPolicyAuthority()) { |
|
111 | - throw new \LogicException("policyAuthority not set."); |
|
112 | - } |
|
113 | - return $this->_policyAuthority; |
|
114 | - } |
|
102 | + /** |
|
103 | + * Get policy authority. |
|
104 | + * |
|
105 | + * @throws \LogicException |
|
106 | + * @return GeneralNames |
|
107 | + */ |
|
108 | + public function policyAuthority(): GeneralNames |
|
109 | + { |
|
110 | + if (!$this->hasPolicyAuthority()) { |
|
111 | + throw new \LogicException("policyAuthority not set."); |
|
112 | + } |
|
113 | + return $this->_policyAuthority; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Get values. |
|
118 | - * |
|
119 | - * @return IetfAttrValue[] |
|
120 | - */ |
|
121 | - public function values(): array |
|
122 | - { |
|
123 | - return $this->_values; |
|
124 | - } |
|
116 | + /** |
|
117 | + * Get values. |
|
118 | + * |
|
119 | + * @return IetfAttrValue[] |
|
120 | + */ |
|
121 | + public function values(): array |
|
122 | + { |
|
123 | + return $this->_values; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Get first value. |
|
128 | - * |
|
129 | - * @throws \LogicException |
|
130 | - * @return IetfAttrValue |
|
131 | - */ |
|
132 | - public function first(): IetfAttrValue |
|
133 | - { |
|
134 | - if (!count($this->_values)) { |
|
135 | - throw new \LogicException("No values."); |
|
136 | - } |
|
137 | - return $this->_values[0]; |
|
138 | - } |
|
126 | + /** |
|
127 | + * Get first value. |
|
128 | + * |
|
129 | + * @throws \LogicException |
|
130 | + * @return IetfAttrValue |
|
131 | + */ |
|
132 | + public function first(): IetfAttrValue |
|
133 | + { |
|
134 | + if (!count($this->_values)) { |
|
135 | + throw new \LogicException("No values."); |
|
136 | + } |
|
137 | + return $this->_values[0]; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * |
|
142 | - * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
143 | - * @return Sequence |
|
144 | - */ |
|
145 | - public function toASN1(): Sequence |
|
146 | - { |
|
147 | - $elements = array(); |
|
148 | - if (isset($this->_policyAuthority)) { |
|
149 | - $elements[] = new ImplicitlyTaggedType(0, |
|
150 | - $this->_policyAuthority->toASN1()); |
|
151 | - } |
|
152 | - $values = array_map( |
|
153 | - function (IetfAttrValue $val) { |
|
154 | - return $val->toASN1(); |
|
155 | - }, $this->_values); |
|
156 | - $elements[] = new Sequence(...$values); |
|
157 | - return new Sequence(...$elements); |
|
158 | - } |
|
140 | + /** |
|
141 | + * |
|
142 | + * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
143 | + * @return Sequence |
|
144 | + */ |
|
145 | + public function toASN1(): Sequence |
|
146 | + { |
|
147 | + $elements = array(); |
|
148 | + if (isset($this->_policyAuthority)) { |
|
149 | + $elements[] = new ImplicitlyTaggedType(0, |
|
150 | + $this->_policyAuthority->toASN1()); |
|
151 | + } |
|
152 | + $values = array_map( |
|
153 | + function (IetfAttrValue $val) { |
|
154 | + return $val->toASN1(); |
|
155 | + }, $this->_values); |
|
156 | + $elements[] = new Sequence(...$values); |
|
157 | + return new Sequence(...$elements); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * |
|
162 | - * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function stringValue(): string |
|
166 | - { |
|
167 | - return "#" . bin2hex($this->toASN1()->toDER()); |
|
168 | - } |
|
160 | + /** |
|
161 | + * |
|
162 | + * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function stringValue(): string |
|
166 | + { |
|
167 | + return "#" . bin2hex($this->toASN1()->toDER()); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * |
|
172 | - * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
173 | - * @return BinaryMatch |
|
174 | - */ |
|
175 | - public function equalityMatchingRule(): BinaryMatch |
|
176 | - { |
|
177 | - return new BinaryMatch(); |
|
178 | - } |
|
170 | + /** |
|
171 | + * |
|
172 | + * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
173 | + * @return BinaryMatch |
|
174 | + */ |
|
175 | + public function equalityMatchingRule(): BinaryMatch |
|
176 | + { |
|
177 | + return new BinaryMatch(); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * |
|
182 | - * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function rfc2253String(): string |
|
186 | - { |
|
187 | - return $this->stringValue(); |
|
188 | - } |
|
180 | + /** |
|
181 | + * |
|
182 | + * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function rfc2253String(): string |
|
186 | + { |
|
187 | + return $this->stringValue(); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * |
|
192 | - * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - protected function _transcodedString(): string |
|
196 | - { |
|
197 | - return $this->stringValue(); |
|
198 | - } |
|
190 | + /** |
|
191 | + * |
|
192 | + * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + protected function _transcodedString(): string |
|
196 | + { |
|
197 | + return $this->stringValue(); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Get number of values. |
|
202 | - * |
|
203 | - * @see \Countable::count() |
|
204 | - * @return int |
|
205 | - */ |
|
206 | - public function count(): int |
|
207 | - { |
|
208 | - return count($this->_values); |
|
209 | - } |
|
200 | + /** |
|
201 | + * Get number of values. |
|
202 | + * |
|
203 | + * @see \Countable::count() |
|
204 | + * @return int |
|
205 | + */ |
|
206 | + public function count(): int |
|
207 | + { |
|
208 | + return count($this->_values); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Get iterator for values. |
|
213 | - * |
|
214 | - * @see \IteratorAggregate::getIterator() |
|
215 | - * @return \ArrayIterator |
|
216 | - */ |
|
217 | - public function getIterator(): \ArrayIterator |
|
218 | - { |
|
219 | - return new \ArrayIterator($this->_values); |
|
220 | - } |
|
211 | + /** |
|
212 | + * Get iterator for values. |
|
213 | + * |
|
214 | + * @see \IteratorAggregate::getIterator() |
|
215 | + * @return \ArrayIterator |
|
216 | + */ |
|
217 | + public function getIterator(): \ArrayIterator |
|
218 | + { |
|
219 | + return new \ArrayIterator($this->_values); |
|
220 | + } |
|
221 | 221 | } |
@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class AccessIdentityAttributeValue extends SvceAuthInfo |
13 | 13 | { |
14 | - const OID = "1.3.6.1.5.5.7.10.2"; |
|
14 | + const OID = "1.3.6.1.5.5.7.10.2"; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param GeneralName $service |
|
20 | - * @param GeneralName $ident |
|
21 | - */ |
|
22 | - public function __construct(GeneralName $service, GeneralName $ident) |
|
23 | - { |
|
24 | - parent::__construct($service, $ident, null); |
|
25 | - $this->_oid = self::OID; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param GeneralName $service |
|
20 | + * @param GeneralName $ident |
|
21 | + */ |
|
22 | + public function __construct(GeneralName $service, GeneralName $ident) |
|
23 | + { |
|
24 | + parent::__construct($service, $ident, null); |
|
25 | + $this->_oid = self::OID; |
|
26 | + } |
|
27 | 27 | } |
@@ -9,16 +9,16 @@ |
||
9 | 9 | */ |
10 | 10 | class GroupAttributeValue extends IetfAttrSyntax |
11 | 11 | { |
12 | - const OID = "1.3.6.1.5.5.7.10.4"; |
|
12 | + const OID = "1.3.6.1.5.5.7.10.4"; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Constructor. |
|
16 | - * |
|
17 | - * @param IetfAttrValue ...$values |
|
18 | - */ |
|
19 | - public function __construct(IetfAttrValue ...$values) |
|
20 | - { |
|
21 | - parent::__construct(...$values); |
|
22 | - $this->_oid = self::OID; |
|
23 | - } |
|
14 | + /** |
|
15 | + * Constructor. |
|
16 | + * |
|
17 | + * @param IetfAttrValue ...$values |
|
18 | + */ |
|
19 | + public function __construct(IetfAttrValue ...$values) |
|
20 | + { |
|
21 | + parent::__construct(...$values); |
|
22 | + $this->_oid = self::OID; |
|
23 | + } |
|
24 | 24 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | // is not in the user-initial-policy-set and is not anyPolicy, |
93 | 93 | // delete this node and all its children. |
94 | 94 | $valid_policy_node_set = array_filter($valid_policy_node_set, |
95 | - function (PolicyNode $node) use ($policies) { |
|
95 | + function(PolicyNode $node) use ($policies) { |
|
96 | 96 | if ($node->isAnyPolicy()) { |
97 | 97 | return true; |
98 | 98 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | }); |
105 | 105 | // array of valid policy OIDs |
106 | 106 | $valid_policy_set = array_map( |
107 | - function (PolicyNode $node) { |
|
107 | + function(PolicyNode $node) { |
|
108 | 108 | return $node->validPolicy(); |
109 | 109 | }, $valid_policy_node_set); |
110 | 110 | // 3. If the valid_policy_tree includes a node of depth n with |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | // for each node in a tree |
386 | 386 | $this->_root->walkNodes( |
387 | - function (PolicyNode $node) use (&$set) { |
|
387 | + function(PolicyNode $node) use (&$set) { |
|
388 | 388 | $parents = $node->parents(); |
389 | 389 | // node has parents |
390 | 390 | if (count($parents)) { |
@@ -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 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $paths = $this->_resolvePathsToTarget($target, $intermediate); |
47 | 47 | // map paths to CertificationPath objects |
48 | 48 | return array_map( |
49 | - function ($certs) { |
|
49 | + function($certs) { |
|
50 | 50 | return new CertificationPath(...$certs); |
51 | 51 | }, $paths); |
52 | 52 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | throw new PathBuildingException("No certification paths."); |
112 | 112 | } |
113 | 113 | usort($paths, |
114 | - function ($a, $b) { |
|
114 | + function($a, $b) { |
|
115 | 115 | return count($a) < count($b) ? -1 : 1; |
116 | 116 | }); |
117 | 117 | return reset($paths); |
@@ -16,137 +16,137 @@ |
||
16 | 16 | */ |
17 | 17 | class CertificationPathBuilder |
18 | 18 | { |
19 | - /** |
|
20 | - * Trust anchors. |
|
21 | - * |
|
22 | - * @var CertificateBundle |
|
23 | - */ |
|
24 | - protected $_trustList; |
|
19 | + /** |
|
20 | + * Trust anchors. |
|
21 | + * |
|
22 | + * @var CertificateBundle |
|
23 | + */ |
|
24 | + protected $_trustList; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param CertificateBundle $trust_list List of trust anchors |
|
30 | - */ |
|
31 | - public function __construct(CertificateBundle $trust_list) |
|
32 | - { |
|
33 | - $this->_trustList = $trust_list; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param CertificateBundle $trust_list List of trust anchors |
|
30 | + */ |
|
31 | + public function __construct(CertificateBundle $trust_list) |
|
32 | + { |
|
33 | + $this->_trustList = $trust_list; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get all certification paths to given target certificate from |
|
38 | - * any trust anchor. |
|
39 | - * |
|
40 | - * @param Certificate $target Target certificate |
|
41 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
42 | - * certificates |
|
43 | - * @return CertificationPath[] |
|
44 | - */ |
|
45 | - public function allPathsToTarget(Certificate $target, |
|
46 | - CertificateBundle $intermediate = null): array |
|
47 | - { |
|
48 | - $paths = $this->_resolvePathsToTarget($target, $intermediate); |
|
49 | - // map paths to CertificationPath objects |
|
50 | - return array_map( |
|
51 | - function ($certs) { |
|
52 | - return new CertificationPath(...$certs); |
|
53 | - }, $paths); |
|
54 | - } |
|
36 | + /** |
|
37 | + * Get all certification paths to given target certificate from |
|
38 | + * any trust anchor. |
|
39 | + * |
|
40 | + * @param Certificate $target Target certificate |
|
41 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
42 | + * certificates |
|
43 | + * @return CertificationPath[] |
|
44 | + */ |
|
45 | + public function allPathsToTarget(Certificate $target, |
|
46 | + CertificateBundle $intermediate = null): array |
|
47 | + { |
|
48 | + $paths = $this->_resolvePathsToTarget($target, $intermediate); |
|
49 | + // map paths to CertificationPath objects |
|
50 | + return array_map( |
|
51 | + function ($certs) { |
|
52 | + return new CertificationPath(...$certs); |
|
53 | + }, $paths); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Resolve all possible certification paths from any trust anchor to |
|
58 | - * the target certificate, using optional intermediate certificates. |
|
59 | - * |
|
60 | - * Helper method for allPathsToTarget to be called recursively. |
|
61 | - * |
|
62 | - * @todo Implement loop detection |
|
63 | - * @param Certificate $target |
|
64 | - * @param CertificateBundle $intermediate |
|
65 | - * @return array[] Array of arrays containing path certificates |
|
66 | - */ |
|
67 | - private function _resolvePathsToTarget(Certificate $target, |
|
68 | - CertificateBundle $intermediate = null): array |
|
69 | - { |
|
70 | - // array of possible paths |
|
71 | - $paths = array(); |
|
72 | - // signed by certificate in the trust list |
|
73 | - foreach ($this->_findIssuers($target, $this->_trustList) as $issuer) { |
|
74 | - // if target is self-signed, path consists of only |
|
75 | - // the target certificate |
|
76 | - if ($target->equals($issuer)) { |
|
77 | - $paths[] = array($target); |
|
78 | - } else { |
|
79 | - $paths[] = array($issuer, $target); |
|
80 | - } |
|
81 | - } |
|
82 | - if (isset($intermediate)) { |
|
83 | - // signed by intermediate certificate |
|
84 | - foreach ($this->_findIssuers($target, $intermediate) as $issuer) { |
|
85 | - // intermediate certificate must not be self-signed |
|
86 | - if ($issuer->isSelfIssued()) { |
|
87 | - continue; |
|
88 | - } |
|
89 | - // resolve paths to issuer |
|
90 | - $subpaths = $this->_resolvePathsToTarget($issuer, $intermediate); |
|
91 | - foreach ($subpaths as $path) { |
|
92 | - $paths[] = array_merge($path, array($target)); |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - return $paths; |
|
97 | - } |
|
56 | + /** |
|
57 | + * Resolve all possible certification paths from any trust anchor to |
|
58 | + * the target certificate, using optional intermediate certificates. |
|
59 | + * |
|
60 | + * Helper method for allPathsToTarget to be called recursively. |
|
61 | + * |
|
62 | + * @todo Implement loop detection |
|
63 | + * @param Certificate $target |
|
64 | + * @param CertificateBundle $intermediate |
|
65 | + * @return array[] Array of arrays containing path certificates |
|
66 | + */ |
|
67 | + private function _resolvePathsToTarget(Certificate $target, |
|
68 | + CertificateBundle $intermediate = null): array |
|
69 | + { |
|
70 | + // array of possible paths |
|
71 | + $paths = array(); |
|
72 | + // signed by certificate in the trust list |
|
73 | + foreach ($this->_findIssuers($target, $this->_trustList) as $issuer) { |
|
74 | + // if target is self-signed, path consists of only |
|
75 | + // the target certificate |
|
76 | + if ($target->equals($issuer)) { |
|
77 | + $paths[] = array($target); |
|
78 | + } else { |
|
79 | + $paths[] = array($issuer, $target); |
|
80 | + } |
|
81 | + } |
|
82 | + if (isset($intermediate)) { |
|
83 | + // signed by intermediate certificate |
|
84 | + foreach ($this->_findIssuers($target, $intermediate) as $issuer) { |
|
85 | + // intermediate certificate must not be self-signed |
|
86 | + if ($issuer->isSelfIssued()) { |
|
87 | + continue; |
|
88 | + } |
|
89 | + // resolve paths to issuer |
|
90 | + $subpaths = $this->_resolvePathsToTarget($issuer, $intermediate); |
|
91 | + foreach ($subpaths as $path) { |
|
92 | + $paths[] = array_merge($path, array($target)); |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + return $paths; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get shortest path to given target certificate from any trust anchor. |
|
101 | - * |
|
102 | - * @param Certificate $target Target certificate |
|
103 | - * @param CertificateBundle|null $intermediate Optional intermediate |
|
104 | - * certificates |
|
105 | - * @throws PathBuildingException |
|
106 | - * @return CertificationPath |
|
107 | - */ |
|
108 | - public function shortestPathToTarget(Certificate $target, |
|
109 | - CertificateBundle $intermediate = null): CertificationPath |
|
110 | - { |
|
111 | - $paths = $this->allPathsToTarget($target, $intermediate); |
|
112 | - if (!count($paths)) { |
|
113 | - throw new PathBuildingException("No certification paths."); |
|
114 | - } |
|
115 | - usort($paths, |
|
116 | - function ($a, $b) { |
|
117 | - return count($a) < count($b) ? -1 : 1; |
|
118 | - }); |
|
119 | - return reset($paths); |
|
120 | - } |
|
99 | + /** |
|
100 | + * Get shortest path to given target certificate from any trust anchor. |
|
101 | + * |
|
102 | + * @param Certificate $target Target certificate |
|
103 | + * @param CertificateBundle|null $intermediate Optional intermediate |
|
104 | + * certificates |
|
105 | + * @throws PathBuildingException |
|
106 | + * @return CertificationPath |
|
107 | + */ |
|
108 | + public function shortestPathToTarget(Certificate $target, |
|
109 | + CertificateBundle $intermediate = null): CertificationPath |
|
110 | + { |
|
111 | + $paths = $this->allPathsToTarget($target, $intermediate); |
|
112 | + if (!count($paths)) { |
|
113 | + throw new PathBuildingException("No certification paths."); |
|
114 | + } |
|
115 | + usort($paths, |
|
116 | + function ($a, $b) { |
|
117 | + return count($a) < count($b) ? -1 : 1; |
|
118 | + }); |
|
119 | + return reset($paths); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Find all issuers of the target certificate from a given bundle. |
|
124 | - * |
|
125 | - * @param Certificate $target Target certificate |
|
126 | - * @param CertificateBundle $bundle Certificates to search |
|
127 | - * @return Certificate[] |
|
128 | - */ |
|
129 | - protected function _findIssuers(Certificate $target, |
|
130 | - CertificateBundle $bundle): array |
|
131 | - { |
|
132 | - $issuers = array(); |
|
133 | - $issuer_name = $target->tbsCertificate()->issuer(); |
|
134 | - $extensions = $target->tbsCertificate()->extensions(); |
|
135 | - // find by authority key identifier |
|
136 | - if ($extensions->hasAuthorityKeyIdentifier()) { |
|
137 | - $ext = $extensions->authorityKeyIdentifier(); |
|
138 | - if ($ext->hasKeyIdentifier()) { |
|
139 | - foreach ($bundle->allBySubjectKeyIdentifier( |
|
140 | - $ext->keyIdentifier()) as $issuer) { |
|
141 | - // check that issuer name matches |
|
142 | - if ($issuer->tbsCertificate() |
|
143 | - ->subject() |
|
144 | - ->equals($issuer_name)) { |
|
145 | - $issuers[] = $issuer; |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - return $issuers; |
|
151 | - } |
|
122 | + /** |
|
123 | + * Find all issuers of the target certificate from a given bundle. |
|
124 | + * |
|
125 | + * @param Certificate $target Target certificate |
|
126 | + * @param CertificateBundle $bundle Certificates to search |
|
127 | + * @return Certificate[] |
|
128 | + */ |
|
129 | + protected function _findIssuers(Certificate $target, |
|
130 | + CertificateBundle $bundle): array |
|
131 | + { |
|
132 | + $issuers = array(); |
|
133 | + $issuer_name = $target->tbsCertificate()->issuer(); |
|
134 | + $extensions = $target->tbsCertificate()->extensions(); |
|
135 | + // find by authority key identifier |
|
136 | + if ($extensions->hasAuthorityKeyIdentifier()) { |
|
137 | + $ext = $extensions->authorityKeyIdentifier(); |
|
138 | + if ($ext->hasKeyIdentifier()) { |
|
139 | + foreach ($bundle->allBySubjectKeyIdentifier( |
|
140 | + $ext->keyIdentifier()) as $issuer) { |
|
141 | + // check that issuer name matches |
|
142 | + if ($issuer->tbsCertificate() |
|
143 | + ->subject() |
|
144 | + ->equals($issuer_name)) { |
|
145 | + $issuers[] = $issuer; |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + return $issuers; |
|
151 | + } |
|
152 | 152 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | // load RSA private key from PEM |
22 | 22 | $private_key_info = PrivateKeyInfo::fromPEM( |
23 | - PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
23 | + PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
24 | 24 | // extract public key from private key |
25 | 25 | $public_key_info = $private_key_info->publicKeyInfo(); |
26 | 26 | // DN of the certification authority |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | // create "to be signed" certificate object with extensions |
31 | 31 | $tbs_cert = new TBSCertificate($name, $public_key_info, $name, $validity); |
32 | 32 | $tbs_cert = $tbs_cert->withRandomSerialNumber()->withAdditionalExtensions( |
33 | - new BasicConstraintsExtension(true, true), |
|
34 | - new SubjectKeyIdentifierExtension(false, $public_key_info->keyIdentifier()), |
|
35 | - new KeyUsageExtension(true, |
|
36 | - KeyUsageExtension::DIGITAL_SIGNATURE | KeyUsageExtension::KEY_CERT_SIGN)); |
|
33 | + new BasicConstraintsExtension(true, true), |
|
34 | + new SubjectKeyIdentifierExtension(false, $public_key_info->keyIdentifier()), |
|
35 | + new KeyUsageExtension(true, |
|
36 | + KeyUsageExtension::DIGITAL_SIGNATURE | KeyUsageExtension::KEY_CERT_SIGN)); |
|
37 | 37 | // sign certificate with private key |
38 | 38 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
39 | - $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
39 | + $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
40 | 40 | $cert = $tbs_cert->sign($algo, $private_key_info); |
41 | 41 | echo $cert; |
@@ -25,27 +25,27 @@ |
||
25 | 25 | $csr = CertificationRequest::fromPEM(PEM::fromFile($argv[2])); |
26 | 26 | // verify CSR |
27 | 27 | if (!$csr->verify()) { |
28 | - echo "Failed to verify certification request signature.\n"; |
|
29 | - exit(1); |
|
28 | + echo "Failed to verify certification request signature.\n"; |
|
29 | + exit(1); |
|
30 | 30 | } |
31 | 31 | // load CA's private key from PEM |
32 | 32 | $private_key_info = PrivateKeyInfo::fromPEM( |
33 | - PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
33 | + PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
34 | 34 | // initialize certificate from CSR and issuer's certificate |
35 | 35 | $tbs_cert = TBSCertificate::fromCSR($csr)->withIssuerCertificate($issuer_cert); |
36 | 36 | // set random serial number |
37 | 37 | $tbs_cert = $tbs_cert->withRandomSerialNumber(); |
38 | 38 | // set validity period |
39 | 39 | $tbs_cert = $tbs_cert->withValidity( |
40 | - Validity::fromStrings("now", "now + 3 months")); |
|
40 | + Validity::fromStrings("now", "now + 3 months")); |
|
41 | 41 | // add extensions |
42 | 42 | $tbs_cert = $tbs_cert->withAdditionalExtensions( |
43 | - new KeyUsageExtension(true, |
|
44 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
45 | - KeyUsageExtension::KEY_ENCIPHERMENT), |
|
46 | - new BasicConstraintsExtension(true, false)); |
|
43 | + new KeyUsageExtension(true, |
|
44 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
45 | + KeyUsageExtension::KEY_ENCIPHERMENT), |
|
46 | + new BasicConstraintsExtension(true, false)); |
|
47 | 47 | // sign certificate with issuer's private key |
48 | 48 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
49 | - $private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier()); |
|
49 | + $private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier()); |
|
50 | 50 | $cert = $tbs_cert->sign($algo, $private_key_info); |
51 | 51 | echo $cert; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | // load EC private key from PEM |
18 | 18 | $private_key_info = PrivateKeyInfo::fromPEM( |
19 | - PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem")); |
|
19 | + PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem")); |
|
20 | 20 | // extract public key from private key |
21 | 21 | $public_key_info = $private_key_info->publicKeyInfo(); |
22 | 22 | // DN of the subject |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | $cri = new CertificationRequestInfo($subject, $public_key_info); |
26 | 26 | // sign certificate request with private key |
27 | 27 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
28 | - $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
28 | + $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
29 | 29 | $csr = $cri->sign($algo, $private_key_info); |
30 | 30 | echo $csr; |