@@ -14,52 +14,52 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class InhibitAnyPolicyExtension extends Extension |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * |
|
| 19 | - * @var int $_skipCerts |
|
| 20 | - */ |
|
| 21 | - protected $_skipCerts; |
|
| 17 | + /** |
|
| 18 | + * |
|
| 19 | + * @var int $_skipCerts |
|
| 20 | + */ |
|
| 21 | + protected $_skipCerts; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param bool $critical |
|
| 27 | - * @param int $skip_certs |
|
| 28 | - */ |
|
| 29 | - public function __construct(bool $critical, int $skip_certs) |
|
| 30 | - { |
|
| 31 | - parent::__construct(self::OID_INHIBIT_ANY_POLICY, $critical); |
|
| 32 | - $this->_skipCerts = $skip_certs; |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param bool $critical |
|
| 27 | + * @param int $skip_certs |
|
| 28 | + */ |
|
| 29 | + public function __construct(bool $critical, int $skip_certs) |
|
| 30 | + { |
|
| 31 | + parent::__construct(self::OID_INHIBIT_ANY_POLICY, $critical); |
|
| 32 | + $this->_skipCerts = $skip_certs; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * |
|
| 37 | - * {@inheritdoc} |
|
| 38 | - * @return self |
|
| 39 | - */ |
|
| 40 | - protected static function _fromDER(string $data, bool $critical): self |
|
| 41 | - { |
|
| 42 | - return new self($critical, |
|
| 43 | - UnspecifiedType::fromDER($data)->asInteger()->intNumber()); |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * |
|
| 37 | + * {@inheritdoc} |
|
| 38 | + * @return self |
|
| 39 | + */ |
|
| 40 | + protected static function _fromDER(string $data, bool $critical): self |
|
| 41 | + { |
|
| 42 | + return new self($critical, |
|
| 43 | + UnspecifiedType::fromDER($data)->asInteger()->intNumber()); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get value. |
|
| 48 | - * |
|
| 49 | - * @return int |
|
| 50 | - */ |
|
| 51 | - public function skipCerts(): int |
|
| 52 | - { |
|
| 53 | - return $this->_skipCerts; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Get value. |
|
| 48 | + * |
|
| 49 | + * @return int |
|
| 50 | + */ |
|
| 51 | + public function skipCerts(): int |
|
| 52 | + { |
|
| 53 | + return $this->_skipCerts; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * |
|
| 58 | - * {@inheritdoc} |
|
| 59 | - * @return Integer |
|
| 60 | - */ |
|
| 61 | - protected function _valueASN1(): Integer |
|
| 62 | - { |
|
| 63 | - return new Integer($this->_skipCerts); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * |
|
| 58 | + * {@inheritdoc} |
|
| 59 | + * @return Integer |
|
| 60 | + */ |
|
| 61 | + protected function _valueASN1(): Integer |
|
| 62 | + { |
|
| 63 | + return new Integer($this->_skipCerts); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Certificate\Extension; |
| 6 | 6 | |
@@ -21,203 +21,203 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class AttributeCertificate |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Attribute certificate info. |
|
| 26 | - * |
|
| 27 | - * @var AttributeCertificateInfo $_acinfo |
|
| 28 | - */ |
|
| 29 | - protected $_acinfo; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Signature algorithm identifier. |
|
| 33 | - * |
|
| 34 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 35 | - */ |
|
| 36 | - protected $_signatureAlgorithm; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Signature value. |
|
| 40 | - * |
|
| 41 | - * @var Signature $_signatureValue |
|
| 42 | - */ |
|
| 43 | - protected $_signatureValue; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Constructor. |
|
| 47 | - * |
|
| 48 | - * @param AttributeCertificateInfo $acinfo |
|
| 49 | - * @param SignatureAlgorithmIdentifier $algo |
|
| 50 | - * @param Signature $signature |
|
| 51 | - */ |
|
| 52 | - public function __construct(AttributeCertificateInfo $acinfo, |
|
| 53 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 54 | - { |
|
| 55 | - $this->_acinfo = $acinfo; |
|
| 56 | - $this->_signatureAlgorithm = $algo; |
|
| 57 | - $this->_signatureValue = $signature; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Initialize from ASN.1. |
|
| 62 | - * |
|
| 63 | - * @param Sequence $seq |
|
| 64 | - * @return self |
|
| 65 | - */ |
|
| 66 | - public static function fromASN1(Sequence $seq): self |
|
| 67 | - { |
|
| 68 | - $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 69 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 70 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 71 | - throw new \UnexpectedValueException( |
|
| 72 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 73 | - } |
|
| 74 | - $signature = Signature::fromSignatureData( |
|
| 75 | - $seq->at(2) |
|
| 76 | - ->asBitString() |
|
| 77 | - ->string(), $algo); |
|
| 78 | - return new self($acinfo, $algo, $signature); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Initialize from DER data. |
|
| 83 | - * |
|
| 84 | - * @param string $data |
|
| 85 | - * @return self |
|
| 86 | - */ |
|
| 87 | - public static function fromDER(string $data): self |
|
| 88 | - { |
|
| 89 | - return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Initialize from PEM. |
|
| 94 | - * |
|
| 95 | - * @param PEM $pem |
|
| 96 | - * @throws \UnexpectedValueException |
|
| 97 | - * @return self |
|
| 98 | - */ |
|
| 99 | - public static function fromPEM(PEM $pem): self |
|
| 100 | - { |
|
| 101 | - if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
| 102 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 103 | - } |
|
| 104 | - return self::fromDER($pem->data()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get attribute certificate info. |
|
| 109 | - * |
|
| 110 | - * @return AttributeCertificateInfo |
|
| 111 | - */ |
|
| 112 | - public function acinfo(): AttributeCertificateInfo |
|
| 113 | - { |
|
| 114 | - return $this->_acinfo; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Get signature algorithm identifier. |
|
| 119 | - * |
|
| 120 | - * @return SignatureAlgorithmIdentifier |
|
| 121 | - */ |
|
| 122 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
| 123 | - { |
|
| 124 | - return $this->_signatureAlgorithm; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Get signature value. |
|
| 129 | - * |
|
| 130 | - * @return Signature |
|
| 131 | - */ |
|
| 132 | - public function signatureValue(): Signature |
|
| 133 | - { |
|
| 134 | - return $this->_signatureValue; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Get ASN.1 structure. |
|
| 139 | - * |
|
| 140 | - * @return Sequence |
|
| 141 | - */ |
|
| 142 | - public function toASN1(): Sequence |
|
| 143 | - { |
|
| 144 | - return new Sequence($this->_acinfo->toASN1(), |
|
| 145 | - $this->_signatureAlgorithm->toASN1(), |
|
| 146 | - $this->_signatureValue->bitString()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Get attribute certificate as a DER. |
|
| 151 | - * |
|
| 152 | - * @return string |
|
| 153 | - */ |
|
| 154 | - public function toDER(): string |
|
| 155 | - { |
|
| 156 | - return $this->toASN1()->toDER(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Get attribute certificate as a PEM. |
|
| 161 | - * |
|
| 162 | - * @return PEM |
|
| 163 | - */ |
|
| 164 | - public function toPEM(): PEM |
|
| 165 | - { |
|
| 166 | - return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Check whether attribute certificate is issued to the subject identified |
|
| 171 | - * by given public key certificate. |
|
| 172 | - * |
|
| 173 | - * @param Certificate $cert Certificate |
|
| 174 | - * @return boolean |
|
| 175 | - */ |
|
| 176 | - public function isHeldBy(Certificate $cert): bool |
|
| 177 | - { |
|
| 178 | - if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - return true; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Check whether attribute certificate is issued by given public key |
|
| 186 | - * certificate. |
|
| 187 | - * |
|
| 188 | - * @param Certificate $cert Certificate |
|
| 189 | - * @return boolean |
|
| 190 | - */ |
|
| 191 | - public function isIssuedBy(Certificate $cert): bool |
|
| 192 | - { |
|
| 193 | - if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - return true; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Verify signature. |
|
| 201 | - * |
|
| 202 | - * @param PublicKeyInfo $pubkey_info Signer's public key |
|
| 203 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 204 | - * @return bool |
|
| 205 | - */ |
|
| 206 | - public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
| 207 | - { |
|
| 208 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
| 209 | - $data = $this->_acinfo->toASN1()->toDER(); |
|
| 210 | - return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
| 211 | - $this->_signatureAlgorithm); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Get attribute certificate as a PEM formatted string. |
|
| 216 | - * |
|
| 217 | - * @return string |
|
| 218 | - */ |
|
| 219 | - public function __toString() |
|
| 220 | - { |
|
| 221 | - return $this->toPEM()->string(); |
|
| 222 | - } |
|
| 24 | + /** |
|
| 25 | + * Attribute certificate info. |
|
| 26 | + * |
|
| 27 | + * @var AttributeCertificateInfo $_acinfo |
|
| 28 | + */ |
|
| 29 | + protected $_acinfo; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Signature algorithm identifier. |
|
| 33 | + * |
|
| 34 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 35 | + */ |
|
| 36 | + protected $_signatureAlgorithm; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Signature value. |
|
| 40 | + * |
|
| 41 | + * @var Signature $_signatureValue |
|
| 42 | + */ |
|
| 43 | + protected $_signatureValue; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Constructor. |
|
| 47 | + * |
|
| 48 | + * @param AttributeCertificateInfo $acinfo |
|
| 49 | + * @param SignatureAlgorithmIdentifier $algo |
|
| 50 | + * @param Signature $signature |
|
| 51 | + */ |
|
| 52 | + public function __construct(AttributeCertificateInfo $acinfo, |
|
| 53 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 54 | + { |
|
| 55 | + $this->_acinfo = $acinfo; |
|
| 56 | + $this->_signatureAlgorithm = $algo; |
|
| 57 | + $this->_signatureValue = $signature; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Initialize from ASN.1. |
|
| 62 | + * |
|
| 63 | + * @param Sequence $seq |
|
| 64 | + * @return self |
|
| 65 | + */ |
|
| 66 | + public static function fromASN1(Sequence $seq): self |
|
| 67 | + { |
|
| 68 | + $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 69 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 70 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 71 | + throw new \UnexpectedValueException( |
|
| 72 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 73 | + } |
|
| 74 | + $signature = Signature::fromSignatureData( |
|
| 75 | + $seq->at(2) |
|
| 76 | + ->asBitString() |
|
| 77 | + ->string(), $algo); |
|
| 78 | + return new self($acinfo, $algo, $signature); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Initialize from DER data. |
|
| 83 | + * |
|
| 84 | + * @param string $data |
|
| 85 | + * @return self |
|
| 86 | + */ |
|
| 87 | + public static function fromDER(string $data): self |
|
| 88 | + { |
|
| 89 | + return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Initialize from PEM. |
|
| 94 | + * |
|
| 95 | + * @param PEM $pem |
|
| 96 | + * @throws \UnexpectedValueException |
|
| 97 | + * @return self |
|
| 98 | + */ |
|
| 99 | + public static function fromPEM(PEM $pem): self |
|
| 100 | + { |
|
| 101 | + if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
| 102 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 103 | + } |
|
| 104 | + return self::fromDER($pem->data()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get attribute certificate info. |
|
| 109 | + * |
|
| 110 | + * @return AttributeCertificateInfo |
|
| 111 | + */ |
|
| 112 | + public function acinfo(): AttributeCertificateInfo |
|
| 113 | + { |
|
| 114 | + return $this->_acinfo; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Get signature algorithm identifier. |
|
| 119 | + * |
|
| 120 | + * @return SignatureAlgorithmIdentifier |
|
| 121 | + */ |
|
| 122 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
| 123 | + { |
|
| 124 | + return $this->_signatureAlgorithm; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Get signature value. |
|
| 129 | + * |
|
| 130 | + * @return Signature |
|
| 131 | + */ |
|
| 132 | + public function signatureValue(): Signature |
|
| 133 | + { |
|
| 134 | + return $this->_signatureValue; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Get ASN.1 structure. |
|
| 139 | + * |
|
| 140 | + * @return Sequence |
|
| 141 | + */ |
|
| 142 | + public function toASN1(): Sequence |
|
| 143 | + { |
|
| 144 | + return new Sequence($this->_acinfo->toASN1(), |
|
| 145 | + $this->_signatureAlgorithm->toASN1(), |
|
| 146 | + $this->_signatureValue->bitString()); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Get attribute certificate as a DER. |
|
| 151 | + * |
|
| 152 | + * @return string |
|
| 153 | + */ |
|
| 154 | + public function toDER(): string |
|
| 155 | + { |
|
| 156 | + return $this->toASN1()->toDER(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Get attribute certificate as a PEM. |
|
| 161 | + * |
|
| 162 | + * @return PEM |
|
| 163 | + */ |
|
| 164 | + public function toPEM(): PEM |
|
| 165 | + { |
|
| 166 | + return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Check whether attribute certificate is issued to the subject identified |
|
| 171 | + * by given public key certificate. |
|
| 172 | + * |
|
| 173 | + * @param Certificate $cert Certificate |
|
| 174 | + * @return boolean |
|
| 175 | + */ |
|
| 176 | + public function isHeldBy(Certificate $cert): bool |
|
| 177 | + { |
|
| 178 | + if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + return true; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Check whether attribute certificate is issued by given public key |
|
| 186 | + * certificate. |
|
| 187 | + * |
|
| 188 | + * @param Certificate $cert Certificate |
|
| 189 | + * @return boolean |
|
| 190 | + */ |
|
| 191 | + public function isIssuedBy(Certificate $cert): bool |
|
| 192 | + { |
|
| 193 | + if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + return true; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Verify signature. |
|
| 201 | + * |
|
| 202 | + * @param PublicKeyInfo $pubkey_info Signer's public key |
|
| 203 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 204 | + * @return bool |
|
| 205 | + */ |
|
| 206 | + public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
| 207 | + { |
|
| 208 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
| 209 | + $data = $this->_acinfo->toASN1()->toDER(); |
|
| 210 | + return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
| 211 | + $this->_signatureAlgorithm); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Get attribute certificate as a PEM formatted string. |
|
| 216 | + * |
|
| 217 | + * @return string |
|
| 218 | + */ |
|
| 219 | + public function __toString() |
|
| 220 | + { |
|
| 221 | + return $this->toPEM()->string(); |
|
| 222 | + } |
|
| 223 | 223 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate; |
| 6 | 6 | |
@@ -19,172 +19,172 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class CertificationRequest |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Certification request info. |
|
| 24 | - * |
|
| 25 | - * @var CertificationRequestInfo $_certificationRequestInfo |
|
| 26 | - */ |
|
| 27 | - protected $_certificationRequestInfo; |
|
| 22 | + /** |
|
| 23 | + * Certification request info. |
|
| 24 | + * |
|
| 25 | + * @var CertificationRequestInfo $_certificationRequestInfo |
|
| 26 | + */ |
|
| 27 | + protected $_certificationRequestInfo; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Signature algorithm. |
|
| 31 | - * |
|
| 32 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 33 | - */ |
|
| 34 | - protected $_signatureAlgorithm; |
|
| 29 | + /** |
|
| 30 | + * Signature algorithm. |
|
| 31 | + * |
|
| 32 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 33 | + */ |
|
| 34 | + protected $_signatureAlgorithm; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Signature. |
|
| 38 | - * |
|
| 39 | - * @var Signature $_signature |
|
| 40 | - */ |
|
| 41 | - protected $_signature; |
|
| 36 | + /** |
|
| 37 | + * Signature. |
|
| 38 | + * |
|
| 39 | + * @var Signature $_signature |
|
| 40 | + */ |
|
| 41 | + protected $_signature; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Constructor. |
|
| 45 | - * |
|
| 46 | - * @param CertificationRequestInfo $info |
|
| 47 | - * @param SignatureAlgorithmIdentifier $algo |
|
| 48 | - * @param Signature $signature |
|
| 49 | - */ |
|
| 50 | - public function __construct(CertificationRequestInfo $info, |
|
| 51 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 52 | - { |
|
| 53 | - $this->_certificationRequestInfo = $info; |
|
| 54 | - $this->_signatureAlgorithm = $algo; |
|
| 55 | - $this->_signature = $signature; |
|
| 56 | - } |
|
| 43 | + /** |
|
| 44 | + * Constructor. |
|
| 45 | + * |
|
| 46 | + * @param CertificationRequestInfo $info |
|
| 47 | + * @param SignatureAlgorithmIdentifier $algo |
|
| 48 | + * @param Signature $signature |
|
| 49 | + */ |
|
| 50 | + public function __construct(CertificationRequestInfo $info, |
|
| 51 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 52 | + { |
|
| 53 | + $this->_certificationRequestInfo = $info; |
|
| 54 | + $this->_signatureAlgorithm = $algo; |
|
| 55 | + $this->_signature = $signature; |
|
| 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 | - $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 67 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 68 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 69 | - throw new \UnexpectedValueException( |
|
| 70 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 71 | - } |
|
| 72 | - $signature = Signature::fromSignatureData( |
|
| 73 | - $seq->at(2) |
|
| 74 | - ->asBitString() |
|
| 75 | - ->string(), $algo); |
|
| 76 | - return new self($info, $algo, $signature); |
|
| 77 | - } |
|
| 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 | + $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 67 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 68 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 69 | + throw new \UnexpectedValueException( |
|
| 70 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 71 | + } |
|
| 72 | + $signature = Signature::fromSignatureData( |
|
| 73 | + $seq->at(2) |
|
| 74 | + ->asBitString() |
|
| 75 | + ->string(), $algo); |
|
| 76 | + return new self($info, $algo, $signature); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Initialize from DER. |
|
| 81 | - * |
|
| 82 | - * @param string $data |
|
| 83 | - * @return self |
|
| 84 | - */ |
|
| 85 | - public static function fromDER(string $data): self |
|
| 86 | - { |
|
| 87 | - return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
| 88 | - } |
|
| 79 | + /** |
|
| 80 | + * Initialize from DER. |
|
| 81 | + * |
|
| 82 | + * @param string $data |
|
| 83 | + * @return self |
|
| 84 | + */ |
|
| 85 | + public static function fromDER(string $data): self |
|
| 86 | + { |
|
| 87 | + return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Initialize from PEM. |
|
| 92 | - * |
|
| 93 | - * @param PEM $pem |
|
| 94 | - * @throws \UnexpectedValueException |
|
| 95 | - * @return self |
|
| 96 | - */ |
|
| 97 | - public static function fromPEM(PEM $pem): self |
|
| 98 | - { |
|
| 99 | - if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
| 100 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 101 | - } |
|
| 102 | - return self::fromDER($pem->data()); |
|
| 103 | - } |
|
| 90 | + /** |
|
| 91 | + * Initialize from PEM. |
|
| 92 | + * |
|
| 93 | + * @param PEM $pem |
|
| 94 | + * @throws \UnexpectedValueException |
|
| 95 | + * @return self |
|
| 96 | + */ |
|
| 97 | + public static function fromPEM(PEM $pem): self |
|
| 98 | + { |
|
| 99 | + if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
| 100 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 101 | + } |
|
| 102 | + return self::fromDER($pem->data()); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Get certification request info. |
|
| 107 | - * |
|
| 108 | - * @return CertificationRequestInfo |
|
| 109 | - */ |
|
| 110 | - public function certificationRequestInfo(): CertificationRequestInfo |
|
| 111 | - { |
|
| 112 | - return $this->_certificationRequestInfo; |
|
| 113 | - } |
|
| 105 | + /** |
|
| 106 | + * Get certification request info. |
|
| 107 | + * |
|
| 108 | + * @return CertificationRequestInfo |
|
| 109 | + */ |
|
| 110 | + public function certificationRequestInfo(): CertificationRequestInfo |
|
| 111 | + { |
|
| 112 | + return $this->_certificationRequestInfo; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Get signature algorithm. |
|
| 117 | - * |
|
| 118 | - * @return SignatureAlgorithmIdentifier |
|
| 119 | - */ |
|
| 120 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
| 121 | - { |
|
| 122 | - return $this->_signatureAlgorithm; |
|
| 123 | - } |
|
| 115 | + /** |
|
| 116 | + * Get signature algorithm. |
|
| 117 | + * |
|
| 118 | + * @return SignatureAlgorithmIdentifier |
|
| 119 | + */ |
|
| 120 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
| 121 | + { |
|
| 122 | + return $this->_signatureAlgorithm; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Get signature. |
|
| 127 | - * |
|
| 128 | - * @return Signature |
|
| 129 | - */ |
|
| 130 | - public function signature(): Signature |
|
| 131 | - { |
|
| 132 | - return $this->_signature; |
|
| 133 | - } |
|
| 125 | + /** |
|
| 126 | + * Get signature. |
|
| 127 | + * |
|
| 128 | + * @return Signature |
|
| 129 | + */ |
|
| 130 | + public function signature(): Signature |
|
| 131 | + { |
|
| 132 | + return $this->_signature; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Generate ASN.1 structure. |
|
| 137 | - * |
|
| 138 | - * @return Sequence |
|
| 139 | - */ |
|
| 140 | - public function toASN1(): Sequence |
|
| 141 | - { |
|
| 142 | - return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
| 143 | - $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
| 144 | - } |
|
| 135 | + /** |
|
| 136 | + * Generate ASN.1 structure. |
|
| 137 | + * |
|
| 138 | + * @return Sequence |
|
| 139 | + */ |
|
| 140 | + public function toASN1(): Sequence |
|
| 141 | + { |
|
| 142 | + return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
| 143 | + $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Get certification request as a DER. |
|
| 148 | - * |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - public function toDER(): string |
|
| 152 | - { |
|
| 153 | - return $this->toASN1()->toDER(); |
|
| 154 | - } |
|
| 146 | + /** |
|
| 147 | + * Get certification request as a DER. |
|
| 148 | + * |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + public function toDER(): string |
|
| 152 | + { |
|
| 153 | + return $this->toASN1()->toDER(); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Get certification request as a PEM. |
|
| 158 | - * |
|
| 159 | - * @return PEM |
|
| 160 | - */ |
|
| 161 | - public function toPEM(): PEM |
|
| 162 | - { |
|
| 163 | - return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
| 164 | - } |
|
| 156 | + /** |
|
| 157 | + * Get certification request as a PEM. |
|
| 158 | + * |
|
| 159 | + * @return PEM |
|
| 160 | + */ |
|
| 161 | + public function toPEM(): PEM |
|
| 162 | + { |
|
| 163 | + return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Verify certification request signature. |
|
| 168 | - * |
|
| 169 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 170 | - * @return bool True if signature matches |
|
| 171 | - */ |
|
| 172 | - public function verify(Crypto $crypto = null): bool |
|
| 173 | - { |
|
| 174 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
| 175 | - $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
| 176 | - $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
| 177 | - return $crypto->verify($data, $this->_signature, $pk_info, |
|
| 178 | - $this->_signatureAlgorithm); |
|
| 179 | - } |
|
| 166 | + /** |
|
| 167 | + * Verify certification request signature. |
|
| 168 | + * |
|
| 169 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 170 | + * @return bool True if signature matches |
|
| 171 | + */ |
|
| 172 | + public function verify(Crypto $crypto = null): bool |
|
| 173 | + { |
|
| 174 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
| 175 | + $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
| 176 | + $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
| 177 | + return $crypto->verify($data, $this->_signature, $pk_info, |
|
| 178 | + $this->_signatureAlgorithm); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Get certification request as a PEM formatted string. |
|
| 183 | - * |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - public function __toString() |
|
| 187 | - { |
|
| 188 | - return $this->toPEM()->string(); |
|
| 189 | - } |
|
| 181 | + /** |
|
| 182 | + * Get certification request as a PEM formatted string. |
|
| 183 | + * |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + public function __toString() |
|
| 187 | + { |
|
| 188 | + return $this->toPEM()->string(); |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\CertificationRequest; |
| 6 | 6 | |
@@ -20,181 +20,181 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class AuthorityKeyIdentifierExtension extends Extension |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Key identifier. |
|
| 25 | - * |
|
| 26 | - * @var string|null $_keyIdentifier |
|
| 27 | - */ |
|
| 28 | - protected $_keyIdentifier; |
|
| 23 | + /** |
|
| 24 | + * Key identifier. |
|
| 25 | + * |
|
| 26 | + * @var string|null $_keyIdentifier |
|
| 27 | + */ |
|
| 28 | + protected $_keyIdentifier; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Issuer name. |
|
| 32 | - * |
|
| 33 | - * @var GeneralNames|null $_authorityCertIssuer |
|
| 34 | - */ |
|
| 35 | - protected $_authorityCertIssuer; |
|
| 30 | + /** |
|
| 31 | + * Issuer name. |
|
| 32 | + * |
|
| 33 | + * @var GeneralNames|null $_authorityCertIssuer |
|
| 34 | + */ |
|
| 35 | + protected $_authorityCertIssuer; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Issuer serial number. |
|
| 39 | - * |
|
| 40 | - * @var string|null $_authorityCertSerialNumber |
|
| 41 | - */ |
|
| 42 | - protected $_authorityCertSerialNumber; |
|
| 37 | + /** |
|
| 38 | + * Issuer serial number. |
|
| 39 | + * |
|
| 40 | + * @var string|null $_authorityCertSerialNumber |
|
| 41 | + */ |
|
| 42 | + protected $_authorityCertSerialNumber; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Constructor. |
|
| 46 | - * |
|
| 47 | - * @param bool $critical Conforming CA's must mark as non-critical (false) |
|
| 48 | - * @param string|null $keyIdentifier |
|
| 49 | - * @param GeneralNames|null $issuer |
|
| 50 | - * @param string|null $serial |
|
| 51 | - */ |
|
| 52 | - public function __construct(bool $critical, $keyIdentifier, |
|
| 53 | - GeneralNames $issuer = null, $serial = null) |
|
| 54 | - { |
|
| 55 | - parent::__construct(self::OID_AUTHORITY_KEY_IDENTIFIER, $critical); |
|
| 56 | - $this->_keyIdentifier = $keyIdentifier; |
|
| 57 | - $this->_authorityCertIssuer = $issuer; |
|
| 58 | - $this->_authorityCertSerialNumber = isset($serial) ? strval($serial) : null; |
|
| 59 | - } |
|
| 44 | + /** |
|
| 45 | + * Constructor. |
|
| 46 | + * |
|
| 47 | + * @param bool $critical Conforming CA's must mark as non-critical (false) |
|
| 48 | + * @param string|null $keyIdentifier |
|
| 49 | + * @param GeneralNames|null $issuer |
|
| 50 | + * @param string|null $serial |
|
| 51 | + */ |
|
| 52 | + public function __construct(bool $critical, $keyIdentifier, |
|
| 53 | + GeneralNames $issuer = null, $serial = null) |
|
| 54 | + { |
|
| 55 | + parent::__construct(self::OID_AUTHORITY_KEY_IDENTIFIER, $critical); |
|
| 56 | + $this->_keyIdentifier = $keyIdentifier; |
|
| 57 | + $this->_authorityCertIssuer = $issuer; |
|
| 58 | + $this->_authorityCertSerialNumber = isset($serial) ? strval($serial) : null; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Create from public key info. |
|
| 63 | - * |
|
| 64 | - * @param PublicKeyInfo $pki |
|
| 65 | - * @return AuthorityKeyIdentifierExtension |
|
| 66 | - */ |
|
| 67 | - public static function fromPublicKeyInfo(PublicKeyInfo $pki) |
|
| 68 | - { |
|
| 69 | - return new self(false, $pki->keyIdentifier()); |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * Create from public key info. |
|
| 63 | + * |
|
| 64 | + * @param PublicKeyInfo $pki |
|
| 65 | + * @return AuthorityKeyIdentifierExtension |
|
| 66 | + */ |
|
| 67 | + public static function fromPublicKeyInfo(PublicKeyInfo $pki) |
|
| 68 | + { |
|
| 69 | + return new self(false, $pki->keyIdentifier()); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * |
|
| 74 | - * {@inheritdoc} |
|
| 75 | - * @return self |
|
| 76 | - */ |
|
| 77 | - protected static function _fromDER(string $data, bool $critical): self |
|
| 78 | - { |
|
| 79 | - $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
| 80 | - $keyIdentifier = null; |
|
| 81 | - $issuer = null; |
|
| 82 | - $serial = null; |
|
| 83 | - if ($seq->hasTagged(0)) { |
|
| 84 | - $keyIdentifier = $seq->getTagged(0) |
|
| 85 | - ->asImplicit(Element::TYPE_OCTET_STRING) |
|
| 86 | - ->asOctetString() |
|
| 87 | - ->string(); |
|
| 88 | - } |
|
| 89 | - if ($seq->hasTagged(1) || $seq->hasTagged(2)) { |
|
| 90 | - if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) { |
|
| 91 | - throw new \UnexpectedValueException( |
|
| 92 | - "AuthorityKeyIdentifier must have both" . |
|
| 93 | - " authorityCertIssuer and authorityCertSerialNumber" . |
|
| 94 | - " present or both absent."); |
|
| 95 | - } |
|
| 96 | - $issuer = GeneralNames::fromASN1( |
|
| 97 | - $seq->getTagged(1) |
|
| 98 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 99 | - ->asSequence()); |
|
| 100 | - $serial = $seq->getTagged(2) |
|
| 101 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 102 | - ->asInteger() |
|
| 103 | - ->number(); |
|
| 104 | - } |
|
| 105 | - return new self($critical, $keyIdentifier, $issuer, $serial); |
|
| 106 | - } |
|
| 72 | + /** |
|
| 73 | + * |
|
| 74 | + * {@inheritdoc} |
|
| 75 | + * @return self |
|
| 76 | + */ |
|
| 77 | + protected static function _fromDER(string $data, bool $critical): self |
|
| 78 | + { |
|
| 79 | + $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
| 80 | + $keyIdentifier = null; |
|
| 81 | + $issuer = null; |
|
| 82 | + $serial = null; |
|
| 83 | + if ($seq->hasTagged(0)) { |
|
| 84 | + $keyIdentifier = $seq->getTagged(0) |
|
| 85 | + ->asImplicit(Element::TYPE_OCTET_STRING) |
|
| 86 | + ->asOctetString() |
|
| 87 | + ->string(); |
|
| 88 | + } |
|
| 89 | + if ($seq->hasTagged(1) || $seq->hasTagged(2)) { |
|
| 90 | + if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) { |
|
| 91 | + throw new \UnexpectedValueException( |
|
| 92 | + "AuthorityKeyIdentifier must have both" . |
|
| 93 | + " authorityCertIssuer and authorityCertSerialNumber" . |
|
| 94 | + " present or both absent."); |
|
| 95 | + } |
|
| 96 | + $issuer = GeneralNames::fromASN1( |
|
| 97 | + $seq->getTagged(1) |
|
| 98 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 99 | + ->asSequence()); |
|
| 100 | + $serial = $seq->getTagged(2) |
|
| 101 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 102 | + ->asInteger() |
|
| 103 | + ->number(); |
|
| 104 | + } |
|
| 105 | + return new self($critical, $keyIdentifier, $issuer, $serial); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Whether key identifier is present. |
|
| 110 | - * |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function hasKeyIdentifier(): bool |
|
| 114 | - { |
|
| 115 | - return isset($this->_keyIdentifier); |
|
| 116 | - } |
|
| 108 | + /** |
|
| 109 | + * Whether key identifier is present. |
|
| 110 | + * |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function hasKeyIdentifier(): bool |
|
| 114 | + { |
|
| 115 | + return isset($this->_keyIdentifier); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Get key identifier. |
|
| 120 | - * |
|
| 121 | - * @throws \LogicException |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function keyIdentifier(): string |
|
| 125 | - { |
|
| 126 | - if (!$this->hasKeyIdentifier()) { |
|
| 127 | - throw new \LogicException("keyIdentifier not set."); |
|
| 128 | - } |
|
| 129 | - return $this->_keyIdentifier; |
|
| 130 | - } |
|
| 118 | + /** |
|
| 119 | + * Get key identifier. |
|
| 120 | + * |
|
| 121 | + * @throws \LogicException |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function keyIdentifier(): string |
|
| 125 | + { |
|
| 126 | + if (!$this->hasKeyIdentifier()) { |
|
| 127 | + throw new \LogicException("keyIdentifier not set."); |
|
| 128 | + } |
|
| 129 | + return $this->_keyIdentifier; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Whether issuer is present. |
|
| 134 | - * |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function hasIssuer(): bool |
|
| 138 | - { |
|
| 139 | - return isset($this->_authorityCertIssuer); |
|
| 140 | - } |
|
| 132 | + /** |
|
| 133 | + * Whether issuer is present. |
|
| 134 | + * |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function hasIssuer(): bool |
|
| 138 | + { |
|
| 139 | + return isset($this->_authorityCertIssuer); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get issuer. |
|
| 144 | - * |
|
| 145 | - * @throws \LogicException |
|
| 146 | - * @return GeneralNames |
|
| 147 | - */ |
|
| 148 | - public function issuer(): GeneralNames |
|
| 149 | - { |
|
| 150 | - if (!$this->hasIssuer()) { |
|
| 151 | - throw new \LogicException("authorityCertIssuer not set."); |
|
| 152 | - } |
|
| 153 | - return $this->_authorityCertIssuer; |
|
| 154 | - } |
|
| 142 | + /** |
|
| 143 | + * Get issuer. |
|
| 144 | + * |
|
| 145 | + * @throws \LogicException |
|
| 146 | + * @return GeneralNames |
|
| 147 | + */ |
|
| 148 | + public function issuer(): GeneralNames |
|
| 149 | + { |
|
| 150 | + if (!$this->hasIssuer()) { |
|
| 151 | + throw new \LogicException("authorityCertIssuer not set."); |
|
| 152 | + } |
|
| 153 | + return $this->_authorityCertIssuer; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Get serial number. |
|
| 158 | - * |
|
| 159 | - * @throws \LogicException |
|
| 160 | - * @return string Base 10 integer string |
|
| 161 | - */ |
|
| 162 | - public function serial(): string |
|
| 163 | - { |
|
| 164 | - // both issuer and serial must be present or both absent |
|
| 165 | - if (!$this->hasIssuer()) { |
|
| 166 | - throw new \LogicException("authorityCertSerialNumber not set."); |
|
| 167 | - } |
|
| 168 | - return $this->_authorityCertSerialNumber; |
|
| 169 | - } |
|
| 156 | + /** |
|
| 157 | + * Get serial number. |
|
| 158 | + * |
|
| 159 | + * @throws \LogicException |
|
| 160 | + * @return string Base 10 integer string |
|
| 161 | + */ |
|
| 162 | + public function serial(): string |
|
| 163 | + { |
|
| 164 | + // both issuer and serial must be present or both absent |
|
| 165 | + if (!$this->hasIssuer()) { |
|
| 166 | + throw new \LogicException("authorityCertSerialNumber not set."); |
|
| 167 | + } |
|
| 168 | + return $this->_authorityCertSerialNumber; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * |
|
| 173 | - * {@inheritdoc} |
|
| 174 | - * @return Sequence |
|
| 175 | - */ |
|
| 176 | - protected function _valueASN1(): Sequence |
|
| 177 | - { |
|
| 178 | - $elements = array(); |
|
| 179 | - if (isset($this->_keyIdentifier)) { |
|
| 180 | - $elements[] = new ImplicitlyTaggedType(0, |
|
| 181 | - new OctetString($this->_keyIdentifier)); |
|
| 182 | - } |
|
| 183 | - // if either issuer or serial is set, both must be set |
|
| 184 | - if (isset($this->_authorityCertIssuer) || |
|
| 185 | - isset($this->_authorityCertSerialNumber)) { |
|
| 186 | - if (!isset($this->_authorityCertIssuer, |
|
| 187 | - $this->_authorityCertSerialNumber)) { |
|
| 188 | - throw new \LogicException( |
|
| 189 | - "AuthorityKeyIdentifier must have both" . |
|
| 190 | - " authorityCertIssuer and authorityCertSerialNumber" . |
|
| 191 | - " present or both absent."); |
|
| 192 | - } |
|
| 193 | - $elements[] = new ImplicitlyTaggedType(1, |
|
| 194 | - $this->_authorityCertIssuer->toASN1()); |
|
| 195 | - $elements[] = new ImplicitlyTaggedType(2, |
|
| 196 | - new Integer($this->_authorityCertSerialNumber)); |
|
| 197 | - } |
|
| 198 | - return new Sequence(...$elements); |
|
| 199 | - } |
|
| 171 | + /** |
|
| 172 | + * |
|
| 173 | + * {@inheritdoc} |
|
| 174 | + * @return Sequence |
|
| 175 | + */ |
|
| 176 | + protected function _valueASN1(): Sequence |
|
| 177 | + { |
|
| 178 | + $elements = array(); |
|
| 179 | + if (isset($this->_keyIdentifier)) { |
|
| 180 | + $elements[] = new ImplicitlyTaggedType(0, |
|
| 181 | + new OctetString($this->_keyIdentifier)); |
|
| 182 | + } |
|
| 183 | + // if either issuer or serial is set, both must be set |
|
| 184 | + if (isset($this->_authorityCertIssuer) || |
|
| 185 | + isset($this->_authorityCertSerialNumber)) { |
|
| 186 | + if (!isset($this->_authorityCertIssuer, |
|
| 187 | + $this->_authorityCertSerialNumber)) { |
|
| 188 | + throw new \LogicException( |
|
| 189 | + "AuthorityKeyIdentifier must have both" . |
|
| 190 | + " authorityCertIssuer and authorityCertSerialNumber" . |
|
| 191 | + " present or both absent."); |
|
| 192 | + } |
|
| 193 | + $elements[] = new ImplicitlyTaggedType(1, |
|
| 194 | + $this->_authorityCertIssuer->toASN1()); |
|
| 195 | + $elements[] = new ImplicitlyTaggedType(2, |
|
| 196 | + new Integer($this->_authorityCertSerialNumber)); |
|
| 197 | + } |
|
| 198 | + return new Sequence(...$elements); |
|
| 199 | + } |
|
| 200 | 200 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Certificate\Extension; |
| 6 | 6 | |
@@ -36,106 +36,106 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | // CA private key |
| 38 | 38 | openssl_pkey_export( |
| 39 | - openssl_pkey_new( |
|
| 40 | - ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
| 41 | - "private_key_bits" => 2048]), $pkey); |
|
| 39 | + openssl_pkey_new( |
|
| 40 | + ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
| 41 | + "private_key_bits" => 2048]), $pkey); |
|
| 42 | 42 | $ca_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
| 43 | 43 | // Issuer private key |
| 44 | 44 | openssl_pkey_export( |
| 45 | - openssl_pkey_new( |
|
| 46 | - ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
| 47 | - "private_key_bits" => 2048]), $pkey); |
|
| 45 | + openssl_pkey_new( |
|
| 46 | + ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
| 47 | + "private_key_bits" => 2048]), $pkey); |
|
| 48 | 48 | $issuer_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
| 49 | 49 | // Holder private key |
| 50 | 50 | openssl_pkey_export( |
| 51 | - openssl_pkey_new( |
|
| 52 | - ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
| 53 | - "private_key_bits" => 2048]), $pkey); |
|
| 51 | + openssl_pkey_new( |
|
| 52 | + ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
|
| 53 | + "private_key_bits" => 2048]), $pkey); |
|
| 54 | 54 | $holder_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
| 55 | 55 | |
| 56 | 56 | // create trust anchor certificate (self signed) |
| 57 | 57 | $tbs_cert = new TBSCertificate( |
| 58 | - Name::fromString("cn=CA"), |
|
| 59 | - $ca_private_key->publicKeyInfo(), |
|
| 60 | - Name::fromString("cn=CA"), |
|
| 61 | - Validity::fromStrings("now", "now + 1 year")); |
|
| 58 | + Name::fromString("cn=CA"), |
|
| 59 | + $ca_private_key->publicKeyInfo(), |
|
| 60 | + Name::fromString("cn=CA"), |
|
| 61 | + Validity::fromStrings("now", "now + 1 year")); |
|
| 62 | 62 | $tbs_cert = $tbs_cert->withRandomSerialNumber() |
| 63 | - ->withAdditionalExtensions( |
|
| 64 | - new BasicConstraintsExtension(true, true), |
|
| 65 | - new SubjectKeyIdentifierExtension(false, |
|
| 66 | - $ca_private_key->publicKeyInfo()->keyIdentifier()), |
|
| 67 | - new KeyUsageExtension(true, |
|
| 68 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
| 69 | - KeyUsageExtension::KEY_CERT_SIGN)); |
|
| 63 | + ->withAdditionalExtensions( |
|
| 64 | + new BasicConstraintsExtension(true, true), |
|
| 65 | + new SubjectKeyIdentifierExtension(false, |
|
| 66 | + $ca_private_key->publicKeyInfo()->keyIdentifier()), |
|
| 67 | + new KeyUsageExtension(true, |
|
| 68 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
| 69 | + KeyUsageExtension::KEY_CERT_SIGN)); |
|
| 70 | 70 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
| 71 | - $ca_private_key->algorithmIdentifier(), |
|
| 72 | - new SHA256AlgorithmIdentifier()); |
|
| 71 | + $ca_private_key->algorithmIdentifier(), |
|
| 72 | + new SHA256AlgorithmIdentifier()); |
|
| 73 | 73 | $ca_cert = $tbs_cert->sign($algo, $ca_private_key); |
| 74 | 74 | |
| 75 | 75 | // create AC issuer certificate |
| 76 | 76 | $tbs_cert = new TBSCertificate( |
| 77 | - Name::fromString("cn=Issuer"), |
|
| 78 | - $issuer_private_key->publicKeyInfo(), |
|
| 79 | - new Name(), |
|
| 80 | - Validity::fromStrings("now", "now + 6 months")); |
|
| 77 | + Name::fromString("cn=Issuer"), |
|
| 78 | + $issuer_private_key->publicKeyInfo(), |
|
| 79 | + new Name(), |
|
| 80 | + Validity::fromStrings("now", "now + 6 months")); |
|
| 81 | 81 | $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert) |
| 82 | - ->withRandomSerialNumber() |
|
| 83 | - ->withAdditionalExtensions( |
|
| 84 | - // issuer must not be a CA |
|
| 85 | - new BasicConstraintsExtension(true, false), |
|
| 86 | - new KeyUsageExtension(true, |
|
| 87 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
| 88 | - KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
| 82 | + ->withRandomSerialNumber() |
|
| 83 | + ->withAdditionalExtensions( |
|
| 84 | + // issuer must not be a CA |
|
| 85 | + new BasicConstraintsExtension(true, false), |
|
| 86 | + new KeyUsageExtension(true, |
|
| 87 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
| 88 | + KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
| 89 | 89 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
| 90 | - $ca_private_key->algorithmIdentifier(), |
|
| 91 | - new SHA256AlgorithmIdentifier()); |
|
| 90 | + $ca_private_key->algorithmIdentifier(), |
|
| 91 | + new SHA256AlgorithmIdentifier()); |
|
| 92 | 92 | $issuer_cert = $tbs_cert->sign($algo, $ca_private_key); |
| 93 | 93 | |
| 94 | 94 | // create AC holder certificate |
| 95 | 95 | $tbs_cert = new TBSCertificate( |
| 96 | - Name::fromString("cn=Holder, gn=John, sn=Doe"), |
|
| 97 | - $holder_private_key->publicKeyInfo(), |
|
| 98 | - new Name(), |
|
| 99 | - Validity::fromStrings("now", "now + 6 months")); |
|
| 96 | + Name::fromString("cn=Holder, gn=John, sn=Doe"), |
|
| 97 | + $holder_private_key->publicKeyInfo(), |
|
| 98 | + new Name(), |
|
| 99 | + Validity::fromStrings("now", "now + 6 months")); |
|
| 100 | 100 | $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert) |
| 101 | - ->withRandomSerialNumber() |
|
| 102 | - ->withAdditionalExtensions( |
|
| 103 | - new BasicConstraintsExtension(true, false), |
|
| 104 | - new KeyUsageExtension(true, |
|
| 105 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
| 106 | - KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
| 101 | + ->withRandomSerialNumber() |
|
| 102 | + ->withAdditionalExtensions( |
|
| 103 | + new BasicConstraintsExtension(true, false), |
|
| 104 | + new KeyUsageExtension(true, |
|
| 105 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
| 106 | + KeyUsageExtension::KEY_ENCIPHERMENT)); |
|
| 107 | 107 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
| 108 | - $ca_private_key->algorithmIdentifier(), |
|
| 109 | - new SHA256AlgorithmIdentifier()); |
|
| 108 | + $ca_private_key->algorithmIdentifier(), |
|
| 109 | + new SHA256AlgorithmIdentifier()); |
|
| 110 | 110 | $holder_cert = $tbs_cert->sign($algo, $ca_private_key); |
| 111 | 111 | |
| 112 | 112 | // named authority that grants the attributes |
| 113 | 113 | $authority = new GeneralNames( |
| 114 | - new UniformResourceIdentifier("uri:trusted_authority")); |
|
| 114 | + new UniformResourceIdentifier("uri:trusted_authority")); |
|
| 115 | 115 | // role attribute |
| 116 | 116 | $attribs = new Attributes( |
| 117 | - Attribute::fromAttributeValues( |
|
| 118 | - RoleAttributeValue::fromString("role-name", $authority))); |
|
| 117 | + Attribute::fromAttributeValues( |
|
| 118 | + RoleAttributeValue::fromString("role-name", $authority))); |
|
| 119 | 119 | $aci = new AttributeCertificateInfo( |
| 120 | - // holder is identified by the holder's public key certificate |
|
| 121 | - new Holder(IssuerSerial::fromPKC($holder_cert)), |
|
| 122 | - AttCertIssuer::fromPKC($issuer_cert), |
|
| 123 | - AttCertValidityPeriod::fromStrings("now - 1 hour", "now + 3 months"), |
|
| 124 | - $attribs); |
|
| 120 | + // holder is identified by the holder's public key certificate |
|
| 121 | + new Holder(IssuerSerial::fromPKC($holder_cert)), |
|
| 122 | + AttCertIssuer::fromPKC($issuer_cert), |
|
| 123 | + AttCertValidityPeriod::fromStrings("now - 1 hour", "now + 3 months"), |
|
| 124 | + $attribs); |
|
| 125 | 125 | $aci = $aci->withRandomSerialNumber() |
| 126 | - ->withAdditionalExtensions( |
|
| 127 | - // named target identifier |
|
| 128 | - TargetInformationExtension::fromTargets( |
|
| 129 | - new TargetName( |
|
| 130 | - new UniformResourceIdentifier("uri:target_identifier"))), |
|
| 131 | - // key identifier of the AC issuer |
|
| 132 | - new AuthorityKeyIdentifierExtension(false, |
|
| 133 | - $issuer_cert->tbsCertificate() |
|
| 134 | - ->subjectPublicKeyInfo() |
|
| 135 | - ->keyIdentifier())); |
|
| 126 | + ->withAdditionalExtensions( |
|
| 127 | + // named target identifier |
|
| 128 | + TargetInformationExtension::fromTargets( |
|
| 129 | + new TargetName( |
|
| 130 | + new UniformResourceIdentifier("uri:target_identifier"))), |
|
| 131 | + // key identifier of the AC issuer |
|
| 132 | + new AuthorityKeyIdentifierExtension(false, |
|
| 133 | + $issuer_cert->tbsCertificate() |
|
| 134 | + ->subjectPublicKeyInfo() |
|
| 135 | + ->keyIdentifier())); |
|
| 136 | 136 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
| 137 | - $issuer_private_key->algorithmIdentifier(), |
|
| 138 | - new SHA256AlgorithmIdentifier()); |
|
| 137 | + $issuer_private_key->algorithmIdentifier(), |
|
| 138 | + new SHA256AlgorithmIdentifier()); |
|
| 139 | 139 | $ac = $aci->sign($algo, $issuer_private_key); |
| 140 | 140 | |
| 141 | 141 | // validate AC |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $validator_config = $validator_config->withTargets($target); |
| 148 | 148 | $validator = new ACValidator($ac, $validator_config); |
| 149 | 149 | if ($validator->validate()) { |
| 150 | - fprintf(STDERR, "AC validation succeeded.\n"); |
|
| 150 | + fprintf(STDERR, "AC validation succeeded.\n"); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | fprintf(STDERR, "Root certificate:\n"); |
@@ -14,86 +14,86 @@ |
||
| 14 | 14 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.2.2 |
| 15 | 15 | */ |
| 16 | 16 | class SubjectInformationAccessExtension extends Extension implements |
| 17 | - \Countable, |
|
| 18 | - \IteratorAggregate |
|
| 17 | + \Countable, |
|
| 18 | + \IteratorAggregate |
|
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Access descriptions. |
|
| 22 | - * |
|
| 23 | - * @var SubjectAccessDescription[] |
|
| 24 | - */ |
|
| 25 | - private $_accessDescriptions; |
|
| 20 | + /** |
|
| 21 | + * Access descriptions. |
|
| 22 | + * |
|
| 23 | + * @var SubjectAccessDescription[] |
|
| 24 | + */ |
|
| 25 | + private $_accessDescriptions; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $critical |
|
| 31 | - * @param SubjectAccessDescription ...$access |
|
| 32 | - */ |
|
| 33 | - public function __construct(bool $critical, |
|
| 34 | - SubjectAccessDescription ...$access) |
|
| 35 | - { |
|
| 36 | - parent::__construct(self::OID_SUBJECT_INFORMATION_ACCESS, $critical); |
|
| 37 | - $this->_accessDescriptions = $access; |
|
| 38 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $critical |
|
| 31 | + * @param SubjectAccessDescription ...$access |
|
| 32 | + */ |
|
| 33 | + public function __construct(bool $critical, |
|
| 34 | + SubjectAccessDescription ...$access) |
|
| 35 | + { |
|
| 36 | + parent::__construct(self::OID_SUBJECT_INFORMATION_ACCESS, $critical); |
|
| 37 | + $this->_accessDescriptions = $access; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - * {@inheritdoc} |
|
| 43 | - * @return self |
|
| 44 | - */ |
|
| 45 | - protected static function _fromDER(string $data, bool $critical): self |
|
| 46 | - { |
|
| 47 | - $access = array_map( |
|
| 48 | - function (UnspecifiedType $el) { |
|
| 49 | - return SubjectAccessDescription::fromASN1($el->asSequence()); |
|
| 50 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 51 | - return new self($critical, ...$access); |
|
| 52 | - } |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + * {@inheritdoc} |
|
| 43 | + * @return self |
|
| 44 | + */ |
|
| 45 | + protected static function _fromDER(string $data, bool $critical): self |
|
| 46 | + { |
|
| 47 | + $access = array_map( |
|
| 48 | + function (UnspecifiedType $el) { |
|
| 49 | + return SubjectAccessDescription::fromASN1($el->asSequence()); |
|
| 50 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 51 | + return new self($critical, ...$access); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get the access descriptions. |
|
| 56 | - * |
|
| 57 | - * @return SubjectAccessDescription[] |
|
| 58 | - */ |
|
| 59 | - public function accessDescriptions(): array |
|
| 60 | - { |
|
| 61 | - return $this->_accessDescriptions; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Get the access descriptions. |
|
| 56 | + * |
|
| 57 | + * @return SubjectAccessDescription[] |
|
| 58 | + */ |
|
| 59 | + public function accessDescriptions(): array |
|
| 60 | + { |
|
| 61 | + return $this->_accessDescriptions; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * |
|
| 66 | - * {@inheritdoc} |
|
| 67 | - * @return Sequence |
|
| 68 | - */ |
|
| 69 | - protected function _valueASN1(): Sequence |
|
| 70 | - { |
|
| 71 | - $elements = array_map( |
|
| 72 | - function (AccessDescription $access) { |
|
| 73 | - return $access->toASN1(); |
|
| 74 | - }, $this->_accessDescriptions); |
|
| 75 | - return new Sequence(...$elements); |
|
| 76 | - } |
|
| 64 | + /** |
|
| 65 | + * |
|
| 66 | + * {@inheritdoc} |
|
| 67 | + * @return Sequence |
|
| 68 | + */ |
|
| 69 | + protected function _valueASN1(): Sequence |
|
| 70 | + { |
|
| 71 | + $elements = array_map( |
|
| 72 | + function (AccessDescription $access) { |
|
| 73 | + return $access->toASN1(); |
|
| 74 | + }, $this->_accessDescriptions); |
|
| 75 | + return new Sequence(...$elements); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get the number of access descriptions. |
|
| 80 | - * |
|
| 81 | - * @see \Countable::count() |
|
| 82 | - * @return int |
|
| 83 | - */ |
|
| 84 | - public function count(): int |
|
| 85 | - { |
|
| 86 | - return count($this->_accessDescriptions); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * Get the number of access descriptions. |
|
| 80 | + * |
|
| 81 | + * @see \Countable::count() |
|
| 82 | + * @return int |
|
| 83 | + */ |
|
| 84 | + public function count(): int |
|
| 85 | + { |
|
| 86 | + return count($this->_accessDescriptions); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get iterator for access descriptions. |
|
| 91 | - * |
|
| 92 | - * @see \IteratorAggregate::getIterator() |
|
| 93 | - * @return \ArrayIterator List of SubjectAccessDescription objects |
|
| 94 | - */ |
|
| 95 | - public function getIterator(): \ArrayIterator |
|
| 96 | - { |
|
| 97 | - return new \ArrayIterator($this->_accessDescriptions); |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * Get iterator for access descriptions. |
|
| 91 | + * |
|
| 92 | + * @see \IteratorAggregate::getIterator() |
|
| 93 | + * @return \ArrayIterator List of SubjectAccessDescription objects |
|
| 94 | + */ |
|
| 95 | + public function getIterator(): \ArrayIterator |
|
| 96 | + { |
|
| 97 | + return new \ArrayIterator($this->_accessDescriptions); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace X509\Certificate\Extension; |
| 5 | 5 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | protected static function _fromDER(string $data, bool $critical): self |
| 46 | 46 | { |
| 47 | 47 | $access = array_map( |
| 48 | - function (UnspecifiedType $el) { |
|
| 48 | + function(UnspecifiedType $el) { |
|
| 49 | 49 | return SubjectAccessDescription::fromASN1($el->asSequence()); |
| 50 | 50 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
| 51 | 51 | return new self($critical, ...$access); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | protected function _valueASN1(): Sequence |
| 70 | 70 | { |
| 71 | 71 | $elements = array_map( |
| 72 | - function (AccessDescription $access) { |
|
| 72 | + function(AccessDescription $access) { |
|
| 73 | 73 | return $access->toASN1(); |
| 74 | 74 | }, $this->_accessDescriptions); |
| 75 | 75 | return new Sequence(...$elements); |
@@ -14,86 +14,86 @@ |
||
| 14 | 14 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.2.1 |
| 15 | 15 | */ |
| 16 | 16 | class AuthorityInformationAccessExtension extends Extension implements |
| 17 | - \Countable, |
|
| 18 | - \IteratorAggregate |
|
| 17 | + \Countable, |
|
| 18 | + \IteratorAggregate |
|
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Access descriptions. |
|
| 22 | - * |
|
| 23 | - * @var AuthorityAccessDescription[] |
|
| 24 | - */ |
|
| 25 | - private $_accessDescriptions; |
|
| 20 | + /** |
|
| 21 | + * Access descriptions. |
|
| 22 | + * |
|
| 23 | + * @var AuthorityAccessDescription[] |
|
| 24 | + */ |
|
| 25 | + private $_accessDescriptions; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $critical |
|
| 31 | - * @param AuthorityAccessDescription ...$access |
|
| 32 | - */ |
|
| 33 | - public function __construct(bool $critical, |
|
| 34 | - AuthorityAccessDescription ...$access) |
|
| 35 | - { |
|
| 36 | - parent::__construct(self::OID_AUTHORITY_INFORMATION_ACCESS, $critical); |
|
| 37 | - $this->_accessDescriptions = $access; |
|
| 38 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $critical |
|
| 31 | + * @param AuthorityAccessDescription ...$access |
|
| 32 | + */ |
|
| 33 | + public function __construct(bool $critical, |
|
| 34 | + AuthorityAccessDescription ...$access) |
|
| 35 | + { |
|
| 36 | + parent::__construct(self::OID_AUTHORITY_INFORMATION_ACCESS, $critical); |
|
| 37 | + $this->_accessDescriptions = $access; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - * {@inheritdoc} |
|
| 43 | - * @return self |
|
| 44 | - */ |
|
| 45 | - protected static function _fromDER(string $data, bool $critical): self |
|
| 46 | - { |
|
| 47 | - $access = array_map( |
|
| 48 | - function (UnspecifiedType $el) { |
|
| 49 | - return AuthorityAccessDescription::fromASN1($el->asSequence()); |
|
| 50 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 51 | - return new self($critical, ...$access); |
|
| 52 | - } |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + * {@inheritdoc} |
|
| 43 | + * @return self |
|
| 44 | + */ |
|
| 45 | + protected static function _fromDER(string $data, bool $critical): self |
|
| 46 | + { |
|
| 47 | + $access = array_map( |
|
| 48 | + function (UnspecifiedType $el) { |
|
| 49 | + return AuthorityAccessDescription::fromASN1($el->asSequence()); |
|
| 50 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 51 | + return new self($critical, ...$access); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get the access descriptions. |
|
| 56 | - * |
|
| 57 | - * @return AuthorityAccessDescription[] |
|
| 58 | - */ |
|
| 59 | - public function accessDescriptions(): array |
|
| 60 | - { |
|
| 61 | - return $this->_accessDescriptions; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Get the access descriptions. |
|
| 56 | + * |
|
| 57 | + * @return AuthorityAccessDescription[] |
|
| 58 | + */ |
|
| 59 | + public function accessDescriptions(): array |
|
| 60 | + { |
|
| 61 | + return $this->_accessDescriptions; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * |
|
| 66 | - * {@inheritdoc} |
|
| 67 | - * @return Sequence |
|
| 68 | - */ |
|
| 69 | - protected function _valueASN1(): Sequence |
|
| 70 | - { |
|
| 71 | - $elements = array_map( |
|
| 72 | - function (AccessDescription $access) { |
|
| 73 | - return $access->toASN1(); |
|
| 74 | - }, $this->_accessDescriptions); |
|
| 75 | - return new Sequence(...$elements); |
|
| 76 | - } |
|
| 64 | + /** |
|
| 65 | + * |
|
| 66 | + * {@inheritdoc} |
|
| 67 | + * @return Sequence |
|
| 68 | + */ |
|
| 69 | + protected function _valueASN1(): Sequence |
|
| 70 | + { |
|
| 71 | + $elements = array_map( |
|
| 72 | + function (AccessDescription $access) { |
|
| 73 | + return $access->toASN1(); |
|
| 74 | + }, $this->_accessDescriptions); |
|
| 75 | + return new Sequence(...$elements); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get the number of access descriptions. |
|
| 80 | - * |
|
| 81 | - * @see \Countable::count() |
|
| 82 | - * @return int |
|
| 83 | - */ |
|
| 84 | - public function count(): int |
|
| 85 | - { |
|
| 86 | - return count($this->_accessDescriptions); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * Get the number of access descriptions. |
|
| 80 | + * |
|
| 81 | + * @see \Countable::count() |
|
| 82 | + * @return int |
|
| 83 | + */ |
|
| 84 | + public function count(): int |
|
| 85 | + { |
|
| 86 | + return count($this->_accessDescriptions); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get iterator for access descriptions. |
|
| 91 | - * |
|
| 92 | - * @see \IteratorAggregate::getIterator() |
|
| 93 | - * @return \ArrayIterator List of AuthorityAccessDescription objects |
|
| 94 | - */ |
|
| 95 | - public function getIterator(): \ArrayIterator |
|
| 96 | - { |
|
| 97 | - return new \ArrayIterator($this->_accessDescriptions); |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * Get iterator for access descriptions. |
|
| 91 | + * |
|
| 92 | + * @see \IteratorAggregate::getIterator() |
|
| 93 | + * @return \ArrayIterator List of AuthorityAccessDescription objects |
|
| 94 | + */ |
|
| 95 | + public function getIterator(): \ArrayIterator |
|
| 96 | + { |
|
| 97 | + return new \ArrayIterator($this->_accessDescriptions); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace X509\Certificate\Extension; |
| 5 | 5 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | protected static function _fromDER(string $data, bool $critical): self |
| 46 | 46 | { |
| 47 | 47 | $access = array_map( |
| 48 | - function (UnspecifiedType $el) { |
|
| 48 | + function(UnspecifiedType $el) { |
|
| 49 | 49 | return AuthorityAccessDescription::fromASN1($el->asSequence()); |
| 50 | 50 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
| 51 | 51 | return new self($critical, ...$access); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | protected function _valueASN1(): Sequence |
| 70 | 70 | { |
| 71 | 71 | $elements = array_map( |
| 72 | - function (AccessDescription $access) { |
|
| 72 | + function(AccessDescription $access) { |
|
| 73 | 73 | return $access->toASN1(); |
| 74 | 74 | }, $this->_accessDescriptions); |
| 75 | 75 | return new Sequence(...$elements); |
@@ -9,31 +9,31 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class SubjectAccessDescription extends AccessDescription |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Access method OID's. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - const OID_METHOD_TIME_STAMPING = "1.3.6.1.5.5.7.48.3"; |
|
| 18 | - const OID_METHOD_CA_REPOSITORY = "1.3.6.1.5.5.7.48.5"; |
|
| 12 | + /** |
|
| 13 | + * Access method OID's. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + const OID_METHOD_TIME_STAMPING = "1.3.6.1.5.5.7.48.3"; |
|
| 18 | + const OID_METHOD_CA_REPOSITORY = "1.3.6.1.5.5.7.48.5"; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Check whether access method is time stamping. |
|
| 22 | - * |
|
| 23 | - * @return bool |
|
| 24 | - */ |
|
| 25 | - public function isTimeStampingMethod(): bool |
|
| 26 | - { |
|
| 27 | - return self::OID_METHOD_TIME_STAMPING === $this->_accessMethod; |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * Check whether access method is time stamping. |
|
| 22 | + * |
|
| 23 | + * @return bool |
|
| 24 | + */ |
|
| 25 | + public function isTimeStampingMethod(): bool |
|
| 26 | + { |
|
| 27 | + return self::OID_METHOD_TIME_STAMPING === $this->_accessMethod; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Check whether access method is CA repository. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function isCARepositoryMethod(): bool |
|
| 36 | - { |
|
| 37 | - return self::OID_METHOD_CA_REPOSITORY === $this->_accessMethod; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Check whether access method is CA repository. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function isCARepositoryMethod(): bool |
|
| 36 | + { |
|
| 37 | + return self::OID_METHOD_CA_REPOSITORY === $this->_accessMethod; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace X509\Certificate\Extension\AccessDescription; |
| 5 | 5 | |
@@ -16,73 +16,73 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | abstract class AccessDescription |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Access method OID. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $_accessMethod; |
|
| 19 | + /** |
|
| 20 | + * Access method OID. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $_accessMethod; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Access location. |
|
| 28 | - * |
|
| 29 | - * @var GeneralName |
|
| 30 | - */ |
|
| 31 | - protected $_accessLocation; |
|
| 26 | + /** |
|
| 27 | + * Access location. |
|
| 28 | + * |
|
| 29 | + * @var GeneralName |
|
| 30 | + */ |
|
| 31 | + protected $_accessLocation; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $method Access method OID |
|
| 37 | - * @param GeneralName $location Access location |
|
| 38 | - */ |
|
| 39 | - public function __construct($method, GeneralName $location) |
|
| 40 | - { |
|
| 41 | - $this->_accessMethod = $method; |
|
| 42 | - $this->_accessLocation = $location; |
|
| 43 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $method Access method OID |
|
| 37 | + * @param GeneralName $location Access location |
|
| 38 | + */ |
|
| 39 | + public function __construct($method, GeneralName $location) |
|
| 40 | + { |
|
| 41 | + $this->_accessMethod = $method; |
|
| 42 | + $this->_accessLocation = $location; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Initialize from ASN.1. |
|
| 47 | - * |
|
| 48 | - * @param Sequence $seq |
|
| 49 | - * @return self |
|
| 50 | - */ |
|
| 51 | - public static function fromASN1(Sequence $seq): self |
|
| 52 | - { |
|
| 53 | - return new static($seq->at(0) |
|
| 54 | - ->asObjectIdentifier() |
|
| 55 | - ->oid(), GeneralName::fromASN1($seq->at(1)->asTagged())); |
|
| 56 | - } |
|
| 45 | + /** |
|
| 46 | + * Initialize from ASN.1. |
|
| 47 | + * |
|
| 48 | + * @param Sequence $seq |
|
| 49 | + * @return self |
|
| 50 | + */ |
|
| 51 | + public static function fromASN1(Sequence $seq): self |
|
| 52 | + { |
|
| 53 | + return new static($seq->at(0) |
|
| 54 | + ->asObjectIdentifier() |
|
| 55 | + ->oid(), GeneralName::fromASN1($seq->at(1)->asTagged())); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Get the access method OID. |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function accessMethod(): string |
|
| 64 | - { |
|
| 65 | - return $this->_accessMethod; |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * Get the access method OID. |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function accessMethod(): string |
|
| 64 | + { |
|
| 65 | + return $this->_accessMethod; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the access location. |
|
| 70 | - * |
|
| 71 | - * @return GeneralName |
|
| 72 | - */ |
|
| 73 | - public function accessLocation(): GeneralName |
|
| 74 | - { |
|
| 75 | - return $this->_accessLocation; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the access location. |
|
| 70 | + * |
|
| 71 | + * @return GeneralName |
|
| 72 | + */ |
|
| 73 | + public function accessLocation(): GeneralName |
|
| 74 | + { |
|
| 75 | + return $this->_accessLocation; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Generate ASN.1 structure. |
|
| 80 | - * |
|
| 81 | - * @return Sequence |
|
| 82 | - */ |
|
| 83 | - public function toASN1() |
|
| 84 | - { |
|
| 85 | - return new Sequence(new ObjectIdentifier($this->_accessMethod), |
|
| 86 | - $this->_accessLocation->toASN1()); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * Generate ASN.1 structure. |
|
| 80 | + * |
|
| 81 | + * @return Sequence |
|
| 82 | + */ |
|
| 83 | + public function toASN1() |
|
| 84 | + { |
|
| 85 | + return new Sequence(new ObjectIdentifier($this->_accessMethod), |
|
| 86 | + $this->_accessLocation->toASN1()); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace X509\Certificate\Extension\AccessDescription; |
| 5 | 5 | |