[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-cryptoapi
Subject:    Re: Invalid handle (code 6) on W2003
From:       John Banes <jbanes () WINDOWS ! MICROSOFT ! COM>
Date:       2003-08-14 15:54:43
[Download RAW message or body]

When you read the key prov info from the certificate context, the low
bit will sometimes be set. I forget why this is--I think it has
something to do with smartcards. In any case, you have to mask off this
bit or else CryptAcquireContext will error out with a "bad flags" error
code since 0x1 is not a valid flag to pass into this function.

This isn't the error code that you're seeing, and so this probably isn't
what's causing your problem, but it's all I can think of. Maybe someone
else on the list will have some ideas.

Regards,
John


-----Original Message-----
From: Microsoft Cryptographic API
[mailto:CryptoAPI@DISCUSS.MICROSOFT.COM] On Behalf Of Peter Persits
Sent: Thursday, August 14, 2003 8:20 AM
To: CryptoAPI@DISCUSS.MICROSOFT.COM
Subject: Invalid handle (code 6) on W2003

I posted this question a few days ago but got no response. 

Can someone from Microsoft respond please? Under what circumstances
would the code below return error 6 ("Invalid Handle")?

The following code, which works fine on NT and 2000, is failing on one
of my clients' 2003 servers. This code retrieves the private key context
from a certificate. The error is occuring on the CryptAcquireContext
line. The variable m_pCertContext is a CERT_CONTEXT *.

TIA!

Peter

-------------------------
 DWORD cbData;
 BYTE * pbData;
 CRYPT_KEY_PROV_INFO * pKeyProvInfo;

 if( !::CertGetCertificateContextProperty(
   m_pCertContext,
   CERT_KEY_PROV_INFO_PROP_ID, 
   NULL,
   &cbData ) )
 {
  return m_pManager->VerbalError( _ERROR_GETPRIVATEKEYPROP );  }

 pbData = (BYTE *)malloc( cbData );
 pKeyProvInfo = (CRYPT_KEY_PROV_INFO *)pbData;

 if( !::CertGetCertificateContextProperty(
   m_pCertContext,
   CERT_KEY_PROV_INFO_PROP_ID, 
   pbData,
   &cbData ) )
 {
  free( pbData );
 return m_pManager->VerbalError( _ERROR_GETPRIVATEKEYPROP );  }

 HCRYPTPROV hProv;
 if( !( CryptAcquireContext(
  &hProv,
  OLE2T(pKeyProvInfo->pwszContainerName),
  OLE2T(pKeyProvInfo->pwszProvName),
  pKeyProvInfo->dwProvType,
  pKeyProvInfo->dwFlags ) ) )
 {
  free( pbData );
  return m_pManager->VerbalError( _ERROR_ACQUIRE_CONTEXT );  }

-------------------
Peter

----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.html
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:CryptoAPI-signoff-request@DISCUSS.MICROSOFT.COM

----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.html
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:CryptoAPI-signoff-request@DISCUSS.MICROSOFT.COM

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic