From: Douglas E E. <dee...@gm...> - 2016-02-19 20:52:57
|
I don't think you are doing anything wrong, but the openpgp card is. Using your private key: echo -ne "CgABEQS/SUEAAAAAAAAINA==" | openssl dgst -sign privkey.pem -sha256 > sig.a /tmp$ od -t x1 sig.a 0000000 00 8c f6 db 29 a7 d7 bd b3 63 4c fe d6 a9 fb a5 0000020 e0 38 7a ca a8 d4 9c 36 99 ab f6 2e 81 45 26 a7 0000040 60 4b 25 91 67 7e 86 31 10 5a db b4 86 d3 98 4d 0000060 34 94 0e 5e 0a ba 00 e0 47 2b e6 d2 1a d8 8a 61 0000100 d1 d1 69 c1 3c 02 ac 9d 2a af 23 0d cb 4f 40 a7 0000120 42 38 62 4b 6c b6 47 9d 36 80 f7 7c 17 60 49 46 0000140 a3 a9 92 73 44 0a 3f 6b ed de ff 85 76 f3 f2 32 0000160 6f 56 f3 1d dd c6 0d fe d0 99 e2 bd 1e 33 ea de 0000200 f1 00 a1 35 2c 80 e2 b9 cc da 23 fc c5 25 f1 05 0000220 7c 42 2b 99 3c ea a8 be 9d 00 da bc b1 da 6f 4d ... 0000660 a8 46 f4 46 c9 b2 ad 8d bf 9f 55 35 00 aa d9 5c 0000700 a2 29 7b c0 00 d0 dc d3 82 4c a9 18 55 f0 c0 74 0000720 bb 7d 6e 4b e0 b7 0f 84 c5 49 e2 92 f3 9c 9d 1c 0000740 9c 58 f4 12 d5 4b 36 db b2 3f d2 a2 ff 49 fb 7e 0000760 cd 94 33 4e f6 fd 78 cb 2c 7d a2 55 01 d4 7b 48 The signatire is 512 bytes with the first byte being 0x00 in bad_signature.txt lines 597-612 return 513 bytes, signature + 9000 *BUT* the card is tot returning the leading 0x00! It appears it is a problem with the card, not with OpenSC. On 2/19/2016 9:08 AM, Joe...@we... wrote: > Hi everyone, > I am using the Gemalto Open GPG dongle v2.1 with a RSA 4096 bit key to generate signatures for relatively short ID-strings. In general the process I set up runs fine, but I get a bad signature for > about 2% of my inputs. Bad means the data is 1 byte short and fails verification with openssl. But is not just truncated, comparing to a valid signature generated with openssl it looks completely > different. > I am doing the following: > $ echo -ne "CgABEQS/SUEAAAAAAAAINA==" | openssl dgst -binary -sha256 > dgst.txt > $ tools/pkcs15-crypt.exe -s -k 1 -r 1 -i dgst.txt -o sig.txt --sha-256 --pkcs1 -p 123456 > $ echo -ne "CgABEQS/SUEAAAAAAAAINA==" | openssl dgst -sha256 -verify pubkey.pem -signature sig.txt > Verification Failure > Doing the same with slightly altered input data runs fine: > $ echo -ne "CgABEQS/SUEAAAAAAAAINB==" | openssl dgst -binary -sha256 > dgst.txt > $ tools/pkcs15-crypt.exe -s -k 1 -r 1 -i dgst.txt -o sig.txt --sha-256 --pkcs1 -p 123456 > $ echo -ne "CgABEQS/SUEAAAAAAAAINB==" | openssl dgst -sha256 -verify pubkey.pem -signature sig.txt > Verified OK > This is reproducible with different keys (each key fails for different input data though), I saw the same issue when generating rsa signatures with pkcs11-tool (using parameters -s -m RSA-PKCS -i > dgst.txt -o sig.txt) , again the bad signatures happen for different input data, so to me it seems that certain key/data combinations may have an issue, or I am doing something wrong... > Please find attached the logs of both runs I mentioned above with OPENSC_DEBUG=9 set (you can see the good run returned 512 bytes as signature, whereas the bad one only returned 511), and the public > and private key stored on the card I used for this example (which I explicitly generated for this test ;-) ) > I have no idea what I might be doing wrong, any help would be highly appreciated! > Thanks > Jörg > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > > > > _______________________________________________ > Opensc-devel mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/opensc-devel > -- Douglas E. Engert <DEE...@gm...> |