Beispiel #1
0
 /**
  * @param string $uri
  * @param array  $payload
  *
  * @return ResponseInterface
  */
 private function signedPostRequest($uri, array $payload)
 {
     $header = ['alg' => 'RS256', 'jwk' => ['kty' => 'RSA', 'n' => Base64Url::encode($this->privateKey->getDetails()['rsa']['n']), 'e' => Base64Url::encode($this->privateKey->getDetails()['rsa']['e'])]];
     $protected = $header;
     $protected['nonce'] = $this->getLastNonce();
     $payload64 = Base64Url::encode(json_encode($payload, JSON_UNESCAPED_SLASHES));
     $protected64 = Base64Url::encode(json_encode($protected));
     $signed64 = Base64Url::encode($this->privateKey->sign($protected64 . '.' . $payload64));
     return $this->request('POST', $uri, ['json' => ['header' => $header, 'protected' => $protected64, 'payload' => $payload64, 'signature' => $signed64]]);
 }
Beispiel #2
0
 /**
  * @param string     $type
  * @param string[]   $data
  * @param PrivateKey $privateKey
  *
  * @return ChallengeInterface|null
  */
 public static function create($type, array $data, PrivateKey $privateKey)
 {
     switch ($type) {
         case ChallengeInterface::HTTP_01:
             $challenge = new Http01Challenge();
             break;
         case ChallengeInterface::DNS_01:
             $challenge = new Dns01Challenge();
             break;
         case ChallengeInterface::TLS_SNI_01:
             $challenge = new TlsSni01Challenge();
             break;
         default:
             return;
     }
     $challenge->setToken($data['token']);
     $challenge->setUri($data['uri']);
     $challenge->setStatus(isset($data['status']) ? $data['status'] : null);
     $header = ['e' => Base64Url::encode($privateKey->getDetails()['rsa']['e']), 'kty' => 'RSA', 'n' => Base64Url::encode($privateKey->getDetails()['rsa']['n'])];
     $authorizationKey = $challenge->getToken() . '.' . Base64Url::encode(hash('sha256', json_encode($header), true));
     $challenge->setAuthorizationKey($authorizationKey);
     return $challenge;
 }