public function testCertificatePairs() { try { $infoCard = new InfoCard\InfoCard(); } catch (InfoCard\Exception $e) { $message = $e->getMessage(); if (preg_match('/requires.+mcrypt/', $message)) { $this->markTestSkipped($message); } else { throw $e; } } $key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey); $this->assertTrue((bool) $key_id); $key_pair = $infoCard->getCertificatePair($key_id); $this->assertTrue(!empty($key_pair['public'])); $this->assertTrue(!empty($key_pair['private'])); $this->assertTrue(!empty($key_pair['type_uri'])); $infoCard->removeCertificatePair($key_id); $failed = false; try { $key_pair = $infoCard->getCertificatePair($key_id); } catch (InfoCard\Exception $e) { $failed = true; } $this->assertTrue($failed); try { $infoCard->addCertificatePair("I don't exist", "I don't exist"); } catch (InfoCard\Exception $e) { $this->assertTrue(true); } catch (\Exception $e) { $this->assertFalse(true); } $key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey, Cipher::ENC_RSA_OAEP_MGF1P, "foo"); try { $key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey, Cipher::ENC_RSA_OAEP_MGF1P, "foo"); } catch (InfoCard\Exception $e) { $this->assertTrue(true); } catch (\Exception $e) { $this->assertFalse(true); } $this->assertTrue(!empty($key_id)); try { $infoCard->removeCertificatePair($key_id); $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey, "Doesn't Exist", "foo"); } catch (InfoCard\Exception $e) { $this->assertTrue(true); } catch (\Exception $e) { $this->assertFalse(true); } }
public function testGetCertificatePairThrowsExceptionOnMissingKeyId() { $this->requireMcryptAndOpensslOrSkip(); $infoCard = new InfoCard\InfoCard(); $key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey); $infoCard->removeCertificatePair($key_id); $this->setExpectedException('Zend\\InfoCard\\Exception\\InvalidArgumentException', 'Invalid Certificate Pair ID provided'); $key_pair = $infoCard->getCertificatePair($key_id); }
/** * Return a Certificate Pair from a key ID * * @param string $keyId The Key ID of the certificate pair in the component * @throws Zend\InfoCard\Exception * @return array An array containing the path to the private/public key files, * the type URI and the password if provided */ public function getCertificatePair($keyId) { return $this->_infoCard->getCertificatePair($keyId); }