コード例 #1
0
 /**
  * @group delete-private
  */
 public function testDeletePrivateKey()
 {
     $keyId = '*****@*****.**';
     $this->gpg->deletePrivateKey($keyId);
     $expectedKeys = array();
     // {{{ first-keypair@example.com
     $key = new Crypt_GPG_Key();
     $expectedKeys[] = $key;
     $userId = new Crypt_GPG_UserId();
     $userId->setName('First Keypair Test Key');
     $userId->setComment('do not encrypt important data with this key');
     $userId->setEmail('*****@*****.**');
     $key->addUserId($userId);
     $subKey = new Crypt_GPG_SubKey();
     $subKey->setId('C097D9EC94C06363');
     $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA);
     $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
     $subKey->setLength(1024);
     $subKey->setCreationDate(1221785805);
     $subKey->setExpirationDate(0);
     $subKey->setCanSign(true);
     $subKey->setCanEncrypt(false);
     $subKey->setHasPrivate(false);
     $key->addSubKey($subKey);
     $subKey = new Crypt_GPG_SubKey();
     $subKey->setId('9F93F9116728EF12');
     $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC);
     $subKey->setFingerprint('C9C65B3BBF040E40D0EA27B79F93F9116728EF12');
     $subKey->setLength(2048);
     $subKey->setCreationDate(1221785821);
     $subKey->setExpirationDate(0);
     $subKey->setCanSign(false);
     $subKey->setCanEncrypt(true);
     $subKey->setHasPrivate(false);
     $key->addSubKey($subKey);
     // }}}
     $keys = $this->gpg->getKeys($keyId);
     $this->assertEquals($expectedKeys, $keys);
 }
コード例 #2
0
ファイル: UserId.php プロジェクト: CDN-Sparks/owncloud
 /**
  * Parses a user id object from a user id string
  *
  * A user id string is of the form:
  * <b><kbd>name (comment) <email-address></kbd></b> with the <i>comment</i>
  * and <i>email-address</i> fields being optional.
  *
  * @param string $string the user id string to parse.
  *
  * @return Crypt_GPG_UserId the user id object parsed from the string.
  */
 public static function parse($string)
 {
     $userId = new Crypt_GPG_UserId();
     $email = '';
     $comment = '';
     // get email address from end of string if it exists
     $matches = array();
     if (preg_match('/^(.+?) <([^>]+)>$/', $string, $matches) === 1) {
         $string = $matches[1];
         $email = $matches[2];
     }
     // get comment from end of string if it exists
     $matches = array();
     if (preg_match('/^(.+?) \\(([^\\)]+)\\)$/', $string, $matches) === 1) {
         $string = $matches[1];
         $comment = $matches[2];
     }
     $name = $string;
     $userId->setName($name);
     $userId->setComment($comment);
     $userId->setEmail($email);
     return $userId;
 }
コード例 #3
0
ファイル: UserIdTest.php プロジェクト: pear/crypt_gpg
 /**
  * @group fluent
  */
 public function testFluentInterface()
 {
     $userId = new Crypt_GPG_UserId();
     $returnedUserId = $userId->setName('Alice');
     $this->assertEquals($userId, $returnedUserId, 'Failed asserting fluent interface works for setName() method.');
     $userId = new Crypt_GPG_UserId();
     $returnedUserId = $userId->setComment('encryption is fun');
     $this->assertEquals($userId, $returnedUserId, 'Failed asserting fluent interface works for setComment() method.');
     $userId = new Crypt_GPG_UserId();
     $returnedUserId = $userId->setEmail('*****@*****.**');
     $this->assertEquals($userId, $returnedUserId, 'Failed asserting fluent interface works for setEmail() method.');
     $userId = new Crypt_GPG_UserId();
     $returnedUserId = $userId->setRevoked(true);
     $this->assertEquals($userId, $returnedUserId, 'Failed asserting fluent interface works for setRevoked() method.');
     $userId = new Crypt_GPG_UserId();
     $returnedUserId = $userId->setValid(true);
     $this->assertEquals($userId, $returnedUserId, 'Failed asserting fluent interface works for setValid() method.');
 }
コード例 #4
0
ファイル: UserId.php プロジェクト: pear/crypt_gpg
 /**
  * Parses a user id object from a user id string
  *
  * A user id string is of the form:
  * <b><kbd>name (comment) <email-address></kbd></b> with the <i>comment</i>
  * and <i>email-address</i> fields being optional.
  *
  * @param string $string the user id string to parse.
  *
  * @return Crypt_GPG_UserId the user id object parsed from the string.
  */
 public static function parse($string)
 {
     $userId = new Crypt_GPG_UserId();
     $name = '';
     $email = '';
     $comment = '';
     // get email address from end of string if it exists
     $matches = array();
     if (preg_match('/^(.*?)<([^>]+)>$/', $string, $matches) === 1) {
         $string = trim($matches[1]);
         $email = $matches[2];
     }
     // get comment from end of string if it exists
     $matches = array();
     if (preg_match('/^(.+?) \\(([^\\)]+)\\)$/', $string, $matches) === 1) {
         $string = $matches[1];
         $comment = $matches[2];
     }
     // there can be an email without a name
     if (!$email && preg_match('/^[\\S]+@[\\S]+$/', $string, $matches) === 1) {
         $email = $string;
     } else {
         $name = $string;
     }
     $userId->setName($name);
     $userId->setComment($comment);
     $userId->setEmail($email);
     return $userId;
 }
コード例 #5
0
 /**
  * @group generate-key
  */
 public function testGenerateKeyWithExpirationDate()
 {
     if (!$this->config['enable-key-generation']) {
         $this->markTestSkipped('Key generation tests are disabled. To run key generation ' . 'tests, enable them in the test configuration. See the ' . 'configuration in \'config.php.dist\' for an exampe.');
     }
     // {{{ generate-test@example.com
     $expectedKey = new Crypt_GPG_Key();
     $userId = new Crypt_GPG_UserId();
     $userId->setName('Test Keypair');
     $userId->setEmail('*****@*****.**');
     $expectedKey->addUserId($userId);
     $subKey = new Crypt_GPG_SubKey();
     $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA);
     $subKey->setLength(1024);
     $subKey->setExpirationDate(1999998000);
     // truncated to day
     $subKey->setCanSign(true);
     $subKey->setCanEncrypt(false);
     $subKey->setHasPrivate(true);
     $expectedKey->addSubKey($subKey);
     $subKey = new Crypt_GPG_SubKey();
     $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC);
     $subKey->setLength(2048);
     $subKey->setExpirationDate(1999998000);
     // truncated to day
     $subKey->setCanSign(false);
     $subKey->setCanEncrypt(true);
     $subKey->setHasPrivate(true);
     $expectedKey->addSubKey($subKey);
     // }}}
     $key = $this->generator->setExpirationDate(2000000000)->generateKey(new Crypt_GPG_UserId('Test Keypair <*****@*****.**>'));
     $this->assertKeyEquals($expectedKey, $key);
 }
コード例 #6
0
ファイル: VerifyTest.php プロジェクト: pear/crypt_gpg
    /**
     * @group file
     */
    public function testVerifyFileDualDetachedSignature()
    {
        // {{{ first signature
        $firstSignature = new Crypt_GPG_Signature();
        $firstSignature->setId('T7+toJbsFr8KMTWN+M7lF3xSmmA');
        $firstSignature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
        $firstSignature->setKeyId('C097D9EC94C06363');
        $firstSignature->setCreationDate(1221960707);
        $firstSignature->setExpirationDate(0);
        $firstSignature->setValid(true);
        $userId = new Crypt_GPG_UserId();
        $userId->setName('First Keypair Test Key');
        $userId->setComment('do not encrypt important data with this key');
        $userId->setEmail('*****@*****.**');
        $firstSignature->setUserId($userId);
        // }}}
        // {{{ second signature
        $secondSignature = new Crypt_GPG_Signature();
        $secondSignature->setId('HJd1yvMbEbW5facuxkDtvwymKrw');
        $secondSignature->setKeyFingerprint('880922DBEA733E906693E4A903CC890AFA1DAD4B');
        $secondSignature->setKeyId('03CC890AFA1DAD4B');
        $secondSignature->setCreationDate(1221960707);
        $secondSignature->setExpirationDate(0);
        $secondSignature->setValid(true);
        $userId = new Crypt_GPG_UserId();
        $userId->setName('Second Keypair Test Key');
        $userId->setComment('do not encrypt important data with this key');
        $userId->setEmail('*****@*****.**');
        $secondSignature->setUserId($userId);
        // }}}
        // {{{ signature data
        $signatureData = <<<TEXT
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBI1aQDwJfZ7JTAY2MRAvkzAKDPnJ030GdYE15mE8smz2oV7zYziwCeJFxf
UaTrAgP1Dck9DhHOBhvhwLuIPwMFAEjVpAMDzIkK+h2tSxEC+TMAn38yx3mXk6wP
JaPThD7lRVE9ve57AJ0Yy7JwiT9sGXomln4JtRvuSpGtsg==
=Gw9D
-----END PGP SIGNATURE-----

TEXT;
        // }}}
        $expectedSignatures = array($firstSignature, $secondSignature);
        $filename = $this->getDataFilename('testFileMedium.plain');
        $signatures = $this->gpg->verifyFile($filename, $signatureData);
        $this->assertSignaturesEquals($expectedSignatures, $signatures);
    }
コード例 #7
0
 /**
  * @group file
  */
 public function testDecryptVerifyFileSignedOnly()
 {
     // {{{ signature
     $signature = new Crypt_GPG_Signature();
     $signature->setId('vctnI/HnsRYmqcVwCJcJhS60lKU');
     $signature->setKeyFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
     $signature->setKeyId('C097D9EC94C06363');
     $signature->setCreationDate(1221960707);
     $signature->setExpirationDate(0);
     $signature->setValid(true);
     $userId = new Crypt_GPG_UserId();
     $userId->setName('First Keypair Test Key');
     $userId->setComment('do not encrypt important data with this key');
     $userId->setEmail('*****@*****.**');
     $signature->setUserId($userId);
     // }}}
     $expectedMd5Sum = 'f96267d87551ee09bfcac16921e351c1';
     $expectedResults = array('data' => null, 'signatures' => array($signature));
     $inputFilename = $this->getDataFilename('testVerifyFileNormalSignedData.asc');
     $outputFilename = $this->getTempFilename('testDecryptVerifyFileSignedData.plain');
     $results = $this->gpg->decryptAndVerifyFile($inputFilename, $outputFilename);
     $this->assertDecryptAndVerifyResultsEquals($expectedResults, $results);
     $md5Sum = $this->getMd5Sum($outputFilename);
     $this->assertEquals($expectedMd5Sum, $md5Sum);
 }