niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl » modules
Win32::OLE and CAPICOM to find a certificate in certificate store will raise exception
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
Author Message
dan2online
*nix forums beginner


Joined: 14 Apr 2006
Posts: 40

PostPosted: Thu Jul 20, 2006 6:44 am    Post subject: Win32::OLE and CAPICOM to find a certificate in certificate store will raise exception Reply with quote

Hi,

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?

Thanks!

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

use strict;
use Win32::OLE;

# CAPICOM constant definitions
use constant {
# Store Location
#
http://msdn.microsoft.com/library/en-us/security/security/capicom_store_location.asp
CAPICOM_LOCAL_MACHINE_STORE => 1,
CAPICOM_CURRENT_USER_STORE => 2,
# Store Open Mode
#
http://msdn.microsoft.com/library/en-us/security/security/capicom_store_open_mode.asp
CAPICOM_STORE_OPEN_READ_ONLY => 0,
# key storage flags
#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/seccrypto/security/certificate_load.asp
CAPICOM_KEY_STORAGE_DEFAULT => 0,
# 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:
#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/seccrypto/security/certificates_find.asp
CAPICOM_CERTIFICATE_FIND_SHA1_HASH => 0,
};

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

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

# Create a new Store object, and use it to open the store. See
#
<http://msdn.microsoft.com/library/en-us/security/security/store.asp>.
my $Store = Win32::OLE->new('CAPICOM.Store', sub {$_[0]->Close();})
or die "Oops, cannot start CAPICOM";
$Store->Open (CAPICOM_LOCAL_MACHINE_STORE, 'ROOT',
CAPICOM_STORE_OPEN_READ_ONLY);

# TEST the certificates->find function
# if no certificate is found, this program will hangup after several
tries!
# here 10 tries, should print out 10 times "continue searching..." if
no exception.
for(1...10)
{
$Store->Certificates->Find(CAPICOM_CERTIFICATE_FIND_SHA1_HASH,
$SHA1);
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
http://www.ActiveState.com
# Built Mar 20 2006 17:54:25
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
The time now is Thu Nov 20, 2008 8:31 pm | All times are GMT
navigation Forum index » Programming » Perl » modules
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Problem with Win32-SerialPort over bluetooth @ windows + ... ctloh Perl 0 Fri Jul 21, 2006 8:08 am
No new posts Bug? Certainly a new *behavior* from subprocess in 2.5 on... Larry Hastings python 2 Thu Jul 20, 2006 11:15 am
No new posts Flash device can't find in kernel and redboot Kevin embedded 1 Thu Jul 20, 2006 10:04 am
No new posts How to find out if a certain value is in a list? TN Perl 3 Thu Jul 20, 2006 9:07 am
No new posts Win32::OLE and CAPICOM to find a certificate in certifica... dan2online Perl 0 Thu Jul 20, 2006 6:47 am

Personal Loans | Mobile Phone | Credit Cards | Credit Card Debt Consolidation | Personal Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1109s ][ Queries: 16 (0.0436s) ][ GZIP on - Debug on ]