Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Mon, 7 Jul 2008 17:35:33 -0700 (PDT),    group: microsoft.public.platformsdk.security        back       


Implementation of CardSignData() in smart card modules (minidrivers)   
Hello there,

I'm trying to write a smart card minidriver interfacing the Base CSP
to PKCS#11. Googling reveals that I'm not the first one; anyway, I'm
"almost there" and I'd like to release this as OSS once it's finished.
It could also help other people who are trying to write a minidriver.

I'm using certutil.exe from the Win 2003 SP1 admin pack under Win XP
Professional SP2. According to certutil -scinfo, I cannot get
CardSignData to work. I'm trying to make signature with a 1024-bit key
stored on a smart card.

What I'm doing is simply:
1. take the 20 bytes of SHA-1 digest provided in pbData,
2. reverse them,
3. feed them to PKCS#11 who prepends the DigestInfo DER encoding, pads
them in an appropriate structure and feeds them to the card;
4. take the resulting 128-byte signature from the card,
5. reverse the signature,
6. copy it into pbSignedData, setting cbSignedData to 128.

I'm also sure that step #3 is right because I've logged the APDU's
from and to the card.

The result is:

Performing AT_SIGNATURE public key matching test...
Public key matching test succeeded
  Key Container = 00000000-0000-0000-0000-123456789AB5
  Provider = Microsoft Base Smart Card Crypto Provider
  ProviderType = 1
  Flags = 1
  KeySpec = 2
420.434.0: 0x80090006 (-2146893818)
ERROR: Certificate public key does NOT match private key
317.686.0: 0x80090006 (-2146893818)

I'm quite convinced that the problem is in my implementation of
CardSignData(), because the certificates are read correctly, the
public keys match those in the certificates and AT_KEYEXCHANGE
(through CardRSADecrypt(), quite easier) works correctly:

Performing AT_KEYEXCHANGE public key matching test...
Public key matching test succeeded
  Key Container = 00000000-0000-0000-0000-123456789AB5
  Provider = Microsoft Base Smart Card Crypto Provider
  ProviderType = 1
  Flags = 1
  KeySpec = 1
Private key verifies

Could you give me any hints? Thanks in advance!

--
Emanuele
date: Mon, 7 Jul 2008 17:35:33 -0700 (PDT)   author:   Emanuele Pucciarelli

Re: Implementation of CardSignData() in smart card modules (minidrivers)   
Hi,

You should not always add the DigestInfo DER into signature in step 3. This 
must be done depending on the value of the dwSigningFlags member of the 
pInfo parameter. I advise you to trace all the content of the pInfo 
parameter to see how certutil is expecting the data to be computed.

Cheers,
-- 
Mounir IDRASSI
IDRIX
http://www.idrix.fr

to reach : mounir_idrix_fr (replace the underscores with the at and dot
characters respectively)

"Emanuele Pucciarelli "  a écrit dans le 
message de news: 
c26bfe26-24e0-474c-8d5c-6e83e51a7c95@d45g2000hsc.googlegroups.com...
> Hello there,
>
> I'm trying to write a smart card minidriver interfacing the Base CSP
> to PKCS#11. Googling reveals that I'm not the first one; anyway, I'm
> "almost there" and I'd like to release this as OSS once it's finished.
> It could also help other people who are trying to write a minidriver.
>
> I'm using certutil.exe from the Win 2003 SP1 admin pack under Win XP
> Professional SP2. According to certutil -scinfo, I cannot get
> CardSignData to work. I'm trying to make signature with a 1024-bit key
> stored on a smart card.
>
> What I'm doing is simply:
> 1. take the 20 bytes of SHA-1 digest provided in pbData,
> 2. reverse them,
> 3. feed them to PKCS#11 who prepends the DigestInfo DER encoding, pads
> them in an appropriate structure and feeds them to the card;
> 4. take the resulting 128-byte signature from the card,
> 5. reverse the signature,
> 6. copy it into pbSignedData, setting cbSignedData to 128.
>
> I'm also sure that step #3 is right because I've logged the APDU's
> from and to the card.
>
> The result is:
>
> Performing AT_SIGNATURE public key matching test...
> Public key matching test succeeded
>  Key Container = 00000000-0000-0000-0000-123456789AB5
>  Provider = Microsoft Base Smart Card Crypto Provider
>  ProviderType = 1
>  Flags = 1
>  KeySpec = 2
> 420.434.0: 0x80090006 (-2146893818)
> ERROR: Certificate public key does NOT match private key
> 317.686.0: 0x80090006 (-2146893818)
>
> I'm quite convinced that the problem is in my implementation of
> CardSignData(), because the certificates are read correctly, the
> public keys match those in the certificates and AT_KEYEXCHANGE
> (through CardRSADecrypt(), quite easier) works correctly:
>
> Performing AT_KEYEXCHANGE public key matching test...
> Public key matching test succeeded
>  Key Container = 00000000-0000-0000-0000-123456789AB5
>  Provider = Microsoft Base Smart Card Crypto Provider
>  ProviderType = 1
>  Flags = 1
>  KeySpec = 1
> Private key verifies
>
> Could you give me any hints? Thanks in advance!
>
> --
> Emanuele
date: Wed, 9 Jul 2008 04:25:57 +0100   author:   Mounir IDRASSI am

Re: Implementation of CardSignData() in smart card modules (minidrivers)   
Dear Mounir,

thanks for your answer!

> You should not always add the DigestInfo DER into signature in step 3. This
> must be done depending on the value of the dwSigningFlags member of the
> pInfo parameter. I advise you to trace all the content of the pInfo
> parameter to see how certutil is expecting the data to be computed.

In this case dwSigningFlags had no low bits set, so I gather that
certutil.exe -SCinfo wanted the DER value to be set… but I'll dump the
whole structure and post it here.

Anyway, it is called pbSigningData instead of pbSignature, but it
wants just the signature, it doesn't want a full PKCS#7 SignedData
blob – does it? Unfortunately the specs take a lot of things for
granted…

Thanks again,

--
Emanuele
date: Wed, 9 Jul 2008 10:25:35 -0700 (PDT)   author:   Emanuele Pucciarelli

Re: Implementation of CardSignData() in smart card modules (minidrivers)   
On 9 Lug, 05:25, "Mounir IDRASSI" <mooni...@newsgroup.nospam> wrote:

> You should not always add the DigestInfo DER into signature in step 3. This
> must be done depending on the value of the dwSigningFlags member of the
> pInfo parameter. I advise you to trace all the content of the pInfo
> parameter to see how certutil is expecting the data to be computed.

I did that. The flags are set to 0, hence I think that the platform
wants me to compute a "standard" signature using the concatenation of
the OID and the SHA1 digest, then PKCS#1 padding.

Could you confirm that CardSignData() should return a plain RSA-
encrypted block, in this case, and not a full ASN.1-encoded PKCS#7
SignedData field? I just find it weird that the parameters are called
cb/pbSignedData and not cb/pbSignature, or something similar…

Thanks,

--
Emanuele
date: Sun, 20 Jul 2008 09:31:56 -0700 (PDT)   author:   Emanuele Pucciarelli

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us