openpgpjs/openpgpjs — Issue #25: [GPGTools compatibility] decryptSecretMPIs fails
Author: oliwr
Created: 2011-12-20 14:28:03+00:00
State: open

Using openpgpjs / GPG4Browsers with GnuPG/GPGTools generated keys (RSA/RSA) works for encrypting, but not for decrypting messages.

I've generated a test keypair to test with: https://gist.github.com/1501684 (secret: 1234). The following message has been encrypting using the test page and the public key from the gist.

-----BEGIN PGP MESSAGE-----
Version: GPG4Browsers 0.1
Comment: http://openpgpjs.org

wcBMA8Y07v9gO2wgAQf+Lk8u6CZRNhkoq+US/jKNfMt8HGiaI0Wa3u0ZCgoH
TCToj4diP9+OuGZdV2O3WkUvwKG2SsmQXoGnsGxSn5A4uJEl5dJ2QUwaYJKe
lTBxVZSrOenyJhSQbwp9g+WXyQ/unkqeWVqkp86n5697FnsOg7oqYXKJ0qDt
MtjqQtH1ZAj8CoixJXJOaHDEeKLZvNdcMTBUnMR8KStpfcFHavTxSyUe/Xzk
LKY8aFVI/zVnPvitxJ0GCXKGBXWnAcIYJZtiIPqB/Us736CbJFm75D69/kg7
0f2DYjzPPx/CmpkEnfEVM+GpE0UtVlxBOCACY6/loDPY4NWM75HPw1KLVUwA
E9JPAQCZE1tXfKwRZx+blTrnxSMy58yo6csuBZEGAXYURar+yqU59y3P0VDd
FNcrAUSFfG8oYjtlfNTj9KMI8vzlEvAy+roTyk8XqWpg2ARs9w==
=wvBO
-----END PGP MESSAGE-----

Decrypting the message using gnupg and the above credentials work fine.
Decrypting the message on the test page fails with an ERROR: Password for secrect key was incorrect!

I traced it back to within openpgp.packet.keymaterial decryptSecretMPIs , and especially the if-case in l. 416ff.
s2usageConvention is 254. I am looking into this and added this here for reference. Is there a compatibility issue with GPGTools itself or can someone verify this using a different GnuPG (i.e., not the Mac GPGTools)?

```
var cleartextMPIslength = cleartextMPIs.length;
if (this.s2kUsageConventions == 254 && str_sha1(cleartextMPIs.substring(0,cleartextMPIs.length - 20)) ==	cleartextMPIs.substring(cleartextMPIs.length - 20)) {
cleartextMPIslength -= 20;
} ...
```
The corresponding passage in the [RFC 4880](http://tools.ietf.org/html/rfc4880) is on page 42:

> If the string-to-key usage octet was 254, then a 20-octet SHA-1 hash of the plaintext of the algorithm-specific portion.

On a related note: At line 421, there is a typo "s2kUsageConcentions" should be "s2kUsageConventions". It's nothing much really, too silly for a diff or pull request.