-
-
Notifications
You must be signed in to change notification settings - Fork 69
Description
There is a problem with the library. Seems like it encrypts files for multiple (the same) recipients.
If you use this code and the public PGP file from data.zip (the private phrase is 123 in a case you want to use the private key):
$key = 'test.public.bin.pgp';
$output = 'test.bin.pgp';
$data_packet = new OpenPGP_LiteralDataPacket('test', ['format' => 'b']);
$encrypted = OpenPGP_Crypt_Symmetric::encrypt(OpenPGP_Message::parse(file_get_contents($key)), new OpenPGP_Message([$data_packet]));
file_put_contents($output, $encrypted->to_bytes());If you try to decrypt test.bin.pgp, let's say in PGPTool (assume you already added the private key to the application). you will see the following result:

The file is encrypted for two (the same) recipients.
If you try to encrypt the same value with PGPTool and decrypt it, you will see that it's encrypted only for single recipient.
Thank you.
P.S.: I think it happens here (OpenPGP_Crypt_Symmetric::encrypt()):
foreach($passphrases_and_keys as $pass) {
if($pass instanceof OpenPGP_PublicKeyPacket) {There are 2 iterations for the condition (one with tag 0x06, another one with tag 0x0E):
if($pass instanceof OpenPGP_PublicKeyPacket)If I remove the second one the problem is gone. I think, the library uses the sub-key (tag 0x0E) as well, when it should not.