| Conditions | 1 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | public static function generate(array $payload, string $url, string $nonce, string $accountKeysPath): array |
||
| 8 | { |
||
| 9 | $privateKey = openssl_pkey_get_private(file_get_contents($accountKeysPath . 'private.pem')); |
||
| 10 | $details = openssl_pkey_get_details($privateKey); |
||
|
|
|||
| 11 | |||
| 12 | $protected = [ |
||
| 13 | 'alg' => 'RS256', |
||
| 14 | 'jwk' => [ |
||
| 15 | 'kty' => 'RSA', |
||
| 16 | 'n' => Base64::UrlSafeEncode($details['rsa']['n']), |
||
| 17 | 'e' => Base64::UrlSafeEncode($details['rsa']['e']), |
||
| 18 | ], |
||
| 19 | 'nonce' => $nonce, |
||
| 20 | 'url' => $url, |
||
| 21 | ]; |
||
| 22 | |||
| 23 | $payload64 = Base64::urlSafeEncode(str_replace('\\/', '/', json_encode($payload))); |
||
| 24 | $protected64 = Base64::urlSafeEncode(json_encode($protected)); |
||
| 25 | |||
| 26 | openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, 'SHA256'); |
||
| 27 | |||
| 28 | $signed64 = Base64::urlSafeEncode($signed); |
||
| 29 | |||
| 30 | return [ |
||
| 31 | 'protected' => $protected64, |
||
| 32 | 'payload' => $payload64, |
||
| 33 | 'signature' => $signed64, |
||
| 34 | ]; |
||
| 37 |