@@ -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 | } |
@@ -17,161 +17,161 @@ |
||
17 | 17 | */ |
18 | 18 | class IetfAttrValue |
19 | 19 | { |
20 | - /** |
|
21 | - * Element type tag. |
|
22 | - * |
|
23 | - * @var int $_type |
|
24 | - */ |
|
25 | - protected $_type; |
|
20 | + /** |
|
21 | + * Element type tag. |
|
22 | + * |
|
23 | + * @var int $_type |
|
24 | + */ |
|
25 | + protected $_type; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Value. |
|
29 | - * |
|
30 | - * @var string $_value |
|
31 | - */ |
|
32 | - protected $_value; |
|
27 | + /** |
|
28 | + * Value. |
|
29 | + * |
|
30 | + * @var string $_value |
|
31 | + */ |
|
32 | + protected $_value; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor. |
|
36 | - * |
|
37 | - * @param string $value |
|
38 | - * @param int $type |
|
39 | - */ |
|
40 | - public function __construct(string $value, int $type) |
|
41 | - { |
|
42 | - $this->_type = $type; |
|
43 | - $this->_value = $value; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Constructor. |
|
36 | + * |
|
37 | + * @param string $value |
|
38 | + * @param int $type |
|
39 | + */ |
|
40 | + public function __construct(string $value, int $type) |
|
41 | + { |
|
42 | + $this->_type = $type; |
|
43 | + $this->_value = $value; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Initialize from ASN.1. |
|
48 | - * |
|
49 | - * @param UnspecifiedType $el |
|
50 | - * @throws \UnexpectedValueException |
|
51 | - * @return self |
|
52 | - */ |
|
53 | - public static function fromASN1(UnspecifiedType $el): self |
|
54 | - { |
|
55 | - switch ($el->tag()) { |
|
56 | - case Element::TYPE_OCTET_STRING: |
|
57 | - case Element::TYPE_UTF8_STRING: |
|
58 | - return new self($el->asString()->string(), $el->tag()); |
|
59 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
60 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
61 | - } |
|
62 | - throw new \UnexpectedValueException( |
|
63 | - "Type " . Element::tagToName($el->tag()) . " not supported."); |
|
64 | - } |
|
46 | + /** |
|
47 | + * Initialize from ASN.1. |
|
48 | + * |
|
49 | + * @param UnspecifiedType $el |
|
50 | + * @throws \UnexpectedValueException |
|
51 | + * @return self |
|
52 | + */ |
|
53 | + public static function fromASN1(UnspecifiedType $el): self |
|
54 | + { |
|
55 | + switch ($el->tag()) { |
|
56 | + case Element::TYPE_OCTET_STRING: |
|
57 | + case Element::TYPE_UTF8_STRING: |
|
58 | + return new self($el->asString()->string(), $el->tag()); |
|
59 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
60 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
61 | + } |
|
62 | + throw new \UnexpectedValueException( |
|
63 | + "Type " . Element::tagToName($el->tag()) . " not supported."); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Initialize from octet string. |
|
68 | - * |
|
69 | - * @param string $octets |
|
70 | - * @return self |
|
71 | - */ |
|
72 | - public static function fromOctets(string $octets): self |
|
73 | - { |
|
74 | - return new self($octets, Element::TYPE_OCTET_STRING); |
|
75 | - } |
|
66 | + /** |
|
67 | + * Initialize from octet string. |
|
68 | + * |
|
69 | + * @param string $octets |
|
70 | + * @return self |
|
71 | + */ |
|
72 | + public static function fromOctets(string $octets): self |
|
73 | + { |
|
74 | + return new self($octets, Element::TYPE_OCTET_STRING); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Initialize from UTF-8 string. |
|
79 | - * |
|
80 | - * @param string $str |
|
81 | - * @return self |
|
82 | - */ |
|
83 | - public static function fromString(string $str): self |
|
84 | - { |
|
85 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
86 | - } |
|
77 | + /** |
|
78 | + * Initialize from UTF-8 string. |
|
79 | + * |
|
80 | + * @param string $str |
|
81 | + * @return self |
|
82 | + */ |
|
83 | + public static function fromString(string $str): self |
|
84 | + { |
|
85 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Initialize from OID. |
|
90 | - * |
|
91 | - * @param string $oid |
|
92 | - * @return self |
|
93 | - */ |
|
94 | - public static function fromOID(string $oid): self |
|
95 | - { |
|
96 | - return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
97 | - } |
|
88 | + /** |
|
89 | + * Initialize from OID. |
|
90 | + * |
|
91 | + * @param string $oid |
|
92 | + * @return self |
|
93 | + */ |
|
94 | + public static function fromOID(string $oid): self |
|
95 | + { |
|
96 | + return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get type tag. |
|
101 | - * |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function type(): int |
|
105 | - { |
|
106 | - return $this->_type; |
|
107 | - } |
|
99 | + /** |
|
100 | + * Get type tag. |
|
101 | + * |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function type(): int |
|
105 | + { |
|
106 | + return $this->_type; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Whether value type is octets. |
|
111 | - * |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - public function isOctets(): bool |
|
115 | - { |
|
116 | - return $this->_type === Element::TYPE_OCTET_STRING; |
|
117 | - } |
|
109 | + /** |
|
110 | + * Whether value type is octets. |
|
111 | + * |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + public function isOctets(): bool |
|
115 | + { |
|
116 | + return $this->_type === Element::TYPE_OCTET_STRING; |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Whether value type is OID. |
|
121 | - * |
|
122 | - * @return bool |
|
123 | - */ |
|
124 | - public function isOID(): bool |
|
125 | - { |
|
126 | - return $this->_type === Element::TYPE_OBJECT_IDENTIFIER; |
|
127 | - } |
|
119 | + /** |
|
120 | + * Whether value type is OID. |
|
121 | + * |
|
122 | + * @return bool |
|
123 | + */ |
|
124 | + public function isOID(): bool |
|
125 | + { |
|
126 | + return $this->_type === Element::TYPE_OBJECT_IDENTIFIER; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Whether value type is string. |
|
131 | - * |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function isString(): bool |
|
135 | - { |
|
136 | - return $this->_type === Element::TYPE_UTF8_STRING; |
|
137 | - } |
|
129 | + /** |
|
130 | + * Whether value type is string. |
|
131 | + * |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function isString(): bool |
|
135 | + { |
|
136 | + return $this->_type === Element::TYPE_UTF8_STRING; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Get value. |
|
141 | - * |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function value(): string |
|
145 | - { |
|
146 | - return $this->_value; |
|
147 | - } |
|
139 | + /** |
|
140 | + * Get value. |
|
141 | + * |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function value(): string |
|
145 | + { |
|
146 | + return $this->_value; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Generate ASN.1 structure. |
|
151 | - * |
|
152 | - * @throws \LogicException |
|
153 | - * @return Element |
|
154 | - */ |
|
155 | - public function toASN1(): Element |
|
156 | - { |
|
157 | - switch ($this->_type) { |
|
158 | - case Element::TYPE_OCTET_STRING: |
|
159 | - return new OctetString($this->_value); |
|
160 | - case Element::TYPE_UTF8_STRING: |
|
161 | - return new UTF8String($this->_value); |
|
162 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
163 | - return new ObjectIdentifier($this->_value); |
|
164 | - } |
|
165 | - throw new \LogicException( |
|
166 | - "Type " . Element::tagToName($this->_type) . " not supported."); |
|
167 | - } |
|
149 | + /** |
|
150 | + * Generate ASN.1 structure. |
|
151 | + * |
|
152 | + * @throws \LogicException |
|
153 | + * @return Element |
|
154 | + */ |
|
155 | + public function toASN1(): Element |
|
156 | + { |
|
157 | + switch ($this->_type) { |
|
158 | + case Element::TYPE_OCTET_STRING: |
|
159 | + return new OctetString($this->_value); |
|
160 | + case Element::TYPE_UTF8_STRING: |
|
161 | + return new UTF8String($this->_value); |
|
162 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
163 | + return new ObjectIdentifier($this->_value); |
|
164 | + } |
|
165 | + throw new \LogicException( |
|
166 | + "Type " . Element::tagToName($this->_type) . " not supported."); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function __toString() |
|
174 | - { |
|
175 | - return $this->_value; |
|
176 | - } |
|
169 | + /** |
|
170 | + * |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function __toString() |
|
174 | + { |
|
175 | + return $this->_value; |
|
176 | + } |
|
177 | 177 | } |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | public static function fromASN1(UnspecifiedType $el): self |
54 | 54 | { |
55 | 55 | switch ($el->tag()) { |
56 | - case Element::TYPE_OCTET_STRING: |
|
57 | - case Element::TYPE_UTF8_STRING: |
|
58 | - return new self($el->asString()->string(), $el->tag()); |
|
59 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
60 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
56 | + case Element::TYPE_OCTET_STRING: |
|
57 | + case Element::TYPE_UTF8_STRING: |
|
58 | + return new self($el->asString()->string(), $el->tag()); |
|
59 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
60 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
61 | 61 | } |
62 | 62 | throw new \UnexpectedValueException( |
63 | 63 | "Type " . Element::tagToName($el->tag()) . " not supported."); |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | public function toASN1(): Element |
156 | 156 | { |
157 | 157 | switch ($this->_type) { |
158 | - case Element::TYPE_OCTET_STRING: |
|
159 | - return new OctetString($this->_value); |
|
160 | - case Element::TYPE_UTF8_STRING: |
|
161 | - return new UTF8String($this->_value); |
|
162 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
163 | - return new ObjectIdentifier($this->_value); |
|
158 | + case Element::TYPE_OCTET_STRING: |
|
159 | + return new OctetString($this->_value); |
|
160 | + case Element::TYPE_UTF8_STRING: |
|
161 | + return new UTF8String($this->_value); |
|
162 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
163 | + return new ObjectIdentifier($this->_value); |
|
164 | 164 | } |
165 | 165 | throw new \LogicException( |
166 | 166 | "Type " . Element::tagToName($this->_type) . " not supported."); |
@@ -19,281 +19,281 @@ |
||
19 | 19 | */ |
20 | 20 | class Holder |
21 | 21 | { |
22 | - /** |
|
23 | - * Holder PKC's issuer and serial. |
|
24 | - * |
|
25 | - * @var IssuerSerial|null $_baseCertificateID |
|
26 | - */ |
|
27 | - protected $_baseCertificateID; |
|
22 | + /** |
|
23 | + * Holder PKC's issuer and serial. |
|
24 | + * |
|
25 | + * @var IssuerSerial|null $_baseCertificateID |
|
26 | + */ |
|
27 | + protected $_baseCertificateID; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Holder PKC's subject. |
|
31 | - * |
|
32 | - * @var GeneralNames|null $_entityName |
|
33 | - */ |
|
34 | - protected $_entityName; |
|
29 | + /** |
|
30 | + * Holder PKC's subject. |
|
31 | + * |
|
32 | + * @var GeneralNames|null $_entityName |
|
33 | + */ |
|
34 | + protected $_entityName; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Linked object. |
|
38 | - * |
|
39 | - * @var ObjectDigestInfo|null $_objectDigestInfo |
|
40 | - */ |
|
41 | - protected $_objectDigestInfo; |
|
36 | + /** |
|
37 | + * Linked object. |
|
38 | + * |
|
39 | + * @var ObjectDigestInfo|null $_objectDigestInfo |
|
40 | + */ |
|
41 | + protected $_objectDigestInfo; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param IssuerSerial|null $issuer_serial |
|
47 | - * @param GeneralNames|null $entity_name |
|
48 | - */ |
|
49 | - public function __construct(IssuerSerial $issuer_serial = null, |
|
50 | - GeneralNames $entity_name = null) |
|
51 | - { |
|
52 | - $this->_baseCertificateID = $issuer_serial; |
|
53 | - $this->_entityName = $entity_name; |
|
54 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param IssuerSerial|null $issuer_serial |
|
47 | + * @param GeneralNames|null $entity_name |
|
48 | + */ |
|
49 | + public function __construct(IssuerSerial $issuer_serial = null, |
|
50 | + GeneralNames $entity_name = null) |
|
51 | + { |
|
52 | + $this->_baseCertificateID = $issuer_serial; |
|
53 | + $this->_entityName = $entity_name; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Initialize from a holder's public key certificate. |
|
58 | - * |
|
59 | - * @param Certificate $cert |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - public static function fromPKC(Certificate $cert): self |
|
63 | - { |
|
64 | - return new self(IssuerSerial::fromPKC($cert)); |
|
65 | - } |
|
56 | + /** |
|
57 | + * Initialize from a holder's public key certificate. |
|
58 | + * |
|
59 | + * @param Certificate $cert |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + public static function fromPKC(Certificate $cert): self |
|
63 | + { |
|
64 | + return new self(IssuerSerial::fromPKC($cert)); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Initialize from ASN.1. |
|
69 | - * |
|
70 | - * @param Sequence $seq |
|
71 | - */ |
|
72 | - public static function fromASN1(Sequence $seq): self |
|
73 | - { |
|
74 | - $cert_id = null; |
|
75 | - $entity_name = null; |
|
76 | - $digest_info = null; |
|
77 | - if ($seq->hasTagged(0)) { |
|
78 | - $cert_id = IssuerSerial::fromASN1( |
|
79 | - $seq->getTagged(0) |
|
80 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
81 | - ->asSequence()); |
|
82 | - } |
|
83 | - if ($seq->hasTagged(1)) { |
|
84 | - $entity_name = GeneralNames::fromASN1( |
|
85 | - $seq->getTagged(1) |
|
86 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
87 | - ->asSequence()); |
|
88 | - } |
|
89 | - if ($seq->hasTagged(2)) { |
|
90 | - $digest_info = ObjectDigestInfo::fromASN1( |
|
91 | - $seq->getTagged(2) |
|
92 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
93 | - ->asSequence()); |
|
94 | - } |
|
95 | - $obj = new self($cert_id, $entity_name); |
|
96 | - $obj->_objectDigestInfo = $digest_info; |
|
97 | - return $obj; |
|
98 | - } |
|
67 | + /** |
|
68 | + * Initialize from ASN.1. |
|
69 | + * |
|
70 | + * @param Sequence $seq |
|
71 | + */ |
|
72 | + public static function fromASN1(Sequence $seq): self |
|
73 | + { |
|
74 | + $cert_id = null; |
|
75 | + $entity_name = null; |
|
76 | + $digest_info = null; |
|
77 | + if ($seq->hasTagged(0)) { |
|
78 | + $cert_id = IssuerSerial::fromASN1( |
|
79 | + $seq->getTagged(0) |
|
80 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
81 | + ->asSequence()); |
|
82 | + } |
|
83 | + if ($seq->hasTagged(1)) { |
|
84 | + $entity_name = GeneralNames::fromASN1( |
|
85 | + $seq->getTagged(1) |
|
86 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
87 | + ->asSequence()); |
|
88 | + } |
|
89 | + if ($seq->hasTagged(2)) { |
|
90 | + $digest_info = ObjectDigestInfo::fromASN1( |
|
91 | + $seq->getTagged(2) |
|
92 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
93 | + ->asSequence()); |
|
94 | + } |
|
95 | + $obj = new self($cert_id, $entity_name); |
|
96 | + $obj->_objectDigestInfo = $digest_info; |
|
97 | + return $obj; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Get self with base certificate ID. |
|
102 | - * |
|
103 | - * @param IssuerSerial $issuer |
|
104 | - * @return self |
|
105 | - */ |
|
106 | - public function withBaseCertificateID(IssuerSerial $issuer): self |
|
107 | - { |
|
108 | - $obj = clone $this; |
|
109 | - $obj->_baseCertificateID = $issuer; |
|
110 | - return $obj; |
|
111 | - } |
|
100 | + /** |
|
101 | + * Get self with base certificate ID. |
|
102 | + * |
|
103 | + * @param IssuerSerial $issuer |
|
104 | + * @return self |
|
105 | + */ |
|
106 | + public function withBaseCertificateID(IssuerSerial $issuer): self |
|
107 | + { |
|
108 | + $obj = clone $this; |
|
109 | + $obj->_baseCertificateID = $issuer; |
|
110 | + return $obj; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get self with entity name. |
|
115 | - * |
|
116 | - * @param GeneralNames $names |
|
117 | - * @return self |
|
118 | - */ |
|
119 | - public function withEntityName(GeneralNames $names): self |
|
120 | - { |
|
121 | - $obj = clone $this; |
|
122 | - $obj->_entityName = $names; |
|
123 | - return $obj; |
|
124 | - } |
|
113 | + /** |
|
114 | + * Get self with entity name. |
|
115 | + * |
|
116 | + * @param GeneralNames $names |
|
117 | + * @return self |
|
118 | + */ |
|
119 | + public function withEntityName(GeneralNames $names): self |
|
120 | + { |
|
121 | + $obj = clone $this; |
|
122 | + $obj->_entityName = $names; |
|
123 | + return $obj; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Get self with object digest info. |
|
128 | - * |
|
129 | - * @param ObjectDigestInfo $odi |
|
130 | - * @return self |
|
131 | - */ |
|
132 | - public function withObjectDigestInfo(ObjectDigestInfo $odi): self |
|
133 | - { |
|
134 | - $obj = clone $this; |
|
135 | - $obj->_objectDigestInfo = $odi; |
|
136 | - return $obj; |
|
137 | - } |
|
126 | + /** |
|
127 | + * Get self with object digest info. |
|
128 | + * |
|
129 | + * @param ObjectDigestInfo $odi |
|
130 | + * @return self |
|
131 | + */ |
|
132 | + public function withObjectDigestInfo(ObjectDigestInfo $odi): self |
|
133 | + { |
|
134 | + $obj = clone $this; |
|
135 | + $obj->_objectDigestInfo = $odi; |
|
136 | + return $obj; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Check whether base certificate ID is present. |
|
141 | - * |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - public function hasBaseCertificateID(): bool |
|
145 | - { |
|
146 | - return isset($this->_baseCertificateID); |
|
147 | - } |
|
139 | + /** |
|
140 | + * Check whether base certificate ID is present. |
|
141 | + * |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + public function hasBaseCertificateID(): bool |
|
145 | + { |
|
146 | + return isset($this->_baseCertificateID); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Get base certificate ID. |
|
151 | - * |
|
152 | - * @throws \LogicException |
|
153 | - * @return IssuerSerial |
|
154 | - */ |
|
155 | - public function baseCertificateID(): IssuerSerial |
|
156 | - { |
|
157 | - if (!$this->hasBaseCertificateID()) { |
|
158 | - throw new \LogicException("baseCertificateID not set."); |
|
159 | - } |
|
160 | - return $this->_baseCertificateID; |
|
161 | - } |
|
149 | + /** |
|
150 | + * Get base certificate ID. |
|
151 | + * |
|
152 | + * @throws \LogicException |
|
153 | + * @return IssuerSerial |
|
154 | + */ |
|
155 | + public function baseCertificateID(): IssuerSerial |
|
156 | + { |
|
157 | + if (!$this->hasBaseCertificateID()) { |
|
158 | + throw new \LogicException("baseCertificateID not set."); |
|
159 | + } |
|
160 | + return $this->_baseCertificateID; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Check whether entity name is present. |
|
165 | - * |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function hasEntityName(): bool |
|
169 | - { |
|
170 | - return isset($this->_entityName); |
|
171 | - } |
|
163 | + /** |
|
164 | + * Check whether entity name is present. |
|
165 | + * |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function hasEntityName(): bool |
|
169 | + { |
|
170 | + return isset($this->_entityName); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Get entity name. |
|
175 | - * |
|
176 | - * @throws \LogicException |
|
177 | - * @return GeneralNames |
|
178 | - */ |
|
179 | - public function entityName(): GeneralNames |
|
180 | - { |
|
181 | - if (!$this->hasEntityName()) { |
|
182 | - throw new \LogicException("entityName not set."); |
|
183 | - } |
|
184 | - return $this->_entityName; |
|
185 | - } |
|
173 | + /** |
|
174 | + * Get entity name. |
|
175 | + * |
|
176 | + * @throws \LogicException |
|
177 | + * @return GeneralNames |
|
178 | + */ |
|
179 | + public function entityName(): GeneralNames |
|
180 | + { |
|
181 | + if (!$this->hasEntityName()) { |
|
182 | + throw new \LogicException("entityName not set."); |
|
183 | + } |
|
184 | + return $this->_entityName; |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Check whether object digest info is present. |
|
189 | - * |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - public function hasObjectDigestInfo(): bool |
|
193 | - { |
|
194 | - return isset($this->_objectDigestInfo); |
|
195 | - } |
|
187 | + /** |
|
188 | + * Check whether object digest info is present. |
|
189 | + * |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + public function hasObjectDigestInfo(): bool |
|
193 | + { |
|
194 | + return isset($this->_objectDigestInfo); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Get object digest info. |
|
199 | - * |
|
200 | - * @throws \LogicException |
|
201 | - * @return ObjectDigestInfo |
|
202 | - */ |
|
203 | - public function objectDigestInfo(): ObjectDigestInfo |
|
204 | - { |
|
205 | - if (!$this->hasObjectDigestInfo()) { |
|
206 | - throw new \LogicException("objectDigestInfo not set."); |
|
207 | - } |
|
208 | - return $this->_objectDigestInfo; |
|
209 | - } |
|
197 | + /** |
|
198 | + * Get object digest info. |
|
199 | + * |
|
200 | + * @throws \LogicException |
|
201 | + * @return ObjectDigestInfo |
|
202 | + */ |
|
203 | + public function objectDigestInfo(): ObjectDigestInfo |
|
204 | + { |
|
205 | + if (!$this->hasObjectDigestInfo()) { |
|
206 | + throw new \LogicException("objectDigestInfo not set."); |
|
207 | + } |
|
208 | + return $this->_objectDigestInfo; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Generate ASN.1 structure. |
|
213 | - * |
|
214 | - * @return Sequence |
|
215 | - */ |
|
216 | - public function toASN1(): Sequence |
|
217 | - { |
|
218 | - $elements = []; |
|
219 | - if (isset($this->_baseCertificateID)) { |
|
220 | - $elements[] = new ImplicitlyTaggedType(0, |
|
221 | - $this->_baseCertificateID->toASN1()); |
|
222 | - } |
|
223 | - if (isset($this->_entityName)) { |
|
224 | - $elements[] = new ImplicitlyTaggedType(1, |
|
225 | - $this->_entityName->toASN1()); |
|
226 | - } |
|
227 | - if (isset($this->_objectDigestInfo)) { |
|
228 | - $elements[] = new ImplicitlyTaggedType(2, |
|
229 | - $this->_objectDigestInfo->toASN1()); |
|
230 | - } |
|
231 | - return new Sequence(...$elements); |
|
232 | - } |
|
211 | + /** |
|
212 | + * Generate ASN.1 structure. |
|
213 | + * |
|
214 | + * @return Sequence |
|
215 | + */ |
|
216 | + public function toASN1(): Sequence |
|
217 | + { |
|
218 | + $elements = []; |
|
219 | + if (isset($this->_baseCertificateID)) { |
|
220 | + $elements[] = new ImplicitlyTaggedType(0, |
|
221 | + $this->_baseCertificateID->toASN1()); |
|
222 | + } |
|
223 | + if (isset($this->_entityName)) { |
|
224 | + $elements[] = new ImplicitlyTaggedType(1, |
|
225 | + $this->_entityName->toASN1()); |
|
226 | + } |
|
227 | + if (isset($this->_objectDigestInfo)) { |
|
228 | + $elements[] = new ImplicitlyTaggedType(2, |
|
229 | + $this->_objectDigestInfo->toASN1()); |
|
230 | + } |
|
231 | + return new Sequence(...$elements); |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * Check whether Holder identifies given certificate. |
|
236 | - * |
|
237 | - * @param Certificate $cert |
|
238 | - * @return boolean |
|
239 | - */ |
|
240 | - public function identifiesPKC(Certificate $cert): bool |
|
241 | - { |
|
242 | - // if neither baseCertificateID nor entityName are present |
|
243 | - if (!$this->_baseCertificateID && !$this->_entityName) { |
|
244 | - return false; |
|
245 | - } |
|
246 | - // if baseCertificateID is present, but doesn't match |
|
247 | - if ($this->_baseCertificateID && |
|
248 | - !$this->_baseCertificateID->identifiesPKC($cert)) { |
|
249 | - return false; |
|
250 | - } |
|
251 | - // if entityName is present, but doesn't match |
|
252 | - if ($this->_entityName && !$this->_checkEntityName($cert)) { |
|
253 | - return false; |
|
254 | - } |
|
255 | - return true; |
|
256 | - } |
|
234 | + /** |
|
235 | + * Check whether Holder identifies given certificate. |
|
236 | + * |
|
237 | + * @param Certificate $cert |
|
238 | + * @return boolean |
|
239 | + */ |
|
240 | + public function identifiesPKC(Certificate $cert): bool |
|
241 | + { |
|
242 | + // if neither baseCertificateID nor entityName are present |
|
243 | + if (!$this->_baseCertificateID && !$this->_entityName) { |
|
244 | + return false; |
|
245 | + } |
|
246 | + // if baseCertificateID is present, but doesn't match |
|
247 | + if ($this->_baseCertificateID && |
|
248 | + !$this->_baseCertificateID->identifiesPKC($cert)) { |
|
249 | + return false; |
|
250 | + } |
|
251 | + // if entityName is present, but doesn't match |
|
252 | + if ($this->_entityName && !$this->_checkEntityName($cert)) { |
|
253 | + return false; |
|
254 | + } |
|
255 | + return true; |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Check whether entityName matches the given certificate. |
|
260 | - * |
|
261 | - * @param Certificate $cert |
|
262 | - * @return boolean |
|
263 | - */ |
|
264 | - private function _checkEntityName(Certificate $cert): bool |
|
265 | - { |
|
266 | - $name = $this->_entityName->firstDN(); |
|
267 | - if ($cert->tbsCertificate() |
|
268 | - ->subject() |
|
269 | - ->equals($name)) { |
|
270 | - return true; |
|
271 | - } |
|
272 | - $exts = $cert->tbsCertificate()->extensions(); |
|
273 | - if ($exts->hasSubjectAlternativeName()) { |
|
274 | - $ext = $exts->subjectAlternativeName(); |
|
275 | - if ($this->_checkEntityAlternativeNames($ext->names())) { |
|
276 | - return true; |
|
277 | - } |
|
278 | - } |
|
279 | - return false; |
|
280 | - } |
|
258 | + /** |
|
259 | + * Check whether entityName matches the given certificate. |
|
260 | + * |
|
261 | + * @param Certificate $cert |
|
262 | + * @return boolean |
|
263 | + */ |
|
264 | + private function _checkEntityName(Certificate $cert): bool |
|
265 | + { |
|
266 | + $name = $this->_entityName->firstDN(); |
|
267 | + if ($cert->tbsCertificate() |
|
268 | + ->subject() |
|
269 | + ->equals($name)) { |
|
270 | + return true; |
|
271 | + } |
|
272 | + $exts = $cert->tbsCertificate()->extensions(); |
|
273 | + if ($exts->hasSubjectAlternativeName()) { |
|
274 | + $ext = $exts->subjectAlternativeName(); |
|
275 | + if ($this->_checkEntityAlternativeNames($ext->names())) { |
|
276 | + return true; |
|
277 | + } |
|
278 | + } |
|
279 | + return false; |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Check whether any of the subject alternative names match entityName. |
|
284 | - * |
|
285 | - * @param GeneralNames $san |
|
286 | - * @return boolean |
|
287 | - */ |
|
288 | - private function _checkEntityAlternativeNames(GeneralNames $san): bool |
|
289 | - { |
|
290 | - // only directory names supported for now |
|
291 | - $name = $this->_entityName->firstDN(); |
|
292 | - foreach ($san->allOf(GeneralName::TAG_DIRECTORY_NAME) as $dn) { |
|
293 | - if ($dn instanceof DirectoryName && $dn->dn()->equals($name)) { |
|
294 | - return true; |
|
295 | - } |
|
296 | - } |
|
297 | - return false; |
|
298 | - } |
|
282 | + /** |
|
283 | + * Check whether any of the subject alternative names match entityName. |
|
284 | + * |
|
285 | + * @param GeneralNames $san |
|
286 | + * @return boolean |
|
287 | + */ |
|
288 | + private function _checkEntityAlternativeNames(GeneralNames $san): bool |
|
289 | + { |
|
290 | + // only directory names supported for now |
|
291 | + $name = $this->_entityName->firstDN(); |
|
292 | + foreach ($san->allOf(GeneralName::TAG_DIRECTORY_NAME) as $dn) { |
|
293 | + if ($dn instanceof DirectoryName && $dn->dn()->equals($name)) { |
|
294 | + return true; |
|
295 | + } |
|
296 | + } |
|
297 | + return false; |
|
298 | + } |
|
299 | 299 | } |
@@ -26,200 +26,200 @@ |
||
26 | 26 | */ |
27 | 27 | class Attributes implements \Countable, \IteratorAggregate |
28 | 28 | { |
29 | - use AttributeContainer; |
|
30 | - |
|
31 | - /** |
|
32 | - * Mapping from OID to attribute value class name. |
|
33 | - * |
|
34 | - * @internal |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - const MAP_OID_TO_CLASS = array( |
|
39 | - /* @formatter:off */ |
|
40 | - AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
41 | - AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
42 | - ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
43 | - GroupAttributeValue::OID => GroupAttributeValue::class, |
|
44 | - AttributeType::OID_ROLE => RoleAttributeValue::class |
|
45 | - /* @formatter:on */ |
|
46 | - ); |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor. |
|
50 | - * |
|
51 | - * @param Attribute[] $attribs |
|
52 | - */ |
|
53 | - public function __construct(Attribute ...$attribs) |
|
54 | - { |
|
55 | - $this->_attributes = $attribs; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Initialize from attribute values. |
|
60 | - * |
|
61 | - * @param AttributeValue[] $values |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
65 | - { |
|
66 | - $attribs = array_map( |
|
67 | - function (AttributeValue $value) { |
|
68 | - return $value->toAttribute(); |
|
69 | - }, $values); |
|
70 | - return new self(...$attribs); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Initialize from ASN.1. |
|
75 | - * |
|
76 | - * @param Sequence $seq |
|
77 | - * @return self |
|
78 | - */ |
|
79 | - public static function fromASN1(Sequence $seq): self |
|
80 | - { |
|
81 | - $attribs = array_map( |
|
82 | - function (UnspecifiedType $el) { |
|
83 | - return Attribute::fromASN1($el->asSequence()); |
|
84 | - }, $seq->elements()); |
|
85 | - // cast attributes |
|
86 | - $attribs = array_map( |
|
87 | - function (Attribute $attr) { |
|
88 | - $oid = $attr->oid(); |
|
89 | - if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
90 | - $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
91 | - $attr = $attr->castValues($cls); |
|
92 | - } |
|
93 | - return $attr; |
|
94 | - }, $attribs); |
|
95 | - return new self(...$attribs); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check whether 'Access Identity' attribute is present. |
|
100 | - * |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function hasAccessIdentity(): bool |
|
104 | - { |
|
105 | - return $this->has(AccessIdentityAttributeValue::OID); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Get the first 'Access Identity' attribute value. |
|
110 | - * |
|
111 | - * @return AccessIdentityAttributeValue |
|
112 | - */ |
|
113 | - public function accessIdentity(): AccessIdentityAttributeValue |
|
114 | - { |
|
115 | - return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Check whether 'Service Authentication Information' attribute is present. |
|
120 | - * |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function hasAuthenticationInformation(): bool |
|
124 | - { |
|
125 | - return $this->has(AuthenticationInfoAttributeValue::OID); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Get the first 'Service Authentication Information' attribute value. |
|
130 | - * |
|
131 | - * @return AuthenticationInfoAttributeValue |
|
132 | - */ |
|
133 | - public function authenticationInformation(): AuthenticationInfoAttributeValue |
|
134 | - { |
|
135 | - return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Check whether 'Charging Identity' attribute is present. |
|
140 | - * |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function hasChargingIdentity(): bool |
|
144 | - { |
|
145 | - return $this->has(ChargingIdentityAttributeValue::OID); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Get the first 'Charging Identity' attribute value. |
|
150 | - * |
|
151 | - * @return ChargingIdentityAttributeValue |
|
152 | - */ |
|
153 | - public function chargingIdentity(): ChargingIdentityAttributeValue |
|
154 | - { |
|
155 | - return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Check whether 'Group' attribute is present. |
|
160 | - * |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function hasGroup(): bool |
|
164 | - { |
|
165 | - return $this->has(GroupAttributeValue::OID); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get the first 'Group' attribute value. |
|
170 | - * |
|
171 | - * @return GroupAttributeValue |
|
172 | - */ |
|
173 | - public function group(): GroupAttributeValue |
|
174 | - { |
|
175 | - return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Check whether 'Role' attribute is present. |
|
180 | - * |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - public function hasRole(): bool |
|
184 | - { |
|
185 | - return $this->has(AttributeType::OID_ROLE); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Get the first 'Role' attribute value. |
|
190 | - * |
|
191 | - * @return RoleAttributeValue |
|
192 | - */ |
|
193 | - public function role(): RoleAttributeValue |
|
194 | - { |
|
195 | - return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get all 'Role' attribute values. |
|
200 | - * |
|
201 | - * @return RoleAttributeValue[] |
|
202 | - */ |
|
203 | - public function roles(): array |
|
204 | - { |
|
205 | - return array_merge(array(), |
|
206 | - ...array_map( |
|
207 | - function (Attribute $attr) { |
|
208 | - return $attr->values(); |
|
209 | - }, $this->allOf(AttributeType::OID_ROLE))); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Generate ASN.1 structure. |
|
214 | - * |
|
215 | - * @return Sequence |
|
216 | - */ |
|
217 | - public function toASN1(): Sequence |
|
218 | - { |
|
219 | - $elements = array_map( |
|
220 | - function (Attribute $attr) { |
|
221 | - return $attr->toASN1(); |
|
222 | - }, array_values($this->_attributes)); |
|
223 | - return new Sequence(...$elements); |
|
224 | - } |
|
29 | + use AttributeContainer; |
|
30 | + |
|
31 | + /** |
|
32 | + * Mapping from OID to attribute value class name. |
|
33 | + * |
|
34 | + * @internal |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + const MAP_OID_TO_CLASS = array( |
|
39 | + /* @formatter:off */ |
|
40 | + AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
41 | + AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
42 | + ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
43 | + GroupAttributeValue::OID => GroupAttributeValue::class, |
|
44 | + AttributeType::OID_ROLE => RoleAttributeValue::class |
|
45 | + /* @formatter:on */ |
|
46 | + ); |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor. |
|
50 | + * |
|
51 | + * @param Attribute[] $attribs |
|
52 | + */ |
|
53 | + public function __construct(Attribute ...$attribs) |
|
54 | + { |
|
55 | + $this->_attributes = $attribs; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Initialize from attribute values. |
|
60 | + * |
|
61 | + * @param AttributeValue[] $values |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
65 | + { |
|
66 | + $attribs = array_map( |
|
67 | + function (AttributeValue $value) { |
|
68 | + return $value->toAttribute(); |
|
69 | + }, $values); |
|
70 | + return new self(...$attribs); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Initialize from ASN.1. |
|
75 | + * |
|
76 | + * @param Sequence $seq |
|
77 | + * @return self |
|
78 | + */ |
|
79 | + public static function fromASN1(Sequence $seq): self |
|
80 | + { |
|
81 | + $attribs = array_map( |
|
82 | + function (UnspecifiedType $el) { |
|
83 | + return Attribute::fromASN1($el->asSequence()); |
|
84 | + }, $seq->elements()); |
|
85 | + // cast attributes |
|
86 | + $attribs = array_map( |
|
87 | + function (Attribute $attr) { |
|
88 | + $oid = $attr->oid(); |
|
89 | + if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
90 | + $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
91 | + $attr = $attr->castValues($cls); |
|
92 | + } |
|
93 | + return $attr; |
|
94 | + }, $attribs); |
|
95 | + return new self(...$attribs); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check whether 'Access Identity' attribute is present. |
|
100 | + * |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function hasAccessIdentity(): bool |
|
104 | + { |
|
105 | + return $this->has(AccessIdentityAttributeValue::OID); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Get the first 'Access Identity' attribute value. |
|
110 | + * |
|
111 | + * @return AccessIdentityAttributeValue |
|
112 | + */ |
|
113 | + public function accessIdentity(): AccessIdentityAttributeValue |
|
114 | + { |
|
115 | + return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Check whether 'Service Authentication Information' attribute is present. |
|
120 | + * |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function hasAuthenticationInformation(): bool |
|
124 | + { |
|
125 | + return $this->has(AuthenticationInfoAttributeValue::OID); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Get the first 'Service Authentication Information' attribute value. |
|
130 | + * |
|
131 | + * @return AuthenticationInfoAttributeValue |
|
132 | + */ |
|
133 | + public function authenticationInformation(): AuthenticationInfoAttributeValue |
|
134 | + { |
|
135 | + return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Check whether 'Charging Identity' attribute is present. |
|
140 | + * |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function hasChargingIdentity(): bool |
|
144 | + { |
|
145 | + return $this->has(ChargingIdentityAttributeValue::OID); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Get the first 'Charging Identity' attribute value. |
|
150 | + * |
|
151 | + * @return ChargingIdentityAttributeValue |
|
152 | + */ |
|
153 | + public function chargingIdentity(): ChargingIdentityAttributeValue |
|
154 | + { |
|
155 | + return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Check whether 'Group' attribute is present. |
|
160 | + * |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function hasGroup(): bool |
|
164 | + { |
|
165 | + return $this->has(GroupAttributeValue::OID); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get the first 'Group' attribute value. |
|
170 | + * |
|
171 | + * @return GroupAttributeValue |
|
172 | + */ |
|
173 | + public function group(): GroupAttributeValue |
|
174 | + { |
|
175 | + return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Check whether 'Role' attribute is present. |
|
180 | + * |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + public function hasRole(): bool |
|
184 | + { |
|
185 | + return $this->has(AttributeType::OID_ROLE); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Get the first 'Role' attribute value. |
|
190 | + * |
|
191 | + * @return RoleAttributeValue |
|
192 | + */ |
|
193 | + public function role(): RoleAttributeValue |
|
194 | + { |
|
195 | + return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get all 'Role' attribute values. |
|
200 | + * |
|
201 | + * @return RoleAttributeValue[] |
|
202 | + */ |
|
203 | + public function roles(): array |
|
204 | + { |
|
205 | + return array_merge(array(), |
|
206 | + ...array_map( |
|
207 | + function (Attribute $attr) { |
|
208 | + return $attr->values(); |
|
209 | + }, $this->allOf(AttributeType::OID_ROLE))); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Generate ASN.1 structure. |
|
214 | + * |
|
215 | + * @return Sequence |
|
216 | + */ |
|
217 | + public function toASN1(): Sequence |
|
218 | + { |
|
219 | + $elements = array_map( |
|
220 | + function (Attribute $attr) { |
|
221 | + return $attr->toASN1(); |
|
222 | + }, array_values($this->_attributes)); |
|
223 | + return new Sequence(...$elements); |
|
224 | + } |
|
225 | 225 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | public static function fromAttributeValues(AttributeValue ...$values): self |
65 | 65 | { |
66 | 66 | $attribs = array_map( |
67 | - function (AttributeValue $value) { |
|
67 | + function(AttributeValue $value) { |
|
68 | 68 | return $value->toAttribute(); |
69 | 69 | }, $values); |
70 | 70 | return new self(...$attribs); |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | public static function fromASN1(Sequence $seq): self |
80 | 80 | { |
81 | 81 | $attribs = array_map( |
82 | - function (UnspecifiedType $el) { |
|
82 | + function(UnspecifiedType $el) { |
|
83 | 83 | return Attribute::fromASN1($el->asSequence()); |
84 | 84 | }, $seq->elements()); |
85 | 85 | // cast attributes |
86 | 86 | $attribs = array_map( |
87 | - function (Attribute $attr) { |
|
87 | + function(Attribute $attr) { |
|
88 | 88 | $oid = $attr->oid(); |
89 | 89 | if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
90 | 90 | $cls = self::MAP_OID_TO_CLASS[$oid]; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | { |
205 | 205 | return array_merge(array(), |
206 | 206 | ...array_map( |
207 | - function (Attribute $attr) { |
|
207 | + function(Attribute $attr) { |
|
208 | 208 | return $attr->values(); |
209 | 209 | }, $this->allOf(AttributeType::OID_ROLE))); |
210 | 210 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | public function toASN1(): Sequence |
218 | 218 | { |
219 | 219 | $elements = array_map( |
220 | - function (Attribute $attr) { |
|
220 | + function(Attribute $attr) { |
|
221 | 221 | return $attr->toASN1(); |
222 | 222 | }, array_values($this->_attributes)); |
223 | 223 | return new Sequence(...$elements); |
@@ -19,172 +19,172 @@ |
||
19 | 19 | */ |
20 | 20 | class IssuerSerial |
21 | 21 | { |
22 | - /** |
|
23 | - * Issuer name. |
|
24 | - * |
|
25 | - * @var GeneralNames $_issuer |
|
26 | - */ |
|
27 | - protected $_issuer; |
|
22 | + /** |
|
23 | + * Issuer name. |
|
24 | + * |
|
25 | + * @var GeneralNames $_issuer |
|
26 | + */ |
|
27 | + protected $_issuer; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Serial number. |
|
31 | - * |
|
32 | - * @var string $_serial |
|
33 | - */ |
|
34 | - protected $_serial; |
|
29 | + /** |
|
30 | + * Serial number. |
|
31 | + * |
|
32 | + * @var string $_serial |
|
33 | + */ |
|
34 | + protected $_serial; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Issuer unique ID. |
|
38 | - * |
|
39 | - * @var UniqueIdentifier|null $_issuerUID |
|
40 | - */ |
|
41 | - protected $_issuerUID; |
|
36 | + /** |
|
37 | + * Issuer unique ID. |
|
38 | + * |
|
39 | + * @var UniqueIdentifier|null $_issuerUID |
|
40 | + */ |
|
41 | + protected $_issuerUID; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param GeneralNames $issuer |
|
47 | - * @param string|int $serial |
|
48 | - * @param UniqueIdentifier|null $uid |
|
49 | - */ |
|
50 | - public function __construct(GeneralNames $issuer, $serial, |
|
51 | - UniqueIdentifier $uid = null) |
|
52 | - { |
|
53 | - $this->_issuer = $issuer; |
|
54 | - $this->_serial = strval($serial); |
|
55 | - $this->_issuerUID = $uid; |
|
56 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param GeneralNames $issuer |
|
47 | + * @param string|int $serial |
|
48 | + * @param UniqueIdentifier|null $uid |
|
49 | + */ |
|
50 | + public function __construct(GeneralNames $issuer, $serial, |
|
51 | + UniqueIdentifier $uid = null) |
|
52 | + { |
|
53 | + $this->_issuer = $issuer; |
|
54 | + $this->_serial = strval($serial); |
|
55 | + $this->_issuerUID = $uid; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Initialize from ASN.1. |
|
60 | - * |
|
61 | - * @param Sequence $seq |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public static function fromASN1(Sequence $seq): self |
|
65 | - { |
|
66 | - $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
67 | - $serial = $seq->at(1) |
|
68 | - ->asInteger() |
|
69 | - ->number(); |
|
70 | - $uid = null; |
|
71 | - if ($seq->has(2, Element::TYPE_BIT_STRING)) { |
|
72 | - $uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString()); |
|
73 | - } |
|
74 | - return new self($issuer, $serial, $uid); |
|
75 | - } |
|
58 | + /** |
|
59 | + * Initialize from ASN.1. |
|
60 | + * |
|
61 | + * @param Sequence $seq |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public static function fromASN1(Sequence $seq): self |
|
65 | + { |
|
66 | + $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
67 | + $serial = $seq->at(1) |
|
68 | + ->asInteger() |
|
69 | + ->number(); |
|
70 | + $uid = null; |
|
71 | + if ($seq->has(2, Element::TYPE_BIT_STRING)) { |
|
72 | + $uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString()); |
|
73 | + } |
|
74 | + return new self($issuer, $serial, $uid); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Initialize from a public key certificate. |
|
79 | - * |
|
80 | - * @param Certificate $cert |
|
81 | - * @return self |
|
82 | - */ |
|
83 | - public static function fromPKC(Certificate $cert) |
|
84 | - { |
|
85 | - $tbsCert = $cert->tbsCertificate(); |
|
86 | - $issuer = new GeneralNames(new DirectoryName($tbsCert->issuer())); |
|
87 | - $serial = $tbsCert->serialNumber(); |
|
88 | - $uid = $tbsCert->hasIssuerUniqueID() ? $tbsCert->issuerUniqueID() : null; |
|
89 | - return new self($issuer, $serial, $uid); |
|
90 | - } |
|
77 | + /** |
|
78 | + * Initialize from a public key certificate. |
|
79 | + * |
|
80 | + * @param Certificate $cert |
|
81 | + * @return self |
|
82 | + */ |
|
83 | + public static function fromPKC(Certificate $cert) |
|
84 | + { |
|
85 | + $tbsCert = $cert->tbsCertificate(); |
|
86 | + $issuer = new GeneralNames(new DirectoryName($tbsCert->issuer())); |
|
87 | + $serial = $tbsCert->serialNumber(); |
|
88 | + $uid = $tbsCert->hasIssuerUniqueID() ? $tbsCert->issuerUniqueID() : null; |
|
89 | + return new self($issuer, $serial, $uid); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Get issuer name. |
|
94 | - * |
|
95 | - * @return GeneralNames |
|
96 | - */ |
|
97 | - public function issuer(): GeneralNames |
|
98 | - { |
|
99 | - return $this->_issuer; |
|
100 | - } |
|
92 | + /** |
|
93 | + * Get issuer name. |
|
94 | + * |
|
95 | + * @return GeneralNames |
|
96 | + */ |
|
97 | + public function issuer(): GeneralNames |
|
98 | + { |
|
99 | + return $this->_issuer; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Get serial number. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function serial(): string |
|
108 | - { |
|
109 | - return $this->_serial; |
|
110 | - } |
|
102 | + /** |
|
103 | + * Get serial number. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function serial(): string |
|
108 | + { |
|
109 | + return $this->_serial; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Check whether issuer unique identifier is present. |
|
114 | - * |
|
115 | - * @return bool |
|
116 | - */ |
|
117 | - public function hasIssuerUID(): bool |
|
118 | - { |
|
119 | - return isset($this->_issuerUID); |
|
120 | - } |
|
112 | + /** |
|
113 | + * Check whether issuer unique identifier is present. |
|
114 | + * |
|
115 | + * @return bool |
|
116 | + */ |
|
117 | + public function hasIssuerUID(): bool |
|
118 | + { |
|
119 | + return isset($this->_issuerUID); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Get issuer unique identifier. |
|
124 | - * |
|
125 | - * @throws \LogicException |
|
126 | - * @return UniqueIdentifier |
|
127 | - */ |
|
128 | - public function issuerUID(): UniqueIdentifier |
|
129 | - { |
|
130 | - if (!$this->hasIssuerUID()) { |
|
131 | - throw new \LogicException("issuerUID not set."); |
|
132 | - } |
|
133 | - return $this->_issuerUID; |
|
134 | - } |
|
122 | + /** |
|
123 | + * Get issuer unique identifier. |
|
124 | + * |
|
125 | + * @throws \LogicException |
|
126 | + * @return UniqueIdentifier |
|
127 | + */ |
|
128 | + public function issuerUID(): UniqueIdentifier |
|
129 | + { |
|
130 | + if (!$this->hasIssuerUID()) { |
|
131 | + throw new \LogicException("issuerUID not set."); |
|
132 | + } |
|
133 | + return $this->_issuerUID; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Generate ASN.1 structure. |
|
138 | - * |
|
139 | - * @return Sequence |
|
140 | - */ |
|
141 | - public function toASN1(): Sequence |
|
142 | - { |
|
143 | - $elements = array($this->_issuer->toASN1(), new Integer($this->_serial)); |
|
144 | - if (isset($this->_issuerUID)) { |
|
145 | - $elements[] = $this->_issuerUID->toASN1(); |
|
146 | - } |
|
147 | - return new Sequence(...$elements); |
|
148 | - } |
|
136 | + /** |
|
137 | + * Generate ASN.1 structure. |
|
138 | + * |
|
139 | + * @return Sequence |
|
140 | + */ |
|
141 | + public function toASN1(): Sequence |
|
142 | + { |
|
143 | + $elements = array($this->_issuer->toASN1(), new Integer($this->_serial)); |
|
144 | + if (isset($this->_issuerUID)) { |
|
145 | + $elements[] = $this->_issuerUID->toASN1(); |
|
146 | + } |
|
147 | + return new Sequence(...$elements); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Check whether this IssuerSerial identifies given certificate. |
|
152 | - * |
|
153 | - * @param Certificate $cert |
|
154 | - * @return boolean |
|
155 | - */ |
|
156 | - public function identifiesPKC(Certificate $cert): bool |
|
157 | - { |
|
158 | - $tbs = $cert->tbsCertificate(); |
|
159 | - if (!$tbs->issuer()->equals($this->_issuer->firstDN())) { |
|
160 | - return false; |
|
161 | - } |
|
162 | - if (strval($tbs->serialNumber()) != strval($this->_serial)) { |
|
163 | - return false; |
|
164 | - } |
|
165 | - if ($this->_issuerUID && !$this->_checkUniqueID($cert)) { |
|
166 | - return false; |
|
167 | - } |
|
168 | - return true; |
|
169 | - } |
|
150 | + /** |
|
151 | + * Check whether this IssuerSerial identifies given certificate. |
|
152 | + * |
|
153 | + * @param Certificate $cert |
|
154 | + * @return boolean |
|
155 | + */ |
|
156 | + public function identifiesPKC(Certificate $cert): bool |
|
157 | + { |
|
158 | + $tbs = $cert->tbsCertificate(); |
|
159 | + if (!$tbs->issuer()->equals($this->_issuer->firstDN())) { |
|
160 | + return false; |
|
161 | + } |
|
162 | + if (strval($tbs->serialNumber()) != strval($this->_serial)) { |
|
163 | + return false; |
|
164 | + } |
|
165 | + if ($this->_issuerUID && !$this->_checkUniqueID($cert)) { |
|
166 | + return false; |
|
167 | + } |
|
168 | + return true; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Check whether issuerUID matches given certificate. |
|
173 | - * |
|
174 | - * @param Certificate $cert |
|
175 | - * @return boolean |
|
176 | - */ |
|
177 | - private function _checkUniqueID(Certificate $cert): bool |
|
178 | - { |
|
179 | - if (!$cert->tbsCertificate()->hasIssuerUniqueID()) { |
|
180 | - return false; |
|
181 | - } |
|
182 | - $uid = $cert->tbsCertificate() |
|
183 | - ->issuerUniqueID() |
|
184 | - ->string(); |
|
185 | - if ($this->_issuerUID->string() != $uid) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - return true; |
|
189 | - } |
|
171 | + /** |
|
172 | + * Check whether issuerUID matches given certificate. |
|
173 | + * |
|
174 | + * @param Certificate $cert |
|
175 | + * @return boolean |
|
176 | + */ |
|
177 | + private function _checkUniqueID(Certificate $cert): bool |
|
178 | + { |
|
179 | + if (!$cert->tbsCertificate()->hasIssuerUniqueID()) { |
|
180 | + return false; |
|
181 | + } |
|
182 | + $uid = $cert->tbsCertificate() |
|
183 | + ->issuerUniqueID() |
|
184 | + ->string(); |
|
185 | + if ($this->_issuerUID->string() != $uid) { |
|
186 | + return false; |
|
187 | + } |
|
188 | + return true; |
|
189 | + } |
|
190 | 190 | } |
@@ -12,112 +12,112 @@ |
||
12 | 12 | */ |
13 | 13 | class ACValidationConfig |
14 | 14 | { |
15 | - /** |
|
16 | - * Certification path of the AC holder. |
|
17 | - * |
|
18 | - * @var CertificationPath |
|
19 | - */ |
|
20 | - protected $_holderPath; |
|
15 | + /** |
|
16 | + * Certification path of the AC holder. |
|
17 | + * |
|
18 | + * @var CertificationPath |
|
19 | + */ |
|
20 | + protected $_holderPath; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Certification path of the AC issuer. |
|
24 | - * |
|
25 | - * @var CertificationPath |
|
26 | - */ |
|
27 | - protected $_issuerPath; |
|
22 | + /** |
|
23 | + * Certification path of the AC issuer. |
|
24 | + * |
|
25 | + * @var CertificationPath |
|
26 | + */ |
|
27 | + protected $_issuerPath; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Evaluation reference time. |
|
31 | - * |
|
32 | - * @var \DateTimeImmutable |
|
33 | - */ |
|
34 | - protected $_evalTime; |
|
29 | + /** |
|
30 | + * Evaluation reference time. |
|
31 | + * |
|
32 | + * @var \DateTimeImmutable |
|
33 | + */ |
|
34 | + protected $_evalTime; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Permitted targets. |
|
38 | - * |
|
39 | - * @var Target[] |
|
40 | - */ |
|
41 | - protected $_targets; |
|
36 | + /** |
|
37 | + * Permitted targets. |
|
38 | + * |
|
39 | + * @var Target[] |
|
40 | + */ |
|
41 | + protected $_targets; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param CertificationPath $holder_path Certification path of the AC holder |
|
47 | - * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
48 | - */ |
|
49 | - public function __construct(CertificationPath $holder_path, |
|
50 | - CertificationPath $issuer_path) |
|
51 | - { |
|
52 | - $this->_holderPath = $holder_path; |
|
53 | - $this->_issuerPath = $issuer_path; |
|
54 | - $this->_evalTime = new \DateTimeImmutable(); |
|
55 | - $this->_targets = array(); |
|
56 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param CertificationPath $holder_path Certification path of the AC holder |
|
47 | + * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
48 | + */ |
|
49 | + public function __construct(CertificationPath $holder_path, |
|
50 | + CertificationPath $issuer_path) |
|
51 | + { |
|
52 | + $this->_holderPath = $holder_path; |
|
53 | + $this->_issuerPath = $issuer_path; |
|
54 | + $this->_evalTime = new \DateTimeImmutable(); |
|
55 | + $this->_targets = array(); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get certification path of the AC's holder. |
|
60 | - * |
|
61 | - * @return CertificationPath |
|
62 | - */ |
|
63 | - public function holderPath(): CertificationPath |
|
64 | - { |
|
65 | - return $this->_holderPath; |
|
66 | - } |
|
58 | + /** |
|
59 | + * Get certification path of the AC's holder. |
|
60 | + * |
|
61 | + * @return CertificationPath |
|
62 | + */ |
|
63 | + public function holderPath(): CertificationPath |
|
64 | + { |
|
65 | + return $this->_holderPath; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Get certification path of the AC's issuer. |
|
70 | - * |
|
71 | - * @return CertificationPath |
|
72 | - */ |
|
73 | - public function issuerPath(): CertificationPath |
|
74 | - { |
|
75 | - return $this->_issuerPath; |
|
76 | - } |
|
68 | + /** |
|
69 | + * Get certification path of the AC's issuer. |
|
70 | + * |
|
71 | + * @return CertificationPath |
|
72 | + */ |
|
73 | + public function issuerPath(): CertificationPath |
|
74 | + { |
|
75 | + return $this->_issuerPath; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get self with given evaluation reference time. |
|
80 | - * |
|
81 | - * @param \DateTimeImmutable $dt |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public function withEvaluationTime(\DateTimeImmutable $dt): self |
|
85 | - { |
|
86 | - $obj = clone $this; |
|
87 | - $obj->_evalTime = $dt; |
|
88 | - return $obj; |
|
89 | - } |
|
78 | + /** |
|
79 | + * Get self with given evaluation reference time. |
|
80 | + * |
|
81 | + * @param \DateTimeImmutable $dt |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public function withEvaluationTime(\DateTimeImmutable $dt): self |
|
85 | + { |
|
86 | + $obj = clone $this; |
|
87 | + $obj->_evalTime = $dt; |
|
88 | + return $obj; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Get the evaluation reference time. |
|
93 | - * |
|
94 | - * @return \DateTimeImmutable |
|
95 | - */ |
|
96 | - public function evaluationTime(): \DateTimeImmutable |
|
97 | - { |
|
98 | - return $this->_evalTime; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Get the evaluation reference time. |
|
93 | + * |
|
94 | + * @return \DateTimeImmutable |
|
95 | + */ |
|
96 | + public function evaluationTime(): \DateTimeImmutable |
|
97 | + { |
|
98 | + return $this->_evalTime; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get self with permitted targets. |
|
103 | - * |
|
104 | - * @param Target ...$targets |
|
105 | - * @return self |
|
106 | - */ |
|
107 | - public function withTargets(Target ...$targets): self |
|
108 | - { |
|
109 | - $obj = clone $this; |
|
110 | - $obj->_targets = $targets; |
|
111 | - return $obj; |
|
112 | - } |
|
101 | + /** |
|
102 | + * Get self with permitted targets. |
|
103 | + * |
|
104 | + * @param Target ...$targets |
|
105 | + * @return self |
|
106 | + */ |
|
107 | + public function withTargets(Target ...$targets): self |
|
108 | + { |
|
109 | + $obj = clone $this; |
|
110 | + $obj->_targets = $targets; |
|
111 | + return $obj; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Get array of permitted targets |
|
116 | - * |
|
117 | - * @return Target[] |
|
118 | - */ |
|
119 | - public function targets(): array |
|
120 | - { |
|
121 | - return $this->_targets; |
|
122 | - } |
|
114 | + /** |
|
115 | + * Get array of permitted targets |
|
116 | + * |
|
117 | + * @return Target[] |
|
118 | + */ |
|
119 | + public function targets(): array |
|
120 | + { |
|
121 | + return $this->_targets; |
|
122 | + } |
|
123 | 123 | } |
@@ -21,178 +21,178 @@ |
||
21 | 21 | */ |
22 | 22 | class ACValidator |
23 | 23 | { |
24 | - /** |
|
25 | - * Attribute certificate. |
|
26 | - * |
|
27 | - * @var AttributeCertificate |
|
28 | - */ |
|
29 | - protected $_ac; |
|
24 | + /** |
|
25 | + * Attribute certificate. |
|
26 | + * |
|
27 | + * @var AttributeCertificate |
|
28 | + */ |
|
29 | + protected $_ac; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Validation configuration. |
|
33 | - * |
|
34 | - * @var ACValidationConfig |
|
35 | - */ |
|
36 | - protected $_config; |
|
31 | + /** |
|
32 | + * Validation configuration. |
|
33 | + * |
|
34 | + * @var ACValidationConfig |
|
35 | + */ |
|
36 | + protected $_config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Crypto engine. |
|
40 | - * |
|
41 | - * @var Crypto |
|
42 | - */ |
|
43 | - protected $_crypto; |
|
38 | + /** |
|
39 | + * Crypto engine. |
|
40 | + * |
|
41 | + * @var Crypto |
|
42 | + */ |
|
43 | + protected $_crypto; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor. |
|
47 | - * |
|
48 | - * @param AttributeCertificate $ac Attribute certificate to validate |
|
49 | - * @param ACValidationConfig $config Validation configuration |
|
50 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
51 | - */ |
|
52 | - public function __construct(AttributeCertificate $ac, |
|
53 | - ACValidationConfig $config, Crypto $crypto = null) |
|
54 | - { |
|
55 | - $this->_ac = $ac; |
|
56 | - $this->_config = $config; |
|
57 | - $this->_crypto = $crypto ?: Crypto::getDefault(); |
|
58 | - } |
|
45 | + /** |
|
46 | + * Constructor. |
|
47 | + * |
|
48 | + * @param AttributeCertificate $ac Attribute certificate to validate |
|
49 | + * @param ACValidationConfig $config Validation configuration |
|
50 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
51 | + */ |
|
52 | + public function __construct(AttributeCertificate $ac, |
|
53 | + ACValidationConfig $config, Crypto $crypto = null) |
|
54 | + { |
|
55 | + $this->_ac = $ac; |
|
56 | + $this->_config = $config; |
|
57 | + $this->_crypto = $crypto ?: Crypto::getDefault(); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Validate attribute certificate. |
|
62 | - * |
|
63 | - * @throws ACValidationException If validation fails |
|
64 | - * @return AttributeCertificate Validated AC |
|
65 | - */ |
|
66 | - public function validate(): AttributeCertificate |
|
67 | - { |
|
68 | - $this->_validateHolder(); |
|
69 | - $issuer = $this->_verifyIssuer(); |
|
70 | - $this->_validateIssuerProfile($issuer); |
|
71 | - $this->_validateTime(); |
|
72 | - $this->_validateTargeting(); |
|
73 | - return $this->_ac; |
|
74 | - } |
|
60 | + /** |
|
61 | + * Validate attribute certificate. |
|
62 | + * |
|
63 | + * @throws ACValidationException If validation fails |
|
64 | + * @return AttributeCertificate Validated AC |
|
65 | + */ |
|
66 | + public function validate(): AttributeCertificate |
|
67 | + { |
|
68 | + $this->_validateHolder(); |
|
69 | + $issuer = $this->_verifyIssuer(); |
|
70 | + $this->_validateIssuerProfile($issuer); |
|
71 | + $this->_validateTime(); |
|
72 | + $this->_validateTargeting(); |
|
73 | + return $this->_ac; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Validate AC holder's certification. |
|
78 | - * |
|
79 | - * @throws ACValidationException |
|
80 | - * @return Certificate Certificate of the AC's holder |
|
81 | - */ |
|
82 | - private function _validateHolder(): Certificate |
|
83 | - { |
|
84 | - $path = $this->_config->holderPath(); |
|
85 | - $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
86 | - count($path))->withDateTime($this->_config->evaluationTime()); |
|
87 | - try { |
|
88 | - $holder = $path->validate($config, $this->_crypto)->certificate(); |
|
89 | - } catch (PathValidationException $e) { |
|
90 | - throw new ACValidationException( |
|
91 | - "Failed to validate holder PKC's certification path.", 0, $e); |
|
92 | - } |
|
93 | - if (!$this->_ac->isHeldBy($holder)) { |
|
94 | - throw new ACValidationException("Name mismatch of AC's holder PKC."); |
|
95 | - } |
|
96 | - return $holder; |
|
97 | - } |
|
76 | + /** |
|
77 | + * Validate AC holder's certification. |
|
78 | + * |
|
79 | + * @throws ACValidationException |
|
80 | + * @return Certificate Certificate of the AC's holder |
|
81 | + */ |
|
82 | + private function _validateHolder(): Certificate |
|
83 | + { |
|
84 | + $path = $this->_config->holderPath(); |
|
85 | + $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
86 | + count($path))->withDateTime($this->_config->evaluationTime()); |
|
87 | + try { |
|
88 | + $holder = $path->validate($config, $this->_crypto)->certificate(); |
|
89 | + } catch (PathValidationException $e) { |
|
90 | + throw new ACValidationException( |
|
91 | + "Failed to validate holder PKC's certification path.", 0, $e); |
|
92 | + } |
|
93 | + if (!$this->_ac->isHeldBy($holder)) { |
|
94 | + throw new ACValidationException("Name mismatch of AC's holder PKC."); |
|
95 | + } |
|
96 | + return $holder; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Verify AC's signature and issuer's certification. |
|
101 | - * |
|
102 | - * @throws ACValidationException |
|
103 | - * @return Certificate Certificate of the AC's issuer |
|
104 | - */ |
|
105 | - private function _verifyIssuer(): Certificate |
|
106 | - { |
|
107 | - $path = $this->_config->issuerPath(); |
|
108 | - $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
109 | - count($path))->withDateTime($this->_config->evaluationTime()); |
|
110 | - try { |
|
111 | - $issuer = $path->validate($config, $this->_crypto)->certificate(); |
|
112 | - } catch (PathValidationException $e) { |
|
113 | - throw new ACValidationException( |
|
114 | - "Failed to validate issuer PKC's certification path.", 0, $e); |
|
115 | - } |
|
116 | - if (!$this->_ac->isIssuedBy($issuer)) { |
|
117 | - throw new ACValidationException("Name mismatch of AC's issuer PKC."); |
|
118 | - } |
|
119 | - $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo(); |
|
120 | - if (!$this->_ac->verify($pubkey_info, $this->_crypto)) { |
|
121 | - throw new ACValidationException("Failed to verify signature."); |
|
122 | - } |
|
123 | - return $issuer; |
|
124 | - } |
|
99 | + /** |
|
100 | + * Verify AC's signature and issuer's certification. |
|
101 | + * |
|
102 | + * @throws ACValidationException |
|
103 | + * @return Certificate Certificate of the AC's issuer |
|
104 | + */ |
|
105 | + private function _verifyIssuer(): Certificate |
|
106 | + { |
|
107 | + $path = $this->_config->issuerPath(); |
|
108 | + $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
109 | + count($path))->withDateTime($this->_config->evaluationTime()); |
|
110 | + try { |
|
111 | + $issuer = $path->validate($config, $this->_crypto)->certificate(); |
|
112 | + } catch (PathValidationException $e) { |
|
113 | + throw new ACValidationException( |
|
114 | + "Failed to validate issuer PKC's certification path.", 0, $e); |
|
115 | + } |
|
116 | + if (!$this->_ac->isIssuedBy($issuer)) { |
|
117 | + throw new ACValidationException("Name mismatch of AC's issuer PKC."); |
|
118 | + } |
|
119 | + $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo(); |
|
120 | + if (!$this->_ac->verify($pubkey_info, $this->_crypto)) { |
|
121 | + throw new ACValidationException("Failed to verify signature."); |
|
122 | + } |
|
123 | + return $issuer; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Validate AC issuer's profile. |
|
128 | - * |
|
129 | - * @link https://tools.ietf.org/html/rfc5755#section-4.5 |
|
130 | - * @param Certificate $cert |
|
131 | - * @throws ACValidationException |
|
132 | - */ |
|
133 | - private function _validateIssuerProfile(Certificate $cert) |
|
134 | - { |
|
135 | - $exts = $cert->tbsCertificate()->extensions(); |
|
136 | - if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) { |
|
137 | - throw new ACValidationException( |
|
138 | - "Issuer PKC's Key Usage extension doesn't permit" . |
|
139 | - " verification of digital signatures."); |
|
140 | - } |
|
141 | - if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) { |
|
142 | - throw new ACValidationException("Issuer PKC must not be a CA."); |
|
143 | - } |
|
144 | - } |
|
126 | + /** |
|
127 | + * Validate AC issuer's profile. |
|
128 | + * |
|
129 | + * @link https://tools.ietf.org/html/rfc5755#section-4.5 |
|
130 | + * @param Certificate $cert |
|
131 | + * @throws ACValidationException |
|
132 | + */ |
|
133 | + private function _validateIssuerProfile(Certificate $cert) |
|
134 | + { |
|
135 | + $exts = $cert->tbsCertificate()->extensions(); |
|
136 | + if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) { |
|
137 | + throw new ACValidationException( |
|
138 | + "Issuer PKC's Key Usage extension doesn't permit" . |
|
139 | + " verification of digital signatures."); |
|
140 | + } |
|
141 | + if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) { |
|
142 | + throw new ACValidationException("Issuer PKC must not be a CA."); |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Validate AC's validity period. |
|
148 | - * |
|
149 | - * @throws ACValidationException |
|
150 | - */ |
|
151 | - private function _validateTime() |
|
152 | - { |
|
153 | - $t = $this->_config->evaluationTime(); |
|
154 | - $validity = $this->_ac->acinfo()->validityPeriod(); |
|
155 | - if ($validity->notBeforeTime()->diff($t)->invert) { |
|
156 | - throw new ACValidationException("Validity period has not started."); |
|
157 | - } |
|
158 | - if ($t->diff($validity->notAfterTime())->invert) { |
|
159 | - throw new ACValidationException("Attribute certificate has expired."); |
|
160 | - } |
|
161 | - } |
|
146 | + /** |
|
147 | + * Validate AC's validity period. |
|
148 | + * |
|
149 | + * @throws ACValidationException |
|
150 | + */ |
|
151 | + private function _validateTime() |
|
152 | + { |
|
153 | + $t = $this->_config->evaluationTime(); |
|
154 | + $validity = $this->_ac->acinfo()->validityPeriod(); |
|
155 | + if ($validity->notBeforeTime()->diff($t)->invert) { |
|
156 | + throw new ACValidationException("Validity period has not started."); |
|
157 | + } |
|
158 | + if ($t->diff($validity->notAfterTime())->invert) { |
|
159 | + throw new ACValidationException("Attribute certificate has expired."); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Validate AC's target information. |
|
165 | - * |
|
166 | - * @throws ACValidationException |
|
167 | - */ |
|
168 | - private function _validateTargeting() |
|
169 | - { |
|
170 | - $exts = $this->_ac->acinfo()->extensions(); |
|
171 | - // if target information extension is not present |
|
172 | - if (!$exts->has(Extension::OID_TARGET_INFORMATION)) { |
|
173 | - return; |
|
174 | - } |
|
175 | - $ext = $exts->get(Extension::OID_TARGET_INFORMATION); |
|
176 | - if ($ext instanceof TargetInformationExtension && |
|
177 | - !$this->_hasMatchingTarget($ext->targets())) { |
|
178 | - throw new ACValidationException( |
|
179 | - "Attribute certificate doesn't have a matching target."); |
|
180 | - } |
|
181 | - } |
|
163 | + /** |
|
164 | + * Validate AC's target information. |
|
165 | + * |
|
166 | + * @throws ACValidationException |
|
167 | + */ |
|
168 | + private function _validateTargeting() |
|
169 | + { |
|
170 | + $exts = $this->_ac->acinfo()->extensions(); |
|
171 | + // if target information extension is not present |
|
172 | + if (!$exts->has(Extension::OID_TARGET_INFORMATION)) { |
|
173 | + return; |
|
174 | + } |
|
175 | + $ext = $exts->get(Extension::OID_TARGET_INFORMATION); |
|
176 | + if ($ext instanceof TargetInformationExtension && |
|
177 | + !$this->_hasMatchingTarget($ext->targets())) { |
|
178 | + throw new ACValidationException( |
|
179 | + "Attribute certificate doesn't have a matching target."); |
|
180 | + } |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Check whether validation configuration has matching targets. |
|
185 | - * |
|
186 | - * @param Targets $targets Set of eligible targets |
|
187 | - * @return boolean |
|
188 | - */ |
|
189 | - private function _hasMatchingTarget(Targets $targets): bool |
|
190 | - { |
|
191 | - foreach ($this->_config->targets() as $target) { |
|
192 | - if ($targets->hasTarget($target)) { |
|
193 | - return true; |
|
194 | - } |
|
195 | - } |
|
196 | - return false; |
|
197 | - } |
|
183 | + /** |
|
184 | + * Check whether validation configuration has matching targets. |
|
185 | + * |
|
186 | + * @param Targets $targets Set of eligible targets |
|
187 | + * @return boolean |
|
188 | + */ |
|
189 | + private function _hasMatchingTarget(Targets $targets): bool |
|
190 | + { |
|
191 | + foreach ($this->_config->targets() as $target) { |
|
192 | + if ($targets->hasTarget($target)) { |
|
193 | + return true; |
|
194 | + } |
|
195 | + } |
|
196 | + return false; |
|
197 | + } |
|
198 | 198 | } |
@@ -18,66 +18,66 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class AttCertIssuer |
20 | 20 | { |
21 | - /** |
|
22 | - * Generate ASN.1 element. |
|
23 | - * |
|
24 | - * @return Element |
|
25 | - */ |
|
26 | - abstract public function toASN1(); |
|
21 | + /** |
|
22 | + * Generate ASN.1 element. |
|
23 | + * |
|
24 | + * @return Element |
|
25 | + */ |
|
26 | + abstract public function toASN1(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Check whether AttCertIssuer identifies given certificate. |
|
30 | - * |
|
31 | - * @param Certificate $cert |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - abstract public function identifiesPKC(Certificate $cert): bool; |
|
28 | + /** |
|
29 | + * Check whether AttCertIssuer identifies given certificate. |
|
30 | + * |
|
31 | + * @param Certificate $cert |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + abstract public function identifiesPKC(Certificate $cert): bool; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Initialize from distinguished name. |
|
38 | - * |
|
39 | - * This conforms to RFC 5755 which states that only v2Form must be used, |
|
40 | - * and issuerName must contain exactly one GeneralName of DirectoryName |
|
41 | - * type. |
|
42 | - * |
|
43 | - * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
44 | - * @param Name $name |
|
45 | - * @return self |
|
46 | - */ |
|
47 | - public static function fromName(Name $name): self |
|
48 | - { |
|
49 | - return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
50 | - } |
|
36 | + /** |
|
37 | + * Initialize from distinguished name. |
|
38 | + * |
|
39 | + * This conforms to RFC 5755 which states that only v2Form must be used, |
|
40 | + * and issuerName must contain exactly one GeneralName of DirectoryName |
|
41 | + * type. |
|
42 | + * |
|
43 | + * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
44 | + * @param Name $name |
|
45 | + * @return self |
|
46 | + */ |
|
47 | + public static function fromName(Name $name): self |
|
48 | + { |
|
49 | + return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Initialize from an issuer's public key certificate. |
|
54 | - * |
|
55 | - * @param Certificate $cert |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromPKC(Certificate $cert): self |
|
59 | - { |
|
60 | - return self::fromName($cert->tbsCertificate()->subject()); |
|
61 | - } |
|
52 | + /** |
|
53 | + * Initialize from an issuer's public key certificate. |
|
54 | + * |
|
55 | + * @param Certificate $cert |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromPKC(Certificate $cert): self |
|
59 | + { |
|
60 | + return self::fromName($cert->tbsCertificate()->subject()); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Initialize from ASN.1. |
|
65 | - * |
|
66 | - * @param UnspecifiedType $el CHOICE |
|
67 | - * @throws \UnexpectedValueException |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public static function fromASN1(UnspecifiedType $el): self |
|
71 | - { |
|
72 | - if (!$el->isTagged()) { |
|
73 | - throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
74 | - } |
|
75 | - $tagged = $el->asTagged(); |
|
76 | - switch ($tagged->tag()) { |
|
77 | - case 0: |
|
78 | - return V2Form::fromV2ASN1( |
|
79 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
80 | - } |
|
81 | - throw new \UnexpectedValueException("Unsupported issuer type."); |
|
82 | - } |
|
63 | + /** |
|
64 | + * Initialize from ASN.1. |
|
65 | + * |
|
66 | + * @param UnspecifiedType $el CHOICE |
|
67 | + * @throws \UnexpectedValueException |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public static function fromASN1(UnspecifiedType $el): self |
|
71 | + { |
|
72 | + if (!$el->isTagged()) { |
|
73 | + throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
74 | + } |
|
75 | + $tagged = $el->asTagged(); |
|
76 | + switch ($tagged->tag()) { |
|
77 | + case 0: |
|
78 | + return V2Form::fromV2ASN1( |
|
79 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
80 | + } |
|
81 | + throw new \UnexpectedValueException("Unsupported issuer type."); |
|
82 | + } |
|
83 | 83 | } |
@@ -15,94 +15,94 @@ |
||
15 | 15 | */ |
16 | 16 | class AttCertValidityPeriod |
17 | 17 | { |
18 | - use DateTimeHelper; |
|
18 | + use DateTimeHelper; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Not before time. |
|
22 | - * |
|
23 | - * @var \DateTimeImmutable |
|
24 | - */ |
|
25 | - protected $_notBeforeTime; |
|
20 | + /** |
|
21 | + * Not before time. |
|
22 | + * |
|
23 | + * @var \DateTimeImmutable |
|
24 | + */ |
|
25 | + protected $_notBeforeTime; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Not after time. |
|
29 | - * |
|
30 | - * @var \DateTimeImmutable |
|
31 | - */ |
|
32 | - protected $_notAfterTime; |
|
27 | + /** |
|
28 | + * Not after time. |
|
29 | + * |
|
30 | + * @var \DateTimeImmutable |
|
31 | + */ |
|
32 | + protected $_notAfterTime; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor. |
|
36 | - * |
|
37 | - * @param \DateTimeImmutable $nb |
|
38 | - * @param \DateTimeImmutable $na |
|
39 | - */ |
|
40 | - public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
41 | - { |
|
42 | - $this->_notBeforeTime = $nb; |
|
43 | - $this->_notAfterTime = $na; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Constructor. |
|
36 | + * |
|
37 | + * @param \DateTimeImmutable $nb |
|
38 | + * @param \DateTimeImmutable $na |
|
39 | + */ |
|
40 | + public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
41 | + { |
|
42 | + $this->_notBeforeTime = $nb; |
|
43 | + $this->_notAfterTime = $na; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Initialize from ASN.1. |
|
48 | - * |
|
49 | - * @param Sequence $seq |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromASN1(Sequence $seq): self |
|
53 | - { |
|
54 | - $nb = $seq->at(0) |
|
55 | - ->asGeneralizedTime() |
|
56 | - ->dateTime(); |
|
57 | - $na = $seq->at(1) |
|
58 | - ->asGeneralizedTime() |
|
59 | - ->dateTime(); |
|
60 | - return new self($nb, $na); |
|
61 | - } |
|
46 | + /** |
|
47 | + * Initialize from ASN.1. |
|
48 | + * |
|
49 | + * @param Sequence $seq |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromASN1(Sequence $seq): self |
|
53 | + { |
|
54 | + $nb = $seq->at(0) |
|
55 | + ->asGeneralizedTime() |
|
56 | + ->dateTime(); |
|
57 | + $na = $seq->at(1) |
|
58 | + ->asGeneralizedTime() |
|
59 | + ->dateTime(); |
|
60 | + return new self($nb, $na); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Initialize from date strings. |
|
65 | - * |
|
66 | - * @param string|null $nb_date Not before date |
|
67 | - * @param string|null $na_date Not after date |
|
68 | - * @param string|null $tz Timezone string |
|
69 | - * @return self |
|
70 | - */ |
|
71 | - public static function fromStrings($nb_date, $na_date, $tz = null): self |
|
72 | - { |
|
73 | - $nb = self::_createDateTime($nb_date, $tz); |
|
74 | - $na = self::_createDateTime($na_date, $tz); |
|
75 | - return new self($nb, $na); |
|
76 | - } |
|
63 | + /** |
|
64 | + * Initialize from date strings. |
|
65 | + * |
|
66 | + * @param string|null $nb_date Not before date |
|
67 | + * @param string|null $na_date Not after date |
|
68 | + * @param string|null $tz Timezone string |
|
69 | + * @return self |
|
70 | + */ |
|
71 | + public static function fromStrings($nb_date, $na_date, $tz = null): self |
|
72 | + { |
|
73 | + $nb = self::_createDateTime($nb_date, $tz); |
|
74 | + $na = self::_createDateTime($na_date, $tz); |
|
75 | + return new self($nb, $na); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get not before time. |
|
80 | - * |
|
81 | - * @return \DateTimeImmutable |
|
82 | - */ |
|
83 | - public function notBeforeTime(): \DateTimeImmutable |
|
84 | - { |
|
85 | - return $this->_notBeforeTime; |
|
86 | - } |
|
78 | + /** |
|
79 | + * Get not before time. |
|
80 | + * |
|
81 | + * @return \DateTimeImmutable |
|
82 | + */ |
|
83 | + public function notBeforeTime(): \DateTimeImmutable |
|
84 | + { |
|
85 | + return $this->_notBeforeTime; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get not after time. |
|
90 | - * |
|
91 | - * @return \DateTimeImmutable |
|
92 | - */ |
|
93 | - public function notAfterTime(): \DateTimeImmutable |
|
94 | - { |
|
95 | - return $this->_notAfterTime; |
|
96 | - } |
|
88 | + /** |
|
89 | + * Get not after time. |
|
90 | + * |
|
91 | + * @return \DateTimeImmutable |
|
92 | + */ |
|
93 | + public function notAfterTime(): \DateTimeImmutable |
|
94 | + { |
|
95 | + return $this->_notAfterTime; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Generate ASN.1 structure. |
|
100 | - * |
|
101 | - * @return Sequence |
|
102 | - */ |
|
103 | - public function toASN1(): Sequence |
|
104 | - { |
|
105 | - return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
106 | - new GeneralizedTime($this->_notAfterTime)); |
|
107 | - } |
|
98 | + /** |
|
99 | + * Generate ASN.1 structure. |
|
100 | + * |
|
101 | + * @return Sequence |
|
102 | + */ |
|
103 | + public function toASN1(): Sequence |
|
104 | + { |
|
105 | + return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
106 | + new GeneralizedTime($this->_notAfterTime)); |
|
107 | + } |
|
108 | 108 | } |