@@ -16,66 +16,66 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class AttCertIssuer |
18 | 18 | { |
19 | - /** |
|
20 | - * Generate ASN.1 element. |
|
21 | - * |
|
22 | - * @return Element |
|
23 | - */ |
|
24 | - abstract public function toASN1(); |
|
19 | + /** |
|
20 | + * Generate ASN.1 element. |
|
21 | + * |
|
22 | + * @return Element |
|
23 | + */ |
|
24 | + abstract public function toASN1(); |
|
25 | 25 | |
26 | - /** |
|
27 | - * Check whether AttCertIssuer identifies given certificate. |
|
28 | - * |
|
29 | - * @param Certificate $cert |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - abstract public function identifiesPKC(Certificate $cert); |
|
26 | + /** |
|
27 | + * Check whether AttCertIssuer identifies given certificate. |
|
28 | + * |
|
29 | + * @param Certificate $cert |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + abstract public function identifiesPKC(Certificate $cert); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Initialize from distinguished name. |
|
36 | - * |
|
37 | - * This conforms to RFC 5755 which states that only v2Form must be used, |
|
38 | - * and issuerName must contain exactly one GeneralName of DirectoryName |
|
39 | - * type. |
|
40 | - * |
|
41 | - * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
42 | - * @param Name $name |
|
43 | - * @return self |
|
44 | - */ |
|
45 | - public static function fromName(Name $name) |
|
46 | - { |
|
47 | - return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
48 | - } |
|
34 | + /** |
|
35 | + * Initialize from distinguished name. |
|
36 | + * |
|
37 | + * This conforms to RFC 5755 which states that only v2Form must be used, |
|
38 | + * and issuerName must contain exactly one GeneralName of DirectoryName |
|
39 | + * type. |
|
40 | + * |
|
41 | + * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
42 | + * @param Name $name |
|
43 | + * @return self |
|
44 | + */ |
|
45 | + public static function fromName(Name $name) |
|
46 | + { |
|
47 | + return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Initialize from an issuer's public key certificate. |
|
52 | - * |
|
53 | - * @param Certificate $cert |
|
54 | - * @return self |
|
55 | - */ |
|
56 | - public static function fromPKC(Certificate $cert) |
|
57 | - { |
|
58 | - return self::fromName($cert->tbsCertificate()->subject()); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Initialize from an issuer's public key certificate. |
|
52 | + * |
|
53 | + * @param Certificate $cert |
|
54 | + * @return self |
|
55 | + */ |
|
56 | + public static function fromPKC(Certificate $cert) |
|
57 | + { |
|
58 | + return self::fromName($cert->tbsCertificate()->subject()); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Initialize from ASN.1. |
|
63 | - * |
|
64 | - * @param UnspecifiedType $el CHOICE |
|
65 | - * @throws \UnexpectedValueException |
|
66 | - * @return self |
|
67 | - */ |
|
68 | - public static function fromASN1(UnspecifiedType $el) |
|
69 | - { |
|
70 | - if (!$el->isTagged()) { |
|
71 | - throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
72 | - } |
|
73 | - $tagged = $el->asTagged(); |
|
74 | - switch ($tagged->tag()) { |
|
75 | - case 0: |
|
76 | - return V2Form::fromV2ASN1( |
|
77 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
78 | - } |
|
79 | - throw new \UnexpectedValueException("Unsupported issuer type."); |
|
80 | - } |
|
61 | + /** |
|
62 | + * Initialize from ASN.1. |
|
63 | + * |
|
64 | + * @param UnspecifiedType $el CHOICE |
|
65 | + * @throws \UnexpectedValueException |
|
66 | + * @return self |
|
67 | + */ |
|
68 | + public static function fromASN1(UnspecifiedType $el) |
|
69 | + { |
|
70 | + if (!$el->isTagged()) { |
|
71 | + throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
72 | + } |
|
73 | + $tagged = $el->asTagged(); |
|
74 | + switch ($tagged->tag()) { |
|
75 | + case 0: |
|
76 | + return V2Form::fromV2ASN1( |
|
77 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
78 | + } |
|
79 | + throw new \UnexpectedValueException("Unsupported issuer type."); |
|
80 | + } |
|
81 | 81 | } |
@@ -72,9 +72,9 @@ |
||
72 | 72 | } |
73 | 73 | $tagged = $el->asTagged(); |
74 | 74 | switch ($tagged->tag()) { |
75 | - case 0: |
|
76 | - return V2Form::fromV2ASN1( |
|
77 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
75 | + case 0: |
|
76 | + return V2Form::fromV2ASN1( |
|
77 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
78 | 78 | } |
79 | 79 | throw new \UnexpectedValueException("Unsupported issuer type."); |
80 | 80 | } |
@@ -18,203 +18,203 @@ |
||
18 | 18 | */ |
19 | 19 | class AttributeCertificate |
20 | 20 | { |
21 | - /** |
|
22 | - * Attribute certificate info. |
|
23 | - * |
|
24 | - * @var AttributeCertificateInfo $_acinfo |
|
25 | - */ |
|
26 | - protected $_acinfo; |
|
27 | - |
|
28 | - /** |
|
29 | - * Signature algorithm identifier. |
|
30 | - * |
|
31 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
32 | - */ |
|
33 | - protected $_signatureAlgorithm; |
|
34 | - |
|
35 | - /** |
|
36 | - * Signature value. |
|
37 | - * |
|
38 | - * @var Signature $_signatureValue |
|
39 | - */ |
|
40 | - protected $_signatureValue; |
|
41 | - |
|
42 | - /** |
|
43 | - * Constructor. |
|
44 | - * |
|
45 | - * @param AttributeCertificateInfo $acinfo |
|
46 | - * @param SignatureAlgorithmIdentifier $algo |
|
47 | - * @param Signature $signature |
|
48 | - */ |
|
49 | - public function __construct(AttributeCertificateInfo $acinfo, |
|
50 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
51 | - { |
|
52 | - $this->_acinfo = $acinfo; |
|
53 | - $this->_signatureAlgorithm = $algo; |
|
54 | - $this->_signatureValue = $signature; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Initialize from ASN.1. |
|
59 | - * |
|
60 | - * @param Sequence $seq |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - public static function fromASN1(Sequence $seq) |
|
64 | - { |
|
65 | - $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
66 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
67 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
68 | - throw new \UnexpectedValueException( |
|
69 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
70 | - } |
|
71 | - $signature = Signature::fromSignatureData( |
|
72 | - $seq->at(2) |
|
73 | - ->asBitString() |
|
74 | - ->string(), $algo); |
|
75 | - return new self($acinfo, $algo, $signature); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Initialize from DER data. |
|
80 | - * |
|
81 | - * @param string $data |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public static function fromDER($data) |
|
85 | - { |
|
86 | - return self::fromASN1(Sequence::fromDER($data)); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Initialize from PEM. |
|
91 | - * |
|
92 | - * @param PEM $pem |
|
93 | - * @throws \UnexpectedValueException |
|
94 | - * @return self |
|
95 | - */ |
|
96 | - public static function fromPEM(PEM $pem) |
|
97 | - { |
|
98 | - if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
99 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
100 | - } |
|
101 | - return self::fromDER($pem->data()); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Get attribute certificate info. |
|
106 | - * |
|
107 | - * @return AttributeCertificateInfo |
|
108 | - */ |
|
109 | - public function acinfo() |
|
110 | - { |
|
111 | - return $this->_acinfo; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Get signature algorithm identifier. |
|
116 | - * |
|
117 | - * @return SignatureAlgorithmIdentifier |
|
118 | - */ |
|
119 | - public function signatureAlgorithm() |
|
120 | - { |
|
121 | - return $this->_signatureAlgorithm; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get signature value. |
|
126 | - * |
|
127 | - * @return Signature |
|
128 | - */ |
|
129 | - public function signatureValue() |
|
130 | - { |
|
131 | - return $this->_signatureValue; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Get ASN.1 structure. |
|
136 | - * |
|
137 | - * @return Sequence |
|
138 | - */ |
|
139 | - public function toASN1() |
|
140 | - { |
|
141 | - return new Sequence($this->_acinfo->toASN1(), |
|
142 | - $this->_signatureAlgorithm->toASN1(), |
|
143 | - $this->_signatureValue->bitString()); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get attribute certificate as a DER. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function toDER() |
|
152 | - { |
|
153 | - return $this->toASN1()->toDER(); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get attribute certificate as a PEM. |
|
158 | - * |
|
159 | - * @return PEM |
|
160 | - */ |
|
161 | - public function toPEM() |
|
162 | - { |
|
163 | - return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Check whether attribute certificate is issued to the subject identified |
|
168 | - * by given public key certificate. |
|
169 | - * |
|
170 | - * @param Certificate $cert Certificate |
|
171 | - * @return boolean |
|
172 | - */ |
|
173 | - public function isHeldBy(Certificate $cert) |
|
174 | - { |
|
175 | - if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
176 | - return false; |
|
177 | - } |
|
178 | - return true; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Check whether attribute certificate is issued by given public key |
|
183 | - * certificate. |
|
184 | - * |
|
185 | - * @param Certificate $cert Certificate |
|
186 | - * @return boolean |
|
187 | - */ |
|
188 | - public function isIssuedBy(Certificate $cert) |
|
189 | - { |
|
190 | - if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
191 | - return false; |
|
192 | - } |
|
193 | - return true; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Verify signature. |
|
198 | - * |
|
199 | - * @param PublicKeyInfo $pubkey_info Signer's public key |
|
200 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null) |
|
204 | - { |
|
205 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
206 | - $data = $this->_acinfo->toASN1()->toDER(); |
|
207 | - return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
208 | - $this->_signatureAlgorithm); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Get attribute certificate as a PEM formatted string. |
|
213 | - * |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public function __toString() |
|
217 | - { |
|
218 | - return $this->toPEM()->string(); |
|
219 | - } |
|
21 | + /** |
|
22 | + * Attribute certificate info. |
|
23 | + * |
|
24 | + * @var AttributeCertificateInfo $_acinfo |
|
25 | + */ |
|
26 | + protected $_acinfo; |
|
27 | + |
|
28 | + /** |
|
29 | + * Signature algorithm identifier. |
|
30 | + * |
|
31 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
32 | + */ |
|
33 | + protected $_signatureAlgorithm; |
|
34 | + |
|
35 | + /** |
|
36 | + * Signature value. |
|
37 | + * |
|
38 | + * @var Signature $_signatureValue |
|
39 | + */ |
|
40 | + protected $_signatureValue; |
|
41 | + |
|
42 | + /** |
|
43 | + * Constructor. |
|
44 | + * |
|
45 | + * @param AttributeCertificateInfo $acinfo |
|
46 | + * @param SignatureAlgorithmIdentifier $algo |
|
47 | + * @param Signature $signature |
|
48 | + */ |
|
49 | + public function __construct(AttributeCertificateInfo $acinfo, |
|
50 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
51 | + { |
|
52 | + $this->_acinfo = $acinfo; |
|
53 | + $this->_signatureAlgorithm = $algo; |
|
54 | + $this->_signatureValue = $signature; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Initialize from ASN.1. |
|
59 | + * |
|
60 | + * @param Sequence $seq |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + public static function fromASN1(Sequence $seq) |
|
64 | + { |
|
65 | + $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
66 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
67 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
68 | + throw new \UnexpectedValueException( |
|
69 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
70 | + } |
|
71 | + $signature = Signature::fromSignatureData( |
|
72 | + $seq->at(2) |
|
73 | + ->asBitString() |
|
74 | + ->string(), $algo); |
|
75 | + return new self($acinfo, $algo, $signature); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Initialize from DER data. |
|
80 | + * |
|
81 | + * @param string $data |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public static function fromDER($data) |
|
85 | + { |
|
86 | + return self::fromASN1(Sequence::fromDER($data)); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Initialize from PEM. |
|
91 | + * |
|
92 | + * @param PEM $pem |
|
93 | + * @throws \UnexpectedValueException |
|
94 | + * @return self |
|
95 | + */ |
|
96 | + public static function fromPEM(PEM $pem) |
|
97 | + { |
|
98 | + if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
99 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
100 | + } |
|
101 | + return self::fromDER($pem->data()); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Get attribute certificate info. |
|
106 | + * |
|
107 | + * @return AttributeCertificateInfo |
|
108 | + */ |
|
109 | + public function acinfo() |
|
110 | + { |
|
111 | + return $this->_acinfo; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Get signature algorithm identifier. |
|
116 | + * |
|
117 | + * @return SignatureAlgorithmIdentifier |
|
118 | + */ |
|
119 | + public function signatureAlgorithm() |
|
120 | + { |
|
121 | + return $this->_signatureAlgorithm; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get signature value. |
|
126 | + * |
|
127 | + * @return Signature |
|
128 | + */ |
|
129 | + public function signatureValue() |
|
130 | + { |
|
131 | + return $this->_signatureValue; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Get ASN.1 structure. |
|
136 | + * |
|
137 | + * @return Sequence |
|
138 | + */ |
|
139 | + public function toASN1() |
|
140 | + { |
|
141 | + return new Sequence($this->_acinfo->toASN1(), |
|
142 | + $this->_signatureAlgorithm->toASN1(), |
|
143 | + $this->_signatureValue->bitString()); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get attribute certificate as a DER. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function toDER() |
|
152 | + { |
|
153 | + return $this->toASN1()->toDER(); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get attribute certificate as a PEM. |
|
158 | + * |
|
159 | + * @return PEM |
|
160 | + */ |
|
161 | + public function toPEM() |
|
162 | + { |
|
163 | + return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Check whether attribute certificate is issued to the subject identified |
|
168 | + * by given public key certificate. |
|
169 | + * |
|
170 | + * @param Certificate $cert Certificate |
|
171 | + * @return boolean |
|
172 | + */ |
|
173 | + public function isHeldBy(Certificate $cert) |
|
174 | + { |
|
175 | + if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
176 | + return false; |
|
177 | + } |
|
178 | + return true; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Check whether attribute certificate is issued by given public key |
|
183 | + * certificate. |
|
184 | + * |
|
185 | + * @param Certificate $cert Certificate |
|
186 | + * @return boolean |
|
187 | + */ |
|
188 | + public function isIssuedBy(Certificate $cert) |
|
189 | + { |
|
190 | + if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
191 | + return false; |
|
192 | + } |
|
193 | + return true; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Verify signature. |
|
198 | + * |
|
199 | + * @param PublicKeyInfo $pubkey_info Signer's public key |
|
200 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null) |
|
204 | + { |
|
205 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
206 | + $data = $this->_acinfo->toASN1()->toDER(); |
|
207 | + return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
208 | + $this->_signatureAlgorithm); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Get attribute certificate as a PEM formatted string. |
|
213 | + * |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public function __toString() |
|
217 | + { |
|
218 | + return $this->toPEM()->string(); |
|
219 | + } |
|
220 | 220 | } |
@@ -13,94 +13,94 @@ |
||
13 | 13 | */ |
14 | 14 | class AttCertValidityPeriod |
15 | 15 | { |
16 | - use DateTimeHelper; |
|
16 | + use DateTimeHelper; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Not before time. |
|
20 | - * |
|
21 | - * @var \DateTimeImmutable |
|
22 | - */ |
|
23 | - protected $_notBeforeTime; |
|
18 | + /** |
|
19 | + * Not before time. |
|
20 | + * |
|
21 | + * @var \DateTimeImmutable |
|
22 | + */ |
|
23 | + protected $_notBeforeTime; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Not after time. |
|
27 | - * |
|
28 | - * @var \DateTimeImmutable |
|
29 | - */ |
|
30 | - protected $_notAfterTime; |
|
25 | + /** |
|
26 | + * Not after time. |
|
27 | + * |
|
28 | + * @var \DateTimeImmutable |
|
29 | + */ |
|
30 | + protected $_notAfterTime; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor. |
|
34 | - * |
|
35 | - * @param \DateTimeImmutable $nb |
|
36 | - * @param \DateTimeImmutable $na |
|
37 | - */ |
|
38 | - public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
39 | - { |
|
40 | - $this->_notBeforeTime = $nb; |
|
41 | - $this->_notAfterTime = $na; |
|
42 | - } |
|
32 | + /** |
|
33 | + * Constructor. |
|
34 | + * |
|
35 | + * @param \DateTimeImmutable $nb |
|
36 | + * @param \DateTimeImmutable $na |
|
37 | + */ |
|
38 | + public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
39 | + { |
|
40 | + $this->_notBeforeTime = $nb; |
|
41 | + $this->_notAfterTime = $na; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Initialize from ASN.1. |
|
46 | - * |
|
47 | - * @param Sequence $seq |
|
48 | - * @return self |
|
49 | - */ |
|
50 | - public static function fromASN1(Sequence $seq) |
|
51 | - { |
|
52 | - $nb = $seq->at(0) |
|
53 | - ->asGeneralizedTime() |
|
54 | - ->dateTime(); |
|
55 | - $na = $seq->at(1) |
|
56 | - ->asGeneralizedTime() |
|
57 | - ->dateTime(); |
|
58 | - return new self($nb, $na); |
|
59 | - } |
|
44 | + /** |
|
45 | + * Initialize from ASN.1. |
|
46 | + * |
|
47 | + * @param Sequence $seq |
|
48 | + * @return self |
|
49 | + */ |
|
50 | + public static function fromASN1(Sequence $seq) |
|
51 | + { |
|
52 | + $nb = $seq->at(0) |
|
53 | + ->asGeneralizedTime() |
|
54 | + ->dateTime(); |
|
55 | + $na = $seq->at(1) |
|
56 | + ->asGeneralizedTime() |
|
57 | + ->dateTime(); |
|
58 | + return new self($nb, $na); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Initialize from date strings. |
|
63 | - * |
|
64 | - * @param string|null $nb_date Not before date |
|
65 | - * @param string|null $na_date Not after date |
|
66 | - * @param string|null $tz Timezone string |
|
67 | - * @return self |
|
68 | - */ |
|
69 | - public static function fromStrings($nb_date, $na_date, $tz = null) |
|
70 | - { |
|
71 | - $nb = self::_createDateTime($nb_date, $tz); |
|
72 | - $na = self::_createDateTime($na_date, $tz); |
|
73 | - return new self($nb, $na); |
|
74 | - } |
|
61 | + /** |
|
62 | + * Initialize from date strings. |
|
63 | + * |
|
64 | + * @param string|null $nb_date Not before date |
|
65 | + * @param string|null $na_date Not after date |
|
66 | + * @param string|null $tz Timezone string |
|
67 | + * @return self |
|
68 | + */ |
|
69 | + public static function fromStrings($nb_date, $na_date, $tz = null) |
|
70 | + { |
|
71 | + $nb = self::_createDateTime($nb_date, $tz); |
|
72 | + $na = self::_createDateTime($na_date, $tz); |
|
73 | + return new self($nb, $na); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Get not before time. |
|
78 | - * |
|
79 | - * @return \DateTimeImmutable |
|
80 | - */ |
|
81 | - public function notBeforeTime() |
|
82 | - { |
|
83 | - return $this->_notBeforeTime; |
|
84 | - } |
|
76 | + /** |
|
77 | + * Get not before time. |
|
78 | + * |
|
79 | + * @return \DateTimeImmutable |
|
80 | + */ |
|
81 | + public function notBeforeTime() |
|
82 | + { |
|
83 | + return $this->_notBeforeTime; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get not after time. |
|
88 | - * |
|
89 | - * @return \DateTimeImmutable |
|
90 | - */ |
|
91 | - public function notAfterTime() |
|
92 | - { |
|
93 | - return $this->_notAfterTime; |
|
94 | - } |
|
86 | + /** |
|
87 | + * Get not after time. |
|
88 | + * |
|
89 | + * @return \DateTimeImmutable |
|
90 | + */ |
|
91 | + public function notAfterTime() |
|
92 | + { |
|
93 | + return $this->_notAfterTime; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Generate ASN.1 structure. |
|
98 | - * |
|
99 | - * @return Sequence |
|
100 | - */ |
|
101 | - public function toASN1() |
|
102 | - { |
|
103 | - return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
104 | - new GeneralizedTime($this->_notAfterTime)); |
|
105 | - } |
|
96 | + /** |
|
97 | + * Generate ASN.1 structure. |
|
98 | + * |
|
99 | + * @return Sequence |
|
100 | + */ |
|
101 | + public function toASN1() |
|
102 | + { |
|
103 | + return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
104 | + new GeneralizedTime($this->_notAfterTime)); |
|
105 | + } |
|
106 | 106 | } |
@@ -10,112 +10,112 @@ |
||
10 | 10 | */ |
11 | 11 | class ACValidationConfig |
12 | 12 | { |
13 | - /** |
|
14 | - * Certification path of the AC holder. |
|
15 | - * |
|
16 | - * @var CertificationPath |
|
17 | - */ |
|
18 | - protected $_holderPath; |
|
13 | + /** |
|
14 | + * Certification path of the AC holder. |
|
15 | + * |
|
16 | + * @var CertificationPath |
|
17 | + */ |
|
18 | + protected $_holderPath; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Certification path of the AC issuer. |
|
22 | - * |
|
23 | - * @var CertificationPath |
|
24 | - */ |
|
25 | - protected $_issuerPath; |
|
20 | + /** |
|
21 | + * Certification path of the AC issuer. |
|
22 | + * |
|
23 | + * @var CertificationPath |
|
24 | + */ |
|
25 | + protected $_issuerPath; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Evaluation reference time. |
|
29 | - * |
|
30 | - * @var \DateTimeImmutable |
|
31 | - */ |
|
32 | - protected $_evalTime; |
|
27 | + /** |
|
28 | + * Evaluation reference time. |
|
29 | + * |
|
30 | + * @var \DateTimeImmutable |
|
31 | + */ |
|
32 | + protected $_evalTime; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Permitted targets. |
|
36 | - * |
|
37 | - * @var Target[] |
|
38 | - */ |
|
39 | - protected $_targets; |
|
34 | + /** |
|
35 | + * Permitted targets. |
|
36 | + * |
|
37 | + * @var Target[] |
|
38 | + */ |
|
39 | + protected $_targets; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor. |
|
43 | - * |
|
44 | - * @param CertificationPath $holder_path Certification path of the AC holder |
|
45 | - * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
46 | - */ |
|
47 | - public function __construct(CertificationPath $holder_path, |
|
48 | - CertificationPath $issuer_path) |
|
49 | - { |
|
50 | - $this->_holderPath = $holder_path; |
|
51 | - $this->_issuerPath = $issuer_path; |
|
52 | - $this->_evalTime = new \DateTimeImmutable(); |
|
53 | - $this->_targets = array(); |
|
54 | - } |
|
41 | + /** |
|
42 | + * Constructor. |
|
43 | + * |
|
44 | + * @param CertificationPath $holder_path Certification path of the AC holder |
|
45 | + * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
46 | + */ |
|
47 | + public function __construct(CertificationPath $holder_path, |
|
48 | + CertificationPath $issuer_path) |
|
49 | + { |
|
50 | + $this->_holderPath = $holder_path; |
|
51 | + $this->_issuerPath = $issuer_path; |
|
52 | + $this->_evalTime = new \DateTimeImmutable(); |
|
53 | + $this->_targets = array(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get certification path of the AC's holder. |
|
58 | - * |
|
59 | - * @return CertificationPath |
|
60 | - */ |
|
61 | - public function holderPath() |
|
62 | - { |
|
63 | - return $this->_holderPath; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Get certification path of the AC's holder. |
|
58 | + * |
|
59 | + * @return CertificationPath |
|
60 | + */ |
|
61 | + public function holderPath() |
|
62 | + { |
|
63 | + return $this->_holderPath; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Get certification path of the AC's issuer. |
|
68 | - * |
|
69 | - * @return CertificationPath |
|
70 | - */ |
|
71 | - public function issuerPath() |
|
72 | - { |
|
73 | - return $this->_issuerPath; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Get certification path of the AC's issuer. |
|
68 | + * |
|
69 | + * @return CertificationPath |
|
70 | + */ |
|
71 | + public function issuerPath() |
|
72 | + { |
|
73 | + return $this->_issuerPath; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Get self with given evaluation reference time. |
|
78 | - * |
|
79 | - * @param \DateTimeImmutable $dt |
|
80 | - * @return self |
|
81 | - */ |
|
82 | - public function withEvaluationTime(\DateTimeImmutable $dt) |
|
83 | - { |
|
84 | - $obj = clone $this; |
|
85 | - $obj->_evalTime = $dt; |
|
86 | - return $obj; |
|
87 | - } |
|
76 | + /** |
|
77 | + * Get self with given evaluation reference time. |
|
78 | + * |
|
79 | + * @param \DateTimeImmutable $dt |
|
80 | + * @return self |
|
81 | + */ |
|
82 | + public function withEvaluationTime(\DateTimeImmutable $dt) |
|
83 | + { |
|
84 | + $obj = clone $this; |
|
85 | + $obj->_evalTime = $dt; |
|
86 | + return $obj; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Get the evaluation reference time. |
|
91 | - * |
|
92 | - * @return \DateTimeImmutable |
|
93 | - */ |
|
94 | - public function evaluationTime() |
|
95 | - { |
|
96 | - return $this->_evalTime; |
|
97 | - } |
|
89 | + /** |
|
90 | + * Get the evaluation reference time. |
|
91 | + * |
|
92 | + * @return \DateTimeImmutable |
|
93 | + */ |
|
94 | + public function evaluationTime() |
|
95 | + { |
|
96 | + return $this->_evalTime; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get self with permitted targets. |
|
101 | - * |
|
102 | - * @param Target ...$targets |
|
103 | - * @return self |
|
104 | - */ |
|
105 | - public function withTargets(Target ...$targets) |
|
106 | - { |
|
107 | - $obj = clone $this; |
|
108 | - $obj->_targets = $targets; |
|
109 | - return $obj; |
|
110 | - } |
|
99 | + /** |
|
100 | + * Get self with permitted targets. |
|
101 | + * |
|
102 | + * @param Target ...$targets |
|
103 | + * @return self |
|
104 | + */ |
|
105 | + public function withTargets(Target ...$targets) |
|
106 | + { |
|
107 | + $obj = clone $this; |
|
108 | + $obj->_targets = $targets; |
|
109 | + return $obj; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Get array of permitted targets |
|
114 | - * |
|
115 | - * @return Target[] |
|
116 | - */ |
|
117 | - public function targets() |
|
118 | - { |
|
119 | - return $this->_targets; |
|
120 | - } |
|
112 | + /** |
|
113 | + * Get array of permitted targets |
|
114 | + * |
|
115 | + * @return Target[] |
|
116 | + */ |
|
117 | + public function targets() |
|
118 | + { |
|
119 | + return $this->_targets; |
|
120 | + } |
|
121 | 121 | } |
@@ -19,178 +19,178 @@ |
||
19 | 19 | */ |
20 | 20 | class ACValidator |
21 | 21 | { |
22 | - /** |
|
23 | - * Attribute certificate. |
|
24 | - * |
|
25 | - * @var AttributeCertificate |
|
26 | - */ |
|
27 | - protected $_ac; |
|
22 | + /** |
|
23 | + * Attribute certificate. |
|
24 | + * |
|
25 | + * @var AttributeCertificate |
|
26 | + */ |
|
27 | + protected $_ac; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Validation configuration. |
|
31 | - * |
|
32 | - * @var ACValidationConfig |
|
33 | - */ |
|
34 | - protected $_config; |
|
29 | + /** |
|
30 | + * Validation configuration. |
|
31 | + * |
|
32 | + * @var ACValidationConfig |
|
33 | + */ |
|
34 | + protected $_config; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Crypto engine. |
|
38 | - * |
|
39 | - * @var Crypto |
|
40 | - */ |
|
41 | - protected $_crypto; |
|
36 | + /** |
|
37 | + * Crypto engine. |
|
38 | + * |
|
39 | + * @var Crypto |
|
40 | + */ |
|
41 | + protected $_crypto; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param AttributeCertificate $ac Attribute certificate to validate |
|
47 | - * @param ACValidationConfig $config Validation configuration |
|
48 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
49 | - */ |
|
50 | - public function __construct(AttributeCertificate $ac, |
|
51 | - ACValidationConfig $config, Crypto $crypto = null) |
|
52 | - { |
|
53 | - $this->_ac = $ac; |
|
54 | - $this->_config = $config; |
|
55 | - $this->_crypto = $crypto ?: Crypto::getDefault(); |
|
56 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param AttributeCertificate $ac Attribute certificate to validate |
|
47 | + * @param ACValidationConfig $config Validation configuration |
|
48 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
49 | + */ |
|
50 | + public function __construct(AttributeCertificate $ac, |
|
51 | + ACValidationConfig $config, Crypto $crypto = null) |
|
52 | + { |
|
53 | + $this->_ac = $ac; |
|
54 | + $this->_config = $config; |
|
55 | + $this->_crypto = $crypto ?: Crypto::getDefault(); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Validate attribute certificate. |
|
60 | - * |
|
61 | - * @throws ACValidationException If validation fails |
|
62 | - * @return AttributeCertificate Validated AC |
|
63 | - */ |
|
64 | - public function validate() |
|
65 | - { |
|
66 | - $this->_validateHolder(); |
|
67 | - $issuer = $this->_verifyIssuer(); |
|
68 | - $this->_validateIssuerProfile($issuer); |
|
69 | - $this->_validateTime(); |
|
70 | - $this->_validateTargeting(); |
|
71 | - return $this->_ac; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Validate attribute certificate. |
|
60 | + * |
|
61 | + * @throws ACValidationException If validation fails |
|
62 | + * @return AttributeCertificate Validated AC |
|
63 | + */ |
|
64 | + public function validate() |
|
65 | + { |
|
66 | + $this->_validateHolder(); |
|
67 | + $issuer = $this->_verifyIssuer(); |
|
68 | + $this->_validateIssuerProfile($issuer); |
|
69 | + $this->_validateTime(); |
|
70 | + $this->_validateTargeting(); |
|
71 | + return $this->_ac; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Validate AC holder's certification. |
|
76 | - * |
|
77 | - * @throws ACValidationException |
|
78 | - * @return Certificate Certificate of the AC's holder |
|
79 | - */ |
|
80 | - private function _validateHolder() |
|
81 | - { |
|
82 | - $path = $this->_config->holderPath(); |
|
83 | - $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
84 | - count($path))->withDateTime($this->_config->evaluationTime()); |
|
85 | - try { |
|
86 | - $holder = $path->validate($config, $this->_crypto)->certificate(); |
|
87 | - } catch (PathValidationException $e) { |
|
88 | - throw new ACValidationException( |
|
89 | - "Failed to validate holder PKC's certification path.", null, $e); |
|
90 | - } |
|
91 | - if (!$this->_ac->isHeldBy($holder)) { |
|
92 | - throw new ACValidationException("Name mismatch of AC's holder PKC."); |
|
93 | - } |
|
94 | - return $holder; |
|
95 | - } |
|
74 | + /** |
|
75 | + * Validate AC holder's certification. |
|
76 | + * |
|
77 | + * @throws ACValidationException |
|
78 | + * @return Certificate Certificate of the AC's holder |
|
79 | + */ |
|
80 | + private function _validateHolder() |
|
81 | + { |
|
82 | + $path = $this->_config->holderPath(); |
|
83 | + $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
84 | + count($path))->withDateTime($this->_config->evaluationTime()); |
|
85 | + try { |
|
86 | + $holder = $path->validate($config, $this->_crypto)->certificate(); |
|
87 | + } catch (PathValidationException $e) { |
|
88 | + throw new ACValidationException( |
|
89 | + "Failed to validate holder PKC's certification path.", null, $e); |
|
90 | + } |
|
91 | + if (!$this->_ac->isHeldBy($holder)) { |
|
92 | + throw new ACValidationException("Name mismatch of AC's holder PKC."); |
|
93 | + } |
|
94 | + return $holder; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Verify AC's signature and issuer's certification. |
|
99 | - * |
|
100 | - * @throws ACValidationException |
|
101 | - * @return Certificate Certificate of the AC's issuer |
|
102 | - */ |
|
103 | - private function _verifyIssuer() |
|
104 | - { |
|
105 | - $path = $this->_config->issuerPath(); |
|
106 | - $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
107 | - count($path))->withDateTime($this->_config->evaluationTime()); |
|
108 | - try { |
|
109 | - $issuer = $path->validate($config, $this->_crypto)->certificate(); |
|
110 | - } catch (PathValidationException $e) { |
|
111 | - throw new ACValidationException( |
|
112 | - "Failed to validate issuer PKC's certification path.", null, $e); |
|
113 | - } |
|
114 | - if (!$this->_ac->isIssuedBy($issuer)) { |
|
115 | - throw new ACValidationException("Name mismatch of AC's issuer PKC."); |
|
116 | - } |
|
117 | - $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo(); |
|
118 | - if (!$this->_ac->verify($pubkey_info, $this->_crypto)) { |
|
119 | - throw new ACValidationException("Failed to verify signature."); |
|
120 | - } |
|
121 | - return $issuer; |
|
122 | - } |
|
97 | + /** |
|
98 | + * Verify AC's signature and issuer's certification. |
|
99 | + * |
|
100 | + * @throws ACValidationException |
|
101 | + * @return Certificate Certificate of the AC's issuer |
|
102 | + */ |
|
103 | + private function _verifyIssuer() |
|
104 | + { |
|
105 | + $path = $this->_config->issuerPath(); |
|
106 | + $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
107 | + count($path))->withDateTime($this->_config->evaluationTime()); |
|
108 | + try { |
|
109 | + $issuer = $path->validate($config, $this->_crypto)->certificate(); |
|
110 | + } catch (PathValidationException $e) { |
|
111 | + throw new ACValidationException( |
|
112 | + "Failed to validate issuer PKC's certification path.", null, $e); |
|
113 | + } |
|
114 | + if (!$this->_ac->isIssuedBy($issuer)) { |
|
115 | + throw new ACValidationException("Name mismatch of AC's issuer PKC."); |
|
116 | + } |
|
117 | + $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo(); |
|
118 | + if (!$this->_ac->verify($pubkey_info, $this->_crypto)) { |
|
119 | + throw new ACValidationException("Failed to verify signature."); |
|
120 | + } |
|
121 | + return $issuer; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Validate AC issuer's profile. |
|
126 | - * |
|
127 | - * @link https://tools.ietf.org/html/rfc5755#section-4.5 |
|
128 | - * @param Certificate $cert |
|
129 | - * @throws ACValidationException |
|
130 | - */ |
|
131 | - private function _validateIssuerProfile(Certificate $cert) |
|
132 | - { |
|
133 | - $exts = $cert->tbsCertificate()->extensions(); |
|
134 | - if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) { |
|
135 | - throw new ACValidationException( |
|
136 | - "Issuer PKC's Key Usage extension doesn't permit" . |
|
137 | - " verification of digital signatures."); |
|
138 | - } |
|
139 | - if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) { |
|
140 | - throw new ACValidationException("Issuer PKC must not be a CA."); |
|
141 | - } |
|
142 | - } |
|
124 | + /** |
|
125 | + * Validate AC issuer's profile. |
|
126 | + * |
|
127 | + * @link https://tools.ietf.org/html/rfc5755#section-4.5 |
|
128 | + * @param Certificate $cert |
|
129 | + * @throws ACValidationException |
|
130 | + */ |
|
131 | + private function _validateIssuerProfile(Certificate $cert) |
|
132 | + { |
|
133 | + $exts = $cert->tbsCertificate()->extensions(); |
|
134 | + if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) { |
|
135 | + throw new ACValidationException( |
|
136 | + "Issuer PKC's Key Usage extension doesn't permit" . |
|
137 | + " verification of digital signatures."); |
|
138 | + } |
|
139 | + if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) { |
|
140 | + throw new ACValidationException("Issuer PKC must not be a CA."); |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Validate AC's validity period. |
|
146 | - * |
|
147 | - * @throws ACValidationException |
|
148 | - */ |
|
149 | - private function _validateTime() |
|
150 | - { |
|
151 | - $t = $this->_config->evaluationTime(); |
|
152 | - $validity = $this->_ac->acinfo()->validityPeriod(); |
|
153 | - if ($validity->notBeforeTime()->diff($t)->invert) { |
|
154 | - throw new ACValidationException("Validity period has not started."); |
|
155 | - } |
|
156 | - if ($t->diff($validity->notAfterTime())->invert) { |
|
157 | - throw new ACValidationException("Attribute certificate has expired."); |
|
158 | - } |
|
159 | - } |
|
144 | + /** |
|
145 | + * Validate AC's validity period. |
|
146 | + * |
|
147 | + * @throws ACValidationException |
|
148 | + */ |
|
149 | + private function _validateTime() |
|
150 | + { |
|
151 | + $t = $this->_config->evaluationTime(); |
|
152 | + $validity = $this->_ac->acinfo()->validityPeriod(); |
|
153 | + if ($validity->notBeforeTime()->diff($t)->invert) { |
|
154 | + throw new ACValidationException("Validity period has not started."); |
|
155 | + } |
|
156 | + if ($t->diff($validity->notAfterTime())->invert) { |
|
157 | + throw new ACValidationException("Attribute certificate has expired."); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Validate AC's target information. |
|
163 | - * |
|
164 | - * @throws ACValidationException |
|
165 | - */ |
|
166 | - private function _validateTargeting() |
|
167 | - { |
|
168 | - $exts = $this->_ac->acinfo()->extensions(); |
|
169 | - // if target information extension is not present |
|
170 | - if (!$exts->has(Extension::OID_TARGET_INFORMATION)) { |
|
171 | - return; |
|
172 | - } |
|
173 | - $ext = $exts->get(Extension::OID_TARGET_INFORMATION); |
|
174 | - if ($ext instanceof TargetInformationExtension && |
|
175 | - !$this->_hasMatchingTarget($ext->targets())) { |
|
176 | - throw new ACValidationException( |
|
177 | - "Attribute certificate doesn't have a matching target."); |
|
178 | - } |
|
179 | - } |
|
161 | + /** |
|
162 | + * Validate AC's target information. |
|
163 | + * |
|
164 | + * @throws ACValidationException |
|
165 | + */ |
|
166 | + private function _validateTargeting() |
|
167 | + { |
|
168 | + $exts = $this->_ac->acinfo()->extensions(); |
|
169 | + // if target information extension is not present |
|
170 | + if (!$exts->has(Extension::OID_TARGET_INFORMATION)) { |
|
171 | + return; |
|
172 | + } |
|
173 | + $ext = $exts->get(Extension::OID_TARGET_INFORMATION); |
|
174 | + if ($ext instanceof TargetInformationExtension && |
|
175 | + !$this->_hasMatchingTarget($ext->targets())) { |
|
176 | + throw new ACValidationException( |
|
177 | + "Attribute certificate doesn't have a matching target."); |
|
178 | + } |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Check whether validation configuration has matching targets. |
|
183 | - * |
|
184 | - * @param Targets $targets Set of eligible targets |
|
185 | - * @return boolean |
|
186 | - */ |
|
187 | - private function _hasMatchingTarget(Targets $targets) |
|
188 | - { |
|
189 | - foreach ($this->_config->targets() as $target) { |
|
190 | - if ($targets->hasTarget($target)) { |
|
191 | - return true; |
|
192 | - } |
|
193 | - } |
|
194 | - return false; |
|
195 | - } |
|
181 | + /** |
|
182 | + * Check whether validation configuration has matching targets. |
|
183 | + * |
|
184 | + * @param Targets $targets Set of eligible targets |
|
185 | + * @return boolean |
|
186 | + */ |
|
187 | + private function _hasMatchingTarget(Targets $targets) |
|
188 | + { |
|
189 | + foreach ($this->_config->targets() as $target) { |
|
190 | + if ($targets->hasTarget($target)) { |
|
191 | + return true; |
|
192 | + } |
|
193 | + } |
|
194 | + return false; |
|
195 | + } |
|
196 | 196 | } |
@@ -15,143 +15,143 @@ |
||
15 | 15 | */ |
16 | 16 | class V2Form extends AttCertIssuer |
17 | 17 | { |
18 | - /** |
|
19 | - * Issuer name. |
|
20 | - * |
|
21 | - * @var GeneralNames $_issuerName |
|
22 | - */ |
|
23 | - protected $_issuerName; |
|
18 | + /** |
|
19 | + * Issuer name. |
|
20 | + * |
|
21 | + * @var GeneralNames $_issuerName |
|
22 | + */ |
|
23 | + protected $_issuerName; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Issuer PKC's issuer and serial. |
|
27 | - * |
|
28 | - * @var IssuerSerial $_baseCertificateID |
|
29 | - */ |
|
30 | - protected $_baseCertificateID; |
|
25 | + /** |
|
26 | + * Issuer PKC's issuer and serial. |
|
27 | + * |
|
28 | + * @var IssuerSerial $_baseCertificateID |
|
29 | + */ |
|
30 | + protected $_baseCertificateID; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Linked object. |
|
34 | - * |
|
35 | - * @var ObjectDigestInfo $_objectDigestInfo |
|
36 | - */ |
|
37 | - protected $_objectDigestInfo; |
|
32 | + /** |
|
33 | + * Linked object. |
|
34 | + * |
|
35 | + * @var ObjectDigestInfo $_objectDigestInfo |
|
36 | + */ |
|
37 | + protected $_objectDigestInfo; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor. |
|
41 | - * |
|
42 | - * @param GeneralNames|null $names |
|
43 | - */ |
|
44 | - public function __construct(GeneralNames $names = null) |
|
45 | - { |
|
46 | - $this->_issuerName = $names; |
|
47 | - $this->_baseCertificateID = null; |
|
48 | - $this->_objectDigestInfo = null; |
|
49 | - } |
|
39 | + /** |
|
40 | + * Constructor. |
|
41 | + * |
|
42 | + * @param GeneralNames|null $names |
|
43 | + */ |
|
44 | + public function __construct(GeneralNames $names = null) |
|
45 | + { |
|
46 | + $this->_issuerName = $names; |
|
47 | + $this->_baseCertificateID = null; |
|
48 | + $this->_objectDigestInfo = null; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Initialize from ASN.1. |
|
53 | - * |
|
54 | - * @param Sequence $seq |
|
55 | - * @return self |
|
56 | - */ |
|
57 | - public static function fromV2ASN1(Sequence $seq) |
|
58 | - { |
|
59 | - $issuer = null; |
|
60 | - $cert_id = null; |
|
61 | - $digest_info = null; |
|
62 | - if ($seq->has(0, Element::TYPE_SEQUENCE)) { |
|
63 | - $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
64 | - } |
|
65 | - if ($seq->hasTagged(0)) { |
|
66 | - $cert_id = IssuerSerial::fromASN1( |
|
67 | - $seq->getTagged(0) |
|
68 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
69 | - ->asSequence()); |
|
70 | - } |
|
71 | - if ($seq->hasTagged(1)) { |
|
72 | - $digest_info = ObjectDigestInfo::fromASN1( |
|
73 | - $seq->getTagged(1) |
|
74 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
75 | - ->asSequence()); |
|
76 | - } |
|
77 | - $obj = new self($issuer); |
|
78 | - $obj->_baseCertificateID = $cert_id; |
|
79 | - $obj->_objectDigestInfo = $digest_info; |
|
80 | - return $obj; |
|
81 | - } |
|
51 | + /** |
|
52 | + * Initialize from ASN.1. |
|
53 | + * |
|
54 | + * @param Sequence $seq |
|
55 | + * @return self |
|
56 | + */ |
|
57 | + public static function fromV2ASN1(Sequence $seq) |
|
58 | + { |
|
59 | + $issuer = null; |
|
60 | + $cert_id = null; |
|
61 | + $digest_info = null; |
|
62 | + if ($seq->has(0, Element::TYPE_SEQUENCE)) { |
|
63 | + $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
64 | + } |
|
65 | + if ($seq->hasTagged(0)) { |
|
66 | + $cert_id = IssuerSerial::fromASN1( |
|
67 | + $seq->getTagged(0) |
|
68 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
69 | + ->asSequence()); |
|
70 | + } |
|
71 | + if ($seq->hasTagged(1)) { |
|
72 | + $digest_info = ObjectDigestInfo::fromASN1( |
|
73 | + $seq->getTagged(1) |
|
74 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
75 | + ->asSequence()); |
|
76 | + } |
|
77 | + $obj = new self($issuer); |
|
78 | + $obj->_baseCertificateID = $cert_id; |
|
79 | + $obj->_objectDigestInfo = $digest_info; |
|
80 | + return $obj; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Check whether issuer name is set. |
|
85 | - * |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function hasIssuerName() |
|
89 | - { |
|
90 | - return isset($this->_issuerName); |
|
91 | - } |
|
83 | + /** |
|
84 | + * Check whether issuer name is set. |
|
85 | + * |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function hasIssuerName() |
|
89 | + { |
|
90 | + return isset($this->_issuerName); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get issuer name. |
|
95 | - * |
|
96 | - * @throws \LogicException |
|
97 | - * @return GeneralNames |
|
98 | - */ |
|
99 | - public function issuerName() |
|
100 | - { |
|
101 | - if (!$this->hasIssuerName()) { |
|
102 | - throw new \LogicException("issuerName not set."); |
|
103 | - } |
|
104 | - return $this->_issuerName; |
|
105 | - } |
|
93 | + /** |
|
94 | + * Get issuer name. |
|
95 | + * |
|
96 | + * @throws \LogicException |
|
97 | + * @return GeneralNames |
|
98 | + */ |
|
99 | + public function issuerName() |
|
100 | + { |
|
101 | + if (!$this->hasIssuerName()) { |
|
102 | + throw new \LogicException("issuerName not set."); |
|
103 | + } |
|
104 | + return $this->_issuerName; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Get DN of the issuer. |
|
109 | - * |
|
110 | - * This is a convenience method conforming to RFC 5755, which states |
|
111 | - * that Issuer must contain only one non-empty distinguished name. |
|
112 | - * |
|
113 | - * @return \X501\ASN1\Name |
|
114 | - */ |
|
115 | - public function name() |
|
116 | - { |
|
117 | - return $this->issuerName()->firstDN(); |
|
118 | - } |
|
107 | + /** |
|
108 | + * Get DN of the issuer. |
|
109 | + * |
|
110 | + * This is a convenience method conforming to RFC 5755, which states |
|
111 | + * that Issuer must contain only one non-empty distinguished name. |
|
112 | + * |
|
113 | + * @return \X501\ASN1\Name |
|
114 | + */ |
|
115 | + public function name() |
|
116 | + { |
|
117 | + return $this->issuerName()->firstDN(); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * |
|
122 | - * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
|
123 | - * @return ImplicitlyTaggedType Tagged Sequence |
|
124 | - */ |
|
125 | - public function toASN1() |
|
126 | - { |
|
127 | - $elements = array(); |
|
128 | - if (isset($this->_issuerName)) { |
|
129 | - $elements[] = $this->_issuerName->toASN1(); |
|
130 | - } |
|
131 | - if (isset($this->_baseCertificateID)) { |
|
132 | - $elements[] = new ImplicitlyTaggedType(0, |
|
133 | - $this->_baseCertificateID->toASN1()); |
|
134 | - } |
|
135 | - if (isset($this->_objectDigestInfo)) { |
|
136 | - $elements[] = new ImplicitlyTaggedType(1, |
|
137 | - $this->_objectDigestInfo->toASN1()); |
|
138 | - } |
|
139 | - return new ImplicitlyTaggedType(0, new Sequence(...$elements)); |
|
140 | - } |
|
120 | + /** |
|
121 | + * |
|
122 | + * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
|
123 | + * @return ImplicitlyTaggedType Tagged Sequence |
|
124 | + */ |
|
125 | + public function toASN1() |
|
126 | + { |
|
127 | + $elements = array(); |
|
128 | + if (isset($this->_issuerName)) { |
|
129 | + $elements[] = $this->_issuerName->toASN1(); |
|
130 | + } |
|
131 | + if (isset($this->_baseCertificateID)) { |
|
132 | + $elements[] = new ImplicitlyTaggedType(0, |
|
133 | + $this->_baseCertificateID->toASN1()); |
|
134 | + } |
|
135 | + if (isset($this->_objectDigestInfo)) { |
|
136 | + $elements[] = new ImplicitlyTaggedType(1, |
|
137 | + $this->_objectDigestInfo->toASN1()); |
|
138 | + } |
|
139 | + return new ImplicitlyTaggedType(0, new Sequence(...$elements)); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * |
|
144 | - * @see \X509\AttributeCertificate\AttCertIssuer::identifiesPKC() |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function identifiesPKC(Certificate $cert) |
|
148 | - { |
|
149 | - $name = $this->_issuerName->firstDN(); |
|
150 | - if (!$cert->tbsCertificate() |
|
151 | - ->subject() |
|
152 | - ->equals($name)) { |
|
153 | - return false; |
|
154 | - } |
|
155 | - return true; |
|
156 | - } |
|
142 | + /** |
|
143 | + * |
|
144 | + * @see \X509\AttributeCertificate\AttCertIssuer::identifiesPKC() |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function identifiesPKC(Certificate $cert) |
|
148 | + { |
|
149 | + $name = $this->_issuerName->firstDN(); |
|
150 | + if (!$cert->tbsCertificate() |
|
151 | + ->subject() |
|
152 | + ->equals($name)) { |
|
153 | + return false; |
|
154 | + } |
|
155 | + return true; |
|
156 | + } |
|
157 | 157 | } |
@@ -18,92 +18,92 @@ |
||
18 | 18 | */ |
19 | 19 | class ObjectDigestInfo |
20 | 20 | { |
21 | - const TYPE_PUBLIC_KEY = 0; |
|
22 | - const TYPE_PUBLIC_KEY_CERT = 1; |
|
23 | - const TYPE_OTHER_OBJECT_TYPES = 2; |
|
21 | + const TYPE_PUBLIC_KEY = 0; |
|
22 | + const TYPE_PUBLIC_KEY_CERT = 1; |
|
23 | + const TYPE_OTHER_OBJECT_TYPES = 2; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Object type. |
|
27 | - * |
|
28 | - * @var int $_digestedObjectType |
|
29 | - */ |
|
30 | - protected $_digestedObjectType; |
|
25 | + /** |
|
26 | + * Object type. |
|
27 | + * |
|
28 | + * @var int $_digestedObjectType |
|
29 | + */ |
|
30 | + protected $_digestedObjectType; |
|
31 | 31 | |
32 | - /** |
|
33 | - * OID of other object type. |
|
34 | - * |
|
35 | - * @var string|null $_otherObjectTypeID |
|
36 | - */ |
|
37 | - protected $_otherObjectTypeID; |
|
32 | + /** |
|
33 | + * OID of other object type. |
|
34 | + * |
|
35 | + * @var string|null $_otherObjectTypeID |
|
36 | + */ |
|
37 | + protected $_otherObjectTypeID; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Digest algorithm. |
|
41 | - * |
|
42 | - * @var AlgorithmIdentifierType $_digestAlgorithm |
|
43 | - */ |
|
44 | - protected $_digestAlgorithm; |
|
39 | + /** |
|
40 | + * Digest algorithm. |
|
41 | + * |
|
42 | + * @var AlgorithmIdentifierType $_digestAlgorithm |
|
43 | + */ |
|
44 | + protected $_digestAlgorithm; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Object digest. |
|
48 | - * |
|
49 | - * @var BitString $_objectDigest |
|
50 | - */ |
|
51 | - protected $_objectDigest; |
|
46 | + /** |
|
47 | + * Object digest. |
|
48 | + * |
|
49 | + * @var BitString $_objectDigest |
|
50 | + */ |
|
51 | + protected $_objectDigest; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Constructor. |
|
55 | - * |
|
56 | - * @param int $type |
|
57 | - * @param AlgorithmIdentifierType $algo |
|
58 | - * @param BitString $digest |
|
59 | - */ |
|
60 | - public function __construct($type, AlgorithmIdentifierType $algo, |
|
61 | - BitString $digest) |
|
62 | - { |
|
63 | - $this->_digestedObjectType = $type; |
|
64 | - $this->_otherObjectTypeID = null; |
|
65 | - $this->_digestAlgorithm = $algo; |
|
66 | - $this->_objectDigest = $digest; |
|
67 | - } |
|
53 | + /** |
|
54 | + * Constructor. |
|
55 | + * |
|
56 | + * @param int $type |
|
57 | + * @param AlgorithmIdentifierType $algo |
|
58 | + * @param BitString $digest |
|
59 | + */ |
|
60 | + public function __construct($type, AlgorithmIdentifierType $algo, |
|
61 | + BitString $digest) |
|
62 | + { |
|
63 | + $this->_digestedObjectType = $type; |
|
64 | + $this->_otherObjectTypeID = null; |
|
65 | + $this->_digestAlgorithm = $algo; |
|
66 | + $this->_objectDigest = $digest; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Initialize from ASN.1. |
|
71 | - * |
|
72 | - * @param Sequence $seq |
|
73 | - * @return self |
|
74 | - */ |
|
75 | - public static function fromASN1(Sequence $seq) |
|
76 | - { |
|
77 | - $type = $seq->at(0) |
|
78 | - ->asEnumerated() |
|
79 | - ->number(); |
|
80 | - $oid = null; |
|
81 | - $idx = 1; |
|
82 | - if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { |
|
83 | - $oid = $seq->at($idx++) |
|
84 | - ->asObjectIdentifier() |
|
85 | - ->oid(); |
|
86 | - } |
|
87 | - $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); |
|
88 | - $digest = $seq->at($idx)->asBitString(); |
|
89 | - $obj = new self($type, $algo, $digest); |
|
90 | - $obj->_otherObjectTypeID = $oid; |
|
91 | - return $obj; |
|
92 | - } |
|
69 | + /** |
|
70 | + * Initialize from ASN.1. |
|
71 | + * |
|
72 | + * @param Sequence $seq |
|
73 | + * @return self |
|
74 | + */ |
|
75 | + public static function fromASN1(Sequence $seq) |
|
76 | + { |
|
77 | + $type = $seq->at(0) |
|
78 | + ->asEnumerated() |
|
79 | + ->number(); |
|
80 | + $oid = null; |
|
81 | + $idx = 1; |
|
82 | + if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { |
|
83 | + $oid = $seq->at($idx++) |
|
84 | + ->asObjectIdentifier() |
|
85 | + ->oid(); |
|
86 | + } |
|
87 | + $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); |
|
88 | + $digest = $seq->at($idx)->asBitString(); |
|
89 | + $obj = new self($type, $algo, $digest); |
|
90 | + $obj->_otherObjectTypeID = $oid; |
|
91 | + return $obj; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Generate ASN.1 structure. |
|
96 | - * |
|
97 | - * @return Sequence |
|
98 | - */ |
|
99 | - public function toASN1() |
|
100 | - { |
|
101 | - $elements = array(new Enumerated($this->_digestedObjectType)); |
|
102 | - if (isset($this->_otherObjectTypeID)) { |
|
103 | - $elements[] = new ObjectIdentifier($this->_otherObjectTypeID); |
|
104 | - } |
|
105 | - $elements[] = $this->_digestAlgorithm->toASN1(); |
|
106 | - $elements[] = $this->_objectDigest; |
|
107 | - return new Sequence(...$elements); |
|
108 | - } |
|
94 | + /** |
|
95 | + * Generate ASN.1 structure. |
|
96 | + * |
|
97 | + * @return Sequence |
|
98 | + */ |
|
99 | + public function toASN1() |
|
100 | + { |
|
101 | + $elements = array(new Enumerated($this->_digestedObjectType)); |
|
102 | + if (isset($this->_otherObjectTypeID)) { |
|
103 | + $elements[] = new ObjectIdentifier($this->_otherObjectTypeID); |
|
104 | + } |
|
105 | + $elements[] = $this->_digestAlgorithm->toASN1(); |
|
106 | + $elements[] = $this->_objectDigest; |
|
107 | + return new Sequence(...$elements); |
|
108 | + } |
|
109 | 109 | } |
@@ -15,161 +15,161 @@ |
||
15 | 15 | */ |
16 | 16 | class IetfAttrValue |
17 | 17 | { |
18 | - /** |
|
19 | - * Element type tag. |
|
20 | - * |
|
21 | - * @var int $_type |
|
22 | - */ |
|
23 | - protected $_type; |
|
18 | + /** |
|
19 | + * Element type tag. |
|
20 | + * |
|
21 | + * @var int $_type |
|
22 | + */ |
|
23 | + protected $_type; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Value. |
|
27 | - * |
|
28 | - * @var string $_value |
|
29 | - */ |
|
30 | - protected $_value; |
|
25 | + /** |
|
26 | + * Value. |
|
27 | + * |
|
28 | + * @var string $_value |
|
29 | + */ |
|
30 | + protected $_value; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor. |
|
34 | - * |
|
35 | - * @param string $value |
|
36 | - * @param int $type |
|
37 | - */ |
|
38 | - public function __construct($value, $type) |
|
39 | - { |
|
40 | - $this->_type = $type; |
|
41 | - $this->_value = $value; |
|
42 | - } |
|
32 | + /** |
|
33 | + * Constructor. |
|
34 | + * |
|
35 | + * @param string $value |
|
36 | + * @param int $type |
|
37 | + */ |
|
38 | + public function __construct($value, $type) |
|
39 | + { |
|
40 | + $this->_type = $type; |
|
41 | + $this->_value = $value; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Initialize from ASN.1. |
|
46 | - * |
|
47 | - * @param UnspecifiedType $el |
|
48 | - * @throws \UnexpectedValueException |
|
49 | - * @return self |
|
50 | - */ |
|
51 | - public static function fromASN1(UnspecifiedType $el) |
|
52 | - { |
|
53 | - switch ($el->tag()) { |
|
54 | - case Element::TYPE_OCTET_STRING: |
|
55 | - case Element::TYPE_UTF8_STRING: |
|
56 | - return new self($el->asString()->string(), $el->tag()); |
|
57 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
58 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
59 | - } |
|
60 | - throw new \UnexpectedValueException( |
|
61 | - "Type " . Element::tagToName($el->tag()) . " not supported."); |
|
62 | - } |
|
44 | + /** |
|
45 | + * Initialize from ASN.1. |
|
46 | + * |
|
47 | + * @param UnspecifiedType $el |
|
48 | + * @throws \UnexpectedValueException |
|
49 | + * @return self |
|
50 | + */ |
|
51 | + public static function fromASN1(UnspecifiedType $el) |
|
52 | + { |
|
53 | + switch ($el->tag()) { |
|
54 | + case Element::TYPE_OCTET_STRING: |
|
55 | + case Element::TYPE_UTF8_STRING: |
|
56 | + return new self($el->asString()->string(), $el->tag()); |
|
57 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
58 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
59 | + } |
|
60 | + throw new \UnexpectedValueException( |
|
61 | + "Type " . Element::tagToName($el->tag()) . " not supported."); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Initialize from octet string. |
|
66 | - * |
|
67 | - * @param string $octets |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public static function fromOctets($octets) |
|
71 | - { |
|
72 | - return new self($octets, Element::TYPE_OCTET_STRING); |
|
73 | - } |
|
64 | + /** |
|
65 | + * Initialize from octet string. |
|
66 | + * |
|
67 | + * @param string $octets |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public static function fromOctets($octets) |
|
71 | + { |
|
72 | + return new self($octets, Element::TYPE_OCTET_STRING); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Initialize from UTF-8 string. |
|
77 | - * |
|
78 | - * @param string $str |
|
79 | - * @return self |
|
80 | - */ |
|
81 | - public static function fromString($str) |
|
82 | - { |
|
83 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
84 | - } |
|
75 | + /** |
|
76 | + * Initialize from UTF-8 string. |
|
77 | + * |
|
78 | + * @param string $str |
|
79 | + * @return self |
|
80 | + */ |
|
81 | + public static function fromString($str) |
|
82 | + { |
|
83 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Initialize from OID. |
|
88 | - * |
|
89 | - * @param string $oid |
|
90 | - * @return self |
|
91 | - */ |
|
92 | - public static function fromOID($oid) |
|
93 | - { |
|
94 | - return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
95 | - } |
|
86 | + /** |
|
87 | + * Initialize from OID. |
|
88 | + * |
|
89 | + * @param string $oid |
|
90 | + * @return self |
|
91 | + */ |
|
92 | + public static function fromOID($oid) |
|
93 | + { |
|
94 | + return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Get type tag. |
|
99 | - * |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function type() |
|
103 | - { |
|
104 | - return $this->_type; |
|
105 | - } |
|
97 | + /** |
|
98 | + * Get type tag. |
|
99 | + * |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function type() |
|
103 | + { |
|
104 | + return $this->_type; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Whether value type is octets. |
|
109 | - * |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isOctets() |
|
113 | - { |
|
114 | - return $this->_type == Element::TYPE_OCTET_STRING; |
|
115 | - } |
|
107 | + /** |
|
108 | + * Whether value type is octets. |
|
109 | + * |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isOctets() |
|
113 | + { |
|
114 | + return $this->_type == Element::TYPE_OCTET_STRING; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Whether value type is OID. |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function isOID() |
|
123 | - { |
|
124 | - return $this->_type == Element::TYPE_OBJECT_IDENTIFIER; |
|
125 | - } |
|
117 | + /** |
|
118 | + * Whether value type is OID. |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function isOID() |
|
123 | + { |
|
124 | + return $this->_type == Element::TYPE_OBJECT_IDENTIFIER; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Whether value type is string. |
|
129 | - * |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public function isString() |
|
133 | - { |
|
134 | - return $this->_type == Element::TYPE_UTF8_STRING; |
|
135 | - } |
|
127 | + /** |
|
128 | + * Whether value type is string. |
|
129 | + * |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public function isString() |
|
133 | + { |
|
134 | + return $this->_type == Element::TYPE_UTF8_STRING; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Get value. |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function value() |
|
143 | - { |
|
144 | - return $this->_value; |
|
145 | - } |
|
137 | + /** |
|
138 | + * Get value. |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function value() |
|
143 | + { |
|
144 | + return $this->_value; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Generate ASN.1 structure. |
|
149 | - * |
|
150 | - * @throws \LogicException |
|
151 | - * @return Element |
|
152 | - */ |
|
153 | - public function toASN1() |
|
154 | - { |
|
155 | - switch ($this->_type) { |
|
156 | - case Element::TYPE_OCTET_STRING: |
|
157 | - return new OctetString($this->_value); |
|
158 | - case Element::TYPE_UTF8_STRING: |
|
159 | - return new UTF8String($this->_value); |
|
160 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
161 | - return new ObjectIdentifier($this->_value); |
|
162 | - } |
|
163 | - throw new \LogicException( |
|
164 | - "Type " . Element::tagToName($this->_type) . " not supported."); |
|
165 | - } |
|
147 | + /** |
|
148 | + * Generate ASN.1 structure. |
|
149 | + * |
|
150 | + * @throws \LogicException |
|
151 | + * @return Element |
|
152 | + */ |
|
153 | + public function toASN1() |
|
154 | + { |
|
155 | + switch ($this->_type) { |
|
156 | + case Element::TYPE_OCTET_STRING: |
|
157 | + return new OctetString($this->_value); |
|
158 | + case Element::TYPE_UTF8_STRING: |
|
159 | + return new UTF8String($this->_value); |
|
160 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
161 | + return new ObjectIdentifier($this->_value); |
|
162 | + } |
|
163 | + throw new \LogicException( |
|
164 | + "Type " . Element::tagToName($this->_type) . " not supported."); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function __toString() |
|
172 | - { |
|
173 | - return $this->_value; |
|
174 | - } |
|
167 | + /** |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function __toString() |
|
172 | + { |
|
173 | + return $this->_value; |
|
174 | + } |
|
175 | 175 | } |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | public static function fromASN1(UnspecifiedType $el) |
52 | 52 | { |
53 | 53 | switch ($el->tag()) { |
54 | - case Element::TYPE_OCTET_STRING: |
|
55 | - case Element::TYPE_UTF8_STRING: |
|
56 | - return new self($el->asString()->string(), $el->tag()); |
|
57 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
58 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
54 | + case Element::TYPE_OCTET_STRING: |
|
55 | + case Element::TYPE_UTF8_STRING: |
|
56 | + return new self($el->asString()->string(), $el->tag()); |
|
57 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
58 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
59 | 59 | } |
60 | 60 | throw new \UnexpectedValueException( |
61 | 61 | "Type " . Element::tagToName($el->tag()) . " not supported."); |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | public function toASN1() |
154 | 154 | { |
155 | 155 | switch ($this->_type) { |
156 | - case Element::TYPE_OCTET_STRING: |
|
157 | - return new OctetString($this->_value); |
|
158 | - case Element::TYPE_UTF8_STRING: |
|
159 | - return new UTF8String($this->_value); |
|
160 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
161 | - return new ObjectIdentifier($this->_value); |
|
156 | + case Element::TYPE_OCTET_STRING: |
|
157 | + return new OctetString($this->_value); |
|
158 | + case Element::TYPE_UTF8_STRING: |
|
159 | + return new UTF8String($this->_value); |
|
160 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
161 | + return new ObjectIdentifier($this->_value); |
|
162 | 162 | } |
163 | 163 | throw new \LogicException( |
164 | 164 | "Type " . Element::tagToName($this->_type) . " not supported."); |
@@ -21,154 +21,154 @@ |
||
21 | 21 | */ |
22 | 22 | class RoleAttributeValue extends AttributeValue |
23 | 23 | { |
24 | - /** |
|
25 | - * Issuing authority. |
|
26 | - * |
|
27 | - * @var GeneralNames $_roleAuthority |
|
28 | - */ |
|
29 | - protected $_roleAuthority; |
|
24 | + /** |
|
25 | + * Issuing authority. |
|
26 | + * |
|
27 | + * @var GeneralNames $_roleAuthority |
|
28 | + */ |
|
29 | + protected $_roleAuthority; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Role name. |
|
33 | - * |
|
34 | - * @var GeneralName $_roleName |
|
35 | - */ |
|
36 | - protected $_roleName; |
|
31 | + /** |
|
32 | + * Role name. |
|
33 | + * |
|
34 | + * @var GeneralName $_roleName |
|
35 | + */ |
|
36 | + protected $_roleName; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param GeneralName $name Role name |
|
42 | - * @param GeneralNames|null $authority Issuing authority |
|
43 | - */ |
|
44 | - public function __construct(GeneralName $name, GeneralNames $authority = null) |
|
45 | - { |
|
46 | - $this->_roleAuthority = $authority; |
|
47 | - $this->_roleName = $name; |
|
48 | - $this->_oid = AttributeType::OID_ROLE; |
|
49 | - } |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param GeneralName $name Role name |
|
42 | + * @param GeneralNames|null $authority Issuing authority |
|
43 | + */ |
|
44 | + public function __construct(GeneralName $name, GeneralNames $authority = null) |
|
45 | + { |
|
46 | + $this->_roleAuthority = $authority; |
|
47 | + $this->_roleName = $name; |
|
48 | + $this->_oid = AttributeType::OID_ROLE; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Initialize from a role string. |
|
53 | - * |
|
54 | - * @param string $role_name Role name in URI format |
|
55 | - * @param GeneralNames|null $authority Issuing authority |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromString($role_name, GeneralNames $authority = null) |
|
59 | - { |
|
60 | - return new self(new UniformResourceIdentifier($role_name), $authority); |
|
61 | - } |
|
51 | + /** |
|
52 | + * Initialize from a role string. |
|
53 | + * |
|
54 | + * @param string $role_name Role name in URI format |
|
55 | + * @param GeneralNames|null $authority Issuing authority |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromString($role_name, GeneralNames $authority = null) |
|
59 | + { |
|
60 | + return new self(new UniformResourceIdentifier($role_name), $authority); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * @param UnspecifiedType $el |
|
66 | - * @return self |
|
67 | - */ |
|
68 | - public static function fromASN1(UnspecifiedType $el) |
|
69 | - { |
|
70 | - $seq = $el->asSequence(); |
|
71 | - $authority = null; |
|
72 | - if ($seq->hasTagged(0)) { |
|
73 | - $authority = GeneralNames::fromASN1( |
|
74 | - $seq->getTagged(0) |
|
75 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
76 | - ->asSequence()); |
|
77 | - } |
|
78 | - $name = GeneralName::fromASN1( |
|
79 | - $seq->getTagged(1) |
|
80 | - ->asExplicit() |
|
81 | - ->asTagged()); |
|
82 | - return new self($name, $authority); |
|
83 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * @param UnspecifiedType $el |
|
66 | + * @return self |
|
67 | + */ |
|
68 | + public static function fromASN1(UnspecifiedType $el) |
|
69 | + { |
|
70 | + $seq = $el->asSequence(); |
|
71 | + $authority = null; |
|
72 | + if ($seq->hasTagged(0)) { |
|
73 | + $authority = GeneralNames::fromASN1( |
|
74 | + $seq->getTagged(0) |
|
75 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
76 | + ->asSequence()); |
|
77 | + } |
|
78 | + $name = GeneralName::fromASN1( |
|
79 | + $seq->getTagged(1) |
|
80 | + ->asExplicit() |
|
81 | + ->asTagged()); |
|
82 | + return new self($name, $authority); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Check whether issuing authority is present. |
|
87 | - * |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function hasRoleAuthority() |
|
91 | - { |
|
92 | - return isset($this->_roleAuthority); |
|
93 | - } |
|
85 | + /** |
|
86 | + * Check whether issuing authority is present. |
|
87 | + * |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function hasRoleAuthority() |
|
91 | + { |
|
92 | + return isset($this->_roleAuthority); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Get issuing authority. |
|
97 | - * |
|
98 | - * @throws \LogicException |
|
99 | - * @return GeneralNames |
|
100 | - */ |
|
101 | - public function roleAuthority() |
|
102 | - { |
|
103 | - if (!$this->hasRoleAuthority()) { |
|
104 | - throw new \LogicException("roleAuthority not set."); |
|
105 | - } |
|
106 | - return $this->_roleAuthority; |
|
107 | - } |
|
95 | + /** |
|
96 | + * Get issuing authority. |
|
97 | + * |
|
98 | + * @throws \LogicException |
|
99 | + * @return GeneralNames |
|
100 | + */ |
|
101 | + public function roleAuthority() |
|
102 | + { |
|
103 | + if (!$this->hasRoleAuthority()) { |
|
104 | + throw new \LogicException("roleAuthority not set."); |
|
105 | + } |
|
106 | + return $this->_roleAuthority; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get role name. |
|
111 | - * |
|
112 | - * @return GeneralName |
|
113 | - */ |
|
114 | - public function roleName() |
|
115 | - { |
|
116 | - return $this->_roleName; |
|
117 | - } |
|
109 | + /** |
|
110 | + * Get role name. |
|
111 | + * |
|
112 | + * @return GeneralName |
|
113 | + */ |
|
114 | + public function roleName() |
|
115 | + { |
|
116 | + return $this->_roleName; |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * |
|
121 | - * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
122 | - * @return Sequence |
|
123 | - */ |
|
124 | - public function toASN1() |
|
125 | - { |
|
126 | - $elements = array(); |
|
127 | - if (isset($this->_roleAuthority)) { |
|
128 | - $elements[] = new ImplicitlyTaggedType(0, |
|
129 | - $this->_roleAuthority->toASN1()); |
|
130 | - } |
|
131 | - $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1()); |
|
132 | - return new Sequence(...$elements); |
|
133 | - } |
|
119 | + /** |
|
120 | + * |
|
121 | + * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
122 | + * @return Sequence |
|
123 | + */ |
|
124 | + public function toASN1() |
|
125 | + { |
|
126 | + $elements = array(); |
|
127 | + if (isset($this->_roleAuthority)) { |
|
128 | + $elements[] = new ImplicitlyTaggedType(0, |
|
129 | + $this->_roleAuthority->toASN1()); |
|
130 | + } |
|
131 | + $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1()); |
|
132 | + return new Sequence(...$elements); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * |
|
137 | - * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function stringValue() |
|
141 | - { |
|
142 | - return "#" . bin2hex($this->toASN1()->toDER()); |
|
143 | - } |
|
135 | + /** |
|
136 | + * |
|
137 | + * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function stringValue() |
|
141 | + { |
|
142 | + return "#" . bin2hex($this->toASN1()->toDER()); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * |
|
147 | - * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
148 | - * @return BinaryMatch |
|
149 | - */ |
|
150 | - public function equalityMatchingRule() |
|
151 | - { |
|
152 | - return new BinaryMatch(); |
|
153 | - } |
|
145 | + /** |
|
146 | + * |
|
147 | + * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
148 | + * @return BinaryMatch |
|
149 | + */ |
|
150 | + public function equalityMatchingRule() |
|
151 | + { |
|
152 | + return new BinaryMatch(); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * |
|
157 | - * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function rfc2253String() |
|
161 | - { |
|
162 | - return $this->stringValue(); |
|
163 | - } |
|
155 | + /** |
|
156 | + * |
|
157 | + * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function rfc2253String() |
|
161 | + { |
|
162 | + return $this->stringValue(); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * |
|
167 | - * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - protected function _transcodedString() |
|
171 | - { |
|
172 | - return $this->stringValue(); |
|
173 | - } |
|
165 | + /** |
|
166 | + * |
|
167 | + * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + protected function _transcodedString() |
|
171 | + { |
|
172 | + return $this->stringValue(); |
|
173 | + } |
|
174 | 174 | } |