Perl Requires Chilkat v10.1.2+
Chilkat2 Perl
Apple Keychain - List Certs on Smartcards and USB Tokens
See more Apple Keychain Examples
Iterates over the certificatse on connected smartcards and USB tokens via the Apple Keychain.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
my $certStore = Chilkat2::CertStore->new;
# On MacOS and iOS, the OpenSmartcard method opens the Keychain.
# The argument passed to OpenSmartcard is ignored.
my $success = $certStore->OpenSmartcard('');
if (!$success) {
print $certStore->LastErrorText, "\n";
exit;
}
my $numCerts = $certStore->NumCertificates;
print 'numCerts = ', $numCerts, "\n";
my $cert = Chilkat2::Cert->new;
my $i = 0;
while ($i < $numCerts) {
# Note: Chilkat also gets the associated private key if it exists.
# You can simply use the cert in other places in Chilkat where a cert w/ private key is required.
$certStore->GetCert($i, $cert);
print $cert->SubjectDN, "\n";
print $cert->SubjectCN, "\n";
print $cert->SerialNumber, "\n";
if ($cert->IsRsa()) {
print "key type is RSA\n";
}
if ($cert->IsEcdsa()) {
print "key type is ECDSA\n";
}
print 'has private key: ', ($cert->HasPrivateKey() ? 1 : 0), "\n";
print "----\n";
$i = $i + 1;
}
$certStore->CloseCertStore();