Closed vanitasvitae closed 6 years ago
Maybe a SHA-1 hash (20 bytes) instead of a checksum (2 bytes) is appened after the secret RSA values, although S2K usage convention is 0 (cf. sec. 5.5.3 RFC 4880). However, both (GPG and pgpdump) fail to detect this issue.
@cwgit do you have an idea?
I have read RFC 4880 again but it seems to me that plain_Secret_Key()
is implemented as the RFC specifies.
Maybe a SHA-1 hash (20 bytes) instead of a checksum (2 bytes) is appened after the secret RSA values, although S2K usage convention is 0 (cf. sec. 5.5.3 RFC 4880). However, both (GPG and pgpdump) fail to detect this issue.
@HeikoStamer You are right. Skipping 18 more bytes displays this data correctly.
So, I believe that this is a bug of bouncycastle 1.59.
@HeikoStamer @kazu-yamamoto Thank you, I will report it back to them and see if I can work around that issue in my case :)
David Hook from BouncyCastle wrote me this:
Ask them to read the last paragraph of Section 5.5.3 RFC 4880.
" The two-octet checksum that follows the algorithm-specific portion is
the algebraic sum, mod 65536, of the plaintext of all the algorithm-
specific octets (including MPI prefix and data). With V3 keys, the
checksum is stored in the clear. With V4 keys, the checksum is
encrypted like the algorithm-specific data. This value is used to
check that the passphrase was correct. However, this checksum is
deprecated; an implementation SHOULD NOT use it, but should rather
use the SHA-1 hash denoted with a usage octet of 254. The reason for
this is that there are some attacks that involve undetectably
modifying the secret key."
There is further discussion on this earlier in Section 5.5.3 as well.
Regards,
David
Update: David is not sure any more, he'll look into it once more.
Yes, the issue was actually the S2K usage. This should now be fixed. Apologies for my confusion.
@vanitasvitae If you post a fixed example key, I can check it against dkg-keycheck with DKGPG
I think this one should be correct. Let me know. Thanks.
-----BEGIN PGP PRIVATE KEY BLOCK----- Version: BCPG v1.60b05
lQOYBFr8nnABCADAnm0auu+rqBL7HdAPo+WKfL47hHNzB6dC34SLWS1UGjPRPQH4 Iqf6/3sqI2XpwJO0yjs1y3WKobb1JQpcdfM12W4O69k4zK5FUMYBQDTOj4LJQeLf xTtJB9sTHjSDMNzRl+sH77sCm0bjpyMDrRy4AaefP0tImDGhudKUzok1swGFP9cN cWVrC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HVsZXQubGl0iQE0BBMBCAAeBQJa /J5wApsvBYsJCAcCBpUKCQgLAgSWAgMBAp4BAAoJEMMQKbEcq6QsPcwH/0y9EcS7 +y7DlG+l/dikC3l/dZXXq/GgQaU7dwntrDdcqDZ7W4qdFcWeBMROSWJ/+gGq68uO sT/qj3fVuCMWYM8ddu+U4vMwV3PF646NR8E1ih8Xhn9l4TBIKJIDGEpHDcBRRJD2 clEtyQNZhe9hqKP8meR/f97tVROAyUft68HjiepqPaC8B+F2U5Amx/+gWtK5h6R4 qYEM1r7yz84pnW44+B+8mbzf2XgxlMYSfJz3L7fsjhZu+8ExB+qrCV8QIMztugFv zP+rlceWu21AJgGtGh31O2evhCRh2/+B2Sfmixn/jJMMjy5EGUqbfzwSJXWeIBYC BuNShngvvR2FPEU= =tt7J -----END PGP PRIVATE KEY BLOCK-----
@bcgit Yes, it seems to be okay.
$ dkg-keycheck -V -V -p bc.asc INFO: using LibTMCG version 1.3.13 INFO: encdatalen = 0 INFO: skalgo = 0 INFO: s2kconv = 0 INFO: s2k_type = 0 s2k_hashalgo = 0 s2k_count = 0 INFO: key ID of private primary key: c3 10 29 b1 1c ab a4 2c INFO: key ID of primary key: c3 10 29 b1 1c ab a4 2c INFO: number of selfsigs = 0 INFO: number of keyrevsigs = 0 INFO: number of certrevsigs = 0 INFO: number of userids = 1 INFO: number of userattributes = 0 INFO: number of subkeys = 0 INFO: number of revkeys = 0 INFO: userid = "xmpp:juliet@capulet.lit" INFO: number of selfsigs = 1 INFO: number of revsigs = 0 INFO: number of certsigs = 0 INFO: user ID is valid INFO: primary key update expirationtime to 0 INFO: primary key update flags to 2f INFO: primary key update features to 1 INFO: primary key update psa to 9 8 7 2 INFO: primary key update pha to 10 9 8 11 2 INFO: primary key update pca to 2 3 1 INFO: primary key update revkeys with added INFO: key flags on primary key are CSEeA INFO: RSA with |n| = 2048 bits, |e| = 17 bits OpenPGP V4 Key ID of primary key: C31029B11CABA42C OpenPGP V4 fingerprint of primary key: EBB9 5CEA C034 D603 9170 C2A2 C310 29B1 1CAB A42C OpenPGP Key Creation Time: Wed May 16 23:11:12 2018 OpenPGP Key Expiration Time: undefined OpenPGP Revocation Keys: none OpenPGP Key Flags: CSEeA Public-key algorithm: RSA Security level of public key: |n| = 2048 bit, e = 65537 n is not probable prime n is congruent 3 mod 4 n = ... Legendre-Jacobi symbol (i/n): #(+1) = 4999340 #(-1) = 5000659 e is probable prime e is okay OpenPGP User ID: xmpp:juliet@capulet.lit
Thanks for confirming it.
Hi! I came across pgpdump failing to dump keys generated using bouncycastle 1.59.
Here is an example key:
pgpdump gives me this output:
On the other hand gpg lists the key as follows:
Most importantly note the differing key id. Do you have any idea what's going on?