For checking the status of a client certificate using OCSP, you can use this script:
<?php
// User variables:
$dir = '/path/to/temp/'; // Directory where apache has access to (chmod 777).
$RootCA = '/path/to/Root.cer'; // Points to the Root CA in PEM format.
$OCSPUrl = 'http://ocsp.url'; //Points to the OCSP URL
// Script:
$a = rand(1000,99999); // Needed if you expect more page clicks in one second!
file_put_contents($dir.$a.'cert_i.pem', $_SERVER['SSL_CLIENT_CERT_CHAIN_0']); // Issuer certificate.
file_put_contents($dir.$a.'cert_c.pem', $_SERVER['SSL_CLIENT_CERT']); // Client (authentication) certificate.
$output = shell_exec('openssl ocsp -CAfile '.$RootCA.' -issuer '.$dir.$a.'cert_i.pem -cert '.$dir.$a.'cert_c.pem -url '.$OCSPUrl);
$output2 = preg_split('/[\r\n]/', $output);
$output3 = preg_split('/: /', $output2[0]);
$ocsp = $output3[1];
echo "OCSP status: ".$ocsp; // will be "good", "revoked", or "unknown"
unlink($dir.$a.'cert_i.pem');
unlink($dir.$a.'cert_c.pem');
?>
It can be ameliorated, but it's just a beginning!
Normally, you can extract the ocsp url from the client certificate. Also, an OCSP request contains only the hash of the issuer name, the hash of the issuer's key, and the serial number of the client certificate. All three can be extracted directly from the client certificate.
OpenSSL
- Introduction
- Installation/Configuration
- Constantes pré-définies
- Paramètres clés/certificats
- Vérification de certificats
- Fonctions OpenSSL
- openssl_csr_export_to_file — Exporte une CSR vers un fichier
- openssl_csr_export — Exporte un CSR vers un fichier ou une variable
- openssl_csr_get_public_key — Retourne la clé publique d'un CERT
- openssl_csr_get_subject — Retourne le sujet d'un CERT
- openssl_csr_new — Génère une CSR
- openssl_csr_sign — Signe un CSR avec un autre certificat (ou lui-même) et génère un certificat
- openssl_error_string — Retourne le message d'erreur OpenSSL
- openssl_free_key — Libère les ressources
- openssl_get_privatekey — Alias de openssl_pkey_get_private
- openssl_get_publickey — Alias de openssl_pkey_get_public
- openssl_open — Ouvre des données scellées
- openssl_pkcs12_export_to_file — Exporte un certificat compatible PKCS#12
- openssl_pkcs12_export — Exporte un certificat compatible PKCS#12 dans une variable
- openssl_pkcs12_read — Lit un certificat PKCS#12 dans un tableau
- openssl_pkcs7_decrypt — Déchiffre un message S/MIME
- openssl_pkcs7_encrypt — Chiffre un message S/MIME
- openssl_pkcs7_sign — Signe un message S/MIME
- openssl_pkcs7_verify — Vérifie la signature d'un message S/MIME
- openssl_pkey_export_to_file — Sauve une clé au format ASCII dans un fichier
- openssl_pkey_export — Stocke une représentation exportable de la clé dans une chaîne de caractères
- openssl_pkey_free — Libère une clé privée
- openssl_pkey_get_details — Retourne un tableau contenant le détail d'une clé
- openssl_pkey_get_private — Lit une clé privée
- openssl_pkey_get_public — Extrait une clé privée d'un certificat, et la prépare
- openssl_pkey_new — Génère une nouvelle clé privée
- openssl_private_decrypt — Déchiffre des données avec une clé privée
- openssl_private_encrypt — Chiffre des données avec une clé privée
- openssl_public_decrypt — Déchiffre des données avec une clé publique
- openssl_public_encrypt — Chiffre des données avec une clé publique
- openssl_seal — Scelle des données
- openssl_sign — Signe les données
- openssl_verify — Vérifie une signature
- openssl_x509_check_private_key — Vérifie si une clé privée correspond à un certificat
- openssl_x509_checkpurpose — Vérifie l'usage d'un certificat
- openssl_x509_export_to_file — Exporte un certificat vers un fichier
- openssl_x509_export — Exporte un certificat vers une chaîne de caractères
- openssl_x509_free — Libère les ressources prises par un certificat
- openssl_x509_parse — Analyse un certificat X509
- openssl_x509_read — Analyse un certificat X.509 et retourne une ressource
OpenSSL
koen dot thomeer at pubmed dot be
31-Aug-2008 08:27
31-Aug-2008 08:27
