Win32::OLE and CAPICOM to find a certificate in certificate store will raise exception

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I am trying to use win32::OLE to access certificate store via CAPICOM.
If  certificates in the store meet the searching criteria, the
certificates object
method "find"  works, but if no certificate meets the searching
criteria, it will raise
an error message:
 OLE exception from "<Unknown Source>": The Data is invalid.

How to solve the problem or catch the exception in Perl script?


===== test case =======
#!c:/Perl/bin/perl.exe -w
#Test store->certificates->Find

use strict;
use Win32::OLE;

# CAPICOM constant definitions
use constant {
    # Store Location
    CAPICOM_CURRENT_USER_STORE            => 2,
    # Store Open Mode
    # key storage flags
    # The Find method returns a Certificates object that contains all
certificates that
    # match the specified search criteria. This method was introduced
in CAPICOM 2.0. see:

# Search the certificate with the thumbprint SHA1 in local certificate
my $SHA1 = "0000000049d8650d2515111709ee1b4800000000";

Win32::OLE->Option ('Warn' => 3);

# Create a new Store object, and use it to open the store.  See
my $Store = Win32::OLE->new('CAPICOM.Store', sub )
           or die "Oops, cannot start CAPICOM";

# TEST the certificates->find function
# if no certificate is found, this program will hangup after several
# here 10 tries, should print out 10 times "continue searching..." if
no exception.
  print "continue searching...\n";
print "\nCompleted.\n";

# perl version
#  This is perl, v5.8.8 built for MSWin32-x86-multi-thread
#  (with 25 registered patches, see perl -V for more detail)
# Copyright 1987-2006, Larry Wall
# Binary build 817 [257965] provided by ActiveState
# Built Mar 20 2006 17:54:25

Re: Win32::OLE and CAPICOM to find a certificate in certificate store will raise exception wrote:
Quoted text here. Click to load it

I'm not sure what catching thrown exceptions has to do with Perl
modules. Have you read the documentation on the 'eval' built-in?

Nit-pick: do you mean the 'Find' function? There does not appear to be
an invocation of 'find' in your code.

Tom Wyant

Site Timeline