Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot decrypt GnuPG message with "partial continue" structure #43

Closed
kaie opened this issue Feb 11, 2019 · 15 comments
Closed

Cannot decrypt GnuPG message with "partial continue" structure #43

kaie opened this issue Feb 11, 2019 · 15 comments

Comments

@kaie
Copy link

kaie commented Feb 11, 2019

I'm trying to decrypt a message with the command line tool, using the decrypt-pka command. It fails inside Message::meaningful. In Message::match p->get_tag() returns 254.

The message was sent using GnuPG. I've built with gpg-debug to enable compatibility.

"OpenPGP show" reports:

Old: Public-Key Encrypted Session Key (Tag 1)
Version: 3
KeyID: ...
Public Key Algorithm: RSA (Encrypt or Sign) (pka 1)
RSA me mod n (3072 bits): ...
Old: Public-Key Encrypted Session Key (Tag 1)
Version: 3
KeyID: ...
Public Key Algorithm: RSA (Encrypt or Sign) (pka 1)
RSA m
e mod n (4090 bits): ...
New: Symmetrically (Conventional) Encrypted Data (Tag 9) (partial start)
Encrypted Data (2048 octets): ...
Old: (partial end)
...

"pgpdump" reports:

Old: Public-Key Encrypted Session Key Packet(tag 1)(396 bytes)
New version(3)
Key ID - ...
Pub alg - RSA Encrypt or Sign(pub 1)
RSA m^e mod n(3072 bits) - ...
-> m = sym alg(1 byte) + checksum(2 bytes) + PKCS-1 block type 02
Old: Public-Key Encrypted Session Key Packet(tag 1)(524 bytes)
New version(3)
Key ID - ...
Pub alg - RSA Encrypt or Sign(pub 1)
RSA m^e mod n(4090 bits) - ...
-> m = sym alg(1 byte) + checksum(2 bytes) + PKCS-1 block type 02
New: Symmetrically Encrypted Data Packet(tag 9)(2048 bytes) partial start
Encrypted data [sym alg is specified in pub-key encrypted session key]
New: (1024 bytes) partial continue
New: (475 bytes) partial end

@calccrypto
Copy link
Owner

Can you please post the message, so that I can trace what it is doing in the code?

@calccrypto
Copy link
Owner

calccrypto commented Feb 16, 2019

Please pull to c21916a master and give it a try

@kaie
Copy link
Author

kaie commented Feb 19, 2019

encrypted.txt

This is the encrypted file, I hope it is helpful.

@calccrypto
Copy link
Owner

Please give the latest master another try.

@calccrypto
Copy link
Owner

@kaie Have the most recent updates fixed this?

@kaie
Copy link
Author

kaie commented Feb 27, 2019

Hello Jason, sorry for the delay. It's not yet working for me, maybe I'm doing something wrong. I get an error:

./cli/OpenPGP decrypt-pka testmail-0227.private passphrase enc.pgp
terminate called after throwing an instance of 'std::runtime_error'
what(): Error: Data does not form a meaningful PGP Key
Aborted (core dumped)

The key pair was generated using:
./cli/OpenPGP generate-keypair --phash SHA256 --pkeysize 3072 --psig SHA256 --shash SHA256 --skeysize 3072 --ssig SHA256 -e idonttellyou@kuix.de -u "Test Mail" -o testmail-0227 -p passphrase

The public key was copied to a different VM, imported into gpg, and a 5 K test message was sent encrypted-only from Thunderbird with Enigmail/GnuPG.

Build flags were
cmake -DCMAKE_INSTALL_PREFIX=/home/user/local/openpgp -DGPG_COMPATIBLE=True ..

I built revision 80e5790 from Feb 25.

@kaie
Copy link
Author

kaie commented Feb 27, 2019

File enc.pgp contains just the
-----BEGIN PGP MESSAGE-----
...
-----END PGP MESSAGE-----
part of the email message.

File testmail-0227.private contains the unmodified private key as generated by the above key generation command.

@kaie
Copy link
Author

kaie commented Feb 27, 2019

Jason, if you point me to your private key, I can send you an equivalent test message. That way you'd be enabled to test it yourself. Thanks.

@calccrypto
Copy link
Owner

You can use the Alicepub key:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mQENBFOm0SgBCAC8BH6U1HHzzL1SXWpvjhf3sfAFJ8ciw5E854f70AkOOvi+fllB
D2OzmDqVB7dhBFwRUQ5i9ajPvNwYCXakwiVze44G2FMfOMbqqZaVTVUhpnYyMfB8
K0NgXQUqvfOdbGaKyUvIn1QwUtBQUwxwxIpJqXCGfAAXj5B23Q4VHSVGMnZ7KSbp
uqIsbQwhPx9F3nSZE5bX6NEFCM9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MqQAPU4ewTtpy9SrzynZCG02vycaBhLJwcP1dKtvae1y8B8zh7zo9F
eLTUewHuyFRpyM5/fj1Dou89AOvDRaiJPaO3RQOmjGG9+D5hDS03CHBXOg/P0gYv
lc1myZNfRtU5+ezMEWA+tqyjyjj3W6nyobtpVtwgpA/od47/UcdGqSkzkmr+zqqH
amPMgSaahcvqPw2VFt4fi00ShN9EguwiV2vJes6VvDq1qE5Ap/zWBn/B7xIc70jD
hHtoB2/2gM/blPn5EPrIht6Kh9njBFYVk+OrV96NpJl08lM=
=xJuO
-----END PGP PUBLIC KEY BLOCK-----

@kaie
Copy link
Author

kaie commented Feb 28, 2019

encrypted-for-tests_testvectors_gpg_Alicepub.txt

$ ./cli/OpenPGP decrypt-pka tests/testvectors/gpg/Alicepri test encrypted-for-tests_testvectors_gpg_Alicepub.txt
terminate called after throwing an instance of 'std::runtime_error'
what(): Error: Data contains message section. Use CleartextSignature to parse this data.
Aborted (core dumped)

Using this key results in a different error.

@calccrypto calccrypto reopened this Mar 1, 2019
@calccrypto
Copy link
Owner

calccrypto commented Mar 1, 2019

I think I fixed it with 272e079. The main issues were:

  • The file you provided has CRLF line endings, which weren't handled before
  • There were some usage errors with Compressed Data Packets (Tag 8)
  • There were some logic errors in OpenPGP::Message

Please let me know if you are still having issues.

@kaie
Copy link
Author

kaie commented Mar 1, 2019

Thanks. I confirm the issue is fixed when using the message encrypted for the Alicepub key.

However, it still fails to process the message that I had encrypted with the key I had generated.
terminate called after throwing an instance of 'std::runtime_error'
what(): Error: Data does not form a meaningful PGP Key

If you're interested to analyze further, feel free to generate a key for yourself with this command, and send me your public key:
./cli/OpenPGP generate-keypair --phash SHA256 --pkeysize 3072 --psig SHA256 --shash SHA256 --skeysize 3072 --ssig SHA256 -e idonttellyou@kuix.de -u "Test Mail" -o testmail-0227 -p passphrase

calccrypto added a commit that referenced this issue Mar 1, 2019
Trim CRLF from user input
    Added tests

Fixed some OpenPGP::Message behavior
    Compressed data should always be treated as raw, not armored

Renamed Packet::read to Packet::actual_read, and wrapped new function in new Packet::read
Renamed some tests
Added extract_decrypted function into tests to easily extract plaintext message packets
calccrypto added a commit that referenced this issue Mar 1, 2019
two octet lengths are different depending on version
renamed *_octet_lengths functions to read_*_octet_lengths, and added format argument, most of which are not used

Added static checks for whether or not packets are allowed to have partial body lengths
@calccrypto
Copy link
Owner

Apparently the error reading the key was caused by using the wrong formula to get a 2 octet length.

calccrypto added a commit that referenced this issue Mar 1, 2019
calccrypto added a commit that referenced this issue Mar 2, 2019
Only strip trailing whitespace from ASCII Armored Messages
    - leading whitespace are errors
Remove trailing whitespace in CleartextSignature::read
Fixed bug with trim_whitespace using the wrong index when not finding whitespace

Removed Partial Packets from TODO list
@calccrypto
Copy link
Owner

@kaie Am I able to close this issue?

@kaie
Copy link
Author

kaie commented Mar 4, 2019

Jason, I confirm you've fixed the issue, I'm able to decrypt my test message, thanks a lot!

@kaie kaie closed this as completed Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants