-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enigma smime signed messages verification #6043
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ class enigma_driver_phpssl extends enigma_driver | |
private $rc; | ||
private $homedir; | ||
private $user; | ||
private $cainfo; | ||
|
||
function __construct($user) | ||
{ | ||
|
@@ -37,6 +38,7 @@ function __construct($user) | |
function init() | ||
{ | ||
$homedir = $this->rc->config->get('enigma_smime_homedir', INSTALL_PATH . '/plugins/enigma/home'); | ||
$this->cainfo = $this->rc->config->get('enigma_smime_ca', array()); | ||
|
||
if (!$homedir) | ||
return new enigma_error(enigma_error::INTERNAL, | ||
|
@@ -65,6 +67,15 @@ function init() | |
|
||
$this->homedir = $homedir; | ||
|
||
#XXX: Workaround for https://bugs.php.net/bug.php?id=75494 | ||
if (count($this->cainfo) > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be a warning if the option in config is not an array. |
||
$dummy_cert_dir = $this->homedir . '/' . 'cert_dummy'; | ||
if (!file_exists($dummy_cert_dir)) { | ||
mkdir($dummy_cert_dir, 0700); | ||
} | ||
$this->cainfo[] = $dummy_cert_dir; | ||
} | ||
|
||
} | ||
|
||
function encrypt($text, $keys, $sign_key = null) | ||
|
@@ -96,11 +107,16 @@ function verify($struct, $message) | |
fclose($fh); | ||
|
||
// @TODO: use stored certificates | ||
|
||
// try with certificate verification | ||
$sig = openssl_pkcs7_verify($msg_file, 0, $cert_file); | ||
// try with global config'd certificates | ||
$sig = openssl_pkcs7_verify($msg_file, 0, $cert_file, $this->cainfo); | ||
$validity = true; | ||
|
||
if ($sig !== true) { | ||
// try with server trusted certificate verification | ||
$sig = openssl_pkcs7_verify($msg_file, 0, $cert_file); | ||
$validity = enigma_error::SERVER_VERIFIED; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would that be an error? Find another way to pass this info, e.g. involving enigma_signature::$partial. |
||
} | ||
|
||
if ($sig !== true) { | ||
// try without certificate verification | ||
$sig = openssl_pkcs7_verify($msg_file, PKCS7_NOVERIFY, $cert_file); | ||
|
@@ -229,6 +245,8 @@ private function parse_sig_cert($file, $validity) | |
// $data->comment = ''; | ||
$data->email = $cert['subject']['emailAddress']; | ||
|
||
rcube::write_log('errors', 'Decrypted sig: ' . $data->name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed. |
||
|
||
return $data; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ class enigma_error | |
const BADPASS = 5; | ||
const EXPIRED = 6; | ||
const UNVERIFIED = 7; | ||
const SERVER_VERIFIED = 8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is conflict that needs to be resolved. |
||
|
||
|
||
function __construct($code = null, $message = '', $data = array()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ class enigma_mime_message extends Mail_mime | |
{ | ||
const PGP_SIGNED = 1; | ||
const PGP_ENCRYPTED = 2; | ||
const SMIME_SIGNED = 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These new const aren't used/implemented yet. I would remove them. |
||
const SMIME_ENCRYPTED = 4; | ||
|
||
protected $type; | ||
protected $message; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using short array syntax now.