Perl
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 chilkat();
$success = 0;
$certStore = chilkat::CkCertStore->new();
# On MacOS and iOS, the OpenSmartcard method opens the Keychain.
# The argument passed to OpenSmartcard is ignored.
$success = $certStore->OpenSmartcard("");
if ($success == 0) {
print $certStore->lastErrorText() . "\r\n";
exit;
}
$numCerts = $certStore->get_NumCertificates();
print "numCerts = " . $numCerts . "\r\n";
$cert = chilkat::CkCert->new();
$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() . "\r\n";
print $cert->subjectCN() . "\r\n";
print $cert->serialNumber() . "\r\n";
if ($cert->IsRsa() == 1) {
print "key type is RSA" . "\r\n";
}
if ($cert->IsEcdsa() == 1) {
print "key type is ECDSA" . "\r\n";
}
print "has private key: " . $cert->HasPrivateKey() . "\r\n";
print "----" . "\r\n";
$i = $i + 1;
}
$certStore->CloseCertStore();