Skip to content

Commit

Permalink
No reason to extend Horde_Crypt_Smime in IMP_Crypt_Smime
Browse files Browse the repository at this point in the history
We can do everything we need by wrapping.
  • Loading branch information
slusarz committed Apr 9, 2015
1 parent 5891b5d commit 8768968
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 71 deletions.
2 changes: 1 addition & 1 deletion imp/lib/Ajax/Application/Handler/Passphrase.php
Expand Up @@ -57,7 +57,7 @@ public function checkPassphrase()
break;

case 'smimePersonal':
$result = $injector->getInstance('IMP_Crypt_Smime')->storePassphrase($this->vars->dialog_input);
$result = $injector->getInstance('IMP_Smime')->storePassphrase($this->vars->dialog_input);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Ajax/Imple/ImportEncryptKey.php
Expand Up @@ -83,7 +83,7 @@ protected function _handle(Horde_Variables $vars)
: $contents->fullMessageText();
$raw_text = $mime_part->replaceEOL($stream, Horde_Mime_Part::RFC_EOL);

$imp_smime = $injector->getInstance('IMP_Crypt_Smime');
$imp_smime = $injector->getInstance('IMP_Smime');
$sig_result = $imp_smime->verifySignature($raw_text);
$imp_smime->addPublicKey($sig_result->cert);
$notification->push(_("Successfully added certificate from message."), 'horde.success');
Expand Down
6 changes: 3 additions & 3 deletions imp/lib/Application.php
Expand Up @@ -96,19 +96,19 @@ protected function _bootstrap()
$factories = array(
'IMP_AuthImap' => 'IMP_Factory_AuthImap',
'IMP_Contacts' => 'IMP_Factory_Contacts',
'IMP_Pgp' => 'IMP_Factory_Pgp',
'IMP_Crypt_Smime' => 'IMP_Factory_Smime',
'IMP_Flags' => 'IMP_Factory_Flags',
'IMP_Identity' => 'IMP_Factory_Identity',
'IMP_Ftree' => 'IMP_Factory_Ftree',
'IMP_Mail' => 'IMP_Factory_Mail',
'IMP_Mail_Autoconfig' => 'IMP_Factory_MailAutoconfig',
'IMP_Mailbox_SessionCache' => 'IMP_Factory_MailboxCache',
'IMP_Maillog' => 'IMP_Factory_Maillog',
'IMP_Pgp' => 'IMP_Factory_Pgp',
'IMP_Prefs_Sort' => 'IMP_Factory_PrefsSort',
'IMP_Quota' => 'IMP_Factory_Quota',
'IMP_Search' => 'IMP_Factory_Search',
'IMP_Sentmail' => 'IMP_Factory_Sentmail'
'IMP_Sentmail' => 'IMP_Factory_Sentmail',
'IMP_Smime' => 'IMP_Factory_Smime'
);

foreach ($factories as $key => $val) {
Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Basic/Smime.php
Expand Up @@ -24,7 +24,7 @@
class IMP_Basic_Smime extends IMP_Basic_Base
{
/**
* @var IMP_Crypt_Smime
* @var IMP_Smime
*/
protected $_smime;

Expand All @@ -34,7 +34,7 @@ protected function _init()
{
global $injector, $notification;

$this->_smime = $injector->getInstance('IMP_Crypt_Smime');
$this->_smime = $injector->getInstance('IMP_Smime');

/* Run through the action handlers */
switch ($this->vars->actionID) {
Expand Down
34 changes: 17 additions & 17 deletions imp/lib/Compose.php
Expand Up @@ -720,8 +720,8 @@ public function hasDrafts()
* One of:
* - IMP_Pgp::ENCRYPT</li>
* - IMP_Pgp::SIGNENC</li>
* - IMP_Crypt_Smime::ENCRYPT</li>
* - IMP_Crypt_Smime::SIGNENC</li>
* - IMP_Smime::ENCRYPT</li>
* - IMP_Smime::SIGNENC</li>
* - html: (boolean) Whether this is an HTML message.
* DEFAULT: false
* - pgp_attach_pubkey: (boolean) Attach the user's PGP public key to the
Expand Down Expand Up @@ -1001,8 +1001,8 @@ protected function _encryptMessage(
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
case IMP_Crypt_Smime::ENCRYPT:
case IMP_Crypt_Smime::SIGNENC:
case IMP_Smime::ENCRYPT:
case IMP_Smime::SIGNENC:
$recip2 = clone $recip;
$recip2->add($from);
break;
Expand Down Expand Up @@ -1085,19 +1085,19 @@ protected function _encryptMessage(
}
break;

case IMP_Crypt_Smime::ENCRYPT:
case IMP_Crypt_Smime::SIGN:
case IMP_Crypt_Smime::SIGNENC:
if (!IMP_Crypt_Smime::enabled()) {
case IMP_Smime::ENCRYPT:
case IMP_Smime::SIGN:
case IMP_Smime::SIGNENC:
if (!IMP_Smime::enabled()) {
break;
}

$imp_smime = $injector->getInstance('IMP_Crypt_Smime');
$imp_smime = $injector->getInstance('IMP_Smime');

/* Check to see if we have the user's passphrase yet. */
switch ($encrypt) {
case IMP_Crypt_Smime::SIGN:
case IMP_Crypt_Smime::SIGNENC:
case IMP_Smime::SIGN:
case IMP_Smime::SIGNENC:
if (($passphrase = $imp_smime->getPassphrase()) === false) {
$e = new IMP_Compose_Exception(
_("S/MIME Error: Need passphrase for personal private key.")
Expand All @@ -1111,16 +1111,16 @@ protected function _encryptMessage(
/* Do the encryption/signing requested. */
try {
switch ($encrypt) {
case IMP_Crypt_Smime::SIGN:
$msg2 = $imp_smime->IMPsignMIMEPart($msg);
case IMP_Smime::SIGN:
$msg2 = $imp_smime->signMimePart($msg);
$this->_setMetadata('encrypt_sign', true);
return $msg2;

case IMP_Crypt_Smime::ENCRYPT:
return $imp_smime->IMPencryptMIMEPart($msg, $recip2);
case IMP_Smime::ENCRYPT:
return $imp_smime->encryptMimePart($msg, $recip2);

case IMP_Crypt_Smime::SIGNENC:
return $imp_smime->IMPsignAndEncryptMIMEPart($msg, $recip2);
case IMP_Smime::SIGNENC:
return $imp_smime->signAndEncryptMimePart($msg, $recip2);
}
} catch (Horde_Exception $e) {
throw new IMP_Compose_Exception(
Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Compose/Ui.php
Expand Up @@ -47,8 +47,8 @@ public function encryptList($default = null, $returnList = false)
$enc_opts += $injector->getInstance('IMP_Pgp')->encryptList();
}

if (IMP_Crypt_Smime::enabled()) {
$enc_opts += $injector->getInstance('IMP_Crypt_Smime')->encryptList();
if (IMP_Smime::enabled()) {
$enc_opts += $injector->getInstance('IMP_Smime')->encryptList();
}

if (!empty($enc_opts)) {
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Dynamic/Compose/Common.php
Expand Up @@ -134,7 +134,7 @@ protected function _compose($base, $view, $args)

$view->priority = $prefs->getValue('set_priority');
if (!$prefs->isLocked('default_encrypt') &&
(IMP_Pgp::enabled() || IMP_Crypt_Smime::enabled())) {
(IMP_Pgp::enabled() || IMP_Smime::enabled())) {
$view->encrypt = $prefs->getValue('default_encrypt');
}

Expand Down
12 changes: 8 additions & 4 deletions imp/lib/Factory/Smime.php
Expand Up @@ -12,7 +12,7 @@
*/

/**
* A Horde_Injector based factory for the IMP_Crypt_Smime object.
* A Horde_Injector based factory for the IMP_Smime object.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
Expand All @@ -23,13 +23,17 @@
class IMP_Factory_Smime extends Horde_Core_Factory_Injector
{
/**
* Return the IMP_Crypt_Smime instance.
* Return the IMP_Smime instance.
*
* @return IMP_Crypt_Smime The singleton instance.
* @return IMP_Smime The singleton instance.
*/
public function create(Horde_Injector $injector)
{
return $injector->getInstance('Horde_Core_Factory_Crypt')->create('IMP_Crypt_Smime');
return new IMP_Smime(
$injector->getInstance('Horde_Core_Factory_Crypt')->create(
'Horde_Crypt_Smime'
)
);
}

}
12 changes: 6 additions & 6 deletions imp/lib/Mime/Viewer/Smime.php
Expand Up @@ -57,9 +57,9 @@ class IMP_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base
);

/**
* IMP_Crypt_Smime object.
* IMP_Smime object.
*
* @var IMP_Crypt_Smime
* @var IMP_Smime
*/
protected $_impsmime = null;

Expand All @@ -68,10 +68,10 @@ class IMP_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base
*/
protected function _initSmime()
{
if (is_null($this->_impsmime) && IMP_Crypt_Smime::enabled()) {
if (is_null($this->_impsmime) && IMP_Smime::enabled()) {
try {
$this->_impsmime = $GLOBALS['injector']->getInstance('IMP_Crypt_Smime');
$this->_impsmime->checkForOpenSSL();
$this->_impsmime = $GLOBALS['injector']->getInstance('IMP_Smime');
$this->_impsmime->checkForOpenSsl();
} catch (Horde_Exception $e) {
$this->_impsmime = null;
}
Expand Down Expand Up @@ -282,7 +282,7 @@ protected function _parseSignedData($sig_only = false)
'wrap' => 'mimePartWrap'
);

if (!IMP_Crypt_Smime::enabled()) {
if (!IMP_Smime::enabled()) {
$status->addText(
_("S/MIME support is not enabled so the digital signature is unable to be verified.")
);
Expand Down
6 changes: 3 additions & 3 deletions imp/lib/Prefs/Special/SmimePrivateKey.php
Expand Up @@ -52,7 +52,7 @@ public function display(Horde_Core_Prefs_Ui $ui)
$view->has_key = ($prefs->getValue('smime_public_key') && $prefs->getValue('smime_private_key'));

if ($view->has_key) {
$smime = $injector->getInstance('IMP_Crypt_Smime');
$smime = $injector->getInstance('IMP_Smime');
$cert = $smime->parseCert($smime->getPersonalPublicKey());
if (!empty($cert['validity']['notafter'])) {
$expired = new Horde_Date($cert['validity']['notafter']);
Expand Down Expand Up @@ -102,10 +102,10 @@ public function update(Horde_Core_Prefs_Ui $ui)
global $injector, $notification;

if (isset($ui->vars->delete_smime_personal)) {
$injector->getInstance('IMP_Crypt_Smime')->deletePersonalKeys();
$injector->getInstance('IMP_Smime')->deletePersonalKeys();
$notification->push(_("Personal S/MIME keys deleted successfully."), 'horde.success');
} elseif (isset($ui->vars->unset_smime_passphrase)) {
$injector->getInstance('IMP_Crypt_Smime')->unsetPassphrase();
$injector->getInstance('IMP_Smime')->unsetPassphrase();
$notification->push(_("S/MIME passphrase successfully unloaded."), 'horde.success');
}

Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Prefs/Special/SmimePublicKey.php
Expand Up @@ -39,7 +39,7 @@ public function display(Horde_Core_Prefs_Ui $ui)
$p_css = new Horde_Themes_Element('prefs.css');
$page_output->addStylesheet($p_css->fs, $p_css->uri);

$imp_smime = $injector->getInstance('IMP_Crypt_Smime');
$imp_smime = $injector->getInstance('IMP_Smime');

/* Get list of Public Keys on keyring. */
try {
Expand Down Expand Up @@ -93,7 +93,7 @@ public function update(Horde_Core_Prefs_Ui $ui)

if (isset($ui->vars->delete_smime_pubkey)) {
try {
$injector->getInstance('IMP_Crypt_Smime')->deletePublicKey($ui->vars->email);
$injector->getInstance('IMP_Smime')->deletePublicKey($ui->vars->email);
$notification->push(sprintf(_("S/MIME Public Key for \"%s\" was successfully deleted."), $ui->vars->email), 'horde.success');
} catch (Horde_Exception $e) {
$notification->push($e);
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Script/Package/Compose.php
Expand Up @@ -36,7 +36,7 @@ public function __construct()
$this->_files[] = new Horde_Script_File_JsDir('imp.js', 'imp');

if (!$prefs->isLocked('default_encrypt') &&
(IMP_Pgp::enabled() || IMP_Crypt_Smime::enabled())) {
(IMP_Pgp::enabled() || IMP_Smime::enabled())) {
$page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
$this->_files[] = new Horde_Script_File_JsDir('passphrase.js', 'imp');
}
Expand Down

0 comments on commit 8768968

Please sign in to comment.