Esempio n. 1
0
 /**
  *
  */
 public function testES512Verify()
 {
     $public_key = new JWK();
     $public_key->setValues(['kty' => 'EC', 'kid' => '*****@*****.**', 'use' => 'sig', 'crv' => 'P-521', 'x' => 'AHKZLLOsCOzz5cY97ewNUajB957y-C-U88c3v13nmGZx6sYl_oJXu9A5RkTKqjqvjyekWF-7ytDyRXYgCF5cj0Kt', 'y' => 'AdymlHvOiLxXkEhayXQnNCvDX4h9htZaCJN34kfmC6pV5OhQHiraVySsUdaQkAgDPrwQrJmbnX9cwlGfP-HqHZR1']);
     $header = 'eyJhbGciOiJFUzUxMiIsImtpZCI6ImJpbGJvLmJhZ2dpbnNAaG9iYml0b24uZXhhbXBsZSJ9';
     $payload = 'SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBkb24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcmUgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4';
     $signature = 'AE_R_YZCChjn4791jSQCrdPZCNYqHXCTZH0-JZGYNlaAjP2kqaluUIIUnC9qvbu9Plon7KRTzoNEuT4Va2cmL1eJAQy3mtPBu_u_sDDyYjnAMDxXPn7XrT0lw-kvAD890jl8e2puQens_IEKBpHABlsbEPX6sFY8OcGDqoRuBomu9xQ2';
     $ecdsa = new ES512();
     $this->assertTrue($ecdsa->verify($public_key, $header . '.' . $payload, Base64Url::decode($signature)));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function createJWK(array $values = [])
 {
     $jwk = new JWK();
     $jwk->setValues($values);
     return $jwk;
 }
Esempio n. 3
0
 /**
  * @param array $complete_header
  *
  * @return \Jose\JWKInterface
  */
 private function getPublicKey(array $complete_header)
 {
     if (!array_key_exists('epk', $complete_header)) {
         throw new \RuntimeException('"epk" parameter missing');
     }
     if (!is_array($complete_header['epk'])) {
         throw new \RuntimeException('"epk" parameter is not an array of parameter');
     }
     $public_key = new JWK();
     $public_key->setValues($complete_header['epk']);
     $this->checkKey($public_key, false);
     return $public_key;
 }
Esempio n. 4
0
 /**
  *
  */
 public function testKey()
 {
     $jwk = new JWK(['kty' => 'EC', 'crv' => 'P-256', 'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', 'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', 'use' => 'sign', 'key_ops' => ['sign'], 'alg' => 'ES256', 'kid' => '0123456789']);
     $this->assertEquals('EC', $jwk->getKeyType());
     $this->assertEquals('ES256', $jwk->getAlgorithm());
     $this->assertEquals('sign', $jwk->getPublicKeyUse());
     $this->assertEquals('0123456789', $jwk->getKeyID());
     $this->assertEquals(['sign'], $jwk->getKeyOperations());
     $this->assertEquals('P-256', $jwk->getValue('crv'));
     $this->assertNull($jwk->getX509Url());
     $this->assertNull($jwk->getX509CertificateChain());
     $this->assertNull($jwk->getX509CertificateSha1Thumbprint());
     $this->assertNull($jwk->getX509CertificateSha256Thumbprint());
     $this->assertEquals('f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', $jwk->getValue('x'));
     $this->assertEquals('x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', $jwk->getValue('y'));
     $this->assertEquals('{"kty":"EC","crv":"P-256","x":"f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU","y":"x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0","use":"sign","key_ops":["sign"],"alg":"ES256","kid":"0123456789"}', json_encode($jwk));
 }
Esempio n. 5
0
 /**
  *
  */
 public function testES512SignAndVerify()
 {
     $public_key = new JWK();
     $public_key->setValues(ECConverter::loadKeyFromFile('file://' . __DIR__ . DIRECTORY_SEPARATOR . 'Keys' . DIRECTORY_SEPARATOR . 'EC' . DIRECTORY_SEPARATOR . 'public.es512.key'));
     $private_key = new JWK();
     $private_key->setValues(ECConverter::loadKeyFromFile('file://' . __DIR__ . DIRECTORY_SEPARATOR . 'Keys' . DIRECTORY_SEPARATOR . 'EC' . DIRECTORY_SEPARATOR . 'private.es512.key'));
     $ecdsa = new ES512();
     $data = 'Je suis Charlie';
     $signature = $ecdsa->sign($private_key, $data);
     $this->assertTrue($ecdsa->verify($public_key, $data, $signature));
 }