@@ -14,133 +14,133 @@ |
||
| 14 | 14 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.12 |
| 15 | 15 | */ |
| 16 | 16 | class ExtendedKeyUsageExtension extends Extension implements |
| 17 | - \Countable, |
|
| 18 | - \IteratorAggregate |
|
| 17 | + \Countable, |
|
| 18 | + \IteratorAggregate |
|
| 19 | 19 | { |
| 20 | - const OID_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"; |
|
| 21 | - const OID_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"; |
|
| 22 | - const OID_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"; |
|
| 23 | - const OID_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"; |
|
| 24 | - const OID_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"; |
|
| 25 | - const OID_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"; |
|
| 26 | - const OID_IPSEC_USER = "1.3.6.1.5.5.7.3.7"; |
|
| 27 | - const OID_TIME_STAMPING = "1.3.6.1.5.5.7.3.8"; |
|
| 28 | - const OID_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"; |
|
| 29 | - const OID_DVCS = "1.3.6.1.5.5.7.3.10"; |
|
| 30 | - const OID_SBGP_CERT_AA_SERVER_AUTH = "1.3.6.1.5.5.7.3.11"; |
|
| 31 | - const OID_SCVP_RESPONDER = "1.3.6.1.5.5.7.3.12"; |
|
| 32 | - const OID_EAP_OVER_PPP = "1.3.6.1.5.5.7.3.13"; |
|
| 33 | - const OID_EAP_OVER_LAN = "1.3.6.1.5.5.7.3.14"; |
|
| 34 | - const OID_SCVP_SERVER = "1.3.6.1.5.5.7.3.15"; |
|
| 35 | - const OID_SCVP_CLIENT = "1.3.6.1.5.5.7.3.16"; |
|
| 36 | - const OID_IPSEC_IKE = "1.3.6.1.5.5.7.3.17"; |
|
| 37 | - const OID_CAPWAP_AC = "1.3.6.1.5.5.7.3.18"; |
|
| 38 | - const OID_CAPWAP_WTP = "1.3.6.1.5.5.7.3.19"; |
|
| 39 | - const OID_SIP_DOMAIN = "1.3.6.1.5.5.7.3.20"; |
|
| 40 | - const OID_SECURE_SHELL_CLIENT = "1.3.6.1.5.5.7.3.21"; |
|
| 41 | - const OID_SECURE_SHELL_SERVER = "1.3.6.1.5.5.7.3.22"; |
|
| 42 | - const OID_SEND_ROUTER = "1.3.6.1.5.5.7.3.23"; |
|
| 43 | - const OID_SEND_PROXY = "1.3.6.1.5.5.7.3.24"; |
|
| 44 | - const OID_SEND_OWNER = "1.3.6.1.5.5.7.3.25"; |
|
| 45 | - const OID_SEND_PROXIED_OWNER = "1.3.6.1.5.5.7.3.26"; |
|
| 46 | - const OID_CMC_CA = "1.3.6.1.5.5.7.3.27"; |
|
| 47 | - const OID_CMC_RA = "1.3.6.1.5.5.7.3.28"; |
|
| 48 | - const OID_CMC_ARCHIVE = "1.3.6.1.5.5.7.3.29"; |
|
| 20 | + const OID_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"; |
|
| 21 | + const OID_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"; |
|
| 22 | + const OID_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"; |
|
| 23 | + const OID_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"; |
|
| 24 | + const OID_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"; |
|
| 25 | + const OID_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"; |
|
| 26 | + const OID_IPSEC_USER = "1.3.6.1.5.5.7.3.7"; |
|
| 27 | + const OID_TIME_STAMPING = "1.3.6.1.5.5.7.3.8"; |
|
| 28 | + const OID_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"; |
|
| 29 | + const OID_DVCS = "1.3.6.1.5.5.7.3.10"; |
|
| 30 | + const OID_SBGP_CERT_AA_SERVER_AUTH = "1.3.6.1.5.5.7.3.11"; |
|
| 31 | + const OID_SCVP_RESPONDER = "1.3.6.1.5.5.7.3.12"; |
|
| 32 | + const OID_EAP_OVER_PPP = "1.3.6.1.5.5.7.3.13"; |
|
| 33 | + const OID_EAP_OVER_LAN = "1.3.6.1.5.5.7.3.14"; |
|
| 34 | + const OID_SCVP_SERVER = "1.3.6.1.5.5.7.3.15"; |
|
| 35 | + const OID_SCVP_CLIENT = "1.3.6.1.5.5.7.3.16"; |
|
| 36 | + const OID_IPSEC_IKE = "1.3.6.1.5.5.7.3.17"; |
|
| 37 | + const OID_CAPWAP_AC = "1.3.6.1.5.5.7.3.18"; |
|
| 38 | + const OID_CAPWAP_WTP = "1.3.6.1.5.5.7.3.19"; |
|
| 39 | + const OID_SIP_DOMAIN = "1.3.6.1.5.5.7.3.20"; |
|
| 40 | + const OID_SECURE_SHELL_CLIENT = "1.3.6.1.5.5.7.3.21"; |
|
| 41 | + const OID_SECURE_SHELL_SERVER = "1.3.6.1.5.5.7.3.22"; |
|
| 42 | + const OID_SEND_ROUTER = "1.3.6.1.5.5.7.3.23"; |
|
| 43 | + const OID_SEND_PROXY = "1.3.6.1.5.5.7.3.24"; |
|
| 44 | + const OID_SEND_OWNER = "1.3.6.1.5.5.7.3.25"; |
|
| 45 | + const OID_SEND_PROXIED_OWNER = "1.3.6.1.5.5.7.3.26"; |
|
| 46 | + const OID_CMC_CA = "1.3.6.1.5.5.7.3.27"; |
|
| 47 | + const OID_CMC_RA = "1.3.6.1.5.5.7.3.28"; |
|
| 48 | + const OID_CMC_ARCHIVE = "1.3.6.1.5.5.7.3.29"; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Purpose OID's. |
|
| 52 | - * |
|
| 53 | - * @var string[] $_purposes |
|
| 54 | - */ |
|
| 55 | - protected $_purposes; |
|
| 50 | + /** |
|
| 51 | + * Purpose OID's. |
|
| 52 | + * |
|
| 53 | + * @var string[] $_purposes |
|
| 54 | + */ |
|
| 55 | + protected $_purposes; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Constructor. |
|
| 59 | - * |
|
| 60 | - * @param bool $critical |
|
| 61 | - * @param string ...$purposes |
|
| 62 | - */ |
|
| 63 | - public function __construct(bool $critical, string ...$purposes) |
|
| 64 | - { |
|
| 65 | - parent::__construct(self::OID_EXT_KEY_USAGE, $critical); |
|
| 66 | - $this->_purposes = $purposes; |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * Constructor. |
|
| 59 | + * |
|
| 60 | + * @param bool $critical |
|
| 61 | + * @param string ...$purposes |
|
| 62 | + */ |
|
| 63 | + public function __construct(bool $critical, string ...$purposes) |
|
| 64 | + { |
|
| 65 | + parent::__construct(self::OID_EXT_KEY_USAGE, $critical); |
|
| 66 | + $this->_purposes = $purposes; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * |
|
| 71 | - * {@inheritdoc} |
|
| 72 | - * @return self |
|
| 73 | - */ |
|
| 74 | - protected static function _fromDER(string $data, bool $critical): self |
|
| 75 | - { |
|
| 76 | - $purposes = array_map( |
|
| 77 | - function (UnspecifiedType $el) { |
|
| 78 | - return $el->asObjectIdentifier()->oid(); |
|
| 79 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 80 | - return new self($critical, ...$purposes); |
|
| 81 | - } |
|
| 69 | + /** |
|
| 70 | + * |
|
| 71 | + * {@inheritdoc} |
|
| 72 | + * @return self |
|
| 73 | + */ |
|
| 74 | + protected static function _fromDER(string $data, bool $critical): self |
|
| 75 | + { |
|
| 76 | + $purposes = array_map( |
|
| 77 | + function (UnspecifiedType $el) { |
|
| 78 | + return $el->asObjectIdentifier()->oid(); |
|
| 79 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 80 | + return new self($critical, ...$purposes); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Whether purposes are present. |
|
| 85 | - * |
|
| 86 | - * If multiple purposes are checked, all must be present. |
|
| 87 | - * |
|
| 88 | - * @param string ...$oids |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function has(string ...$oids): bool |
|
| 92 | - { |
|
| 93 | - foreach ($oids as $oid) { |
|
| 94 | - if (!in_array($oid, $this->_purposes)) { |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - return true; |
|
| 99 | - } |
|
| 83 | + /** |
|
| 84 | + * Whether purposes are present. |
|
| 85 | + * |
|
| 86 | + * If multiple purposes are checked, all must be present. |
|
| 87 | + * |
|
| 88 | + * @param string ...$oids |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function has(string ...$oids): bool |
|
| 92 | + { |
|
| 93 | + foreach ($oids as $oid) { |
|
| 94 | + if (!in_array($oid, $this->_purposes)) { |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + return true; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get key usage purpose OID's. |
|
| 103 | - * |
|
| 104 | - * @return string[] |
|
| 105 | - */ |
|
| 106 | - public function purposes(): array |
|
| 107 | - { |
|
| 108 | - return $this->_purposes; |
|
| 109 | - } |
|
| 101 | + /** |
|
| 102 | + * Get key usage purpose OID's. |
|
| 103 | + * |
|
| 104 | + * @return string[] |
|
| 105 | + */ |
|
| 106 | + public function purposes(): array |
|
| 107 | + { |
|
| 108 | + return $this->_purposes; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * |
|
| 113 | - * {@inheritdoc} |
|
| 114 | - * @return Sequence |
|
| 115 | - */ |
|
| 116 | - protected function _valueASN1(): Sequence |
|
| 117 | - { |
|
| 118 | - $elements = array_map( |
|
| 119 | - function ($oid) { |
|
| 120 | - return new ObjectIdentifier($oid); |
|
| 121 | - }, $this->_purposes); |
|
| 122 | - return new Sequence(...$elements); |
|
| 123 | - } |
|
| 111 | + /** |
|
| 112 | + * |
|
| 113 | + * {@inheritdoc} |
|
| 114 | + * @return Sequence |
|
| 115 | + */ |
|
| 116 | + protected function _valueASN1(): Sequence |
|
| 117 | + { |
|
| 118 | + $elements = array_map( |
|
| 119 | + function ($oid) { |
|
| 120 | + return new ObjectIdentifier($oid); |
|
| 121 | + }, $this->_purposes); |
|
| 122 | + return new Sequence(...$elements); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Get the number of purposes. |
|
| 127 | - * |
|
| 128 | - * @see \Countable::count() |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function count(): int |
|
| 132 | - { |
|
| 133 | - return count($this->_purposes); |
|
| 134 | - } |
|
| 125 | + /** |
|
| 126 | + * Get the number of purposes. |
|
| 127 | + * |
|
| 128 | + * @see \Countable::count() |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function count(): int |
|
| 132 | + { |
|
| 133 | + return count($this->_purposes); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Get iterator for usage purposes. |
|
| 138 | - * |
|
| 139 | - * @see \IteratorAggregate::getIterator() |
|
| 140 | - * @return \ArrayIterator |
|
| 141 | - */ |
|
| 142 | - public function getIterator(): \ArrayIterator |
|
| 143 | - { |
|
| 144 | - return new \ArrayIterator($this->_purposes); |
|
| 145 | - } |
|
| 136 | + /** |
|
| 137 | + * Get iterator for usage purposes. |
|
| 138 | + * |
|
| 139 | + * @see \IteratorAggregate::getIterator() |
|
| 140 | + * @return \ArrayIterator |
|
| 141 | + */ |
|
| 142 | + public function getIterator(): \ArrayIterator |
|
| 143 | + { |
|
| 144 | + return new \ArrayIterator($this->_purposes); |
|
| 145 | + } |
|
| 146 | 146 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | protected static function _fromDER(string $data, bool $critical): self |
| 75 | 75 | { |
| 76 | 76 | $purposes = array_map( |
| 77 | - function (UnspecifiedType $el) { |
|
| 77 | + function(UnspecifiedType $el) { |
|
| 78 | 78 | return $el->asObjectIdentifier()->oid(); |
| 79 | 79 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
| 80 | 80 | return new self($critical, ...$purposes); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | protected function _valueASN1(): Sequence |
| 117 | 117 | { |
| 118 | 118 | $elements = array_map( |
| 119 | - function ($oid) { |
|
| 119 | + function($oid) { |
|
| 120 | 120 | return new ObjectIdentifier($oid); |
| 121 | 121 | }, $this->_purposes); |
| 122 | 122 | return new Sequence(...$elements); |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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); |
@@ -18,275 +18,275 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class Extension |
| 20 | 20 | { |
| 21 | - // OID's from standard certificate extensions |
|
| 22 | - const OID_OBSOLETE_AUTHORITY_KEY_IDENTIFIER = "2.5.29.1"; |
|
| 23 | - const OID_OBSOLETE_KEY_ATTRIBUTES = "2.5.29.2"; |
|
| 24 | - const OID_OBSOLETE_CERTIFICATE_POLICIES = "2.5.29.3"; |
|
| 25 | - const OID_OBSOLETE_KEY_USAGE_RESTRICTION = "2.5.29.4"; |
|
| 26 | - const OID_OBSOLETE_POLICY_MAPPING = "2.5.29.5"; |
|
| 27 | - const OID_OBSOLETE_SUBTREES_CONSTRAINT = "2.5.29.6"; |
|
| 28 | - const OID_OBSOLETE_SUBJECT_ALT_NAME = "2.5.29.7"; |
|
| 29 | - const OID_OBSOLETE_ISSUER_ALT_NAME = "2.5.29.8"; |
|
| 30 | - const OID_SUBJECT_DIRECTORY_ATTRIBUTES = "2.5.29.9"; |
|
| 31 | - const OID_OBSOLETE_BASIC_CONSTRAINTS = "2.5.29.10"; |
|
| 32 | - const OID_SUBJECT_KEY_IDENTIFIER = "2.5.29.14"; |
|
| 33 | - const OID_KEY_USAGE = "2.5.29.15"; |
|
| 34 | - const OID_PRIVATE_KEY_USAGE_PERIOD = "2.5.29.16"; |
|
| 35 | - const OID_SUBJECT_ALT_NAME = "2.5.29.17"; |
|
| 36 | - const OID_ISSUER_ALT_NAME = "2.5.29.18"; |
|
| 37 | - const OID_BASIC_CONSTRAINTS = "2.5.29.19"; |
|
| 38 | - const OID_CRL_NUMBER = "2.5.29.20"; |
|
| 39 | - const OID_REASON_CODE = "2.5.29.21"; |
|
| 40 | - const OID_OBSOLETE_EXPIRATION_DATE = "2.5.29.22"; |
|
| 41 | - const OID_INSTRUCTION_CODE = "2.5.29.23"; |
|
| 42 | - const OID_INVALIDITY_DATE = "2.5.29.24"; |
|
| 43 | - const OID_OBSOLETE_CRL_DISTRIBUTION_POINTS = "2.5.29.25"; |
|
| 44 | - const OID_OBSOLETE_ISSUING_DISTRIBUTION_POINT = "2.5.29.26"; |
|
| 45 | - const OID_DELTA_CRL_INDICATOR = "2.5.29.27"; |
|
| 46 | - const OID_ISSUING_DISTRIBUTION_POINT = "2.5.29.28"; |
|
| 47 | - const OID_CERTIFICATE_ISSUER = "2.5.29.29"; |
|
| 48 | - const OID_NAME_CONSTRAINTS = "2.5.29.30"; |
|
| 49 | - const OID_CRL_DISTRIBUTION_POINTS = "2.5.29.31"; |
|
| 50 | - const OID_CERTIFICATE_POLICIES = "2.5.29.32"; |
|
| 51 | - const OID_POLICY_MAPPINGS = "2.5.29.33"; |
|
| 52 | - const OID_OBSOLETE_POLICY_CONSTRAINTS = "2.5.29.34"; |
|
| 53 | - const OID_AUTHORITY_KEY_IDENTIFIER = "2.5.29.35"; |
|
| 54 | - const OID_POLICY_CONSTRAINTS = "2.5.29.36"; |
|
| 55 | - const OID_EXT_KEY_USAGE = "2.5.29.37"; |
|
| 56 | - const OID_AUTHORITY_ATTRIBUTE_IDENTIFIER = "2.5.29.38"; |
|
| 57 | - const OID_ROLE_SPEC_CERT_IDENTIFIER = "2.5.29.39"; |
|
| 58 | - const OID_CRL_STREAM_IDENTIFIER = "2.5.29.40"; |
|
| 59 | - const OID_BASIC_ATT_CONSTRAINTS = "2.5.29.41"; |
|
| 60 | - const OID_DELEGATED_NAME_CONSTRAINTS = "2.5.29.42"; |
|
| 61 | - const OID_TIME_SPECIFICATION = "2.5.29.43"; |
|
| 62 | - const OID_CRL_SCOPE = "2.5.29.44"; |
|
| 63 | - const OID_STATUS_REFERRALS = "2.5.29.45"; |
|
| 64 | - const OID_FRESHEST_CRL = "2.5.29.46"; |
|
| 65 | - const OID_ORDERED_LIST = "2.5.29.47"; |
|
| 66 | - const OID_ATTRIBUTE_DESCRIPTOR = "2.5.29.48"; |
|
| 67 | - const OID_USER_NOTICE = "2.5.29.49"; |
|
| 68 | - const OID_SOA_IDENTIFIER = "2.5.29.50"; |
|
| 69 | - const OID_BASE_UPDATE_TIME = "2.5.29.51"; |
|
| 70 | - const OID_ACCEPTABLE_CERT_POLICIES = "2.5.29.52"; |
|
| 71 | - const OID_DELTA_INFO = "2.5.29.53"; |
|
| 72 | - const OID_INHIBIT_ANY_POLICY = "2.5.29.54"; |
|
| 73 | - const OID_TARGET_INFORMATION = "2.5.29.55"; |
|
| 74 | - const OID_NO_REV_AVAIL = "2.5.29.56"; |
|
| 75 | - const OID_ACCEPTABLE_PRIVILEGE_POLICIES = "2.5.29.57"; |
|
| 76 | - const OID_TO_BE_REVOKED = "2.5.29.58"; |
|
| 77 | - const OID_REVOKED_GROUPS = "2.5.29.59"; |
|
| 78 | - const OID_EXPIRED_CERTS_ON_CRL = "2.5.29.60"; |
|
| 79 | - const OID_INDIRECT_ISSUER = "2.5.29.61"; |
|
| 80 | - const OID_NO_ASSERTION = "2.5.29.62"; |
|
| 81 | - const OID_AA_ISSUING_DISTRIBUTION_POINT = "2.5.29.63"; |
|
| 82 | - const OID_ISSUED_ON_BEHALF_OF = "2.5.29.64"; |
|
| 83 | - const OID_SINGLE_USE = "2.5.29.65"; |
|
| 84 | - const OID_GROUP_AC = "2.5.29.66"; |
|
| 85 | - const OID_ALLOWED_ATT_ASS = "2.5.29.67"; |
|
| 86 | - const OID_ATTRIBUTE_MAPPINGS = "2.5.29.68"; |
|
| 87 | - const OID_HOLDER_NAME_CONSTRAINTS = "2.5.29.69"; |
|
| 21 | + // OID's from standard certificate extensions |
|
| 22 | + const OID_OBSOLETE_AUTHORITY_KEY_IDENTIFIER = "2.5.29.1"; |
|
| 23 | + const OID_OBSOLETE_KEY_ATTRIBUTES = "2.5.29.2"; |
|
| 24 | + const OID_OBSOLETE_CERTIFICATE_POLICIES = "2.5.29.3"; |
|
| 25 | + const OID_OBSOLETE_KEY_USAGE_RESTRICTION = "2.5.29.4"; |
|
| 26 | + const OID_OBSOLETE_POLICY_MAPPING = "2.5.29.5"; |
|
| 27 | + const OID_OBSOLETE_SUBTREES_CONSTRAINT = "2.5.29.6"; |
|
| 28 | + const OID_OBSOLETE_SUBJECT_ALT_NAME = "2.5.29.7"; |
|
| 29 | + const OID_OBSOLETE_ISSUER_ALT_NAME = "2.5.29.8"; |
|
| 30 | + const OID_SUBJECT_DIRECTORY_ATTRIBUTES = "2.5.29.9"; |
|
| 31 | + const OID_OBSOLETE_BASIC_CONSTRAINTS = "2.5.29.10"; |
|
| 32 | + const OID_SUBJECT_KEY_IDENTIFIER = "2.5.29.14"; |
|
| 33 | + const OID_KEY_USAGE = "2.5.29.15"; |
|
| 34 | + const OID_PRIVATE_KEY_USAGE_PERIOD = "2.5.29.16"; |
|
| 35 | + const OID_SUBJECT_ALT_NAME = "2.5.29.17"; |
|
| 36 | + const OID_ISSUER_ALT_NAME = "2.5.29.18"; |
|
| 37 | + const OID_BASIC_CONSTRAINTS = "2.5.29.19"; |
|
| 38 | + const OID_CRL_NUMBER = "2.5.29.20"; |
|
| 39 | + const OID_REASON_CODE = "2.5.29.21"; |
|
| 40 | + const OID_OBSOLETE_EXPIRATION_DATE = "2.5.29.22"; |
|
| 41 | + const OID_INSTRUCTION_CODE = "2.5.29.23"; |
|
| 42 | + const OID_INVALIDITY_DATE = "2.5.29.24"; |
|
| 43 | + const OID_OBSOLETE_CRL_DISTRIBUTION_POINTS = "2.5.29.25"; |
|
| 44 | + const OID_OBSOLETE_ISSUING_DISTRIBUTION_POINT = "2.5.29.26"; |
|
| 45 | + const OID_DELTA_CRL_INDICATOR = "2.5.29.27"; |
|
| 46 | + const OID_ISSUING_DISTRIBUTION_POINT = "2.5.29.28"; |
|
| 47 | + const OID_CERTIFICATE_ISSUER = "2.5.29.29"; |
|
| 48 | + const OID_NAME_CONSTRAINTS = "2.5.29.30"; |
|
| 49 | + const OID_CRL_DISTRIBUTION_POINTS = "2.5.29.31"; |
|
| 50 | + const OID_CERTIFICATE_POLICIES = "2.5.29.32"; |
|
| 51 | + const OID_POLICY_MAPPINGS = "2.5.29.33"; |
|
| 52 | + const OID_OBSOLETE_POLICY_CONSTRAINTS = "2.5.29.34"; |
|
| 53 | + const OID_AUTHORITY_KEY_IDENTIFIER = "2.5.29.35"; |
|
| 54 | + const OID_POLICY_CONSTRAINTS = "2.5.29.36"; |
|
| 55 | + const OID_EXT_KEY_USAGE = "2.5.29.37"; |
|
| 56 | + const OID_AUTHORITY_ATTRIBUTE_IDENTIFIER = "2.5.29.38"; |
|
| 57 | + const OID_ROLE_SPEC_CERT_IDENTIFIER = "2.5.29.39"; |
|
| 58 | + const OID_CRL_STREAM_IDENTIFIER = "2.5.29.40"; |
|
| 59 | + const OID_BASIC_ATT_CONSTRAINTS = "2.5.29.41"; |
|
| 60 | + const OID_DELEGATED_NAME_CONSTRAINTS = "2.5.29.42"; |
|
| 61 | + const OID_TIME_SPECIFICATION = "2.5.29.43"; |
|
| 62 | + const OID_CRL_SCOPE = "2.5.29.44"; |
|
| 63 | + const OID_STATUS_REFERRALS = "2.5.29.45"; |
|
| 64 | + const OID_FRESHEST_CRL = "2.5.29.46"; |
|
| 65 | + const OID_ORDERED_LIST = "2.5.29.47"; |
|
| 66 | + const OID_ATTRIBUTE_DESCRIPTOR = "2.5.29.48"; |
|
| 67 | + const OID_USER_NOTICE = "2.5.29.49"; |
|
| 68 | + const OID_SOA_IDENTIFIER = "2.5.29.50"; |
|
| 69 | + const OID_BASE_UPDATE_TIME = "2.5.29.51"; |
|
| 70 | + const OID_ACCEPTABLE_CERT_POLICIES = "2.5.29.52"; |
|
| 71 | + const OID_DELTA_INFO = "2.5.29.53"; |
|
| 72 | + const OID_INHIBIT_ANY_POLICY = "2.5.29.54"; |
|
| 73 | + const OID_TARGET_INFORMATION = "2.5.29.55"; |
|
| 74 | + const OID_NO_REV_AVAIL = "2.5.29.56"; |
|
| 75 | + const OID_ACCEPTABLE_PRIVILEGE_POLICIES = "2.5.29.57"; |
|
| 76 | + const OID_TO_BE_REVOKED = "2.5.29.58"; |
|
| 77 | + const OID_REVOKED_GROUPS = "2.5.29.59"; |
|
| 78 | + const OID_EXPIRED_CERTS_ON_CRL = "2.5.29.60"; |
|
| 79 | + const OID_INDIRECT_ISSUER = "2.5.29.61"; |
|
| 80 | + const OID_NO_ASSERTION = "2.5.29.62"; |
|
| 81 | + const OID_AA_ISSUING_DISTRIBUTION_POINT = "2.5.29.63"; |
|
| 82 | + const OID_ISSUED_ON_BEHALF_OF = "2.5.29.64"; |
|
| 83 | + const OID_SINGLE_USE = "2.5.29.65"; |
|
| 84 | + const OID_GROUP_AC = "2.5.29.66"; |
|
| 85 | + const OID_ALLOWED_ATT_ASS = "2.5.29.67"; |
|
| 86 | + const OID_ATTRIBUTE_MAPPINGS = "2.5.29.68"; |
|
| 87 | + const OID_HOLDER_NAME_CONSTRAINTS = "2.5.29.69"; |
|
| 88 | 88 | |
| 89 | - // OID's from private certificate extensions arc |
|
| 90 | - const OID_AUTHORITY_INFORMATION_ACCESS = "1.3.6.1.5.5.7.1.1"; |
|
| 91 | - const OID_AA_CONTROLS = "1.3.6.1.5.5.7.1.6"; |
|
| 92 | - const OID_SUBJECT_INFORMATION_ACCESS = "1.3.6.1.5.5.7.1.11"; |
|
| 93 | - const OID_LOGOTYPE = "1.3.6.1.5.5.7.1.12"; |
|
| 89 | + // OID's from private certificate extensions arc |
|
| 90 | + const OID_AUTHORITY_INFORMATION_ACCESS = "1.3.6.1.5.5.7.1.1"; |
|
| 91 | + const OID_AA_CONTROLS = "1.3.6.1.5.5.7.1.6"; |
|
| 92 | + const OID_SUBJECT_INFORMATION_ACCESS = "1.3.6.1.5.5.7.1.11"; |
|
| 93 | + const OID_LOGOTYPE = "1.3.6.1.5.5.7.1.12"; |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Mapping from extension ID to implementation class name. |
|
| 97 | - * |
|
| 98 | - * @internal |
|
| 99 | - * |
|
| 100 | - * @var array |
|
| 101 | - */ |
|
| 102 | - const MAP_OID_TO_CLASS = array( |
|
| 103 | - /* @formatter:off */ |
|
| 104 | - self::OID_AUTHORITY_KEY_IDENTIFIER => AuthorityKeyIdentifierExtension::class, |
|
| 105 | - self::OID_SUBJECT_KEY_IDENTIFIER => SubjectKeyIdentifierExtension::class, |
|
| 106 | - self::OID_KEY_USAGE => KeyUsageExtension::class, |
|
| 107 | - self::OID_CERTIFICATE_POLICIES => CertificatePoliciesExtension::class, |
|
| 108 | - self::OID_POLICY_MAPPINGS => PolicyMappingsExtension::class, |
|
| 109 | - self::OID_SUBJECT_ALT_NAME => SubjectAlternativeNameExtension::class, |
|
| 110 | - self::OID_ISSUER_ALT_NAME => IssuerAlternativeNameExtension::class, |
|
| 111 | - self::OID_SUBJECT_DIRECTORY_ATTRIBUTES => SubjectDirectoryAttributesExtension::class, |
|
| 112 | - self::OID_BASIC_CONSTRAINTS => BasicConstraintsExtension::class, |
|
| 113 | - self::OID_NAME_CONSTRAINTS => NameConstraintsExtension::class, |
|
| 114 | - self::OID_POLICY_CONSTRAINTS => PolicyConstraintsExtension::class, |
|
| 115 | - self::OID_EXT_KEY_USAGE => ExtendedKeyUsageExtension::class, |
|
| 116 | - self::OID_CRL_DISTRIBUTION_POINTS => CRLDistributionPointsExtension::class, |
|
| 117 | - self::OID_INHIBIT_ANY_POLICY => InhibitAnyPolicyExtension::class, |
|
| 118 | - self::OID_FRESHEST_CRL => FreshestCRLExtension::class, |
|
| 119 | - self::OID_NO_REV_AVAIL => NoRevocationAvailableExtension::class, |
|
| 120 | - self::OID_TARGET_INFORMATION => TargetInformationExtension::class, |
|
| 121 | - self::OID_AUTHORITY_INFORMATION_ACCESS => AuthorityInformationAccessExtension::class, |
|
| 122 | - self::OID_AA_CONTROLS => AAControlsExtension::class, |
|
| 123 | - self::OID_SUBJECT_INFORMATION_ACCESS => SubjectInformationAccessExtension::class |
|
| 124 | - /* @formatter:on */ |
|
| 125 | - ); |
|
| 95 | + /** |
|
| 96 | + * Mapping from extension ID to implementation class name. |
|
| 97 | + * |
|
| 98 | + * @internal |
|
| 99 | + * |
|
| 100 | + * @var array |
|
| 101 | + */ |
|
| 102 | + const MAP_OID_TO_CLASS = array( |
|
| 103 | + /* @formatter:off */ |
|
| 104 | + self::OID_AUTHORITY_KEY_IDENTIFIER => AuthorityKeyIdentifierExtension::class, |
|
| 105 | + self::OID_SUBJECT_KEY_IDENTIFIER => SubjectKeyIdentifierExtension::class, |
|
| 106 | + self::OID_KEY_USAGE => KeyUsageExtension::class, |
|
| 107 | + self::OID_CERTIFICATE_POLICIES => CertificatePoliciesExtension::class, |
|
| 108 | + self::OID_POLICY_MAPPINGS => PolicyMappingsExtension::class, |
|
| 109 | + self::OID_SUBJECT_ALT_NAME => SubjectAlternativeNameExtension::class, |
|
| 110 | + self::OID_ISSUER_ALT_NAME => IssuerAlternativeNameExtension::class, |
|
| 111 | + self::OID_SUBJECT_DIRECTORY_ATTRIBUTES => SubjectDirectoryAttributesExtension::class, |
|
| 112 | + self::OID_BASIC_CONSTRAINTS => BasicConstraintsExtension::class, |
|
| 113 | + self::OID_NAME_CONSTRAINTS => NameConstraintsExtension::class, |
|
| 114 | + self::OID_POLICY_CONSTRAINTS => PolicyConstraintsExtension::class, |
|
| 115 | + self::OID_EXT_KEY_USAGE => ExtendedKeyUsageExtension::class, |
|
| 116 | + self::OID_CRL_DISTRIBUTION_POINTS => CRLDistributionPointsExtension::class, |
|
| 117 | + self::OID_INHIBIT_ANY_POLICY => InhibitAnyPolicyExtension::class, |
|
| 118 | + self::OID_FRESHEST_CRL => FreshestCRLExtension::class, |
|
| 119 | + self::OID_NO_REV_AVAIL => NoRevocationAvailableExtension::class, |
|
| 120 | + self::OID_TARGET_INFORMATION => TargetInformationExtension::class, |
|
| 121 | + self::OID_AUTHORITY_INFORMATION_ACCESS => AuthorityInformationAccessExtension::class, |
|
| 122 | + self::OID_AA_CONTROLS => AAControlsExtension::class, |
|
| 123 | + self::OID_SUBJECT_INFORMATION_ACCESS => SubjectInformationAccessExtension::class |
|
| 124 | + /* @formatter:on */ |
|
| 125 | + ); |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Mapping from extensions ID to short name. |
|
| 129 | - * |
|
| 130 | - * @internal |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - const MAP_OID_TO_NAME = array( |
|
| 135 | - /* @formatter:off */ |
|
| 136 | - self::OID_AUTHORITY_KEY_IDENTIFIER => "authorityKeyIdentifier", |
|
| 137 | - self::OID_SUBJECT_KEY_IDENTIFIER => "subjectKeyIdentifier", |
|
| 138 | - self::OID_KEY_USAGE => "keyUsage", |
|
| 139 | - self::OID_PRIVATE_KEY_USAGE_PERIOD => "privateKeyUsagePeriod", |
|
| 140 | - self::OID_CERTIFICATE_POLICIES => "certificatePolicies", |
|
| 141 | - self::OID_POLICY_MAPPINGS => "policyMappings", |
|
| 142 | - self::OID_SUBJECT_ALT_NAME => "subjectAltName", |
|
| 143 | - self::OID_ISSUER_ALT_NAME => "issuerAltName", |
|
| 144 | - self::OID_SUBJECT_DIRECTORY_ATTRIBUTES => "subjectDirectoryAttributes", |
|
| 145 | - self::OID_BASIC_CONSTRAINTS => "basicConstraints", |
|
| 146 | - self::OID_NAME_CONSTRAINTS => "nameConstraints", |
|
| 147 | - self::OID_POLICY_CONSTRAINTS => "policyConstraints", |
|
| 148 | - self::OID_EXT_KEY_USAGE => "extKeyUsage", |
|
| 149 | - self::OID_CRL_DISTRIBUTION_POINTS => "cRLDistributionPoints", |
|
| 150 | - self::OID_INHIBIT_ANY_POLICY => "inhibitAnyPolicy", |
|
| 151 | - self::OID_FRESHEST_CRL => "freshestCRL", |
|
| 152 | - self::OID_NO_REV_AVAIL => "noRevAvail", |
|
| 153 | - self::OID_TARGET_INFORMATION => "targetInformation", |
|
| 154 | - self::OID_AUTHORITY_INFORMATION_ACCESS => "authorityInfoAccess", |
|
| 155 | - self::OID_AA_CONTROLS => "aaControls", |
|
| 156 | - self::OID_SUBJECT_INFORMATION_ACCESS => "subjectInfoAccess", |
|
| 157 | - self::OID_LOGOTYPE => "logotype" |
|
| 158 | - /* @formatter:on */ |
|
| 159 | - ); |
|
| 127 | + /** |
|
| 128 | + * Mapping from extensions ID to short name. |
|
| 129 | + * |
|
| 130 | + * @internal |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + const MAP_OID_TO_NAME = array( |
|
| 135 | + /* @formatter:off */ |
|
| 136 | + self::OID_AUTHORITY_KEY_IDENTIFIER => "authorityKeyIdentifier", |
|
| 137 | + self::OID_SUBJECT_KEY_IDENTIFIER => "subjectKeyIdentifier", |
|
| 138 | + self::OID_KEY_USAGE => "keyUsage", |
|
| 139 | + self::OID_PRIVATE_KEY_USAGE_PERIOD => "privateKeyUsagePeriod", |
|
| 140 | + self::OID_CERTIFICATE_POLICIES => "certificatePolicies", |
|
| 141 | + self::OID_POLICY_MAPPINGS => "policyMappings", |
|
| 142 | + self::OID_SUBJECT_ALT_NAME => "subjectAltName", |
|
| 143 | + self::OID_ISSUER_ALT_NAME => "issuerAltName", |
|
| 144 | + self::OID_SUBJECT_DIRECTORY_ATTRIBUTES => "subjectDirectoryAttributes", |
|
| 145 | + self::OID_BASIC_CONSTRAINTS => "basicConstraints", |
|
| 146 | + self::OID_NAME_CONSTRAINTS => "nameConstraints", |
|
| 147 | + self::OID_POLICY_CONSTRAINTS => "policyConstraints", |
|
| 148 | + self::OID_EXT_KEY_USAGE => "extKeyUsage", |
|
| 149 | + self::OID_CRL_DISTRIBUTION_POINTS => "cRLDistributionPoints", |
|
| 150 | + self::OID_INHIBIT_ANY_POLICY => "inhibitAnyPolicy", |
|
| 151 | + self::OID_FRESHEST_CRL => "freshestCRL", |
|
| 152 | + self::OID_NO_REV_AVAIL => "noRevAvail", |
|
| 153 | + self::OID_TARGET_INFORMATION => "targetInformation", |
|
| 154 | + self::OID_AUTHORITY_INFORMATION_ACCESS => "authorityInfoAccess", |
|
| 155 | + self::OID_AA_CONTROLS => "aaControls", |
|
| 156 | + self::OID_SUBJECT_INFORMATION_ACCESS => "subjectInfoAccess", |
|
| 157 | + self::OID_LOGOTYPE => "logotype" |
|
| 158 | + /* @formatter:on */ |
|
| 159 | + ); |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Extension's OID. |
|
| 163 | - * |
|
| 164 | - * @var string $_oid |
|
| 165 | - */ |
|
| 166 | - protected $_oid; |
|
| 161 | + /** |
|
| 162 | + * Extension's OID. |
|
| 163 | + * |
|
| 164 | + * @var string $_oid |
|
| 165 | + */ |
|
| 166 | + protected $_oid; |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Whether extension is critical. |
|
| 170 | - * |
|
| 171 | - * @var bool $_critical |
|
| 172 | - */ |
|
| 173 | - protected $_critical; |
|
| 168 | + /** |
|
| 169 | + * Whether extension is critical. |
|
| 170 | + * |
|
| 171 | + * @var bool $_critical |
|
| 172 | + */ |
|
| 173 | + protected $_critical; |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Get ASN.1 structure of the extension value. |
|
| 177 | - * |
|
| 178 | - * @return Element |
|
| 179 | - */ |
|
| 180 | - abstract protected function _valueASN1(); |
|
| 175 | + /** |
|
| 176 | + * Get ASN.1 structure of the extension value. |
|
| 177 | + * |
|
| 178 | + * @return Element |
|
| 179 | + */ |
|
| 180 | + abstract protected function _valueASN1(); |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Parse extension value from DER. |
|
| 184 | - * |
|
| 185 | - * @param string $data DER data |
|
| 186 | - * @param bool $critical Whether extension is critical |
|
| 187 | - * @throws \BadMethodCallException |
|
| 188 | - * @return self |
|
| 189 | - */ |
|
| 190 | - protected static function _fromDER(string $data, bool $critical) |
|
| 191 | - { |
|
| 192 | - throw new \BadMethodCallException( |
|
| 193 | - __FUNCTION__ . " must be implemented in derived class."); |
|
| 194 | - } |
|
| 182 | + /** |
|
| 183 | + * Parse extension value from DER. |
|
| 184 | + * |
|
| 185 | + * @param string $data DER data |
|
| 186 | + * @param bool $critical Whether extension is critical |
|
| 187 | + * @throws \BadMethodCallException |
|
| 188 | + * @return self |
|
| 189 | + */ |
|
| 190 | + protected static function _fromDER(string $data, bool $critical) |
|
| 191 | + { |
|
| 192 | + throw new \BadMethodCallException( |
|
| 193 | + __FUNCTION__ . " must be implemented in derived class."); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Constructor. |
|
| 198 | - * |
|
| 199 | - * @param string $oid Extension OID |
|
| 200 | - * @param bool $critical Whether extension is critical |
|
| 201 | - */ |
|
| 202 | - public function __construct(string $oid, bool $critical) |
|
| 203 | - { |
|
| 204 | - $this->_oid = $oid; |
|
| 205 | - $this->_critical = $critical; |
|
| 206 | - } |
|
| 196 | + /** |
|
| 197 | + * Constructor. |
|
| 198 | + * |
|
| 199 | + * @param string $oid Extension OID |
|
| 200 | + * @param bool $critical Whether extension is critical |
|
| 201 | + */ |
|
| 202 | + public function __construct(string $oid, bool $critical) |
|
| 203 | + { |
|
| 204 | + $this->_oid = $oid; |
|
| 205 | + $this->_critical = $critical; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Initialize from ASN.1. |
|
| 210 | - * |
|
| 211 | - * @param Sequence $seq |
|
| 212 | - * @return self |
|
| 213 | - */ |
|
| 214 | - public static function fromASN1(Sequence $seq): Extension |
|
| 215 | - { |
|
| 216 | - $extnID = $seq->at(0) |
|
| 217 | - ->asObjectIdentifier() |
|
| 218 | - ->oid(); |
|
| 219 | - $critical = false; |
|
| 220 | - $idx = 1; |
|
| 221 | - if ($seq->has($idx, Element::TYPE_BOOLEAN)) { |
|
| 222 | - $critical = $seq->at($idx++) |
|
| 223 | - ->asBoolean() |
|
| 224 | - ->value(); |
|
| 225 | - } |
|
| 226 | - $data = $seq->at($idx) |
|
| 227 | - ->asOctetString() |
|
| 228 | - ->string(); |
|
| 229 | - if (array_key_exists($extnID, self::MAP_OID_TO_CLASS)) { |
|
| 230 | - $cls = self::MAP_OID_TO_CLASS[$extnID]; |
|
| 231 | - return $cls::_fromDER($data, $critical); |
|
| 232 | - } |
|
| 233 | - return new UnknownExtension($extnID, $critical, new DERData($data)); |
|
| 234 | - } |
|
| 208 | + /** |
|
| 209 | + * Initialize from ASN.1. |
|
| 210 | + * |
|
| 211 | + * @param Sequence $seq |
|
| 212 | + * @return self |
|
| 213 | + */ |
|
| 214 | + public static function fromASN1(Sequence $seq): Extension |
|
| 215 | + { |
|
| 216 | + $extnID = $seq->at(0) |
|
| 217 | + ->asObjectIdentifier() |
|
| 218 | + ->oid(); |
|
| 219 | + $critical = false; |
|
| 220 | + $idx = 1; |
|
| 221 | + if ($seq->has($idx, Element::TYPE_BOOLEAN)) { |
|
| 222 | + $critical = $seq->at($idx++) |
|
| 223 | + ->asBoolean() |
|
| 224 | + ->value(); |
|
| 225 | + } |
|
| 226 | + $data = $seq->at($idx) |
|
| 227 | + ->asOctetString() |
|
| 228 | + ->string(); |
|
| 229 | + if (array_key_exists($extnID, self::MAP_OID_TO_CLASS)) { |
|
| 230 | + $cls = self::MAP_OID_TO_CLASS[$extnID]; |
|
| 231 | + return $cls::_fromDER($data, $critical); |
|
| 232 | + } |
|
| 233 | + return new UnknownExtension($extnID, $critical, new DERData($data)); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Get extension OID. |
|
| 238 | - * |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public function oid(): string |
|
| 242 | - { |
|
| 243 | - return $this->_oid; |
|
| 244 | - } |
|
| 236 | + /** |
|
| 237 | + * Get extension OID. |
|
| 238 | + * |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public function oid(): string |
|
| 242 | + { |
|
| 243 | + return $this->_oid; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * Check whether extension is critical. |
|
| 248 | - * |
|
| 249 | - * @return bool |
|
| 250 | - */ |
|
| 251 | - public function isCritical(): bool |
|
| 252 | - { |
|
| 253 | - return $this->_critical; |
|
| 254 | - } |
|
| 246 | + /** |
|
| 247 | + * Check whether extension is critical. |
|
| 248 | + * |
|
| 249 | + * @return bool |
|
| 250 | + */ |
|
| 251 | + public function isCritical(): bool |
|
| 252 | + { |
|
| 253 | + return $this->_critical; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Generate ASN.1 structure. |
|
| 258 | - * |
|
| 259 | - * @return Sequence |
|
| 260 | - */ |
|
| 261 | - public function toASN1(): Sequence |
|
| 262 | - { |
|
| 263 | - $elements = array(new ObjectIdentifier($this->_oid)); |
|
| 264 | - if ($this->_critical) { |
|
| 265 | - $elements[] = new Boolean(true); |
|
| 266 | - } |
|
| 267 | - $elements[] = new OctetString($this->_valueASN1()->toDER()); |
|
| 268 | - return new Sequence(...$elements); |
|
| 269 | - } |
|
| 256 | + /** |
|
| 257 | + * Generate ASN.1 structure. |
|
| 258 | + * |
|
| 259 | + * @return Sequence |
|
| 260 | + */ |
|
| 261 | + public function toASN1(): Sequence |
|
| 262 | + { |
|
| 263 | + $elements = array(new ObjectIdentifier($this->_oid)); |
|
| 264 | + if ($this->_critical) { |
|
| 265 | + $elements[] = new Boolean(true); |
|
| 266 | + } |
|
| 267 | + $elements[] = new OctetString($this->_valueASN1()->toDER()); |
|
| 268 | + return new Sequence(...$elements); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Get short name of the extension. |
|
| 273 | - * |
|
| 274 | - * @return string |
|
| 275 | - */ |
|
| 276 | - public function extensionName(): string |
|
| 277 | - { |
|
| 278 | - if (array_key_exists($this->_oid, self::MAP_OID_TO_NAME)) { |
|
| 279 | - return self::MAP_OID_TO_NAME[$this->_oid]; |
|
| 280 | - } |
|
| 281 | - return $this->oid(); |
|
| 282 | - } |
|
| 271 | + /** |
|
| 272 | + * Get short name of the extension. |
|
| 273 | + * |
|
| 274 | + * @return string |
|
| 275 | + */ |
|
| 276 | + public function extensionName(): string |
|
| 277 | + { |
|
| 278 | + if (array_key_exists($this->_oid, self::MAP_OID_TO_NAME)) { |
|
| 279 | + return self::MAP_OID_TO_NAME[$this->_oid]; |
|
| 280 | + } |
|
| 281 | + return $this->oid(); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function __toString(): string |
|
| 289 | - { |
|
| 290 | - return $this->extensionName(); |
|
| 291 | - } |
|
| 284 | + /** |
|
| 285 | + * |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function __toString(): string |
|
| 289 | + { |
|
| 290 | + return $this->extensionName(); |
|
| 291 | + } |
|
| 292 | 292 | } |