/[openpgpmdrv]/trunk/OpenPGPminidriver/CryptoOperations.c
ViewVC logotype

Diff of /trunk/OpenPGPminidriver/CryptoOperations.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by vletoux, Thu Mar 11 20:32:26 2010 UTC revision 9 by vletoux, Mon Mar 15 09:47:30 2010 UTC
# Line 26  Line 26 
26  #include "PublicDataOperations.h"  #include "PublicDataOperations.h"
27  #include "tlv.h"  #include "tlv.h"
28    
29  OPENPGP_CONTAINER_INFO Containers[] =  OPENPGP_KEY_INFO Keys[] =
30  {  {
31          {0xB6, 0xCE, 0xC7, CALG_RSA_SIGN, AT_SIGNATURE, ROLE_SIGNATURE},          {0xB6, 0xCE, 0xC7, CALG_RSA_SIGN}, // signature
32          {0xA4, 0xD0, 0xC9, CALG_RSA_SIGN, AT_SIGNATURE, ROLE_AUTHENTICATION},          {0xA4, 0xD0, 0xC9, CALG_RSA_SIGN}, // authentication
33          {0xB8, 0xCF, 0xC8, CALG_RSA_KEYX, AT_KEYEXCHANGE, ROLE_CONFIDENTIALITY}          {0xB8, 0xCF, 0xC8, CALG_RSA_KEYX}  // confidentiality
           
34  };  };
35    
36    OPENPGP_CONTAINER_INFO Containers[] =
37    {
38            {ROLE_SIGNATURE, AT_SIGNATURE},
39            {ROLE_AUTHENTICATION, AT_SIGNATURE},
40            {ROLE_CONFIDENTIALITY, AT_KEYEXCHANGE}
41    };
42  typedef struct _OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM  typedef struct _OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM
43  {  {
44          ALG_ID aiHashAlg;          ALG_ID aiHashAlg;
45          DWORD  dwHashSize;          DWORD  dwHashSize;
46          PBYTE pbEncodedOid;          PBYTE pbEncodedOid;
47          DWORD dwEncodedOidSize;          DWORD dwEncodedOidSize;
48            PWSTR szAlgId;
49  } OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM, *POPENPGP_SUPPORTED_SIGNATURE_ALGORITHM;  } OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM, *POPENPGP_SUPPORTED_SIGNATURE_ALGORITHM;
50    
51  BYTE dwSHA1EncodedOid[] = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,  BYTE dwSHA1EncodedOid[] = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
# Line 55  OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM Si Line 61  OPENPGP_SUPPORTED_SIGNATURE_ALGORITHM Si
61  {  {
62          {CALG_SHA1,20,          {CALG_SHA1,20,
63                          dwSHA1EncodedOid,                          dwSHA1EncodedOid,
64                          ARRAYSIZE(dwSHA1EncodedOid)},                          ARRAYSIZE(dwSHA1EncodedOid), BCRYPT_SHA1_ALGORITHM},
65          {CALG_SHA-256,32,          {CALG_SHA-256,32,
66                          dwSHA256EncodedOid,                          dwSHA256EncodedOid,
67                          ARRAYSIZE(dwSHA256EncodedOid)},                          ARRAYSIZE(dwSHA256EncodedOid), BCRYPT_SHA256_ALGORITHM},
68          {CALG_SHA-384,48,          {CALG_SHA-384,48,
69                          dwSHA384EncodedOid,                          dwSHA384EncodedOid,
70                          ARRAYSIZE(dwSHA384EncodedOid)},                          ARRAYSIZE(dwSHA384EncodedOid), BCRYPT_SHA384_ALGORITHM},
71          {CALG_SHA-512,64,          {CALG_SHA-512,64,
72                          dwSHA512EncodedOid,                          dwSHA512EncodedOid,
73                          ARRAYSIZE(dwSHA512EncodedOid)},                          ARRAYSIZE(dwSHA512EncodedOid), BCRYPT_SHA512_ALGORITHM},
74  };  };
75    
76  DWORD dwSignatureAlgorithmCount = ARRAYSIZE(SignatureAlgorithm);  DWORD dwSignatureAlgorithmCount = ARRAYSIZE(SignatureAlgorithm);
# Line 80  typedef struct _RSAPUBLICKEYBLOB Line 86  typedef struct _RSAPUBLICKEYBLOB
86    
87    
88  DWORD OCardGetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,  DWORD OCardGetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,
89                                                                  __in OPENPGP_CONTAINER dwContainer,                                                                  __in OPENPGP_KEY dwKey,
90                                                                  __out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)                                                                  __out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
91  {  {
92          DWORD dwReturn;          DWORD dwReturn;
# Line 90  DWORD OCardGetKeyAlgorithmAttributes(__i Line 96  DWORD OCardGetKeyAlgorithmAttributes(__i
96          WORD wTemp;          WORD wTemp;
97          __try          __try
98          {          {
99                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwKey);
100                  switch(dwContainer)                  switch(dwKey)
101                  {                  {
102                  case Signature:                  case KeySignature:
103                          szAlgorithmAttributes = szOpenPGPAlgoAttributesSignature;                          szAlgorithmAttributes = szOpenPGPAlgoAttributesSignature;
104                          break;                          break;
105                  case Authentication:                  case KeyAuthentication:
106                          szAlgorithmAttributes = szOpenPGPAlgoAttributesDecryption;                          szAlgorithmAttributes = szOpenPGPAlgoAttributesDecryption;
107                          break;                          break;
108                  case Confidentiality:                  case KeyConfidentiality:
109                          szAlgorithmAttributes = szOpenPGPAlgoAttributesAuthentication;                          szAlgorithmAttributes = szOpenPGPAlgoAttributesAuthentication;
110                          break;                          break;
111                  default:                  default:
112                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
113                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
114                          __leave;                          __leave;
115                  }                  }
116                  dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, &pbData, &dwResponseSize);                  dwReturn = OCardReadFile(pCardData, szOpenPGPDir, szAlgorithmAttributes, &pbData, &dwResponseSize);
# Line 137  DWORD OCardGetKeyAlgorithmAttributes(__i Line 143  DWORD OCardGetKeyAlgorithmAttributes(__i
143  }  }
144    
145  DWORD OCardSetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,  DWORD OCardSetKeyAlgorithmAttributes(__in PCARD_DATA pCardData,
146                                                                  __in OPENPGP_CONTAINER dwContainer,                                                                  __in OPENPGP_KEY dwKey,
147                                                                  __out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)                                                                  __out POPENPGP_ALGORITHM_ATTRIBUTE pAttributes)
148  {  {
149          DWORD dwReturn;          DWORD dwReturn;
# Line 146  DWORD OCardSetKeyAlgorithmAttributes(__i Line 152  DWORD OCardSetKeyAlgorithmAttributes(__i
152          WORD wTemp;          WORD wTemp;
153          __try          __try
154          {          {
155                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwKey);
156                  switch(dwContainer)                  switch(dwKey)
157                  {                  {
158                  case Signature:                  case KeySignature:
159                          szAlgorithmAttributes = szOpenPGPAlgoAttributesSignature;                          szAlgorithmAttributes = szOpenPGPAlgoAttributesSignature;
160                          break;                          break;
161                  case Authentication:                  case KeyAuthentication:
162                          szAlgorithmAttributes = szOpenPGPAlgoAttributesDecryption;                          szAlgorithmAttributes = szOpenPGPAlgoAttributesDecryption;
163                          break;                          break;
164                  case Confidentiality:                  case KeyConfidentiality:
165                          szAlgorithmAttributes = szOpenPGPAlgoAttributesAuthentication;                          szAlgorithmAttributes = szOpenPGPAlgoAttributesAuthentication;
166                          break;                          break;
167                  default:                  default:
168                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
169                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
170                          __leave;                          __leave;
171                  }                  }
172                  memcpy(&TempAttributes, pAttributes, sizeof(OPENPGP_ALGORITHM_ATTRIBUTE));                  memcpy(&TempAttributes, pAttributes, sizeof(OPENPGP_ALGORITHM_ATTRIBUTE));
# Line 211  DWORD BuildSingleTlv(__in PBYTE buffer, Line 217  DWORD BuildSingleTlv(__in PBYTE buffer,
217  }  }
218    
219  DWORD BuildPrivateKeyTlv(__in PCARD_DATA pCardData, __in PRSAPUBLICKEYBLOB pbPublicKeyBlob,  DWORD BuildPrivateKeyTlv(__in PCARD_DATA pCardData, __in PRSAPUBLICKEYBLOB pbPublicKeyBlob,
220                                                    __in OPENPGP_CONTAINER dwContainer, __in BYTE bFormat,                                                    __in OPENPGP_KEY dwKey, __in BYTE bFormat,
221                                                   __out PBYTE * ppbTlv, __out PDWORD pdwTlvSize)                                                   __out PBYTE * ppbTlv, __out PDWORD pdwTlvSize)
222  {  {
223          // structure of the keyblob          // structure of the keyblob
# Line 298  DWORD BuildPrivateKeyTlv(__in PCARD_DATA Line 304  DWORD BuildPrivateKeyTlv(__in PCARD_DATA
304                  memcpy(*ppbTlv + dwOffset, b4DHeader, dw4DHeaderSize);                  memcpy(*ppbTlv + dwOffset, b4DHeader, dw4DHeaderSize);
305                  dwOffset += dw4DHeaderSize;                  dwOffset += dw4DHeaderSize;
306                  // control reference templace                  // control reference templace
307                  (*ppbTlv)[dwOffset++] = Containers[dwContainer].bKeyTag;                  (*ppbTlv)[dwOffset++] = Keys[dwKey].bKeyTag;
308                  (*ppbTlv)[dwOffset++] = 0;                  (*ppbTlv)[dwOffset++] = 0;
309                  // cardholder private key template                  // cardholder private key template
310                  memcpy(*ppbTlv + dwOffset, b7F48Header, dw7F48HeaderSize);                  memcpy(*ppbTlv + dwOffset, b7F48Header, dw7F48HeaderSize);
# Line 368  DWORD BuildPrivateKeyTlv(__in PCARD_DATA Line 374  DWORD BuildPrivateKeyTlv(__in PCARD_DATA
374          return dwReturn;          return dwReturn;
375  }  }
376    
377  DWORD UpdateGenerationDateTime(__in PCARD_DATA pCardData, __in OPENPGP_CONTAINER dwContainer,  DWORD UpdateGenerationDateTime(__in PCARD_DATA pCardData, __in OPENPGP_KEY dwKey,
378                                                             __out PDWORD pdwSecondsSince1970)                                                             __out PDWORD pdwSecondsSince1970)
379  {  {
380          DWORD dwReturn = 0;          DWORD dwReturn = 0;
# Line 395  DWORD UpdateGenerationDateTime(__in PCAR Line 401  DWORD UpdateGenerationDateTime(__in PCAR
401                  WindowsTime.LowPart = WindowsFileTime.dwLowDateTime;                  WindowsTime.LowPart = WindowsFileTime.dwLowDateTime;
402                  *pdwSecondsSince1970 = (DWORD)((WindowsTime.QuadPart - UnixZeroTime.QuadPart) / 10000000);                  *pdwSecondsSince1970 = (DWORD)((WindowsTime.QuadPart - UnixZeroTime.QuadPart) / 10000000);
403                                    
404                  pbCommand[3] = Containers[dwContainer].bDateTimeTag;                  pbCommand[3] = Keys[dwKey].bDateTimeTag;
405                  pbCommand[5] = (BYTE) (*pdwSecondsSince1970 / 0x1000000);                  pbCommand[5] = (BYTE) (*pdwSecondsSince1970 / 0x1000000);
406                  pbCommand[6] = (BYTE) ((*pdwSecondsSince1970 % 0x1000000) / 0x10000);                  pbCommand[6] = (BYTE) ((*pdwSecondsSince1970 % 0x1000000) / 0x10000);
407                  pbCommand[7] = (BYTE) ((*pdwSecondsSince1970 % 0x10000) / 0x100);                  pbCommand[7] = (BYTE) ((*pdwSecondsSince1970 % 0x10000) / 0x100);
# Line 409  DWORD UpdateGenerationDateTime(__in PCAR Line 415  DWORD UpdateGenerationDateTime(__in PCAR
415          return dwReturn;          return dwReturn;
416  }  }
417    
418  DWORD UpdateFingerPrint(__in PCARD_DATA pCardData, __in OPENPGP_CONTAINER dwContainer,  DWORD UpdateFingerPrint(__in PCARD_DATA pCardData, __in OPENPGP_KEY dwKey,
419                                                  __in DWORD dwSecondsSince1970,                                                  __in DWORD dwSecondsSince1970,
420                                                  __in PBYTE pbModulus, __in DWORD dwModulusSizeInBit,                                                  __in PBYTE pbModulus, __in DWORD dwModulusSizeInBit,
421                                                  __in BOOL fIsModulusInBigEndian,                                                  __in BOOL fIsModulusInBigEndian,
# Line 498  DWORD UpdateFingerPrint(__in PCARD_DATA Line 504  DWORD UpdateFingerPrint(__in PCARD_DATA
504                          Trace(WINEVENT_LEVEL_ERROR, L"CryptGetHashParam 0x%08X", dwReturn);                          Trace(WINEVENT_LEVEL_ERROR, L"CryptGetHashParam 0x%08X", dwReturn);
505                          __leave;                          __leave;
506                  }                  }
507                  pbCommand[3] = Containers[dwContainer].bSignatureTag;                  pbCommand[3] = Keys[dwKey].bSignatureTag;
508                  dwReturn = OCardSendCommand(pCardData, pbCommand, dwCommandSize);                  dwReturn = OCardSendCommand(pCardData, pbCommand, dwCommandSize);
509    
510          }          }
# Line 517  DWORD UpdateFingerPrint(__in PCARD_DATA Line 523  DWORD UpdateFingerPrint(__in PCARD_DATA
523    
524  }  }
525    
526  DWORD OCardReadPublicKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, PBYTE *pbPublicKey, PDWORD pdwPublicKeySize)  DWORD OCardReadPublicKey(PCARD_DATA pCardData, OPENPGP_KEY dwKey, PBYTE *pbPublicKey, PDWORD pdwPublicKeySize)
527  {  {
528          DWORD dwReturn;          DWORD dwReturn;
529          PBYTE pbData = NULL;          PBYTE pbData = NULL;
# Line 543  DWORD OCardReadPublicKey(PCARD_DATA pCar Line 549  DWORD OCardReadPublicKey(PCARD_DATA pCar
549          DWORD dwTotalTlvSize, dwOffset;          DWORD dwTotalTlvSize, dwOffset;
550          __try          __try
551          {          {
552                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwKey=%d",dwKey);
553                  if (dwContainer >= MaxContainer)                  if (dwKey >= KeyMax)
554                  {                  {
555                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
556                          Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);                          Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
557                          __leave;                          __leave;
558                  }                  }
559                  pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;                  pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
560                  pbCmd[7] = Containers[dwContainer].bKeyTag;                  pbCmd[7] = Keys[dwKey].bKeyTag;
561                  dwCmdSize = 9;                  dwCmdSize = 9;
562                  if (pContext->fExtentedLeLcFields)                  if (pContext->fExtentedLeLcFields)
563                  {                  {
# Line 588  DWORD OCardReadPublicKey(PCARD_DATA pCar Line 594  DWORD OCardReadPublicKey(PCARD_DATA pCar
594                  if (!*pbPublicKey)                  if (!*pbPublicKey)
595                  {                  {
596                          dwReturn = SCARD_E_NO_MEMORY;                          dwReturn = SCARD_E_NO_MEMORY;
597                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY %d", dwContainer);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_MEMORY %d", dwKey);
598                          __leave;                          __leave;
599                  }                  }
600                  pbBlob = (PRSAPUBLICKEYBLOB) *pbPublicKey;                  pbBlob = (PRSAPUBLICKEYBLOB) *pbPublicKey;
# Line 596  DWORD OCardReadPublicKey(PCARD_DATA pCar Line 602  DWORD OCardReadPublicKey(PCARD_DATA pCar
602                  pbBlob->blobheader.bType = PUBLICKEYBLOB;                  pbBlob->blobheader.bType = PUBLICKEYBLOB;
603                  pbBlob->blobheader.bVersion = CUR_BLOB_VERSION;                  pbBlob->blobheader.bVersion = CUR_BLOB_VERSION;
604                  pbBlob->blobheader.reserved = 0;                  pbBlob->blobheader.reserved = 0;
605                  pbBlob->blobheader.aiKeyAlg = Containers[dwContainer].aiKeyAlg;                  pbBlob->blobheader.aiKeyAlg = Keys[dwKey].aiKeyAlg;
606                  pbBlob->rsapubkey.magic = 0x31415352; //'RSA1';                  pbBlob->rsapubkey.magic = 0x31415352; //'RSA1';
607                  pbBlob->rsapubkey.bitlen = dwModulusSize*8;                  pbBlob->rsapubkey.bitlen = dwModulusSize*8;
608                  pbBlob->rsapubkey.pubexp = pbExponent[0] * 0x1000000  + pbExponent[1] * 0x10000  + pbExponent[2] * 0x100 + pbExponent[3];                  pbBlob->rsapubkey.pubexp = pbExponent[0] * 0x1000000  + pbExponent[1] * 0x10000  + pbExponent[2] * 0x100 + pbExponent[3];
# Line 611  DWORD OCardReadPublicKey(PCARD_DATA pCar Line 617  DWORD OCardReadPublicKey(PCARD_DATA pCar
617          }          }
618          __finally          __finally
619          {          {
620                    if (pbData)
621                            pCardData->pfnCspFree(pbData);
622          }          }
623          Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);          Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
624          return dwReturn;          return dwReturn;
625  }  }
626    
627  DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_CONTAINER dwContainer, DWORD dwBitLen)  DWORD OCardCreateKey(PCARD_DATA pCardData, OPENPGP_KEY dwKey, DWORD dwBitLen)
628  {  {
629          DWORD dwReturn;          DWORD dwReturn;
630          PBYTE pbData = NULL;          PBYTE pbData = NULL;
# Line 641  DWORD OCardCreateKey(PCARD_DATA pCardDat Line 649  DWORD OCardCreateKey(PCARD_DATA pCardDat
649          DWORD dwTotalTlvSize, dwOffset;          DWORD dwTotalTlvSize, dwOffset;
650          __try          __try
651          {          {
652                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwKey=%d",dwKey);
653                  if (dwContainer >= MaxContainer)                  if (dwKey >= KeyMax)
654                  {                  {
655                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
656                          Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwContainer);                          Trace(WINEVENT_LEVEL_INFO, L"SCARD_E_NO_KEY_CONTAINER %d", dwKey);
657                          __leave;                          __leave;
658                  }                  }
659                  // key len                  // key len
660                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
661                  if (dwReturn)                  if (dwReturn)
662                  {                  {
663                          __leave;                          __leave;
664                  }                  }
665                  Attributes.wModulusLengthInBit = (WORD) dwBitLen;                  Attributes.wModulusLengthInBit = (WORD) dwBitLen;
666                  dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);                  dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
667                  if (dwReturn)                  if (dwReturn)
668                  {                  {
669                          __leave;                          __leave;
670                  }                  }
671    
672                  pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;                  pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
673                  pbCmd[7] = Containers[dwContainer].bKeyTag;                  pbCmd[7] = Keys[dwKey].bKeyTag;
674                  dwCmdSize = 9;                  dwCmdSize = 9;
675                  if (pContext->fExtentedLeLcFields)                  if (pContext->fExtentedLeLcFields)
676                  {                  {
# Line 694  DWORD OCardCreateKey(PCARD_DATA pCardDat Line 702  DWORD OCardCreateKey(PCARD_DATA pCardDat
702                          __leave;                          __leave;
703                  }                  }
704                  dwExponent = pbExponent[0] * 0x1000000  + pbExponent[1] * 0x10000  + pbExponent[2] * 0x100 + pbExponent[3];                  dwExponent = pbExponent[0] * 0x1000000  + pbExponent[1] * 0x10000  + pbExponent[2] * 0x100 + pbExponent[3];
705                  dwReturn = UpdateGenerationDateTime(pCardData, dwContainer, &dwSecondsSince1970);                  dwReturn = UpdateGenerationDateTime(pCardData, dwKey, &dwSecondsSince1970);
706                  if (dwReturn)                  if (dwReturn)
707                  {                  {
708                          __leave;                          __leave;
709                  }                  }
710                  dwReturn = UpdateFingerPrint(pCardData, dwContainer, dwSecondsSince1970,                  dwReturn = UpdateFingerPrint(pCardData, dwKey, dwSecondsSince1970,
711                                                                                  pbModulus,                                                                                  pbModulus,
712                                                                                  dwModulusSize * 8,                                                                                  dwModulusSize * 8,
713                                                                                  TRUE,                                                                                  TRUE,
# Line 709  DWORD OCardCreateKey(PCARD_DATA pCardDat Line 717  DWORD OCardCreateKey(PCARD_DATA pCardDat
717                  {                  {
718                          __leave;                          __leave;
719                  }                  }
720                  switch(dwContainer)                  pContext->fHasKey[dwKey] = TRUE;
                 {  
                 case Signature:  
                         pContext->fHasSignature = TRUE;  
                         break;  
                 case Authentication:  
                         pContext->fHasAuthentication = TRUE;  
                         break;  
                 case Confidentiality:  
                         pContext->fHasDecryption = TRUE;  
                         break;  
                 }  
721          }          }
722          __finally          __finally
723          {          {
# Line 732  DWORD OCardCreateKey(PCARD_DATA pCardDat Line 729  DWORD OCardCreateKey(PCARD_DATA pCardDat
729  }  }
730    
731  DWORD OCardImportKey(PCARD_DATA pCardData,  DWORD OCardImportKey(PCARD_DATA pCardData,
732                                           OPENPGP_CONTAINER dwContainer,                                           OPENPGP_KEY dwKey,
733                                           PBYTE pBlob,                                           PBYTE pBlob,
734                                           DWORD dwKeySize)                                           DWORD dwKeySize)
735  {  {
# Line 746  DWORD OCardImportKey(PCARD_DATA pCardDat Line 743  DWORD OCardImportKey(PCARD_DATA pCardDat
743          PRSAPUBLICKEYBLOB pbPublicKeyBlob = (PRSAPUBLICKEYBLOB) pBlob;          PRSAPUBLICKEYBLOB pbPublicKeyBlob = (PRSAPUBLICKEYBLOB) pBlob;
744          BYTE bCommand[] = {0x00,0xDB,0x3F,0xFF};          BYTE bCommand[] = {0x00,0xDB,0x3F,0xFF};
745          DWORD dwSecondsSince1970;          DWORD dwSecondsSince1970;
746            POPENPGP_CONTEXT pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
747          __try          __try
748          {          {
749                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwContainer);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",dwKey);
750                  // check blob                  // check blob
751                  if (pbPublicKeyBlob->blobheader.aiKeyAlg != CALG_RSA_SIGN &&                  if (pbPublicKeyBlob->blobheader.aiKeyAlg != CALG_RSA_SIGN &&
752                          pbPublicKeyBlob->blobheader.aiKeyAlg != CALG_RSA_KEYX)                          pbPublicKeyBlob->blobheader.aiKeyAlg != CALG_RSA_KEYX)
# Line 770  DWORD OCardImportKey(PCARD_DATA pCardDat Line 768  DWORD OCardImportKey(PCARD_DATA pCardDat
768                          __leave;                          __leave;
769                  }                  }
770                                    
771                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
772                  if (dwReturn)                  if (dwReturn)
773                  {                  {
774                          __leave;                          __leave;
775                  }                  }
776                  Attributes.wModulusLengthInBit = (WORD) pbPublicKeyBlob->rsapubkey.bitlen;                  Attributes.wModulusLengthInBit = (WORD) pbPublicKeyBlob->rsapubkey.bitlen;
777                  dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwContainer, &Attributes);                  dwReturn = OCardSetKeyAlgorithmAttributes(pCardData, dwKey, &Attributes);
778                  if (dwReturn)                  if (dwReturn)
779                  {                  {
780                          __leave;                          __leave;
781                  }                  }
782                  dwReturn = BuildPrivateKeyTlv(pCardData, pbPublicKeyBlob, dwContainer, Attributes.bFormat, &pbTlv, &dwTlvSize);                  dwReturn = BuildPrivateKeyTlv(pCardData, pbPublicKeyBlob, dwKey, Attributes.bFormat, &pbTlv, &dwTlvSize);
783                  if (dwReturn)                  if (dwReturn)
784                  {                  {
785                          __leave;                          __leave;
# Line 820  DWORD OCardImportKey(PCARD_DATA pCardDat Line 818  DWORD OCardImportKey(PCARD_DATA pCardDat
818                  {                  {
819                          __leave;                          __leave;
820                  }                  }
821                  dwReturn = UpdateGenerationDateTime(pCardData, dwContainer, &dwSecondsSince1970);                  dwReturn = UpdateGenerationDateTime(pCardData, dwKey, &dwSecondsSince1970);
822                  if (dwReturn)                  if (dwReturn)
823                  {                  {
824                          __leave;                          __leave;
825                  }                  }
826                  dwReturn = UpdateFingerPrint(pCardData, dwContainer, dwSecondsSince1970,                  dwReturn = UpdateFingerPrint(pCardData, dwKey, dwSecondsSince1970,
827                                                                                  pbPublicKeyBlob->modulus,                                                                                  pbPublicKeyBlob->modulus,
828                                                                                  pbPublicKeyBlob->rsapubkey.bitlen,                                                                                  pbPublicKeyBlob->rsapubkey.bitlen,
829                                                                                  FALSE,                                                                                  FALSE,
# Line 835  DWORD OCardImportKey(PCARD_DATA pCardDat Line 833  DWORD OCardImportKey(PCARD_DATA pCardDat
833                  {                  {
834                          __leave;                          __leave;
835                  }                  }
836                  switch(dwContainer)                  pContext->fHasKey[dwKey] = TRUE;
                 {  
                 case Signature:  
                         pContext->fHasSignature = TRUE;  
                         break;  
                 case Authentication:  
                         pContext->fHasAuthentication = TRUE;  
                         break;  
                 case Confidentiality:  
                         pContext->fHasDecryption = TRUE;  
                         break;  
                 }  
837          }          }
838          __finally          __finally
839          {          {
# Line 865  DWORD OCardImportKey(PCARD_DATA pCardDat Line 852  DWORD OCardImportKey(PCARD_DATA pCardDat
852          return dwReturn;          return dwReturn;
853  }  }
854    
855  DWORD OCardSign(PCARD_DATA pCardData,  DWORD OCardCheckSigningInfo(__in PCARD_SIGNING_INFO  pInfo, __out PDWORD pdwIndex)
                                 PCARD_SIGNING_INFO  pInfo)  
856  {  {
857          DWORD dwReturn;          DWORD dwReturn, dwI;
         PBYTE pbData = NULL;  
         DWORD dwCmdSize = 0, dwI;  
         POPENPGP_CONTEXT pContext;  
         OPENPGP_ALGORITHM_ATTRIBUTE Attributes;  
         BYTE pbCmd[6 + 256 + 256] = {0x00,  
                                     0x2A,  
                                         0x9E,  
                                         0x9A,  
                                         0x00,  
                                         0x00,  
                                         };  
858          __try          __try
859          {          {
                 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);  
860                  if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))                  if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))
861                  {                  {
862                          Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);                          Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);
# Line 893  DWORD OCardSign(PCARD_DATA pCardData, Line 867  DWORD OCardSign(PCARD_DATA pCardData,
867                  {                  {
868                          if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)                          if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)
869                          {                          {
870                                  dwReturn = SCARD_E_UNSUPPORTED_FEATURE;                                  BCRYPT_PKCS1_PADDING_INFO* padding = (BCRYPT_PKCS1_PADDING_INFO*) pInfo->pPaddingInfo;
871                                  Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");                                  for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
872                                  __leave;                                  {
873                                            if (wcscmp(SignatureAlgorithm[dwI].szAlgId,padding->pszAlgId) == 0)
874                                            {
875                                                    // found
876                                                    break;
877                                            }
878                                    }
879                                    if (dwI >= dwSignatureAlgorithmCount)
880                                    {
881                                            Trace(WINEVENT_LEVEL_ERROR, L"alg not found %s", padding->pszAlgId);
882                                            dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
883                                            __leave;
884                                    }
885                          }                          }
886                          else if (pInfo->dwPaddingType == CARD_PADDING_PSS)                          else if (pInfo->dwPaddingType == CARD_PADDING_PSS)
887                          {                          {
# Line 910  DWORD OCardSign(PCARD_DATA pCardData, Line 896  DWORD OCardSign(PCARD_DATA pCardData,
896                                  __leave;                                  __leave;
897                          }                          }
898                  }                  }
899                  if (!(pInfo->aiHashAlg & ALG_CLASS_HASH))                  else
                 {  
                         dwReturn = SCARD_E_INVALID_PARAMETER;  
                         Trace(WINEVENT_LEVEL_ERROR, L"pInfo->aiHashAlg == %d", pInfo->aiHashAlg);  
                         __leave;  
                 }  
                 for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)  
900                  {                  {
901                          if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)                          if (!(pInfo->aiHashAlg & ALG_CLASS_HASH))
902                          {                          {
903                                  // found                                  dwReturn = SCARD_E_INVALID_PARAMETER;
904                                  break;                                  Trace(WINEVENT_LEVEL_ERROR, L"pInfo->aiHashAlg == %d", pInfo->aiHashAlg);
905                                    __leave;
906                            }
907                            for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)
908                            {
909                                    if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)
910                                    {
911                                            // found
912                                            break;
913                                    }
914                            }
915                            if (dwI >= dwSignatureAlgorithmCount)
916                            {
917                                    Trace(WINEVENT_LEVEL_ERROR, L"alg not found %d", pInfo->aiHashAlg);
918                                    dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
919                                    __leave;
920                          }                          }
                 }  
                 if (dwI >= dwSignatureAlgorithmCount)  
                 {  
                         Trace(WINEVENT_LEVEL_ERROR, L"alg not found %d", pInfo->aiHashAlg);  
                         dwReturn = SCARD_E_UNSUPPORTED_FEATURE;  
                         __leave;  
921                  }                  }
922                  if (SignatureAlgorithm[dwI].dwHashSize != pInfo->cbData)                  if (SignatureAlgorithm[dwI].dwHashSize != pInfo->cbData)
923                  {                  {
# Line 936  DWORD OCardSign(PCARD_DATA pCardData, Line 925  DWORD OCardSign(PCARD_DATA pCardData,
925                          dwReturn = SCARD_E_INVALID_PARAMETER;                          dwReturn = SCARD_E_INVALID_PARAMETER;
926                          __leave;                          __leave;
927                  }                  }
928                  if (pInfo->bContainerIndex != Signature)                  *pdwIndex = dwI;
929                    dwReturn = 0;
930            }
931            __finally
932            {
933            }
934            return dwReturn;
935    }
936    
937    DWORD OCardSign(PCARD_DATA pCardData,
938                                    PCARD_SIGNING_INFO  pInfo)
939    {
940            DWORD dwReturn;
941            PBYTE pbData = NULL;
942            DWORD dwCmdSize = 0, dwIndex, dwI;
943            POPENPGP_CONTEXT pContext;
944            OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
945            BYTE pbCmd[6 + 256 + 256] = {0x00,
946                                        0x2A,
947                                            0x9E,
948                                            0x9A,
949                                            0x00,
950                                            0x00,
951                                            };
952            __try
953            {
954                    Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
955                    dwReturn = OCardCheckSigningInfo(pInfo, &dwIndex);
956                    if (dwReturn)
957                    {
958                            __leave;
959                    }
960                    if (pInfo->bContainerIndex != ContainerSignature)
961                  {                  {
962                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
963                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
# Line 946  DWORD OCardSign(PCARD_DATA pCardData, Line 967  DWORD OCardSign(PCARD_DATA pCardData,
967                  {                  {
968                          // optimisation :                          // optimisation :
969                          // return the buffer size only                          // return the buffer size only
970                          dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);                          dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeySignature, &Attributes);
971                          if (dwReturn)                          if (dwReturn)
972                          {                          {
973                                  __leave;                                  __leave;
# Line 963  DWORD OCardSign(PCARD_DATA pCardData, Line 984  DWORD OCardSign(PCARD_DATA pCardData,
984                  {                  {
985                          dwCmdSize++;                          dwCmdSize++;
986                  }                  }
987                  pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwI].dwEncodedOidSize + pInfo->cbData);                  pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwIndex].dwEncodedOidSize + pInfo->cbData);
988                  memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwI].pbEncodedOid,SignatureAlgorithm[dwI].dwEncodedOidSize);                  memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwIndex].pbEncodedOid,SignatureAlgorithm[dwIndex].dwEncodedOidSize);
989                  dwCmdSize += SignatureAlgorithm[dwI].dwEncodedOidSize;                  dwCmdSize += SignatureAlgorithm[dwIndex].dwEncodedOidSize;
990                  /*for(dwI = 0 ; dwI < pInfo->cbData ; dwI++)                  /*for(dwI = 0 ; dwI < pInfo->cbData ; dwI++)
991                  {                  {
992                          pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData - dwI -1];                          pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData - dwI -1];
# Line 1018  DWORD OCardAuthenticate(PCARD_DATA pCard Line 1039  DWORD OCardAuthenticate(PCARD_DATA pCard
1039  {  {
1040          DWORD dwReturn;          DWORD dwReturn;
1041          PBYTE pbData = NULL;          PBYTE pbData = NULL;
1042          DWORD dwCmdSize = 0, dwI;          DWORD dwCmdSize = 0, dwIndex, dwI;
1043          POPENPGP_CONTEXT pContext;          POPENPGP_CONTEXT pContext;
1044          OPENPGP_ALGORITHM_ATTRIBUTE Attributes;          OPENPGP_ALGORITHM_ATTRIBUTE Attributes;
1045          BYTE pbCmd[6 + 256 + 256] = {0x00,          BYTE pbCmd[6 + 256 + 256] = {0x00,
# Line 1031  DWORD OCardAuthenticate(PCARD_DATA pCard Line 1052  DWORD OCardAuthenticate(PCARD_DATA pCard
1052          __try          __try
1053          {          {
1054                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
1055                  if (pInfo->dwSigningFlags & ~(CARD_PADDING_INFO_PRESENT | CARD_BUFFER_SIZE_ONLY | CRYPT_NOHASHOID | CRYPT_TYPE2_FORMAT))                  dwReturn = OCardCheckSigningInfo(pInfo, &dwIndex);
1056                  {                  if (dwReturn)
                         Trace(WINEVENT_LEVEL_ERROR, L"wrong flag %d", pInfo->dwSigningFlags);  
                         dwReturn = SCARD_E_INVALID_PARAMETER;  
                         __leave;  
                 }  
                 if (pInfo->dwSigningFlags & CARD_PADDING_INFO_PRESENT)  
                 {  
                         if ( pInfo->dwPaddingType == CARD_PADDING_PKCS1)  
                         {  
                                 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;  
                                 Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PKCS1");  
                                 __leave;  
                         }  
                         else if (pInfo->dwPaddingType == CARD_PADDING_PSS)  
                         {  
                                 dwReturn = SCARD_E_UNSUPPORTED_FEATURE;  
                                 Trace(WINEVENT_LEVEL_ERROR, L"CARD_PADDING_PSS");  
                                 __leave;  
                         }  
                         else  
                         {  
                                 dwReturn = SCARD_E_INVALID_PARAMETER;  
                                 Trace(WINEVENT_LEVEL_ERROR, L"pInfo->dwPaddingType = %d", pInfo->dwPaddingType);  
                                 __leave;  
                         }  
                 }  
                 for(dwI = 0 ; dwI < dwSignatureAlgorithmCount ; dwI++)  
                 {  
                         if (SignatureAlgorithm[dwI].aiHashAlg == pInfo->aiHashAlg)  
                         {  
                                 // found  
                                 break;  
                         }  
                 }  
                 if (dwI >= dwSignatureAlgorithmCount)  
                 {  
                         Trace(WINEVENT_LEVEL_ERROR, L"alg not found %d", pInfo->aiHashAlg);  
                         __leave;  
                 }  
                 if (SignatureAlgorithm[dwI].dwHashSize != pInfo->cbData)  
1057                  {                  {
                         Trace(WINEVENT_LEVEL_ERROR, L"wrong hash size %d", pInfo->cbData);  
1058                          __leave;                          __leave;
1059                  }                  }
1060                  if (pInfo->bContainerIndex != Authentication)                  if (pInfo->bContainerIndex != ContainerAuthentication)
1061                  {                  {
1062                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
1063                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
# Line 1086  DWORD OCardAuthenticate(PCARD_DATA pCard Line 1067  DWORD OCardAuthenticate(PCARD_DATA pCard
1067                  {                  {
1068                          // optimisation :                          // optimisation :
1069                          // return the buffer size only                          // return the buffer size only
1070                          dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);                          dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyAuthentication, &Attributes);
1071                          if (dwReturn)                          if (dwReturn)
1072                          {                          {
1073                                  __leave;                                  __leave;
# Line 1103  DWORD OCardAuthenticate(PCARD_DATA pCard Line 1084  DWORD OCardAuthenticate(PCARD_DATA pCard
1084                  {                  {
1085                          dwCmdSize++;                          dwCmdSize++;
1086                  }                  }
1087                  pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwI].dwEncodedOidSize + pInfo->cbData);                  pbCmd[dwCmdSize++] = (BYTE) (SignatureAlgorithm[dwIndex].dwEncodedOidSize + pInfo->cbData);
1088                  memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwI].pbEncodedOid,SignatureAlgorithm[dwI].dwEncodedOidSize);                  memcpy(pbCmd + dwCmdSize , SignatureAlgorithm[dwIndex].pbEncodedOid,SignatureAlgorithm[dwIndex].dwEncodedOidSize);
1089                  dwCmdSize += SignatureAlgorithm[dwI].dwEncodedOidSize;                  dwCmdSize += SignatureAlgorithm[dwIndex].dwEncodedOidSize;
1090                  /*for(dwI = 0 ; dwI < pInfo->cbData ; dwI++)                  /*for(dwI = 0 ; dwI < pInfo->cbData ; dwI++)
1091                  {                  {
1092                          pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData - dwI -1];                          pbCmd[dwCmdSize + dwI] = pInfo->pbData[pInfo->cbData - dwI -1];
# Line 1171  DWORD OCardDecrypt(PCARD_DATA pCardData, Line 1152  DWORD OCardDecrypt(PCARD_DATA pCardData,
1152          __try          __try
1153          {          {
1154                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);                  Trace(WINEVENT_LEVEL_VERBOSE, L"Enter dwContainer=%d",pInfo->bContainerIndex);
1155                  if (pInfo->bContainerIndex >= MaxContainer)                  if (pInfo->bContainerIndex >= ContainerMax)
1156                  {                  {
1157                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
1158                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
1159                          __leave;                          __leave;
1160                  }                  }
1161                  if (pInfo->bContainerIndex != Confidentiality)                  if (pInfo->bContainerIndex != ContainerConfidentiality)
1162                  {                  {
1163                          dwReturn = SCARD_E_NO_KEY_CONTAINER;                          dwReturn = SCARD_E_NO_KEY_CONTAINER;
1164                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);                          Trace(WINEVENT_LEVEL_ERROR, L"SCARD_E_NO_KEY_CONTAINER %d", pInfo->bContainerIndex);
1165                          __leave;                          __leave;
1166                  }                  }
1167                  // check the buffer size                  // check the buffer size
1168                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Confidentiality, &Attributes);                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyConfidentiality, &Attributes);
1169                  if (dwReturn)                  if (dwReturn)
1170                  {                  {
1171                          __leave;                          __leave;
# Line 1274  DWORD OCardReadContainerMapFile(__in PCA Line 1255  DWORD OCardReadContainerMapFile(__in PCA
1255          {          {
1256                  PCONTAINER_MAP_RECORD pContainer = NULL;                  PCONTAINER_MAP_RECORD pContainer = NULL;
1257                  BOOL fIsDefaultContainerSet = FALSE;                  BOOL fIsDefaultContainerSet = FALSE;
1258                  *pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * MaxContainer;                  *pdwResponseSize = sizeof(CONTAINER_MAP_RECORD) * ContainerMax;
1259                  *ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);                  *ppbResponse = pCardData->pfnCspAlloc(*pdwResponseSize);
1260                  if (! *ppbResponse )                  if (! *ppbResponse )
1261                  {                  {
# Line 1283  DWORD OCardReadContainerMapFile(__in PCA Line 1264  DWORD OCardReadContainerMapFile(__in PCA
1264                          __leave;                          __leave;
1265                  }                  }
1266                  pContainer = (PCONTAINER_MAP_RECORD) *ppbResponse;                  pContainer = (PCONTAINER_MAP_RECORD) *ppbResponse;
1267                  memset(pContainer,0,sizeof(CONTAINER_MAP_RECORD) * 3);                  memset(pContainer,0,sizeof(CONTAINER_MAP_RECORD) * ContainerMax);
1268                                    
1269                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Authentication, &Attributes);                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyAuthentication, &Attributes);
1270                  if (dwReturn)                  if (dwReturn)
1271                  {                  {
1272                          __leave;                          __leave;
1273                  }                  }
1274                  pContainer[Authentication].wSigKeySizeBits = Attributes.wModulusLengthInBit;                  pContainer[ContainerAuthentication].wSigKeySizeBits = Attributes.wModulusLengthInBit;
1275                  swprintf_s(pContainer[Authentication].wszGuid,MAX_CONTAINER_NAME_LEN + 1,                  swprintf_s(pContainer[ContainerAuthentication].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
1276                          L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Authenticate",                          L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Authenticate",
1277                          pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],                          pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
1278                          pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],                          pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
1279                          pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],                          pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
1280                          pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);                          pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
1281                  if (pContext->fHasAuthentication)                  if (pContext->fHasKey[KeyAuthentication])
1282                  {                  {
1283                          pContainer[Authentication].bFlags = CONTAINER_MAP_VALID_CONTAINER | CONTAINER_MAP_DEFAULT_CONTAINER;                          pContainer[ContainerAuthentication].bFlags = CONTAINER_MAP_VALID_CONTAINER | CONTAINER_MAP_DEFAULT_CONTAINER;
1284                          fIsDefaultContainerSet = TRUE;                          fIsDefaultContainerSet = TRUE;
1285                  }                  }
1286                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Signature, &Attributes);  
1287                    dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeyConfidentiality, &Attributes);
1288                  if (dwReturn)                  if (dwReturn)
1289                  {                  {
1290                          __leave;                          __leave;
1291                  }                  }
1292                  pContainer[Signature].wSigKeySizeBits = Attributes.wModulusLengthInBit;                  pContainer[ContainerConfidentiality].wKeyExchangeKeySizeBits = Attributes.wModulusLengthInBit;
1293                  swprintf_s(pContainer[Signature].wszGuid,MAX_CONTAINER_NAME_LEN + 1,                  swprintf_s(pContainer[ContainerConfidentiality].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
1294                          L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Signature",                          L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Confidential",
1295                          pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],                          pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
1296                          pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],                          pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
1297                          pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],                          pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
1298                          pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);                          pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
1299                  if (pContext->fHasSignature)                  if (pContext->fHasKey[KeyConfidentiality])
1300                  {                  {
1301                          pContainer[Signature].bFlags = CONTAINER_MAP_VALID_CONTAINER;                          pContainer[ContainerConfidentiality].bFlags = CONTAINER_MAP_VALID_CONTAINER;
1302                          if (!fIsDefaultContainerSet)                          if (!fIsDefaultContainerSet)
1303                          {                          {
1304                                  pContainer[Signature].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;                                  pContainer[ContainerConfidentiality].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
1305                                  fIsDefaultContainerSet = TRUE;                                  fIsDefaultContainerSet = TRUE;
1306                          }                          }
1307                  }                  }
1308                    
1309                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, Confidentiality, &Attributes);                  dwReturn = OCardGetKeyAlgorithmAttributes(pCardData, KeySignature, &Attributes);
1310                  if (dwReturn)                  if (dwReturn)
1311                  {                  {
1312                          __leave;                          __leave;
1313                  }                  }
1314                  pContainer[Confidentiality].wKeyExchangeKeySizeBits = Attributes.wModulusLengthInBit;                  pContainer[ContainerSignature].wSigKeySizeBits = Attributes.wModulusLengthInBit;
1315                                    swprintf_s(pContainer[ContainerSignature].wszGuid,MAX_CONTAINER_NAME_LEN + 1,
1316                  swprintf_s(pContainer[Confidentiality].wszGuid,MAX_CONTAINER_NAME_LEN + 1,                          L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Signature",
                         L"OPENPGP_%02X%02X_%02X%02X_%02X%02X%02X%02X_Confidential",  
1317                          pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],                          pContext->Aid.AidVersion[0],pContext->Aid.AidVersion[1],
1318                          pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],                          pContext->Aid.AidManufacturer[0],pContext->Aid.AidManufacturer[1],
1319                          pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],                          pContext->Aid.AidSerialNumber[0],pContext->Aid.AidSerialNumber[1],
1320                          pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);                          pContext->Aid.AidSerialNumber[2],pContext->Aid.AidSerialNumber[3]);
1321                  if (pContext->fHasDecryption)                  if (pContext->fHasKey[KeySignature])
1322                  {                  {
1323                          pContainer[Confidentiality].bFlags = CONTAINER_MAP_VALID_CONTAINER;                          pContainer[ContainerSignature].bFlags = CONTAINER_MAP_VALID_CONTAINER;
1324                          if (!fIsDefaultContainerSet)                          if (!fIsDefaultContainerSet)
1325                          {                          {
1326                                  pContainer[Confidentiality].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;                                  pContainer[ContainerSignature].bFlags |= CONTAINER_MAP_DEFAULT_CONTAINER;
1327                                  fIsDefaultContainerSet = TRUE;                                  fIsDefaultContainerSet = TRUE;
1328                          }                          }
1329                  }                  }

Legend:
Removed from v.8  
changed lines
  Added in v.9

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26