*** How to install a PKCS7 Certificate with Perl ***

First of all, you may think in a few Questions:

What is the certificate purpose and where do you want to install the
certificate.

For example, if you want to install a certificate for your wireless WPA
infraestructure, you, probably want to install a machine / computer
certificate, and if you want to install a CA root certificate to browse in
some websites without errors, probably you want to install the certificate
in the Local User Store.
Moreover, you have to consider if the certificate is a Root CA, a Personal
Certificate or a Certificate from other People.
Look this for more info (http://msdn2.microsoft.com/En-US/library/aa388130.aspx
)

First, you must get a copy of CAPICOM dll. You can find it in microsoft
website.

Example 1: "Install a PKCS7 Certificate for personal use in the USER
storage"

---
use strict;
use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::TieRegistry(Delimiter=>"/");


use constant CAPICOM_CURRENT_USER_STORE => 1;
use constant CAPICOM_LOCAL_MACHINE_STORE => 1;
use constant CAPICOM_STORE_OPEN_READ_WRITE => 1;


my $store = Win32::OLE->new("CAPICOM.Store") || die "Could create object:
".Win32::FormatMessage Win32::GetLastError()."\n";


$store->Open (CAPICOM_CURRENT_USER_STORE, 'MY',
CAPICOM_STORE_OPEN_READ_WRITE) ;


$store->Load ("test.p7b") ;

---

Example 2 : "Install a PKCS7 Certificate from other people in the USER
storage" (for example to cipher e-mails to this person)

---
use strict;
use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::TieRegistry(Delimiter=>"/");


use constant CAPICOM_CURRENT_USER_STORE => 1;
#use constant CAPICOM_LOCAL_MACHINE_STORE => 1;
use constant CAPICOM_STORE_OPEN_READ_WRITE => 1;

my $store = Win32::OLE->new("CAPICOM.Store") || die "Could create object:
".Win32::FormatMessage Win32::GetLastError()."\n";


$store->Open (CAPICOM_CURRENT_USER_STORE, 'AddressBook',
CAPICOM_STORE_OPEN_READ_WRITE) ;


$store->Load ("test.p7b") ;

---

Example 3: "Install CA root certificate for USER"

---
use strict;
use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::TieRegistry(Delimiter=>"/");


use constant CAPICOM_CURRENT_USER_STORE => 1;
#use constant CAPICOM_LOCAL_MACHINE_STORE => 1;
use constant CAPICOM_STORE_OPEN_READ_WRITE => 1;

my $store = Win32::OLE->new("CAPICOM.Store") || die "Could create object:
".Win32::FormatMessage Win32::GetLastError()."\n";


$store->Open (CAPICOM_CURRENT_USER_STORE, 'ROOT',
CAPICOM_STORE_OPEN_READ_WRITE) ;


$store->Load ("test.p7b") ;

---

Example 4 : "Install CA root certificate for MACHINE / Computer"

---
use strict;
use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::TieRegistry(Delimiter=>"/");


#use constant CAPICOM_CURRENT_USER_STORE => 1;
use constant CAPICOM_LOCAL_MACHINE_STORE => 1;
use constant CAPICOM_STORE_OPEN_READ_WRITE => 1;

my $store = Win32::OLE->new("CAPICOM.Store") || die "Could create object:
".Win32::FormatMessage Win32::GetLastError()."\n";


$store->Open (CAPICOM_LOCAL_MACHINE_STORE, 'ROOT',
CAPICOM_STORE_OPEN_READ_WRITE) ;


$store->Load ("test.p7b") ;

---

Example 5: "Install a secondary CA certificate in MACHINE / Computer Store"

---
use strict;
use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::TieRegistry(Delimiter=>"/");


#use constant CAPICOM_CURRENT_USER_STORE => 1;
use constant CAPICOM_LOCAL_MACHINE_STORE => 1;
use constant CAPICOM_STORE_OPEN_READ_WRITE => 1;

my $store = Win32::OLE->new("CAPICOM.Store") || die "Could create object:
".Win32::FormatMessage Win32::GetLastError()."\n";


$store->Open (CAPICOM_LOCAL_MACHINE_STORE, 'CA',
CAPICOM_STORE_OPEN_READ_WRITE) ;


$store->Load ("test.p7b") ;

---

Ok, thats all.
Of course, in some cases (install certificates in MACHINE store) you must be
Administrator


On 3/9/07, [EMAIL PROTECTED] < [EMAIL PROTECTED]>
wrote:


Gurus,

I'm looking at having to install a certificate without user interaction.
Is there a way to do this?  I have a script that uses InstallPKCS7, but that
puts up a message window that requires a click on an OK button. That's a
no-go solution.

TIA,

Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150

"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of ideas
that could provoke such a question." -- Charles Babbage
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to