keybase / kbpgp

OpenPGP (RFC4880) Implementation in IcedCoffeeScript
https://keybase.io/kbpgp
BSD 3-Clause "New" or "Revised" License
534 stars 74 forks source link

'key not found' error trying to decrypt #111

Closed trogau closed 8 years ago

trogau commented 8 years ago

I'm trying to do a decrypt of some content but I'm getting an error:

Error: key not found: ["2d79418b3396f4cc"]

This key ID appears to be a subkey of the secret key:

:secret sub key packet: version 4, algo 1, created 1295399867, expires 0 skey[0]: [2048 bits] skey[1]: [17 bits] iter+salt S2K, algo: 9, SHA1 protection, hash: 2, salt: 5937b15e5e22906b protect count: 786432 (152) protect IV: 46 48 b3 07 b8 85 60 d2 9f 01 ff 13 10 c2 2e 2e encrypted stuff follows keyid: 2D79418B3396F4CC

The keyring loads OK (just doing it as per the example on the Decrypt documentation); when I issue a quick hacky "console.log(key.get_all_pgp_key_ids());" to see what IDs are present, it prints:

Buffer e3 89 be cb e3 5b a2 c9, Buffer 2d 79 41 8b 33 96 f4 cc

... so it looks like the key is actually present, but it's just not getting picked correctly as available for decryption by unbox?

I tested the code just with verification on a signed chunk and it worked fine - just as soon as I try to use unbox it breaks. (I've created the encrypted file with gpg v1 on Linux, gpg v2 on Windows and also through kbpgp; GPG can deal with it fine but I get the same error trying to decrypt with kbpgp in all cases.)

I found a few other mentions of this error which suggested passing 'strict: false' to unbox (although it looked like a difference issue); I've tried that to no avail.

Been beating my head against this all day so hoping it's not something obvious I'm missing!

edit: I've created some test code to replicate:

https://github.com/trogau/kbpgptesting

Reproduction:

1) Run 'node test-generate.js' to generate a new key pair

2) Run 'node test-encrypt.js kbpgp-pubkey.txt' to do a test encryption (parameter is the public key generated in step 1)

3) Run 'node test-decrypt.js kbpgp-privkey.txt kbpgp-encrypted-output.txt' (parameters are private key generated in step 1 and encrypted file generated in step 2)

Output I get is:

Key loaded Key fingerprint: ac4670f85c85f26b84ac98a204fc07024fa1592c Key ID: 04fc07024fa1592c Short key ID: 4FA1592C 04fc07024fa1592c 5bcbf12ba8cea6a8 Problem: Error: key not found: ["5bcbf12ba8cea6a8"]

maxtaco commented 8 years ago

Have you unlocked the key? Maybe post your code.

On Monday, March 21, 2016, David Harrison notifications@github.com wrote:

I'm trying to do a decrypt of some content but I'm getting an error:

Error: key not found: ["2d79418b3396f4cc"]

This key ID appears to be a subkey of the secret key:

:secret sub key packet: version 4, algo 1, created 1295399867, expires 0 skey[0]: [2048 bits] skey[1]: [17 bits] iter+salt S2K, algo: 9, SHA1 protection, hash: 2, salt: 5937b15e5e22906b protect count: 786432 (152) protect IV: 46 48 b3 07 b8 85 60 d2 9f 01 ff 13 10 c2 2e 2e encrypted stuff follows keyid: 2D79418B3396F4CC

The keyring loads OK (just doing it as per the example on the Decrypt documentation); when I issue a quick hacky "console.log(key.get_all_pgp_key_ids());" to see what IDs are present, it prints:

[ , ]

... so it looks like the key is actually present, but it's just not getting picked correctly as available for decryption by unbox?

I tested the code just with verification on a signed chunk and it worked fine - just as soon as I try to use unbox it breaks. (I've created the encrypted file with gpg v1 on Linux, gpg v2 on Windows and also through kbpgp; GPG can deal with it fine but I get the same error trying to decrypt with kbpgp in all cases.)

Been beating my head against this all day so hoping it's not something obvious I'm missing!

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/keybase/kbpgp/issues/111

trogau commented 8 years ago

Argh!! Sorry, that was the problem. Missed the unlocking step completely. Thanks!!