WIP of SMIME support: Add method to extract certificate's info from pkcs12

This commit is contained in:
Hadi Nategh 2017-01-25 18:04:54 +01:00
parent efbb02b1b7
commit 572ae1d77e

View File

@ -20,7 +20,9 @@ use Horde_Crypt_Smime;
*/
class Smime extends Horde_Crypt_Smime
{
/*
* SMIME types
*/
static $SMIME_TYPES = array (
'application/pkcs8',
'application/pkcs7',
@ -32,6 +34,27 @@ class Smime extends Horde_Crypt_Smime
'application/pkcs7-mime',
'application/pkcs7-signature',
);
/*
* SMIME public key regular expresion
*/
static public $pubkey_regexp = '/-----BEGIN PUBLIC KEY-----.*-----END PUBLIC KEY-----\r?\n/s/';
/*
* SMIME encrypted private key regular expresion
*/
static public $privkey_encrypted_regexp = '/-----BEGIN ENCRYPTED PRIVATE KEY-----.*-----END ENCRYPTED PRIVATE KEY-----\r?\n/s/';
/*
* SMIME private key regular expresion
*/
static public $privkey_regexp = '/-----BEGIN PRIVATE KEY-----.*-----END PRIVATE KEY-----\r?\n/s/';
/*
* SMIME certificate regular expresion
*/
static public $certificate_regexp = '/-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----\r?\n/s/';
/**
* Constructor.
*
@ -82,4 +105,24 @@ class Smime extends Horde_Crypt_Smime
$keyData = openssl_pkey_get_details($handle);
return $keyData['key'];
}
/**
* Extract certificates info from a p12 file
*
* @param string $pkcs12
* @param string $passphrase
* @return boolean|array returns array of certs info or false if not successful
*/
public function extractCertPKCS12 ($pkcs12, $passphrase)
{
$certs = array ();
if (openssl_pkcs12_read($pkcs12, $certs, $passphrase))
{
return $certs;
}
else
{
return false;
}
}
}