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
- Einführung
- Installation/Konfiguration
- Vordefinierte Konstanten
- Schlüssel/Zertifikat Parameter
- Zertifikatprüfung
- OpenSSL Funktionen
- openssl_csr_export_to_file — Exportiert ein CSR in eine Datei
- openssl_csr_export — Exportiert einen CSR als Zeichenkette
- openssl_csr_get_public_key — Returns the public key of a CERT
- openssl_csr_get_subject — Returns the subject of a CERT
- openssl_csr_new — Erzeugt einen CSR
- openssl_csr_sign — Signiert einen CSR mit einem anderen Zertifikat (oder sich selbst) und generiert ein Zertifikat
- openssl_error_string — Gibt eine openSSL Fehlermeldung zurück
- openssl_free_key — Free key resource
- openssl_get_privatekey — Alias von openssl_pkey_get_private
- openssl_get_publickey — Alias von openssl_pkey_get_public
- openssl_open — Öffnet versiegelte Daten
- openssl_pkcs12_export_to_file — Exports a PKCS#12 Compatible Certificate Store File
- openssl_pkcs12_export — Exports a PKCS#12 Compatible Certificate Store File to variable.
- openssl_pkcs12_read — Parse a PKCS#12 Certificate Store into an array
- openssl_pkcs7_decrypt — Entschlüssen einer S/MIME verschlüsselten Nachricht
- openssl_pkcs7_encrypt — Verschlüsseln einer S/MIME Nachricht
- openssl_pkcs7_sign — Signieren einer S/MIME Nachricht
- openssl_pkcs7_verify — Überprüft die Unterschrift einer mit S/MIME unterschriebenen Nachricht
- openssl_pkey_export_to_file — Liefert eine exportierbare Representation eines Schlüssels in einer Datei
- openssl_pkey_export — Liefert eine exportierbare Representation eines Schlüssels in einem String
- openssl_pkey_free — Frees a private key
- openssl_pkey_get_details — Returns an array with the key details
- openssl_pkey_get_private — Liefert einen privaten Schlüssel
- openssl_pkey_get_public — Extrahiert einen öffentlichen Schlüssel aus einem Zertifikat und bereitet diesen zur Nutzung vor
- openssl_pkey_new — Erzeugt einen neuen privaten Schlüssel
- openssl_private_decrypt — Entschlüsselt Daten mit einem privaten Schlüssel
- openssl_private_encrypt — Verschlüsselt Daten mit einem privaten Schlüssel
- openssl_public_decrypt — Entschlüsselt Daten mit einem öffentlichen Schlüssel
- openssl_public_encrypt — Verschlüsselt Daten mit einem öffentlichen Schlüssel
- openssl_seal — Verschlüsselt (versiegelt) Daten
- openssl_sign — Erzeugen einer Unterschrift
- openssl_verify — Überprüft eine Unterschrift
- openssl_x509_check_private_key — Überprüft, ob ein privater Schlüssel zu einem Zertifikat passt
- openssl_x509_checkpurpose — Überprüft ob ein Zertifikat für einen bestimmten Zweck benutzt werden kann
- openssl_x509_export_to_file — Exportiert ein Zertifikat in eine Datei
- openssl_x509_export — Exports a certificate as a string
- openssl_x509_free — Freigabe einer Zertifikats Resource
- openssl_x509_parse — Analyse eines X509 Zertifikats und Rückgabe der Information in einem Array
- openssl_x509_read — Analysiert ein X.509 Zertitifikat und gibt eine Ressource-Kennung zurück
OpenSSL
koen dot thomeer at pubmed dot be
31-Aug-2008 07:27
31-Aug-2008 07:27
