bcgit / bc-java

Bouncy Castle Java Distribution (Mirror)
https://www.bouncycastle.org/java.html
MIT License
2.33k stars 1.14k forks source link

Fix LibrePGP OCBEncryptedData packet decryption using SKESKv5 and PKESKv3 #1809

Closed vanitasvitae closed 2 months ago

vanitasvitae commented 2 months ago

This PR incorporates and obsoletes #1793 and #1795

Decryption of symmetrically encrypted LibrePGP messages which make used of AEAD (SKESKv5 and OCBEDv1) was failing due to erroneous parsing of the SKESKv5 packet (which does omit some counter octets introduced in v6), plus decryption of the session key from the SKESKv5 packet omits a HKDF step also introduced with v6.

Decryption of asymmetrically encrypted LibrePGP messages using AEAD (PKESKv3 and OCBEDv1 using an ECDH (legacy X25519) was also failing (which took me 3 days or so to get to the bottom of the bug), because it turns out that during the ECDH handshake, the "UserKeyingMaterial" which contains the fingerprint of the recipient key would only get updated with 20 of the 32 fingerprint octets of a v5 key (https://www.ietf.org/archive/id/draft-koch-librepgp-01.html#section-13.5-4.5).

These issues have been fixed and are now covered by test cases.

vanitasvitae commented 2 months ago

In main as c00542481d7677f8c2cd98892707c58cabcdfc58