Re: possibly capicom bug?

From: Dimitar Lazarov (lazarov_at_csoft.bg)
Date: 04/22/05

  • Next message: Rhett Gong [MSFT]: "RE: Windows Server 2003 SP1 DCOM using RPC PROXY"
    Date: Fri, 22 Apr 2005 11:21:52 +0300
    
    

    I'm sure that it's not a bug. :-) What is the hr value when the export fail?

    Dimitar

    "LY" <LY@discussions.microsoft.com> wrote in message
    news:33F85B55-EDE1-4F80-BD73-2FE1A5F40638@microsoft.com...
    > what I want to do is retrive a certificate from MY store and then export
    > it
    > to local hard drive. I am using the store example in the redistributable
    > packet for capicom 2.0.0.3 with the following changes:
    >
    >
    > /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    >
    >
    >
    >
    >
    > THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    > KIND,
    >
    > EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
    >
    > WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
    >
    >
    >
    > Copyright (C) 1999 - 2000. Microsoft Corporation. All rights reserved.
    >
    >
    >
    > Module: Store.cpp
    >
    >
    >
    > Abstract: Main program of CAPICOM Store sample. See ReadMe.txt for more
    >
    > detail information about this sample.
    >
    >
    >
    > Environment: Win32 console, UNICODE ready.
    >
    >
    >
    > ------------------------------------------------------------------------------*/
    >
    >
    >
    > #include <tchar.h>
    >
    > #include <stdio.h>
    >
    > #include <atlbase.h>
    >
    > #include <windows.h>
    >
    >
    >
    > #pragma warning (disable : 4192)
    >
    >
    >
    > //
    >
    > // Import TLB from DLL
    >
    > //
    >
    > // Note: Make sure either you have the DLL in the current directory, or
    > point
    >
    > // it to the correct directory on you drive.
    >
    > //
    >
    > #import "capicom.dll"
    >
    >
    >
    > //
    >
    > // Use CAPICOM namespace.
    >
    > //
    >
    > using namespace CAPICOM;
    >
    >
    >
    > /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    >
    >
    >
    > Module: main()
    >
    >
    >
    > Remark: Entry point of CAPICOM Store C++ sample.
    >
    >
    >
    > -----------------------------------------------------------------------------*/
    >
    >
    >
    > char filename[]="c:\\my.pfx";
    >
    > int __cdecl _tmain (int argc, _TCHAR * argv[])
    >
    > {
    >
    > HRESULT hr = S_OK;
    >
    >
    >
    > //
    >
    > // Initialize COM library.
    >
    > //
    >
    > CoInitialize(0);
    >
    >
    >
    > try
    >
    > {
    >
    > //
    >
    > // Open current user My store.
    >
    > //
    >
    > _bstr_t bstrName = _T("MY");
    >
    > IStorePtr pIStore(__uuidof(Store));
    >
    >
    >
    > if (FAILED(hr = pIStore->Open(CAPICOM_CURRENT_USER_STORE,
    >
    > bstrName,
    >
    > CAPICOM_STORE_OPEN_READ_ONLY)))
    >
    > {
    >
    > ATLTRACE(_T("Error [%#x]: pIStore->Open() failed at line
    > %d.\n"), hr, __LINE__);
    >
    > throw hr;
    >
    > }
    >
    >
    >
    > //
    >
    > // Display all certificate in the store.
    >
    > //
    >
    > IUnknownPtr pIUnknown;
    >
    > IEnumVARIANTPtr pIEnum;
    >
    > _variant_t pDisp;
    >
    > ULONG ulFetched;
    >
    >
    >
    > //
    >
    > // Get _NewEnum of Certificates collection.
    >
    > //
    >
    > if (FAILED(hr = pIStore->Certificates->get__NewEnum(&pIUnknown)))
    >
    > {
    >
    > ATLTRACE(_T("Error [%#x]: pIStore->Certificates->get__NewEnum()
    > failed at line
    > %d.\n"), hr, __LINE__);
    >
    > throw hr;
    >
    > }
    >
    >
    >
    > //
    >
    > // Get IEnumVARIANT interface of _NewEnum.
    >
    > //
    >
    > if (FAILED(hr = pIUnknown->QueryInterface(IID_IEnumVARIANT, (void
    > **) &pIEnum)))
    >
    > {
    >
    > ATLTRACE(_T("Error [%#x]: pIUnknown->QueryInterface() failed at
    > line %d.\n"), hr,
    > __LINE__);
    >
    > throw hr;
    >
    > }
    >
    >
    >
    > //
    >
    > // Now loop through all items in the collection.
    >
    > //
    >
    > while (pIEnum->Next(1, &pDisp, &ulFetched) == S_OK)
    >
    > {
    >
    > //
    >
    > // Display the certificate. This function is always ok on
    > both version of windows!
    >
    > //
    >
    > if (FAILED(hr = ((ICertificatePtr) pDisp.pdispVal)->Display()))
    >
    > {
    >
    > ATLTRACE(_T("Error [%#x]: ((ICertificatePtr)
    > pDisp.pdispVal)->Display() failed at
    > line %d.\n"), hr, __LINE__);
    >
    > throw hr;
    >
    > }
    >
    >
    >
    > //export certificate to a pfx file always failed on an English
    > version windows! May it a
    > bug of capicom!
    >
    > if(FAILED(hr=((structICertificate2*)
    > pDisp.pdispVal)->Save(_T(filename),_T("abcd"),CAPICOM_CERTIFICATE_SAVE_AS_PFX,CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY)))
    >
    > {
    >
    > ATLTRACE(_T("Error [%#x]: ((ICertificatePtr)
    > pDisp.pdispVal)->Display() failed at
    > line %d.\n"), hr, __LINE__);
    >
    > printf("save certificate to file failed!");
    >
    > throw hr;
    >
    > }
    >
    > pDisp.Clear();
    >
    > }
    >
    > }
    >
    >
    >
    > catch (_com_error e)
    >
    > {
    >
    > hr = e.Error();
    >
    > ATLTRACE(_T("Error [%#x]: %s.\n"), hr, e.ErrorMessage());
    >
    > printf("%s",e.ErrorMessage());
    >
    > }
    >
    >
    >
    > catch (HRESULT hr)
    >
    > {
    >
    > ATLTRACE(_T("Error [%#x]: CAPICOM error.\n"), hr);
    >
    > }
    >
    >
    >
    > catch(...)
    >
    > {
    >
    > hr = CAPICOM_E_UNKNOWN;
    >
    > ATLTRACE(_T("Unknown error.\n"));
    >
    > }
    >
    >
    >
    > CoUninitialize();
    >
    >
    >
    > return (int) hr;
    >
    > }
    >
    >
    >
    > The problem is that though it can work on an Chinese version of
    > windows(2000,xp ,and 2003 server) ,it always failed in exporting the
    > certificate in an English version windows. Can any one be of help? Thanks
    > in
    > advance!


  • Next message: Rhett Gong [MSFT]: "RE: Windows Server 2003 SP1 DCOM using RPC PROXY"

    Relevant Pages

    • Re: Newbie: Getting my head around Certificates
      ... and does not ship with Windows. ... CAPICOM as part of your application. ... To retrieve the server SSL certificate used by IE, ... > .Display() method of the ICertificate2 interface. ...
      (microsoft.public.platformsdk.security)
    • RE: CAPICOM on Windows NT
      ... Microsoft Internet Explorer 5 or later is required ... Windows 2000/NT, Windows Me/98/95 ... | Subject: CAPICOM on Windows NT ... | 2000 Server machine as an internal Certificate Authority ...
      (microsoft.public.platformsdk.security)
    • possibly capicom bug?
      ... I am using the store example in the redistributable ... Main program of CAPICOM Store sample. ... both version of windows! ... certificate in an English version windows. ...
      (microsoft.public.platformsdk.security)
    • Bug in Certificates viewer on Win 2K
      ... We have a class 3 code-signing certificate issued by Verisign. ... Somebody incorrectly installed the certificate on a Windows 2000 machine, which brought to light the following bug in the Windows Certificates viewer: ... The intermediate CA's certificate was incorrectly installed by someone here in the Personal store, rather than in the Intermediate Ceritificate Authorities store where it should have been. ...
      (microsoft.public.platformsdk.security)
    • There No one at microsoft.public.security.crypto
      ... The CAPICOM 2.1.0.2 update addresses an argument validation issue with the ... Allows the caller to delete non-system certificate stores. ... Allows the caller to close a certificate store. ...
      (microsoft.public.windowsxp.general)