mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-05-06 18:04:11 +02:00
[securemail] Upgrade Composer dependencies to fix PHP8 issue
- Upgrading phpseclib/phpseclib (2.0.4 => 2.0.34) - Upgrading singpolyma/openpgp-php (0.3.0 => 0.5.0)
This commit is contained in:
parent
fb77e3c5ea
commit
0c7fd9a34d
65 changed files with 5407 additions and 3230 deletions
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/* The tests which require phpseclib */
|
||||
|
||||
|
@ -6,7 +7,7 @@ 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';
|
||||
|
||||
class MessageVerification extends PHPUnit_Framework_TestCase {
|
||||
class MessageVerification extends TestCase {
|
||||
public function oneMessageRSA($pkey, $path) {
|
||||
$pkeyM = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $pkey));
|
||||
$m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
|
||||
|
@ -51,7 +52,7 @@ class MessageVerification extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
|
||||
class KeyVerification extends PHPUnit_Framework_TestCase {
|
||||
class KeyVerification extends TestCase {
|
||||
public function oneKeyRSA($path) {
|
||||
$m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
|
||||
$verify = new OpenPGP_Crypt_RSA($m);
|
||||
|
@ -64,7 +65,7 @@ class KeyVerification extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
|
||||
class Decryption extends PHPUnit_Framework_TestCase {
|
||||
class Decryption extends TestCase {
|
||||
public function oneSymmetric($pass, $cnt, $path) {
|
||||
$m = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/' . $path));
|
||||
$m2 = OpenPGP_Crypt_Symmetric::decryptSymmetric($pass, $m);
|
||||
|
@ -76,18 +77,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 +120,89 @@ 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 testEncryptSecretKeyRoundtrip() {
|
||||
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||
$enkey = OpenPGP_Crypt_Symmetric::encryptSecretKey("password", $key[0]);
|
||||
$skey = OpenPGP_Crypt_Symmetric::decryptSecretKey("password", $enkey);
|
||||
$this->assertEquals($key[0], $skey);
|
||||
}
|
||||
|
||||
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() {
|
||||
class Encryption extends TestCase {
|
||||
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.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue