2017-01-18 19:03:17 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware Api: generic base class for SMIME
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package api
|
|
|
|
* @subpackage mail
|
|
|
|
* @author Hadi Nategh <hn@egrupware.org>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License Version 2+
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace EGroupware\Api\Mail;
|
|
|
|
|
|
|
|
use EGroupware\Api;
|
|
|
|
use Horde_Crypt_Smime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EMailAdmin generic base class for SMTP
|
|
|
|
*/
|
|
|
|
class Smime extends Horde_Crypt_Smime
|
|
|
|
{
|
|
|
|
|
|
|
|
static $SMIME_TYPES = array (
|
|
|
|
'application/pkcs8',
|
|
|
|
'application/pkcs7',
|
|
|
|
'application/pkcs10',
|
|
|
|
'application/pkcs8',
|
|
|
|
'multipart/signed',
|
|
|
|
'application/x-pkcs7-signature',
|
2017-01-19 18:52:28 +01:00
|
|
|
'application/x-pkcs7-mime',
|
|
|
|
'application/pkcs7-mime',
|
|
|
|
'application/pkcs7-signature',
|
2017-01-18 19:03:17 +01:00
|
|
|
);
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param Horde_Crypt_Smime $smime S/MIME object.
|
|
|
|
*/
|
|
|
|
public function __construct($params = array())
|
|
|
|
{
|
|
|
|
parent::__construct($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given mime type is smime type
|
|
|
|
*
|
|
|
|
* @param string $_mime mime type
|
|
|
|
*
|
|
|
|
* @return boolean returns TRUE if the given mime is smime
|
|
|
|
*/
|
|
|
|
public static function isSmime ($_mime)
|
|
|
|
{
|
|
|
|
return in_array($_mime, self::$SMIME_TYPES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the openssl is supported
|
|
|
|
*
|
|
|
|
* @return boolean returns True if openssl is supported
|
|
|
|
*/
|
|
|
|
public function enabled ()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->checkForOpenSSL();
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-23 16:19:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract public key from certificate
|
|
|
|
*
|
|
|
|
* @param type $cert
|
|
|
|
* @return string returns public key
|
|
|
|
*/
|
|
|
|
public function get_publickey ($cert)
|
|
|
|
{
|
|
|
|
$handle = openssl_get_publickey($cert);
|
|
|
|
$keyData = openssl_pkey_get_details($handle);
|
|
|
|
return $keyData['key'];
|
|
|
|
}
|
2017-01-18 19:03:17 +01:00
|
|
|
}
|