@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace security\rsa; |
16 | 16 |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace security\rsa; |
16 | 16 |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace security\rsa; |
16 | 16 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param string $password |
35 | 35 | * @throws RSABadPEMFormat |
36 | 36 | */ |
37 | - public function __construct($pem_format, $password = null){ |
|
37 | + public function __construct($pem_format, $password = null) { |
|
38 | 38 | parent::__construct($pem_format, $password); |
39 | 39 | $this->e = $this->rsa_imp->publicExponent; |
40 | 40 | } |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | public function getEncoded() |
63 | 63 | { |
64 | 64 | $pem = $this->rsa_imp->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_PKCS8); |
65 | - $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/','',$pem); |
|
66 | - $pem = preg_replace('/\-+END PUBLIC KEY\-+/','',$pem); |
|
67 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
65 | + $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/', '', $pem); |
|
66 | + $pem = preg_replace('/\-+END PUBLIC KEY\-+/', '', $pem); |
|
67 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
68 | 68 | return $pem; |
69 | 69 | } |
70 | 70 |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace security\rsa; |
16 | 16 |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | */ |
34 | 34 | private $rsa_imp; |
35 | 35 | |
36 | - private function __construct(){ |
|
36 | + private function __construct() { |
|
37 | 37 | $this->rsa_imp = new \Crypt_RSA(); |
38 | 38 | } |
39 | 39 | |
40 | - private function __clone(){} |
|
40 | + private function __clone() {} |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @return RSAFacade |
44 | 44 | */ |
45 | - public static function getInstance(){ |
|
46 | - if(!is_object(self::$instance)){ |
|
45 | + public static function getInstance() { |
|
46 | + if (!is_object(self::$instance)) { |
|
47 | 47 | self::$instance = new RSAFacade(); |
48 | 48 | } |
49 | 49 | return self::$instance; |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @param $bits |
54 | 54 | * @return KeyPair |
55 | 55 | */ |
56 | - public function buildKeyPair($bits){ |
|
56 | + public function buildKeyPair($bits) { |
|
57 | 57 | $this->rsa_imp->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); |
58 | 58 | $this->rsa_imp->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1); |
59 | 59 | |
60 | 60 | $list = $this->rsa_imp->createKey($bits); |
61 | - return new KeyPair( new _RSAPublicKeyPEMFornat($list['publickey']), new _RSAPrivateKeyPEMFornat($list['privatekey'])); |
|
61 | + return new KeyPair(new _RSAPublicKeyPEMFornat($list['publickey']), new _RSAPrivateKeyPEMFornat($list['privatekey'])); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param \Math_BigInteger $e |
67 | 67 | * @return RSAPublicKey |
68 | 68 | */ |
69 | - public function buildPublicKey(\Math_BigInteger $n, \Math_BigInteger $e){ |
|
69 | + public function buildPublicKey(\Math_BigInteger $n, \Math_BigInteger $e) { |
|
70 | 70 | $public_key_pem = $this->rsa_imp->_convertPublicKey($n, $e); |
71 | 71 | return new _RSAPublicKeyPEMFornat($public_key_pem); |
72 | 72 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param \Math_BigInteger $d |
77 | 77 | * @return RSAPrivateKey |
78 | 78 | */ |
79 | - public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d){ |
|
79 | + public function buildMinimalPrivateKey(\Math_BigInteger $n, \Math_BigInteger $d) { |
|
80 | 80 | $this->rsa_imp->modulus = $n; |
81 | 81 | $this->rsa_imp->exponent = $d; |
82 | 82 | $private_key_pem = $this->rsa_imp->_getPrivatePublicKey(); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | \Math_BigInteger $q, |
102 | 102 | \Math_BigInteger $dp, |
103 | 103 | \Math_BigInteger $dq, |
104 | - \Math_BigInteger $qi){ |
|
104 | + \Math_BigInteger $qi) { |
|
105 | 105 | |
106 | 106 | $private_key_pem = $this->rsa_imp->_convertPrivateKey( |
107 | 107 | $n, |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @return RSAPrivateKey |
121 | 121 | * @throws RSABadPEMFormat |
122 | 122 | */ |
123 | - public function buildPrivateKeyFromPEM($private_key_pem, $password = null){ |
|
123 | + public function buildPrivateKeyFromPEM($private_key_pem, $password = null) { |
|
124 | 124 | return new _RSAPrivateKeyPEMFornat($private_key_pem, $password); |
125 | 125 | } |
126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return RSAPublicKey |
130 | 130 | * @throws RSABadPEMFormat |
131 | 131 | */ |
132 | - public function buildPublicKeyFromPEM($public_key_pem){ |
|
132 | + public function buildPublicKeyFromPEM($public_key_pem) { |
|
133 | 133 | return new _RSAPublicKeyPEMFornat($public_key_pem); |
134 | 134 | } |
135 | 135 |
@@ -43,17 +43,17 @@ |
||
43 | 43 | * @param string $password |
44 | 44 | * @throws RSABadPEMFormat |
45 | 45 | */ |
46 | - public function __construct($pem_format, $password = null){ |
|
46 | + public function __construct($pem_format, $password = null) { |
|
47 | 47 | |
48 | 48 | $this->pem_format = $pem_format; |
49 | 49 | $this->rsa_imp = new \Crypt_RSA(); |
50 | 50 | |
51 | - if(!empty($password)) |
|
51 | + if (!empty($password)) |
|
52 | 52 | $this->rsa_imp->setPassword($password); |
53 | 53 | |
54 | 54 | $res = $this->rsa_imp->loadKey($this->pem_format, CRYPT_RSA_PRIVATE_FORMAT_PKCS1); |
55 | 55 | |
56 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
56 | + if (!$res) throw new RSABadPEMFormat(sprintf('pem %s', $pem_format)); |
|
57 | 57 | |
58 | 58 | $this->n = $this->rsa_imp->modulus; |
59 | 59 | } |
@@ -48,12 +48,15 @@ |
||
48 | 48 | $this->pem_format = $pem_format; |
49 | 49 | $this->rsa_imp = new \Crypt_RSA(); |
50 | 50 | |
51 | - if(!empty($password)) |
|
52 | - $this->rsa_imp->setPassword($password); |
|
51 | + if(!empty($password)) { |
|
52 | + $this->rsa_imp->setPassword($password); |
|
53 | + } |
|
53 | 54 | |
54 | 55 | $res = $this->rsa_imp->loadKey($this->pem_format, CRYPT_RSA_PRIVATE_FORMAT_PKCS1); |
55 | 56 | |
56 | - if(!$res) throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
57 | + if(!$res) { |
|
58 | + throw new RSABadPEMFormat(sprintf('pem %s',$pem_format )); |
|
59 | + } |
|
57 | 60 | |
58 | 61 | $this->n = $this->rsa_imp->modulus; |
59 | 62 | } |
@@ -33,20 +33,20 @@ |
||
33 | 33 | * @param PublicKey $public_key |
34 | 34 | * @param PrivateKey $private_key |
35 | 35 | */ |
36 | - public function __construct(PublicKey $public_key, PrivateKey $private_key){ |
|
36 | + public function __construct(PublicKey $public_key, PrivateKey $private_key) { |
|
37 | 37 | |
38 | 38 | $this->private_key = $private_key; |
39 | - $this->public_key = $public_key; |
|
39 | + $this->public_key = $public_key; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @return PublicKey |
44 | 44 | */ |
45 | - public function getPublic(){ return $this->public_key; } |
|
45 | + public function getPublic() { return $this->public_key; } |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @return PrivateKey |
49 | 49 | */ |
50 | - public function getPrivate(){ return $this->private_key; } |
|
50 | + public function getPrivate() { return $this->private_key; } |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param string $pem |
25 | 25 | * @return X509Certificate |
26 | 26 | */ |
27 | - static public function buildFromPEM($pem){ |
|
27 | + static public function buildFromPEM($pem) { |
|
28 | 28 | return new _X509Certificate($pem); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @var array |
29 | 29 | */ |
30 | - private $info = array(); |
|
30 | + private $info = array(); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @var \File_X509|null |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | */ |
40 | 40 | private $original_pem = null; |
41 | 41 | |
42 | - public function __construct($pem){ |
|
42 | + public function __construct($pem) { |
|
43 | 43 | |
44 | 44 | $this->file = new \File_X509(); |
45 | 45 | $this->info = $this->file->loadX509($pem); |
46 | - if($this->info === false) throw new InvalidX509CertificateException($pem); |
|
46 | + if ($this->info === false) throw new InvalidX509CertificateException($pem); |
|
47 | 47 | $this->original_pem = $pem; |
48 | 48 | } |
49 | 49 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | return $this->original_pem; |
56 | 56 | } |
57 | 57 | |
58 | - private function calculateThumbprint($alg){ |
|
59 | - $pem = str_replace( array("\n","\r"), '', trim($this->original_pem)); |
|
58 | + private function calculateThumbprint($alg) { |
|
59 | + $pem = str_replace(array("\n", "\r"), '', trim($this->original_pem)); |
|
60 | 60 | return strtoupper(hash($alg, base64_decode($pem))); |
61 | 61 | } |
62 | 62 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | public function getPublicKey() |
83 | 83 | { |
84 | 84 | $pem = (string)$this->file->getPublicKey(); |
85 | - $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/','',$pem); |
|
86 | - $pem = preg_replace('/\-+END PUBLIC KEY\-+/','',$pem); |
|
87 | - $pem = str_replace( array("\n","\r","\t"), '', trim($pem)); |
|
85 | + $pem = preg_replace('/\-+BEGIN PUBLIC KEY\-+/', '', $pem); |
|
86 | + $pem = preg_replace('/\-+END PUBLIC KEY\-+/', '', $pem); |
|
87 | + $pem = str_replace(array("\n", "\r", "\t"), '', trim($pem)); |
|
88 | 88 | return $pem; |
89 | 89 | } |
90 | 90 |
@@ -43,7 +43,9 @@ |
||
43 | 43 | |
44 | 44 | $this->file = new \File_X509(); |
45 | 45 | $this->info = $this->file->loadX509($pem); |
46 | - if($this->info === false) throw new InvalidX509CertificateException($pem); |
|
46 | + if($this->info === false) { |
|
47 | + throw new InvalidX509CertificateException($pem); |
|
48 | + } |
|
47 | 49 | $this->original_pem = $pem; |
48 | 50 | } |
49 | 51 |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace security; |
16 | 16 |