blautenb    2003/10/11 23:32:03

  Modified:    c/src/tools/templatesign templatesign.cpp
  Log:
  Update provided by Milan Tomic to Windows certificate code in templatesign
  
  Revision  Changes    Path
  1.15      +16 -26    xml-security/c/src/tools/templatesign/templatesign.cpp
  
  Index: templatesign.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/tools/templatesign/templatesign.cpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- templatesign.cpp  12 Oct 2003 06:23:40 -0000      1.14
  +++ templatesign.cpp  12 Oct 2003 06:32:03 -0000      1.15
  @@ -980,16 +980,19 @@
                
                // Code provided by Milan Tomic
   
  +             //Please note that this example below use 
CryptAcquireCertificatePrivateKey() function
  +             //which is not declared in wincrypt.h that ships with VC++ 6. 
If you would like to run
  +             //this example you'll need to replace your old wincrypt.h and 
crypt32.lib with new versions.
  +             //This example below is compatible with Windows 98/IE 5 and 
above OS/IE versions.
  +
                else if (stricmp(argv[paramCount], "--wincer") == 0 || 
stricmp(argv[paramCount], "-wc") == 0) {
                        WinCAPICryptoProvider * cp;
                        PCCERT_CONTEXT          pSignerCert = NULL;
                        DWORD                   dwKeySpec;
                        HCERTSTORE                              hStoreHandle;
  -                     HCRYPTPROV                              hCryptProv;
  -
                        #define MY_ENCODING_TYPE  (PKCS_7_ASN_ENCODING | 
X509_ASN_ENCODING)
   
  -                     // Obtain default PROV_DSS and PROV_RSA_FULL, with 
default user key containers
  +                     // Obtain default PROV_DSS with default user key 
container
                        if (!CryptAcquireContext(&win32DSSCSP,
                                NULL,
                                NULL,
  @@ -999,18 +1002,6 @@
                                        return 2;
                        }//*/
   
  -                     if (!CryptAcquireContext(&win32RSACSP,
  -                             NULL,
  -                             NULL,
  -                             PROV_RSA_FULL,
  -                             0)) {
  -                                     cerr << "Error acquiring RSA Crypto 
Service Provider" << endl;
  -                                     return 2;
  -                     }//*/
  -
  -                     cp = new WinCAPICryptoProvider(win32DSSCSP, 
win32RSACSP);
  -                     XSECPlatformUtils::SetCryptoProvider(cp);
  -
                        // Open 'Personal' certificate store 
                        if (!(hStoreHandle = 
CertOpenStore(CERT_STORE_PROV_SYSTEM,
                                0,
  @@ -1036,24 +1027,20 @@
                        if (!CryptAcquireCertificatePrivateKey(pSignerCert,
                                0,
                                NULL,
  -                             &hCryptProv,
  +                             &win32RSACSP,
                                &dwKeySpec,
                                NULL)) {
                                        cerr << "Can't acquire private key of 
'" << argv[paramCount+1] << "' certificate." << endl;
                                        exit(1);
                        }
   
  -#if 0
  -                     //Added just for debugging
  -                     if (dwKeySpec == AT_SIGNATURE)
  -                     cerr << "Your key is AT_SIGNATURE" << endl;
  -                     else if (dwKeySpec == AT_KEYEXCHANGE)
  -                     cerr << "Your key is AT_KEYEXCHANGE" << endl;
  -#endif
  +                     cp = new WinCAPICryptoProvider(win32DSSCSP, 
win32RSACSP);
  +                     XSECPlatformUtils::SetCryptoProvider(cp);
  +
                        HCRYPTKEY k;
                        BOOL fResult = CryptGetUserKey(
  -                             hCryptProv,
  -                             dwKeySpec,//AT_SIGNATURE,
  +                             win32RSACSP,
  +                             dwKeySpec,
                                &k);
   
                        if (!fResult || k == 0) {
  @@ -1064,6 +1051,9 @@
                        winKeyRSA = new WinCAPICryptoKeyRSA(cp, k, true);
                        key = winKeyRSA;
                        paramCount += 2;
  +
  +                     CertFreeCertificateContext(pSignerCert);
  +                     CertCloseStore(hStoreHandle, 0);
                }
   
   #endif /* CRYPT_ACQUIRE_CACHE_FLAG */
  
  
  

Reply via email to