@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * @return null|string |
45 | 45 | */ |
46 | - public function getPassword():?string{ |
|
46 | + public function getPassword(): ?string{ |
|
47 | 47 | return $this->password; |
48 | 48 | } |
49 | 49 | |
@@ -59,19 +59,19 @@ discard block |
||
59 | 59 | * @param string $password |
60 | 60 | * @throws RSABadPEMFormat |
61 | 61 | */ |
62 | - public function __construct($pem_format, $password = null){ |
|
62 | + public function __construct($pem_format, $password = null) { |
|
63 | 63 | |
64 | 64 | $this->pem_format = $pem_format; |
65 | 65 | $this->rsa_imp = new RSA(); |
66 | 66 | |
67 | - if(!empty($password)) { |
|
67 | + if (!empty($password)) { |
|
68 | 68 | $this->password = trim($password); |
69 | 69 | $this->rsa_imp->setPassword($this->password); |
70 | 70 | } |
71 | 71 | |
72 | 72 | $res = $this->rsa_imp->loadKey($this->pem_format, RSA::PRIVATE_FORMAT_PKCS1); |
73 | 73 | |
74 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
74 | + if (!$res) throw new RSABadPEMFormat(sprintf('pem %s', $pem_format)); |
|
75 | 75 | |
76 | 76 | $this->n = $this->rsa_imp->modulus; |
77 | 77 | } |
@@ -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->rsa_imp->exponent; |
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 |
@@ -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->rsa_imp->publicExponent; |
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 |
@@ -21,7 +21,7 @@ |
||
21 | 21 | /** |
22 | 22 | * @return null|string |
23 | 23 | */ |
24 | - public function getPassword():?string; |
|
24 | + public function getPassword(): ?string; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @return bool |
@@ -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,13 +179,13 @@ 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 | 190 | return !is_null($x509) && $x509->getPublicKey() !== $this->public_key->getStrippedEncoded(); |
191 | 191 | } |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | * @return $this |
196 | 196 | * @throws X509CertMismatchException |
197 | 197 | */ |
198 | - public function setX509CertificateChain(array $x5c){ |
|
198 | + public function setX509CertificateChain(array $x5c) { |
|
199 | 199 | // json array |
200 | - foreach($x5c as $x509_pem){ |
|
200 | + foreach ($x5c as $x509_pem) { |
|
201 | 201 | array_push($this->x509_certificates_chain, X509CertificateFactory::buildFromPEM($x509_pem)); |
202 | 202 | } |
203 | 203 | |
204 | - if($this->checkX509CertMismatch()){ |
|
204 | + if ($this->checkX509CertMismatch()) { |
|
205 | 205 | throw new X509CertMismatchException; |
206 | 206 | } |
207 | 207 |