SocialConnect /
auth
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * SocialConnect project |
||
| 4 | * @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
||
| 5 | */ |
||
| 6 | declare(strict_types=1); |
||
| 7 | |||
| 8 | namespace SocialConnect\OAuth1\Signature; |
||
| 9 | |||
| 10 | use SocialConnect\Provider\Consumer; |
||
| 11 | use SocialConnect\OAuth1\Token; |
||
| 12 | use SocialConnect\OAuth1\Util; |
||
| 13 | |||
| 14 | class MethodRSASHA1 extends AbstractSignatureMethod |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var string Path to the private key used for signing |
||
| 18 | */ |
||
| 19 | private $privateKey; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * MethodRSASHA1 constructor. |
||
| 23 | * |
||
| 24 | * @param string $privateKey The path to the private key used for signing |
||
| 25 | */ |
||
| 26 | 12 | public function __construct($privateKey) |
|
| 27 | { |
||
| 28 | 12 | if (!is_readable($privateKey)) { |
|
| 29 | 1 | throw new \InvalidArgumentException('The private key is not readable'); |
|
| 30 | } |
||
| 31 | |||
| 32 | 11 | if (!function_exists('openssl_pkey_get_private')) { |
|
| 33 | throw new \InvalidArgumentException('The OpenSSL-Extension seems not to be available. That is necessary to handle RSA-SHA1'); |
||
| 34 | } |
||
| 35 | |||
| 36 | 11 | $this->privateKey = $privateKey; |
|
| 37 | 11 | } |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | 2 | public function getName() |
|
| 43 | { |
||
| 44 | 2 | return 'RSA-SHA1'; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param string $signatureBase |
||
| 49 | * @param Consumer $consumer |
||
| 50 | * @param Token $token |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 2 | public function buildSignature(string $signatureBase, Consumer $consumer, Token $token) |
|
| 54 | { |
||
| 55 | 2 | $certificate = openssl_pkey_get_private('file://' . $this->privateKey); |
|
| 56 | 2 | $privateKeyId = openssl_pkey_get_private($certificate); |
|
| 57 | |||
| 58 | 2 | $signature = null; |
|
| 59 | |||
| 60 | 2 | openssl_sign($signatureBase, $signature, $privateKeyId, OPENSSL_ALGO_SHA1); |
|
| 61 | 2 | openssl_free_key($privateKeyId); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 62 | |||
| 63 | 2 | return base64_encode($signature); |
|
| 64 | } |
||
| 65 | } |
||
| 66 |