openpgp/packet: reject too-short decrypted session key in EncryptedKey.Decrypt#359
Conversation
|
This PR (HEAD: 5fa27db) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/crypto/+/790422. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/790422. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/790422. |
EncryptedKey.Decrypt reads the decrypted session key as b[0] (cipher), b[1:len(b)-2] (key) and b[len(b)-2:] (checksum) without a length check. A crafted public-key-encrypted message whose RSA, ElGamal or ECDH ciphertext decrypts to fewer than three octets makes these index and slice operations panic (index out of range / slice bounds out of range). This is reachable from ReadMessage when decrypting an attacker-supplied message, a denial of service for programs that decrypt untrusted OpenPGP messages. Reject len(b) < 3 with a StructuralError before indexing.
5fa27db to
a9eefe7
Compare
|
This PR (HEAD: a9eefe7) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/crypto/+/790422. Important tips:
|
EncryptedKey.Decrypt (openpgp/packet/encrypted_key.go) decrypts a
public-key-encrypted session key and then reads it without any length
check:
b is the result of RSA, ElGamal or ECDH decryption. A crafted
public-key-encrypted message whose ciphertext decrypts to fewer than
three octets makes these operations panic: len(b)==0 panics on b[0],
and len(b)<3 panics on b[1:len(b)-2] (e.g. b[1:0]). This is reachable
from ReadMessage when decrypting an attacker-supplied message with the
recipient's private key, a denial of service for any program that
decrypts untrusted OpenPGP messages.
The fix rejects len(b) < 3 with a StructuralError before indexing. A
valid session key is one cipher-algorithm octet plus key material plus
a two-octet checksum, so three octets is the minimum. This complements
PR #348 (which guards elgamal.Decrypt against an empty result): the
caller still needs at least the cipher octet plus the two checksum
octets, and the RSA and ECDH decryption paths were unguarded entirely.