From: Douglas E E. <dee...@gm...> - 2016-02-22 18:17:01
|
On 2/22/2016 9:51 AM, Joe...@we... wrote: > Thanks for providing this patch, with this I got it _almost_ working :-) > I ran into one real and two minor issues: > 1) The real issue is that the outlen does not seem to be the expected signature length, > but the size of the buffer with some extra space. In my case it is 1024 and not the expected > 512, so this does not work. But I guess it would be possible to compute the expected signature > length in a general way? sc_pkcs15_compute_signature set modlen lines 324-336 from the type of key and its size, then tests if outlen is big enough: 339 if (inlen > sizeof(buf) || outlen < modlen) But then it passes to lower levels, it passes outlen: 434 r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen, 435 out, outlen); In all cases other then the card you have this is not a problem. So one possible fix is to set line 435 to: out, modlen); then do the memmove stuff if its too short. BUT THIS IS A GLOBAL CHANGE, and would need testing for other cards. I don't see why it would be an issue, but you never know... If you try and do an openpgp only fix, it looks like by the time pgp_set_security_env and pgp_compute_signature are called, they size of the key is not known, just the outlen. Som info cold be saved in the Another way: card-openpgp.c only supports RSA. And only 4K, 2K and maybe 1K keys are used. So if apdu.resplen within 4 bytes of one of these values, assume it is dropped 1, 2, 3 or 4 bytes, and do the memmove stuff then. (Not perfect, but chance of failure to catch a short signature is 1/2^32) There may be more info in the OpenPGP documents that would show how to save the key size internally in one of the card-openpgp.c internal structures. > 2) Minor techical issues: the apdu was not updated in the end to return the new length, > and src and dest were mixed up in the memmove OK, I never tested the code. good to here you got it working. > With this hacked up version of your patch I was able to get a valid signature :-) , but obviously it works only > for exactly my usecase with at most one leading zero: > --- a/src/libopensc/card-openpgp.c > +++ b/src/libopensc/card-openpgp.c > @@ -1656,6 +1656,13 @@ pgp_compute_signature(sc_card_t *card, const u8 *data, > r = sc_check_sw(card, apdu.sw1, apdu.sw2); > LOG_TEST_RET(card->ctx, r, "Card returned error"); > > + /* some cards may drop leading 0x00 byte on a signature */ > + if (apdu.resplen < 512) { > + memmove(out + 1 , out, apdu.resplen); /* overlaping */ > + memset(out, 0, 1); > + apdu.resplen = 512; > + } > + > *Gesendet:* Sonntag, 21. Februar 2016 um 20:54 Uhr > *Von:* "Douglas E Engert" <dee...@gm...> > *An:* ope...@li... > *Betreff:* Re: [Opensc-devel] Bad signature generated by pkcs15-crypt ? > The patch I sent you has a bug: > > memmove(out, out -(outlen - apdu.resplen), apdu.resplen); /* overlaping */ > should be: > > memmove(out, out + (outlen - apdu.resplen), apdu.resplen); /* overlaping */ > > > I have not tried the patch. > > On 2/21/2016 7:53 AM, Douglas E Engert wrote: > > > Try the attache patch. It is against http:/github.com/OpenSC/OpenSC > > > > > -- > > Douglas E. Engert <DEE...@gm...> > > > ------------------------------------------------------------------------------ > 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 > > > ------------------------------------------------------------------------------ > 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...> |