Author: Titouan Galopin
Example #1
0
 public function test parse PublicKey returns instance of ParsedKey()
 {
     $result = $this->service->parse($this->getPublicKey());
     $this->assertInstanceOf(ParsedKey::class, $result);
     $this->assertInstanceOf(Key::class, $result->getSource());
     $this->assertEquals(OPENSSL_KEYTYPE_RSA, $result->getType());
     $this->assertEquals(4096, $result->getBits());
     $this->assertInternalType('array', $result->getDetails());
     $this->assertEquals(trim($this->getPublicKey()->getPEM()), trim($result->getKey()));
 }
Example #2
0
 /**
  * Send a request encoded in the format defined by the ACME protocol.
  *
  * @param string $method
  * @param string $endpoint
  * @param array  $payload
  * @param bool   $returnJson
  *
  * @throws AcmeCoreServerException When the ACME server returns an error HTTP status code.
  * @throws AcmeCoreClientException When an error occured during response parsing.
  *
  * @return array|string Array of parsed JSON if $returnJson = true, string otherwise
  */
 public function signedRequest($method, $endpoint, array $payload = [], $returnJson = true)
 {
     $privateKey = $this->accountKeyPair->getPrivateKey();
     $parsedKey = $this->keyParser->parse($privateKey);
     $header = ['alg' => 'RS256', 'jwk' => ['kty' => 'RSA', 'n' => $this->base64Encoder->encode($parsedKey->getDetail('n')), 'e' => $this->base64Encoder->encode($parsedKey->getDetail('e'))]];
     $protected = $header;
     if ($this->lastResponse) {
         $protected['nonce'] = $this->lastResponse->getHeaderLine('Replay-Nonce');
     }
     $protected = $this->base64Encoder->encode(json_encode($protected));
     $payload = $this->base64Encoder->encode(json_encode($payload, JSON_UNESCAPED_SLASHES));
     $signature = $this->base64Encoder->encode($this->dataSigner->signData($protected . '.' . $payload, $privateKey));
     $payload = ['header' => $header, 'protected' => $protected, 'payload' => $payload, 'signature' => $signature];
     return $this->unsignedRequest($method, $endpoint, $payload, $returnJson);
 }