Discussion:
checksum mismatch at 0 of 20 while trying to extract PGP Secret Key with Umlaut PIN created by gnupg
Harakiri
2014-06-04 09:22:43 UTC
Permalink
Hello,

im attaching a testkey that im unable to use with bc due a passphrase with umlauts.

The passphrase is

123ä

I looked at the sample here: https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java

but this does not work for me im getting

org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)

I tried it with 1.45 and 1.50 both with

PGPPrivateKey pKey =
pgpKey.extractPrivateKey(pin.toCharArray(), "BC");

and

PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build();

PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());

PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);

I also made sure of the string encoding

String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");

also tried with UTF-16.

Im still using JDK 1.6.

Thanks
David Hook
2014-06-07 23:02:37 UTC
Permalink
Have you tried decrypting the key using an 8 bit conversion? Looking at
the key my initial guess is that it wasn't done using UTF-8.

Regards,

David
Post by Harakiri
Hello,
im attaching a testkey that im unable to use with bc due a passphrase with umlauts.
The passphrase is
123ä
I looked at the sample here: https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java
but this does not work for me im getting
org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)
I tried it with 1.45 and 1.50 both with
PGPPrivateKey pKey =
pgpKey.extractPrivateKey(pin.toCharArray(), "BC");
and
PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());
PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);
I also made sure of the string encoding
String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");
also tried with UTF-16.
Im still using JDK 1.6.
Thanks
Harakiri
2014-06-16 09:07:50 UTC
Permalink
I was unable to get this to work - im not sure what 8 bit conversion means - 8bit is automatically done for UTF-8.

I looked at the GPG Source - this is the function that encodes a PW

http://pastebin.com/s07miBuj



This is how it is called from the key edit function


   s2k->mode = opt.s2k_mode;
   s2k->hash_algo = S2K_DIGEST_ALGO;
   dek = passphrase_to_dek( NULL, 0, opt.s2k_cipher_algo,
                                     s2k, 2, errtext, NULL);


There is also talk about "This is used for the old rfc1991 mode"
in the comments - dunno if this is related.


Any assistance would be greatly appreciated, thanks.


----------------------

Have you tried decrypting the key using an 8 bit conversion? Looking at the key my initial guess is that it wasn't done using UTF-8.


Regards,

David


________________________________
From: Harakiri <harakiri_23-/***@public.gmane.org>
To: dev-crypto-***@public.gmane.org
Sent: Wednesday, June 4, 2014 11:22 AM
Subject: checksum mismatch at 0 of 20 while trying to extract PGP Secret Key with Umlaut PIN created by gnupg


Hello,

im attaching a testkey that im unable to use with bc due a passphrase with umlauts.

The passphrase is

123ä

I looked at the sample here: https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java

but this does not work for me im getting

org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
    at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
    at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)

I tried it with 1.45 and 1.50 both with

PGPPrivateKey pKey =
                        pgpKey.extractPrivateKey(pin.toCharArray(), "BC");

and

PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
                    .setProvider(BouncyCastleProvider.PROVIDER_NAME).build();

                PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
                    .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());

                PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);

I also made sure of the string encoding

String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");

also tried with UTF-16.

Im still using JDK 1.6.

Thanks
David Hook
2014-06-17 00:08:02 UTC
Permalink
UTF-8 is an 8 bit encoding of UTF. 8 bit ASCII, on the other hand, is a
loose term to describe a range of extended character sets which do
incorporate things like umlauts. It's probably not as simple as just
converting by dropping the high order 8 bits in the java character
(worth a try though) - you may need to find out what the actual
character set was that was used to encrypt the key.

Regards,

David
Post by Harakiri
I was unable to get this to work - im not sure what 8 bit conversion
means - 8bit is automatically done for UTF-8.
I looked at the GPG Source - this is the function that encodes a PW
http://pastebin.com/s07miBuj <http://pastebin.com/4H8SG90w>
This is how it is called from the key edit function
s2k->mode = opt.s2k_mode;
s2k->hash_algo = S2K_DIGEST_ALGO;
dek = passphrase_to_dek( NULL, 0, opt.s2k_cipher_algo,
s2k, 2, errtext, NULL);
There is also talk about "This is used for the old rfc1991 mode"
in the comments - dunno if this is related.
Any assistance would be greatly appreciated, thanks.
----------------------
Have you tried decrypting the key using an 8 bit conversion? Looking
at the key my initial guess is that it wasn't done using UTF-8.
Regards,
David
------------------------------------------------------------------------
*Sent:* Wednesday, June 4, 2014 11:22 AM
*Subject:* checksum mismatch at 0 of 20 while trying to extract PGP
Secret Key with Umlaut PIN created by gnupg
Hello,
im attaching a testkey that im unable to use with bc due a passphrase with umlauts.
The passphrase is
123ä
https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java
but this does not work for me im getting
org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)
I tried it with 1.45 and 1.50 both with
PGPPrivateKey pKey =
pgpKey.extractPrivateKey(pin.toCharArray(), "BC");
and
PGPDigestCalculatorProvider calcProvider = new
JcaPGPDigestCalculatorProviderBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
PBESecretKeyDecryptor decryptor = new
JcePBESecretKeyDecryptorBuilder(calcProvider)
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());
PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);
I also made sure of the string encoding
String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");
also tried with UTF-16.
Im still using JDK 1.6.
Thanks
Harakiri
2014-06-23 11:42:48 UTC
Permalink
I still fighting with this issue.



I asked the GNUPG list and turns out - there is no standard on how the passphrase is encoded - the original PGP implementation just used the current system locale/encoding.
And this is exactly what gnupg does.

So basically you have to brute force all possible encodings for a passphrase, thats pretty bad.

According to the gnupg developer, thats what they actually do for P12 import.




________________________________
From: Harakiri <***@yahoo.com>
To: "dev-crypto-***@public.gmane.org" <dev-crypto-***@public.gmane.org>
Sent: Monday, June 16, 2014 11:07 AM
Subject: Re: checksum mismatch at 0 of 20 while trying to extract PGP Secret Key with Umlaut PIN created by gnupg



I was unable to get this to work - im not sure what 8 bit conversion means - 8bit is automatically done for UTF-8.

I looked at the GPG Source - this is the function that encodes a PW

http://pastebin.com/s07miBuj



This is how it is called from the key edit function


   s2k->mode = opt.s2k_mode;
   s2k->hash_algo = S2K_DIGEST_ALGO;
   dek = passphrase_to_dek( NULL, 0, opt.s2k_cipher_algo,
                                     s2k, 2, errtext, NULL);


There is also talk about "This is used for the old rfc1991 mode"
in the comments - dunno if this is related.


Any assistance would be greatly appreciated, thanks.


----------------------

Have you tried decrypting the key using an 8 bit conversion? Looking at the key my initial guess is that it wasn't done using UTF-8.


Regards,

David




________________________________
From: Harakiri <harakiri_23-/***@public.gmane.org>
To: dev-***@bouncycastle.org
Sent: Wednesday, June 4, 2014 11:22 AM
Subject: checksum mismatch at 0 of 20 while trying to extract PGP Secret Key with Umlaut PIN created by gnupg


Hello,

im attaching a testkey that im unable to use with bc due a passphrase with umlauts.

The passphrase is

123ä

I looked at the sample here: https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java

but this does not work for me im getting

org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
    at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
    at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)

I tried it with 1.45 and 1.50 both with

PGPPrivateKey pKey =
                        pgpKey.extractPrivateKey(pin.toCharArray(), "BC");

and

PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
                    .setProvider(BouncyCastleProvider.PROVIDER_NAME).build();

                PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
                    .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());

                PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);

I also made sure of the string encoding

String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");

also tried with UTF-16.

Im still using JDK 1.6.

Thanks
David Hook
2014-06-23 12:15:29 UTC
Permalink
The last bit is not correct - PKCS#12 defines passwords as BMP strings.
It's a Unicode standard with each character taking 2 bytes and the
standard defines how those 2 bytes are created from a character.

Unfortunately, the first bit probably explains why you're having your
issue though.

Regards,

David
Post by Harakiri
I still fighting with this issue.
I asked the GNUPG list and turns out - there is no standard on how the
passphrase is encoded - the original PGP implementation just used the
current system locale/encoding.
And this is exactly what gnupg does.
So basically you have to brute force all possible encodings for a
passphrase, thats pretty bad.
According to the gnupg developer, thats what they actually do for P12 import.
------------------------------------------------------------------------
*Sent:* Monday, June 16, 2014 11:07 AM
*Subject:* Re: checksum mismatch at 0 of 20 while trying to extract
PGP Secret Key with Umlaut PIN created by gnupg
I was unable to get this to work - im not sure what 8 bit conversion
means - 8bit is automatically done for UTF-8.
I looked at the GPG Source - this is the function that encodes a PW
http://pastebin.com/s07miBuj <http://pastebin.com/4H8SG90w>
This is how it is called from the key edit function
s2k->mode = opt.s2k_mode;
s2k->hash_algo = S2K_DIGEST_ALGO;
dek = passphrase_to_dek( NULL, 0, opt.s2k_cipher_algo,
s2k, 2, errtext, NULL);
There is also talk about "This is used for the old rfc1991 mode"
in the comments - dunno if this is related.
Any assistance would be greatly appreciated, thanks.
----------------------
Have you tried decrypting the key using an 8 bit conversion? Looking
at the key my initial guess is that it wasn't done using UTF-8.
Regards,
David
------------------------------------------------------------------------
*Sent:* Wednesday, June 4, 2014 11:22 AM
*Subject:* checksum mismatch at 0 of 20 while trying to extract PGP
Secret Key with Umlaut PIN created by gnupg
Hello,
im attaching a testkey that im unable to use with bc due a passphrase with umlauts.
The passphrase is
123ä
https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java
but this does not work for me im getting
org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)
I tried it with 1.45 and 1.50 both with
PGPPrivateKey pKey =
pgpKey.extractPrivateKey(pin.toCharArray(), "BC");
and
PGPDigestCalculatorProvider calcProvider = new
JcaPGPDigestCalculatorProviderBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
PBESecretKeyDecryptor decryptor = new
JcePBESecretKeyDecryptorBuilder(calcProvider)
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());
PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);
I also made sure of the string encoding
String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");
also tried with UTF-16.
Im still using JDK 1.6.
Thanks
Dirk-Willem van Gulik
2014-06-23 13:31:25 UTC
Permalink
I struggled with this recently as well (quite a pain if your chipcard locks up after 3 tries!). And I think it is slightly more subtle. GNUPG assumes UTF-8 for PKCS#12 passwords unless a locale (e.g. Latin1, CP850) has been explictly set with --p12-charset. Utilities like gpgsm are a bit more clever/worse and try a whole bunch (unless —p12-charset is set). See minip12.c; function decrypt_block; it will try the local locale/raw, ISO-8859-1, 15, 2,3, 4 - 9, KOI8, IBM437, 850, EUC, and BIG5. Most other utils just try utf8, the locale and then iso_8859-1(5). All in that order. And in each case it will clean any mess found - by re-encoding where needed as proper utf8 or UCS-2 in BMP when a charset is specified.

Dw.
The last bit is not correct - PKCS#12 defines passwords as BMP strings. It's a Unicode standard with each character taking 2 bytes and the standard defines how those 2 bytes are created from a character.
Unfortunately, the first bit probably explains why you're having your issue though.
Regards,
David
Post by Harakiri
I still fighting with this issue.
I asked the GNUPG list and turns out - there is no standard on how the passphrase is encoded - the original PGP implementation just used the current system locale/encoding.
And this is exactly what gnupg does.
So basically you have to brute force all possible encodings for a passphrase, thats pretty bad.
According to the gnupg developer, thats what they actually do for P12 import.
Sent: Monday, June 16, 2014 11:07 AM
Subject: Re: checksum mismatch at 0 of 20 while trying to extract PGP Secret Key with Umlaut PIN created by gnupg
I was unable to get this to work - im not sure what 8 bit conversion means - 8bit is automatically done for UTF-8.
I looked at the GPG Source - this is the function that encodes a PW
http://pastebin.com/s07miBuj
This is how it is called from the key edit function
s2k->mode = opt.s2k_mode;
s2k->hash_algo = S2K_DIGEST_ALGO;
dek = passphrase_to_dek( NULL, 0, opt.s2k_cipher_algo,
s2k, 2, errtext, NULL);
There is also talk about "This is used for the old rfc1991 mode"
in the comments - dunno if this is related.
Any assistance would be greatly appreciated, thanks.
----------------------
Have you tried decrypting the key using an 8 bit conversion? Looking at the key my initial guess is that it wasn't done using UTF-8.
Regards,
David
Sent: Wednesday, June 4, 2014 11:22 AM
Subject: checksum mismatch at 0 of 20 while trying to extract PGP Secret Key with Umlaut PIN created by gnupg
Hello,
im attaching a testkey that im unable to use with bc due a passphrase with umlauts.
The passphrase is
123ä
I looked at the sample here: https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java
but this does not work for me im getting
org.bouncycastle.openpgp.PGPException: checksum mismatch at 0 of 20
at org.bouncycastle.openpgp.PGPSecretKey.extractKeyData(Unknown Source)
at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)
I tried it with 1.45 and 1.50 both with
PGPPrivateKey pKey =
pgpKey.extractPrivateKey(pin.toCharArray(), "BC");
and
PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pin.toCharArray());
PGPPrivateKey pKey = pgpKey.extractPrivateKey(decryptor);
I also made sure of the string encoding
String passphrase = new String("123ä".getBytes("UTF-8"), "UTF-8");
also tried with UTF-16.
Im still using JDK 1.6.
Thanks
Loading...