Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
67aba78699 | ||
|
c0e6aeb163 | ||
|
5e6a097677 | ||
|
f8e0e997fc | ||
|
fb671e183d | ||
|
f43fbdc053 | ||
|
cd33ba1af1 | ||
|
34ffc765ec | ||
|
752d80f14a | ||
|
575baaf3f2 | ||
|
aeb919abc3 | ||
|
cba1ecce8a | ||
|
f2e1710da5 | ||
|
44e1bb2902 | ||
|
43497a15c0 | ||
|
5a6b605710 | ||
|
d756110821 | ||
|
724d5b16f3 | ||
|
26560f7bca | ||
|
498e60602b | ||
|
413741fa84 | ||
|
a9fc3f9322 | ||
|
facaaa4dbb | ||
|
ba3c3fd42d | ||
|
ebce9c014c | ||
|
f42afa0ca3 | ||
|
e8a56241a5 | ||
|
69d935435c | ||
|
541328576a | ||
|
a8e7690a69 | ||
|
c9ae8251b6 | ||
|
95facfb57f |
47
.travis.yml
47
.travis.yml
@@ -1,18 +1,51 @@
|
||||
---
|
||||
language: php
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
# - nightly
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 5.6
|
||||
|
||||
dist: trusty
|
||||
|
||||
env:
|
||||
- PHPSECLIB='^2.0 !=2.0.8'
|
||||
- PHPSECLIB="2.0.0"
|
||||
- PHPSECLIB="2.0.1"
|
||||
- PHPSECLIB="2.0.2"
|
||||
- PHPSECLIB="2.0.3"
|
||||
- PHPSECLIB="2.0.4"
|
||||
- PHPSECLIB="2.0.5"
|
||||
- PHPSECLIB="2.0.6"
|
||||
- PHPSECLIB="2.0.7"
|
||||
- PHPSECLIB="2.0.9"
|
||||
- PHPSECLIB="2.0.10"
|
||||
- PHPSECLIB="2.0.11"
|
||||
|
||||
before_script: 'sed -i "s/\"phpseclib\/phpseclib\": \"[^\"]*/\"phpseclib\/phpseclib\": \"$PHPSECLIB/" composer.json && composer install --prefer-source --dev'
|
||||
matrix:
|
||||
exclude:
|
||||
- php: 7.1
|
||||
- env: PHPSECLIB="2.0.0"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.0"
|
||||
- php: 7.1
|
||||
- env: PHPSECLIB="2.0.1"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.1"
|
||||
- php: 7.1
|
||||
- env: PHPSECLIB="2.0.2"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.2"
|
||||
- php: 7.1
|
||||
- env: PHPSECLIB="2.0.3"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.3"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.4"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.5"
|
||||
- php: 7.2
|
||||
- env: PHPSECLIB="2.0.6"
|
||||
fast_finish: true
|
||||
|
||||
before_script: 'sed -i "s/\"phpseclib\/phpseclib\": \"[^\"]*/\"phpseclib\/phpseclib\": \"$PHPSECLIB/" composer.json && composer install --prefer-source'
|
||||
|
38
README.md
38
README.md
@@ -1,11 +1,14 @@
|
||||
[](https://travis-ci.org/singpolyma/openpgp-php)
|
||||
|
||||
OpenPGP.php: OpenPGP for PHP
|
||||
============================
|
||||
|
||||
This is a pure-PHP implementation of the OpenPGP Message Format (RFC 4880).
|
||||
|
||||
* <http://github.com/bendiken/openpgp-php>
|
||||
* <https://github.com/singpolyma/openpgp-php>
|
||||
|
||||
### About OpenPGP
|
||||
About OpenPGP
|
||||
-------------
|
||||
|
||||
OpenPGP is the most widely-used e-mail encryption standard in the world. It
|
||||
is defined by the OpenPGP Working Group of the Internet Engineering Task
|
||||
@@ -13,8 +16,8 @@ Force (IETF) Proposed Standard RFC 4880. The OpenPGP standard was originally
|
||||
derived from PGP (Pretty Good Privacy), first created by Phil Zimmermann in
|
||||
1991.
|
||||
|
||||
* <http://tools.ietf.org/html/rfc4880>
|
||||
* <http://www.openpgp.org/>
|
||||
* <https://tools.ietf.org/html/rfc4880>
|
||||
* <https://www.openpgp.org/>
|
||||
|
||||
Features
|
||||
--------
|
||||
@@ -22,15 +25,26 @@ Features
|
||||
* Encodes and decodes ASCII-armored OpenPGP messages.
|
||||
* Parses OpenPGP messages into their constituent packets.
|
||||
* Supports both old-format (PGP 2.6.x) and new-format (RFC 4880) packets.
|
||||
* Helper class for verifying, signing, encrypting, and decrypting messages using Crypt_RSA from <http://phpseclib.sourceforge.net>
|
||||
* Helper class for encrypting and decrypting messages and keys using Crypt_AES and Crypt_TripleDES from <http://phpseclib.sourceforge.net>
|
||||
* Helper class for verifying, signing, encrypting, and decrypting messages <http://phpseclib.sourceforge.net>
|
||||
* Helper class for encrypting and decrypting messages and keys using <http://phpseclib.sourceforge.net>
|
||||
* openssl or mcrypt required for CAST5 encryption and decryption
|
||||
|
||||
Bugs, Feature Requests, Patches
|
||||
-------------------------------
|
||||
|
||||
This project is primarily maintained by a single volunteer with many other
|
||||
things vying for their attention, please be patient.
|
||||
|
||||
Bugs, feature request, pull requests, patches, and general discussion may
|
||||
be submitted publicly via email to: dev@singpolyma.net
|
||||
|
||||
Github users may alternately submit on the web there.
|
||||
|
||||
Users
|
||||
-----
|
||||
|
||||
OpenPGP.php is currently being used in the following projects:
|
||||
|
||||
* <https://drupal.org/project/openpgp>
|
||||
* <https://wordpress.org/plugins/wp-pgp-encrypted-emails/>
|
||||
|
||||
Download
|
||||
@@ -38,21 +52,21 @@ Download
|
||||
|
||||
To get a local working copy of the development repository, do:
|
||||
|
||||
% git clone git://github.com/bendiken/openpgp-php.git
|
||||
git clone https://github.com/singpolyma/openpgp-php.git
|
||||
|
||||
Alternatively, you can download the latest development version as a tarball
|
||||
as follows:
|
||||
|
||||
% wget http://github.com/bendiken/openpgp-php/tarball/master
|
||||
wget https://github.com/singpolyma/openpgp-php/tarball/master
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
* [Arto Bendiken](mailto:arto.bendiken@gmail.com) - <http://ar.to/>
|
||||
* [Stephen Paul Weber](mailto:singpolyma@singpolyma.net) - <http://singpolyma.net/>
|
||||
* [Arto Bendiken](mailto:arto.bendiken@gmail.com) (Original author) - <http://ar.to/>
|
||||
* [Stephen Paul Weber](mailto:singpolyma@singpolyma.net) (Maintainer) - <https://singpolyma.net/>
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
OpenPGP.php is free and unencumbered public domain software. For more
|
||||
information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
|
||||
information, see <https://unlicense.org/> or the accompanying UNLICENSE file.
|
||||
|
@@ -13,10 +13,14 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"phpseclib/phpseclib": ">=2.0.0 <=2.0.4"
|
||||
"php": "^5.6 || ^7.0",
|
||||
"phpseclib/phpseclib": "^2.0 !=2.0.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
"phpunit/phpunit": "^5.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mcrypt": "required if you use encryption cast5"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": ["lib/"]
|
||||
|
22
examples/README.md
Normal file
22
examples/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
OpenPGP.php Examples
|
||||
====================
|
||||
|
||||
The scripts in this folder show how to use this library to perform various tasks
|
||||
such as [generating a new key](keygen.php), [signing a message](sign.php), and
|
||||
[verifying a message](verify.php) that has been signed.
|
||||
|
||||
To use these examples, make sure [`phpseclib`](http://phpseclib.sourceforge.net/) is available. You can install it
|
||||
using [Composer](https://getcomposer.org/):
|
||||
|
||||
```sh
|
||||
git clone https://github.com/singpolyma/openpgp-php.git # Clone the repository.
|
||||
cd openpgp-php
|
||||
composer install # Use Composer to install the requirements.
|
||||
```
|
||||
|
||||
Once Composer has installed the requirements, run the examples using PHP:
|
||||
|
||||
```sh
|
||||
# Generate a new OpenPGP key; see the `keygen.php` file for parameters.
|
||||
php ./examples/keygen.php > mykey.gpg
|
||||
```
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
||||
|
||||
@@ -27,5 +28,3 @@ echo "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA256\n\n";
|
||||
// trailing whitespace to lines.
|
||||
echo preg_replace("/^-/", "- -", $packets[0]->data)."\n";
|
||||
echo OpenPGP::enarmor($packets[1][0]->to_bytes(), "PGP SIGNATURE");
|
||||
|
||||
?>
|
||||
|
@@ -3,6 +3,7 @@
|
||||
// USAGE: php examples/deASCIIdeCrypt.php secretkey.asc password message.asc
|
||||
// This will fail if the algo on key or message is not 3DES or AES
|
||||
|
||||
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_symmetric.php';
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_symmetric.php';
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
||||
|
||||
@@ -18,5 +19,3 @@ $m = $sign->sign($data);
|
||||
|
||||
/* Output the raw message bytes to STDOUT */
|
||||
echo $m->to_bytes();
|
||||
|
||||
?>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
||||
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
||||
|
||||
@@ -14,5 +15,3 @@ $verify = new OpenPGP_Crypt_RSA($wkey);
|
||||
|
||||
/* Dump verification information to STDOUT */
|
||||
var_dump($verify->verify($m));
|
||||
|
||||
?>
|
||||
|
@@ -18,6 +18,8 @@
|
||||
* @see http://tools.ietf.org/html/rfc4880
|
||||
*/
|
||||
class OpenPGP {
|
||||
const VERSION = array(0, 4, 0);
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-6
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-6.2
|
||||
@@ -28,7 +30,7 @@ class OpenPGP {
|
||||
foreach ($headers as $key => $value) {
|
||||
$text .= $key . ': ' . (string)$value . "\n";
|
||||
}
|
||||
$text .= "\n" . base64_encode($data);
|
||||
$text .= "\n" . wordwrap(base64_encode($data), 76, "\n", true);
|
||||
$text .= "\n".'=' . base64_encode(substr(pack('N', self::crc24($data)), 1)) . "\n";
|
||||
$text .= self::footer($marker) . "\n";
|
||||
return $text;
|
||||
@@ -150,10 +152,12 @@ class OpenPGP_S2K {
|
||||
$bytes .= chr($this->hash_algorithm);
|
||||
break;
|
||||
case 1:
|
||||
if(strlen($this->salt) != 8) throw new Exception("Invalid salt length");
|
||||
$bytes .= chr($this->hash_algorithm);
|
||||
$bytes .= $this->salt;
|
||||
break;
|
||||
case 3:
|
||||
if(strlen($this->salt) != 8) throw new Exception("Invalid salt length");
|
||||
$bytes .= chr($this->hash_algorithm);
|
||||
$bytes .= $this->salt;
|
||||
$bytes .= chr(OpenPGP::encode_s2k_count($this->count));
|
||||
@@ -685,7 +689,9 @@ class OpenPGP_SignaturePacket extends OpenPGP_Packet {
|
||||
switch($this->version = ord($this->read_byte())) {
|
||||
case 2:
|
||||
case 3:
|
||||
assert(ord($this->read_byte()) == 5);
|
||||
if(ord($this->read_byte()) != 5) {
|
||||
throw new Exception("Invalid version 2 or 3 SignaturePacket");
|
||||
}
|
||||
$this->signature_type = ord($this->read_byte());
|
||||
$creation_time = $this->read_timestamp();
|
||||
$keyid = $this->read_bytes(8);
|
||||
|
@@ -208,7 +208,8 @@ class OpenPGP_Crypt_RSA {
|
||||
|
||||
static function try_decrypt_session($key, $edata) {
|
||||
$key->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
|
||||
$data = $key->decrypt($edata);
|
||||
$data = @$key->decrypt($edata);
|
||||
if(!$data) return NULL;
|
||||
$sk = substr($data, 1, strlen($data)-3);
|
||||
$chk = unpack('n', substr($data, -2));
|
||||
$chk = reset($chk);
|
||||
|
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
use phpseclib\Crypt\TripleDES as Crypt_TripleDES;
|
||||
use phpseclib\Crypt\AES as Crypt_AES;
|
||||
use phpseclib\Crypt\Blowfish as Crypt_Blowfish;
|
||||
use phpseclib\Crypt\TripleDES as Crypt_TripleDES;
|
||||
use phpseclib\Crypt\Twofish as Crypt_Twofish;
|
||||
use phpseclib\Crypt\Random;
|
||||
|
||||
define('CRYPT_DES_MODE_CFB', Crypt_TripleDES::MODE_CFB);
|
||||
define('CRYPT_AES_MODE_CFB', Crypt_AES::MODE_CFB);
|
||||
|
||||
require_once dirname(__FILE__).'/openpgp.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_crypt_rsa.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_mcrypt_wrapper.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_openssl_wrapper.php';
|
||||
|
||||
class OpenPGP_Crypt_Symmetric {
|
||||
public static function encrypt($passphrases_and_keys, $message, $symmetric_algorithm=9) {
|
||||
@@ -40,7 +40,7 @@ class OpenPGP_Crypt_Symmetric {
|
||||
$esk = pack('n', OpenPGP::bitlength($esk)) . $esk;
|
||||
array_unshift($encrypted, new OpenPGP_AsymmetricSessionKeyPacket($pass->algorithm, $pass->fingerprint(), $esk));
|
||||
} else if(is_string($pass)) {
|
||||
$s2k = new OpenPGP_S2K(Random::string(10));
|
||||
$s2k = new OpenPGP_S2K(Random::string(8));
|
||||
$cipher->setKey($s2k->make_key($pass, $key_bytes));
|
||||
$esk = $cipher->encrypt(chr($symmetric_algorithm) . $key);
|
||||
array_unshift($encrypted, new OpenPGP_SymmetricSessionKeyPacket($s2k, $esk, $symmetric_algorithm));
|
||||
@@ -146,29 +146,45 @@ class OpenPGP_Crypt_Symmetric {
|
||||
public static function getCipher($algo) {
|
||||
$cipher = NULL;
|
||||
switch($algo) {
|
||||
case NULL:
|
||||
case 0:
|
||||
throw new Exception("Data is already unencrypted");
|
||||
case 2:
|
||||
$cipher = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
|
||||
$key_bytes = 24;
|
||||
$key_block_bytes = 8;
|
||||
$cipher = new Crypt_TripleDES(Crypt_TripleDES::MODE_CFB);
|
||||
$key_bytes = 24;
|
||||
$key_block_bytes = 8;
|
||||
break;
|
||||
case 3:
|
||||
if(defined('MCRYPT_CAST_128')) {
|
||||
if(class_exists('OpenSSLWrapper')) {
|
||||
$cipher = new OpenSSLWrapper("CAST5-CFB");
|
||||
} else if(defined('MCRYPT_CAST_128')) {
|
||||
$cipher = new MCryptWrapper(MCRYPT_CAST_128);
|
||||
} else {
|
||||
throw new Exception("Unsupported cipher: you must have mcrypt installed to use CAST5");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
$cipher = new Crypt_Blowfish(Crypt_Blowfish::MODE_CFB);
|
||||
$key_bytes = 16;
|
||||
$key_block_bytes = 8;
|
||||
break;
|
||||
case 7:
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher->setKeyLength(128);
|
||||
$cipher = new Crypt_AES(Crypt_AES::MODE_CFB);
|
||||
$cipher->setKeyLength(128);
|
||||
break;
|
||||
case 8:
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher->setKeyLength(192);
|
||||
$cipher = new Crypt_AES(Crypt_AES::MODE_CFB);
|
||||
$cipher->setKeyLength(192);
|
||||
break;
|
||||
case 9:
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher = new Crypt_AES(Crypt_AES::MODE_CFB);
|
||||
$cipher->setKeyLength(256);
|
||||
break;
|
||||
case 10:
|
||||
$cipher = new Crypt_Twofish(Crypt_Twofish::MODE_CFB);
|
||||
if(method_exists($cipher, 'setKeyLength')) {
|
||||
$cipher->setKeyLength(256);
|
||||
} else {
|
||||
$cipher = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(!$cipher) return array(NULL, NULL, NULL); // Unsupported cipher
|
||||
|
33
lib/openpgp_openssl_wrapper.php
Normal file
33
lib/openpgp_openssl_wrapper.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
if(function_exists('openssl_encrypt')) {
|
||||
class OpenSSLWrapper {
|
||||
public $cipher, $key, $iv, $key_size, $block_size;
|
||||
|
||||
|
||||
function __construct($cipher) {
|
||||
if($cipher != "CAST5-CFB") throw Exception("OpenSSLWrapper is only used for CAST5 right now");
|
||||
|
||||
$this->cipher = $cipher;
|
||||
$this->key_size = 16;
|
||||
$this->block_size = 8;
|
||||
$this->iv = str_repeat("\0", 8);
|
||||
}
|
||||
|
||||
function setKey($key) {
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
function setIV($iv) {
|
||||
$this->iv = $iv;
|
||||
}
|
||||
|
||||
function encrypt($data) {
|
||||
return openssl_encrypt($data, $this->cipher, $this->key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $this->iv);
|
||||
}
|
||||
|
||||
function decrypt($data) {
|
||||
return openssl_decrypt($data, $this->cipher, $this->key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $this->iv);
|
||||
}
|
||||
}
|
||||
}
|
1
tests/data/symmetric-blowfish.gpg
Normal file
1
tests/data/symmetric-blowfish.gpg
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD>
|
3
tests/data/symmetric-twofish.gpg
Normal file
3
tests/data/symmetric-twofish.gpg
Normal file
@@ -0,0 +1,3 @@
|
||||
<EFBFBD>
|
||||
|
||||
c<>І<0B><><EFBFBD><EFBFBD><EFBFBD>9=<3D><><EFBFBD><EFBFBD>]<5D>Tf<54>A<0B>c<EFBFBD>v<EFBFBD><76>e<EFBFBD>k<EFBFBD><6B><EFBFBD>ʲ<EFBFBD><CAB2><EFBFBD>n}%.<16>l<16><>u<>?\<5C><>I
|
@@ -76,18 +76,28 @@ class Decryption extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public function testDecryptAES() {
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-aes.gpg");
|
||||
}
|
||||
|
||||
public function testDecrypt3DES() {
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-3des.gpg");
|
||||
}
|
||||
|
||||
public function testDecryptCAST5() { // Requires mcrypt
|
||||
public function testDecryptCAST5() { // Requires mcrypt or openssl
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-cast5.gpg");
|
||||
}
|
||||
|
||||
public function testDecryptBlowfish() {
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-blowfish.gpg");
|
||||
}
|
||||
|
||||
public function testDecryptAES() {
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-aes.gpg");
|
||||
}
|
||||
|
||||
public function testDecryptTwofish() {
|
||||
if(OpenPGP_Crypt_Symmetric::getCipher(10)[0]) {
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-twofish.gpg");
|
||||
}
|
||||
}
|
||||
|
||||
public function testDecryptSessionKey() {
|
||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg");
|
||||
}
|
||||
@@ -109,25 +119,82 @@ class Decryption extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public function testDecryptRoundtrip() {
|
||||
$m = new OpenPGP_Message(array(new OpenPGP_LiteralDataPacket("hello\n")));
|
||||
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
$em = OpenPGP_Crypt_Symmetric::encrypt($key, $m);
|
||||
|
||||
foreach($key as $packet) {
|
||||
if(!($packet instanceof OpenPGP_SecretKeyPacket)) continue;
|
||||
$decryptor = new OpenPGP_Crypt_RSA($packet);
|
||||
$m2 = $decryptor->decrypt($em);
|
||||
|
||||
foreach($m2 as $p) {
|
||||
if($p instanceof OpenPGP_LiteralDataPacket) {
|
||||
$this->assertEquals($p->data, "hello\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testDecryptSecretKey() {
|
||||
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/encryptedSecretKey.gpg'));
|
||||
$skey = OpenPGP_Crypt_Symmetric::decryptSecretKey("hello", $key[0]);
|
||||
$this->assertSame(!!$skey, true);
|
||||
}
|
||||
|
||||
public function testAlreadyDecryptedSecretKey() {
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Data is already unencrypted");
|
||||
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
OpenPGP_Crypt_Symmetric::decryptSecretKey("hello", $key[0]);
|
||||
}
|
||||
}
|
||||
|
||||
class Encryption extends PHPUnit_Framework_TestCase {
|
||||
public function testEncryptSymmetric() {
|
||||
public function oneSymmetric($algorithm) {
|
||||
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||
$encrypted = OpenPGP_Crypt_Symmetric::encrypt('secret', new OpenPGP_Message(array($data)));
|
||||
$encrypted = OpenPGP_Crypt_Symmetric::encrypt('secret', new OpenPGP_Message(array($data)), $algorithm);
|
||||
$encrypted = OpenPGP_Message::parse($encrypted->to_bytes());
|
||||
$decrypted = OpenPGP_Crypt_Symmetric::decryptSymmetric('secret', $encrypted);
|
||||
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
||||
}
|
||||
|
||||
public function testEncryptSymmetric3DES() {
|
||||
$this->oneSymmetric(2);
|
||||
}
|
||||
|
||||
public function testEncryptSymmetricCAST5() {
|
||||
$this->oneSymmetric(3);
|
||||
}
|
||||
|
||||
public function testEncryptSymmetricBlowfish() {
|
||||
$this->oneSymmetric(4);
|
||||
}
|
||||
|
||||
public function testEncryptSymmetricAES128() {
|
||||
$this->oneSymmetric(7);
|
||||
}
|
||||
|
||||
public function testEncryptSymmetricAES192() {
|
||||
$this->oneSymmetric(8);
|
||||
}
|
||||
|
||||
public function testEncryptSymmetricAES256() {
|
||||
$this->oneSymmetric(9);
|
||||
}
|
||||
|
||||
public function testEncryptSymmetricTwofish() {
|
||||
if(OpenPGP_Crypt_Symmetric::getCipher(10)[0]) {
|
||||
$this->oneSymmetric(10);
|
||||
}
|
||||
}
|
||||
|
||||
public function testEncryptAsymmetric() {
|
||||
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||
$encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message(array($data)));
|
||||
$encrypted = OpenPGP_Message::parse($encrypted->to_bytes());
|
||||
$decryptor = new OpenPGP_Crypt_RSA($key);
|
||||
$decrypted = $decryptor->decrypt($encrypted);
|
||||
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
||||
|
175
tests/suite.php
175
tests/suite.php
@@ -14,355 +14,354 @@ class Serialization extends PHPUnit_Framework_TestCase {
|
||||
$this->oneSerialization("000001-006.public_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000002013user_id() {
|
||||
$this->oneSerialization("000002-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000003002sig() {
|
||||
$this->oneSerialization("000003-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000004012ring_trust() {
|
||||
$this->oneSerialization("000004-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000005002sig() {
|
||||
$this->oneSerialization("000005-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000006012ring_trust() {
|
||||
$this->oneSerialization("000006-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000007002sig() {
|
||||
$this->oneSerialization("000007-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000008012ring_trust() {
|
||||
$this->oneSerialization("000008-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000009002sig() {
|
||||
$this->oneSerialization("000009-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000010012ring_trust() {
|
||||
$this->oneSerialization("000010-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000011002sig() {
|
||||
$this->oneSerialization("000011-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000012012ring_trust() {
|
||||
$this->oneSerialization("000012-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000013014public_subkey() {
|
||||
$this->oneSerialization("000013-014.public_subkey");
|
||||
}
|
||||
|
||||
|
||||
public function test000014002sig() {
|
||||
$this->oneSerialization("000014-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000015012ring_trust() {
|
||||
$this->oneSerialization("000015-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000016006public_key() {
|
||||
$this->oneSerialization("000016-006.public_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000017002sig() {
|
||||
$this->oneSerialization("000017-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000018012ring_trust() {
|
||||
$this->oneSerialization("000018-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000019013user_id() {
|
||||
$this->oneSerialization("000019-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000020002sig() {
|
||||
$this->oneSerialization("000020-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000021012ring_trust() {
|
||||
$this->oneSerialization("000021-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000022002sig() {
|
||||
$this->oneSerialization("000022-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000023012ring_trust() {
|
||||
$this->oneSerialization("000023-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000024014public_subkey() {
|
||||
$this->oneSerialization("000024-014.public_subkey");
|
||||
}
|
||||
|
||||
|
||||
public function test000025002sig() {
|
||||
$this->oneSerialization("000025-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000026012ring_trust() {
|
||||
$this->oneSerialization("000026-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000027006public_key() {
|
||||
$this->oneSerialization("000027-006.public_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000028002sig() {
|
||||
$this->oneSerialization("000028-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000029012ring_trust() {
|
||||
$this->oneSerialization("000029-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000030013user_id() {
|
||||
$this->oneSerialization("000030-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000031002sig() {
|
||||
$this->oneSerialization("000031-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000032012ring_trust() {
|
||||
$this->oneSerialization("000032-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000033002sig() {
|
||||
$this->oneSerialization("000033-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000034012ring_trust() {
|
||||
$this->oneSerialization("000034-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000035006public_key() {
|
||||
$this->oneSerialization("000035-006.public_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000036013user_id() {
|
||||
$this->oneSerialization("000036-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000037002sig() {
|
||||
$this->oneSerialization("000037-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000038012ring_trust() {
|
||||
$this->oneSerialization("000038-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000039002sig() {
|
||||
$this->oneSerialization("000039-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000040012ring_trust() {
|
||||
$this->oneSerialization("000040-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000041017attribute() {
|
||||
$this->oneSerialization("000041-017.attribute");
|
||||
}
|
||||
|
||||
|
||||
public function test000042002sig() {
|
||||
$this->oneSerialization("000042-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000043012ring_trust() {
|
||||
$this->oneSerialization("000043-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000044014public_subkey() {
|
||||
$this->oneSerialization("000044-014.public_subkey");
|
||||
}
|
||||
|
||||
|
||||
public function test000045002sig() {
|
||||
$this->oneSerialization("000045-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000046012ring_trust() {
|
||||
$this->oneSerialization("000046-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000047005secret_key() {
|
||||
$this->oneSerialization("000047-005.secret_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000048013user_id() {
|
||||
$this->oneSerialization("000048-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000049002sig() {
|
||||
$this->oneSerialization("000049-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000050012ring_trust() {
|
||||
$this->oneSerialization("000050-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000051007secret_subkey() {
|
||||
$this->oneSerialization("000051-007.secret_subkey");
|
||||
}
|
||||
|
||||
|
||||
public function test000052002sig() {
|
||||
$this->oneSerialization("000052-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000053012ring_trust() {
|
||||
$this->oneSerialization("000053-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000054005secret_key() {
|
||||
$this->oneSerialization("000054-005.secret_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000055002sig() {
|
||||
$this->oneSerialization("000055-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000056012ring_trust() {
|
||||
$this->oneSerialization("000056-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000057013user_id() {
|
||||
$this->oneSerialization("000057-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000058002sig() {
|
||||
$this->oneSerialization("000058-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000059012ring_trust() {
|
||||
$this->oneSerialization("000059-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000060007secret_subkey() {
|
||||
$this->oneSerialization("000060-007.secret_subkey");
|
||||
}
|
||||
|
||||
|
||||
public function test000061002sig() {
|
||||
$this->oneSerialization("000061-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000062012ring_trust() {
|
||||
$this->oneSerialization("000062-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000063005secret_key() {
|
||||
$this->oneSerialization("000063-005.secret_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000064002sig() {
|
||||
$this->oneSerialization("000064-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000065012ring_trust() {
|
||||
$this->oneSerialization("000065-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000066013user_id() {
|
||||
$this->oneSerialization("000066-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000067002sig() {
|
||||
$this->oneSerialization("000067-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000068012ring_trust() {
|
||||
$this->oneSerialization("000068-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000069005secret_key() {
|
||||
$this->oneSerialization("000069-005.secret_key");
|
||||
}
|
||||
|
||||
|
||||
public function test000070013user_id() {
|
||||
$this->oneSerialization("000070-013.user_id");
|
||||
}
|
||||
|
||||
|
||||
public function test000071002sig() {
|
||||
$this->oneSerialization("000071-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000072012ring_trust() {
|
||||
$this->oneSerialization("000072-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000073017attribute() {
|
||||
$this->oneSerialization("000073-017.attribute");
|
||||
}
|
||||
|
||||
|
||||
public function test000074002sig() {
|
||||
$this->oneSerialization("000074-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000075012ring_trust() {
|
||||
$this->oneSerialization("000075-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test000076007secret_subkey() {
|
||||
$this->oneSerialization("000076-007.secret_subkey");
|
||||
}
|
||||
|
||||
|
||||
public function test000077002sig() {
|
||||
$this->oneSerialization("000077-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function test000078012ring_trust() {
|
||||
$this->oneSerialization("000078-012.ring_trust");
|
||||
}
|
||||
|
||||
|
||||
public function test002182002sig() {
|
||||
$this->oneSerialization("002182-002.sig");
|
||||
}
|
||||
|
||||
|
||||
public function testpubringgpg() {
|
||||
$this->oneSerialization("pubring.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testsecringgpg() {
|
||||
$this->oneSerialization("secring.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testcompressedsiggpg() {
|
||||
$this->oneSerialization("compressedsig.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testcompressedsigzlibgpg() {
|
||||
$this->oneSerialization("compressedsig-zlib.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testcompressedsigbzip2gpg() {
|
||||
$this->oneSerialization("compressedsig-bzip2.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testonepass_sig() {
|
||||
$this->oneSerialization("onepass_sig");
|
||||
}
|
||||
|
||||
|
||||
public function testsymmetrically_encrypted() {
|
||||
$this->oneSerialization("symmetrically_encrypted");
|
||||
}
|
||||
|
||||
|
||||
public function testuncompressedopsdsagpg() {
|
||||
$this->oneSerialization("uncompressed-ops-dsa.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testuncompressedopsdsasha384txtgpg() {
|
||||
$this->oneSerialization("uncompressed-ops-dsa-sha384.txt.gpg");
|
||||
}
|
||||
|
||||
|
||||
public function testuncompressedopsrsagpg() {
|
||||
$this->oneSerialization("uncompressed-ops-rsa.gpg");
|
||||
}
|
||||
|
Reference in New Issue
Block a user