@@ -59,32 +59,32 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | parent::__construct($headers); |
| 61 | 61 | |
| 62 | - if(count($headers) === 0 ) return; |
|
| 62 | + if (count($headers) === 0) return; |
|
| 63 | 63 | |
| 64 | 64 | // certificates |
| 65 | - if(in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])){ |
|
| 65 | + if (in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])) { |
|
| 66 | 66 | |
| 67 | 67 | // json array |
| 68 | - foreach($headers[PublicJSONWebKeyParameters::X_509CertificateChain] as $x509_pem){ |
|
| 69 | - $this->x509_certificates_chain[] = X509CertificateFactory::buildFromPEM($x509_pem); |
|
| 68 | + foreach ($headers[PublicJSONWebKeyParameters::X_509CertificateChain] as $x509_pem) { |
|
| 69 | + $this->x509_certificates_chain[] = X509CertificateFactory::buildFromPEM($x509_pem); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if($this->checkX509CertMismatch()){ |
|
| 72 | + if ($this->checkX509CertMismatch()) { |
|
| 73 | 73 | throw new X509CertMismatchException; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $this->set[PublicJSONWebKeyParameters::X_509CertificateChain] = new JsonArray($headers[PublicJSONWebKeyParameters::X_509CertificateChain]); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if(in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint, $headers)){ |
|
| 80 | - $this->set[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]) ; |
|
| 79 | + if (in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint, $headers)) { |
|
| 80 | + $this->set[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if(in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint, $headers)){ |
|
| 83 | + if (in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint, $headers)) { |
|
| 84 | 84 | $this->set[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if(in_array(PublicJSONWebKeyParameters::X_509Url, $headers)){ |
|
| 87 | + if (in_array(PublicJSONWebKeyParameters::X_509Url, $headers)) { |
|
| 88 | 88 | $this->set[PublicJSONWebKeyParameters::X_509Url] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509Url]); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function setVisibility($visibility) |
| 106 | 106 | { |
| 107 | - if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
| 107 | + if (!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
| 108 | 108 | throw new InvalidJWKVisibilityException; |
| 109 | 109 | $this->visibility = $visibility; |
| 110 | 110 | return $this; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * @return null | X509Certificate |
| 131 | 131 | */ |
| 132 | - public function getX509LeafCertificate(){ |
|
| 132 | + public function getX509LeafCertificate() { |
|
| 133 | 133 | return count($this->x509_certificates_chain) > 0 ? $this->x509_certificates_chain[0] : null; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function getX509CertificateSha1Thumbprint($fallback_on_x5c = false) |
| 150 | 150 | { |
| 151 | - $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint])? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]->getString(); |
|
| 152 | - if(empty($res) && $fallback_on_x5c){ |
|
| 151 | + $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]) ? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]->getString(); |
|
| 152 | + if (empty($res) && $fallback_on_x5c) { |
|
| 153 | 153 | $x509 = $this->getX509LeafCertificate(); |
| 154 | - if(!is_null($x509)){ |
|
| 154 | + if (!is_null($x509)) { |
|
| 155 | 155 | return $x509->getSHA_1_Thumbprint(); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function getX509CertificateSha256Thumbprint($fallback_on_x5c = false) |
| 166 | 166 | { |
| 167 | - $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint])? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]->getString(); |
|
| 168 | - if(empty($res) && $fallback_on_x5c){ |
|
| 167 | + $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]) ? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]->getString(); |
|
| 168 | + if (empty($res) && $fallback_on_x5c) { |
|
| 169 | 169 | $x509 = $this->getX509LeafCertificate(); |
| 170 | - if(!is_null($x509)){ |
|
| 170 | + if (!is_null($x509)) { |
|
| 171 | 171 | return $x509->getSHA_256_Thumbprint(); |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -179,18 +179,18 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | public function getX509Url() |
| 181 | 181 | { |
| 182 | - return is_null($this[PublicJSONWebKeyParameters::X_509Url])? null : $this[PublicJSONWebKeyParameters::X_509Url]->getString(); |
|
| 182 | + return is_null($this[PublicJSONWebKeyParameters::X_509Url]) ? null : $this[PublicJSONWebKeyParameters::X_509Url]->getString(); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * @return bool |
| 187 | 187 | */ |
| 188 | - protected function checkX509CertMismatch(){ |
|
| 188 | + protected function checkX509CertMismatch() { |
|
| 189 | 189 | $x509 = $this->getX509LeafCertificate(); |
| 190 | - if(is_null($x509)) return false; |
|
| 190 | + if (is_null($x509)) return false; |
|
| 191 | 191 | $ppk1 = $x509->getPublicKey(); |
| 192 | 192 | $ppk2 = $this->public_key->getStrippedEncoded(); |
| 193 | - return $ppk1 !== $ppk2 ; |
|
| 193 | + return $ppk1 !== $ppk2; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | * @return $this |
| 199 | 199 | * @throws X509CertMismatchException |
| 200 | 200 | */ |
| 201 | - public function setX509CertificateChain(array $x5c){ |
|
| 201 | + public function setX509CertificateChain(array $x5c) { |
|
| 202 | 202 | // json array |
| 203 | - foreach($x5c as $x509_pem){ |
|
| 203 | + foreach ($x5c as $x509_pem) { |
|
| 204 | 204 | array_push($this->x509_certificates_chain, X509CertificateFactory::buildFromPEM($x509_pem)); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if($this->checkX509CertMismatch()){ |
|
| 207 | + if ($this->checkX509CertMismatch()) { |
|
| 208 | 208 | throw new X509CertMismatchException; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | parent::__construct($headers); |
| 61 | 61 | |
| 62 | - if(count($headers) === 0 ) return; |
|
| 62 | + if(count($headers) === 0 ) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 63 | 65 | |
| 64 | 66 | // certificates |
| 65 | 67 | if(in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])){ |
@@ -104,8 +106,9 @@ discard block |
||
| 104 | 106 | */ |
| 105 | 107 | public function setVisibility($visibility) |
| 106 | 108 | { |
| 107 | - if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
| 108 | - throw new InvalidJWKVisibilityException; |
|
| 109 | + if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) { |
|
| 110 | + throw new InvalidJWKVisibilityException; |
|
| 111 | + } |
|
| 109 | 112 | $this->visibility = $visibility; |
| 110 | 113 | return $this; |
| 111 | 114 | } |
@@ -187,7 +190,9 @@ discard block |
||
| 187 | 190 | */ |
| 188 | 191 | protected function checkX509CertMismatch(){ |
| 189 | 192 | $x509 = $this->getX509LeafCertificate(); |
| 190 | - if(is_null($x509)) return false; |
|
| 193 | + if(is_null($x509)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 191 | 196 | $ppk1 = $x509->getPublicKey(); |
| 192 | 197 | $ppk2 = $this->public_key->getStrippedEncoded(); |
| 193 | 198 | return $ppk1 !== $ppk2 ; |
@@ -34,17 +34,17 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private $rsa_imp; |
| 36 | 36 | |
| 37 | - private function __construct(){ |
|
| 37 | + private function __construct() { |
|
| 38 | 38 | $this->rsa_imp = new RSA(); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - private function __clone(){} |
|
| 41 | + private function __clone() {} |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * @return RSAFacade |
| 45 | 45 | */ |
| 46 | - public static function getInstance(){ |
|
| 47 | - if(!is_object(self::$instance)){ |
|
| 46 | + public static function getInstance() { |
|
| 47 | + if (!is_object(self::$instance)) { |
|
| 48 | 48 | self::$instance = new RSAFacade(); |
| 49 | 49 | } |
| 50 | 50 | return self::$instance; |
@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | * @param $bits |
| 55 | 55 | * @return KeyPair |
| 56 | 56 | */ |
| 57 | - public function buildKeyPair($bits){ |
|
| 57 | + public function buildKeyPair($bits) { |
|
| 58 | 58 | $this->rsa_imp->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS1); |
| 59 | 59 | $this->rsa_imp->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS1); |
| 60 | 60 | |
| 61 | 61 | $list = $this->rsa_imp->createKey($bits); |
| 62 | - return new KeyPair( new _RSAPublicKeyPEMFormat($list['publickey']), new _RSAPrivateKeyPEMFormat($list['privatekey'])); |
|
| 62 | + return new KeyPair(new _RSAPublicKeyPEMFormat($list['publickey']), new _RSAPrivateKeyPEMFormat($list['privatekey'])); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param BigInteger $e |
| 68 | 68 | * @return RSAPublicKey |
| 69 | 69 | */ |
| 70 | - public function buildPublicKey(BigInteger $n, BigInteger $e){ |
|
| 70 | + public function buildPublicKey(BigInteger $n, BigInteger $e) { |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | 73 | $key = PublicKeyLoader::load([ |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param \Math_BigInteger $d |
| 85 | 85 | * @return RSAPrivateKey |
| 86 | 86 | */ |
| 87 | - public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d){ |
|
| 87 | + public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d) { |
|
| 88 | 88 | $this->rsa_imp->modulus = $n; |
| 89 | 89 | $this->rsa_imp->exponent = $d; |
| 90 | 90 | $private_key_pem = $this->rsa_imp->_getPrivatePublicKey(); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | BigInteger $q, |
| 110 | 110 | BigInteger $dp, |
| 111 | 111 | BigInteger $dq, |
| 112 | - BigInteger $qi){ |
|
| 112 | + BigInteger $qi) { |
|
| 113 | 113 | |
| 114 | 114 | $private_key_pem = $this->rsa_imp->_convertPrivateKey( |
| 115 | 115 | $n, |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return RSAPrivateKey |
| 129 | 129 | * @throws RSABadPEMFormat |
| 130 | 130 | */ |
| 131 | - public function buildPrivateKeyFromPEM($private_key_pem, $password = null){ |
|
| 131 | + public function buildPrivateKeyFromPEM($private_key_pem, $password = null) { |
|
| 132 | 132 | return new _RSAPrivateKeyPEMFormat($private_key_pem, $password); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @return RSAPublicKey |
| 138 | 138 | * @throws RSABadPEMFormat |
| 139 | 139 | */ |
| 140 | - public function buildPublicKeyFromPEM($public_key_pem){ |
|
| 140 | + public function buildPublicKeyFromPEM($public_key_pem) { |
|
| 141 | 141 | return new _RSAPublicKeyPEMFormat($public_key_pem); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param string $password |
| 33 | 33 | * @throws RSABadPEMFormat |
| 34 | 34 | */ |
| 35 | - public function __construct($pem_format, $password = null){ |
|
| 35 | + public function __construct($pem_format, $password = null) { |
|
| 36 | 36 | parent::__construct($pem_format, $password); |
| 37 | 37 | $this->e = $this->key->getPublicExponent(); |
| 38 | 38 | } |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getStrippedEncoded(): string |
| 85 | 85 | { |
| 86 | - $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/','', $this->getEncoded()); |
|
| 87 | - $pem = preg_replace('/\-+END PUBLIC KEY\-+/','',$pem); |
|
| 88 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
| 86 | + $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/', '', $this->getEncoded()); |
|
| 87 | + $pem = preg_replace('/\-+END PUBLIC KEY\-+/', '', $pem); |
|
| 88 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
| 89 | 89 | return $pem; |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | \ No newline at end of file |
@@ -23,19 +23,19 @@ |
||
| 23 | 23 | { |
| 24 | 24 | |
| 25 | 25 | protected $key; |
| 26 | - public function __construct(AsymmetricKey $key){ |
|
| 26 | + public function __construct(AsymmetricKey $key) { |
|
| 27 | 27 | parent::__construct(); |
| 28 | 28 | $this->key = $key; |
| 29 | 29 | } |
| 30 | - public function getModulus(){ |
|
| 30 | + public function getModulus() { |
|
| 31 | 31 | return $this->key->modulus; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function getPrivateExponent(){ |
|
| 34 | + public function getPrivateExponent() { |
|
| 35 | 35 | return $this->key->exponent; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function getPublicExponent(){ |
|
| 38 | + public function getPublicExponent() { |
|
| 39 | 39 | return $this->key->publicExponent; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | * @param string $password |
| 33 | 33 | * @throws RSABadPEMFormat |
| 34 | 34 | */ |
| 35 | - public function __construct($pem_format, $password = null){ |
|
| 35 | + public function __construct($pem_format, $password = null) { |
|
| 36 | 36 | |
| 37 | 37 | parent::__construct($pem_format, $password); |
| 38 | 38 | $this->d = $this->key->getPrivateExponent(); |
| 39 | - if($this->d->toString() === $this->e->toString()) |
|
| 39 | + if ($this->d->toString() === $this->e->toString()) |
|
| 40 | 40 | throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function getStrippedEncoded(): string |
| 73 | 73 | { |
| 74 | - $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/','',$this->getEncoded()); |
|
| 75 | - $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/','',$pem); |
|
| 76 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
| 74 | + $pem = preg_replace('/\-+BEGIN RSA PRIVATE KEY\-+/', '', $this->getEncoded()); |
|
| 75 | + $pem = preg_replace('/\-+END RSA PRIVATE KEY\-+/', '', $pem); |
|
| 76 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
| 77 | 77 | return $pem; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -36,8 +36,9 @@ |
||
| 36 | 36 | |
| 37 | 37 | parent::__construct($pem_format, $password); |
| 38 | 38 | $this->d = $this->key->getPrivateExponent(); |
| 39 | - if($this->d->toString() === $this->e->toString()) |
|
| 40 | - throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
|
| 39 | + if($this->d->toString() === $this->e->toString()) { |
|
| 40 | + throw new RSABadPEMFormat(sprintf('pem %s is a public key!', $pem_format)); |
|
| 41 | + } |
|
| 41 | 42 | } |
| 42 | 43 | |
| 43 | 44 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return null|string |
| 49 | 49 | */ |
| 50 | - public function getPassword():?string{ |
|
| 50 | + public function getPassword(): ?string{ |
|
| 51 | 51 | return $this->password; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -63,18 +63,18 @@ discard block |
||
| 63 | 63 | * @param string $password |
| 64 | 64 | * @throws RSABadPEMFormat |
| 65 | 65 | */ |
| 66 | - public function __construct($pem_format, $password = null){ |
|
| 66 | + public function __construct($pem_format, $password = null) { |
|
| 67 | 67 | |
| 68 | 68 | $this->pem_format = $pem_format; |
| 69 | 69 | $this->rsa_imp = new RSA(); |
| 70 | 70 | |
| 71 | - if(!empty($password)) { |
|
| 71 | + if (!empty($password)) { |
|
| 72 | 72 | $this->password = trim($password); |
| 73 | 73 | $this->rsa_imp->setPassword($this->password); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
| 77 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
| 77 | + if (!$res) throw new RSABadPEMFormat(sprintf('pem %s', $pem_format)); |
|
| 78 | 78 | $this->key = new CustomAsymmetricKey(PublicKeyLoader::load($this->pem_format, $this->password)); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -74,7 +74,9 @@ |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
| 77 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
| 77 | + if(!$res) { |
|
| 78 | + throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
| 79 | + } |
|
| 78 | 80 | $this->key = new CustomAsymmetricKey(PublicKeyLoader::load($this->pem_format, $this->password)); |
| 79 | 81 | } |
| 80 | 82 | |