Exemplo n.º 1
0
 public function testGettersAndSetters()
 {
     $public_contents = file_get_contents($this->pubkey);
     $private_contents = file_get_contents($this->privkey);
     $key = new KeyPair();
     $key->setPublicKey($public_contents);
     $this->assertEquals($public_contents, $key->getPublicKey());
     $key->setPrivateKey($private_contents);
     $this->assertEquals($private_contents, $key->getPrivateKey());
 }
Exemplo n.º 2
0
 public function testSignAndVerify()
 {
     $key = new KeyPair();
     $key->generate();
     $key->store($this->pubkey, $this->privkey);
     $this->assertTrue(file_exists($this->pubkey));
     $this->assertTrue(file_exists($this->privkey));
     $client = new Client();
     $client->setPrivateKey($this->privkey);
     $data = ['fox' => 'quick', 'colour' => 'brown', 'dog' => 'lazy'];
     $signature = $client->createSignature($data);
     $this->assertNotEmpty($signature);
     $this->assertTrue(is_string($data['cnonce']));
     $this->assertTrue(is_string($data['sig']));
     $server = new Server();
     $server->setPublicKey($this->pubkey);
     $server->verifySignature($data);
     $this->assertTrue(true);
     // Can't verify without signature
     unset($data['sig']);
     try {
         $server->verifySignature($data);
         $this->assertTrue(false);
     } catch (SignatureException $e) {
         $this->assertTrue(true);
     }
     // Can't verify garbage signature
     $data['sig'] = 'Garbage';
     try {
         $server->verifySignature($data);
         $this->assertTrue(false);
     } catch (SignatureException $e) {
         $this->assertTrue(true);
     }
     // Can't verify without cnonce
     $data = ['fox' => 'quick', 'colour' => 'brown', 'dog' => 'lazy'];
     $signature = $client->createSignature($data);
     $this->assertNotEmpty($signature);
     unset($data['cnonce']);
     try {
         $server->verifySignature($data);
         $this->assertTrue(false);
     } catch (SignatureException $e) {
         $this->assertTrue(true);
     }
 }