/** */ protected function _init() { global $injector, $notification; $this->_smime = $injector->getInstance('IMP_Crypt_Smime'); /* Run through the action handlers */ switch ($this->vars->actionID) { case 'import_public_key': $this->_importKeyDialog('process_import_public_key'); break; case 'process_import_public_key': try { $publicKey = $this->_getImportKey($this->vars->import_key); /* Add the public key to the storage system. */ $this->_smime->addPublicKey($publicKey); $notification->push(_("S/MIME public key successfully added."), 'horde.success'); $this->_reloadWindow(); } catch (Horde_Browser_Exception $e) { $notification->push(_("No S/MIME public key imported."), 'horde.error'); } catch (Horde_Exception $e) { $notification->push($e); } $this->vars->actionID = 'import_public_key'; $this->_importKeyDialog('process_import_public_key'); break; case 'view_public_key': case 'info_public_key': try { $key = $this->_smime->getPublicKey($this->vars->email); } catch (Horde_Exception $e) { $key = $e->getMessage(); } if ($this->vars->actionID == 'view_public_key') { $this->_textWindowOutput('S/MIME Public Key', $key); } $this->_printCertInfo($key); break; case 'view_personal_public_key': $this->_textWindowOutput('S/MIME Personal Public Key', $this->_smime->getPersonalPublicKey()); break; case 'info_personal_public_key': $this->_printCertInfo($this->_smime->getPersonalPublicKey()); break; case 'view_personal_private_key': $this->_textWindowOutput('S/MIME Personal Private Key', $this->_smime->getPersonalPrivateKey()); break; case 'import_personal_certs': $this->_importKeyDialog('process_import_personal_certs'); break; case 'process_import_personal_certs': try { $pkcs12 = $this->_getImportKey($this->vars->import_key); $this->_smime->addFromPKCS12($pkcs12, $this->vars->upload_key_pass, $this->vars->upload_key_pk_pass); $notification->push(_("S/MIME Public/Private Keypair successfully added."), 'horde.success'); $this->_reloadWindow(); } catch (Horde_Browser_Exception $e) { $notification->push(_("Personal S/MIME certificates NOT imported."), 'horde.error'); } catch (Horde_Exception $e) { $notification->push(_("Personal S/MIME certificates NOT imported: ") . $e->getMessage(), 'horde.error'); } $this->vars->actionID = 'import_personal_certs'; $this->_importKeyDialog('process_import_personal_certs'); break; } }
/** * Parse signed data. * * @param boolean $sig_only Only do signature checking? * * @return mixed See self::_getEmbeddedMimeParts(). */ protected function _parseSignedData($sig_only = false) { $partlist = array_keys($this->_mimepart->contentTypeMap()); $base_id = reset($partlist); $data_id = next($partlist); $sig_id = Horde_Mime::mimeIdArithmetic($data_id, 'next'); /* Initialize inline data. */ $status = new IMP_Mime_Status(_("The data in this part has been digitally signed via S/MIME.")); $status->icon('mime/encryption.png', 'S/MIME'); $cache = $this->getConfigParam('imp_contents')->getViewCache(); $cache->smime[$base_id] = array('sig' => $sig_id, 'status' => $status, 'wrap' => 'mimePartWrap'); if (!$GLOBALS['prefs']->getValue('use_smime')) { $status->addText(_("S/MIME support is not enabled so the digital signature is unable to be verified.")); return null; } /* Sanity checking to make sure MIME structure is correct. */ if (!in_array($sig_id, $partlist)) { $status->action(IMP_Mime_Status::ERROR); $cache->smime[$base_id]['wrap'] = 'mimePartWrapInvalid'; $status->addText(_("Invalid S/MIME data.")); /* This will suppress displaying the invalid part. */ $cache->smime[$base_id]['sig'] = $data_id; return null; } $imp_contents = $this->getConfigParam('imp_contents'); $stream = $imp_contents->isEmbedded($base_id) ? $this->_mimepart->getMetadata('imp-smime-decrypt')->stream : $this->_getPartStream($base_id); $raw_text = $this->_mimepart->replaceEOL($stream, Horde_Mime_Part::RFC_EOL); $this->_initSmime(); $sig_result = null; if ($GLOBALS['prefs']->getValue('smime_verify') || $GLOBALS['injector']->getInstance('Horde_Variables')->smime_verify_msg) { try { $sig_result = $this->_impsmime->verifySignature($raw_text); if ($sig_result->verify) { $status->action(IMP_Mime_Status::SUCCESS); } else { $status->action(IMP_Mime_Status::WARNING); } $cache->smime[$base_id]['wrap'] = 'mimePartWrapValid'; $email = is_array($sig_result->email) ? implode(', ', $sig_result->email) : $sig_result->email; $status->addText($sig_result->msg); if (!empty($sig_result->cert)) { $cert = $this->_impsmime->parseCert($sig_result->cert); if (isset($cert['certificate']['subject']['CommonName']) && strcasecmp($email, $cert['certificate']['subject']['CommonName']) !== 0) { $email = $cert['certificate']['subject']['CommonName'] . ' (' . trim($email) . ')'; } } if (!empty($sig_result->cert) && isset($sig_result->email) && $GLOBALS['registry']->hasMethod('contacts/addField') && $GLOBALS['prefs']->getValue('add_source')) { $status->addText(sprintf(_("Sender: %s"), $imp_contents->linkViewJS($this->_mimepart, 'view_attach', htmlspecialchars(strlen($email) ? $email : $sig_result->email), array('jstext' => _("View certificate details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE, 'view_smime_key' => 1))))); try { $this->_impsmime->getPublicKey($sig_result->email); } catch (Horde_Exception $e) { $imple = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_ImportEncryptKey', array('mime_id' => $base_id, 'muid' => strval($imp_contents->getIndicesOb()), 'type' => 'smime')); $status->addText(Horde::link('#', '', '', '', '', '', '', array('id' => $imple->getDomId())) . _("Save the certificate to your Address Book.") . '</a>'); } } elseif (strlen($email)) { $status->addText(sprintf(_("Sender: %s"), htmlspecialchars($email))); } } catch (Horde_Exception $e) { $status->action(IMP_Mime_Status::ERROR); $cache->smime[$base_id]['wrap'] = 'mimePartWrapInvalid'; $status->addText($e->getMessage()); } } else { switch ($GLOBALS['registry']->getView()) { case Horde_Registry::VIEW_BASIC: $status->addText(Horde::link(Horde::selfUrlParams()->add('smime_verify_msg', 1)) . _("Click HERE to verify the data.") . '</a>'); break; case Horde_Registry::VIEW_DYNAMIC: $status->addText(Horde::link('#', '', 'smimeVerifyMsg') . _("Click HERE to verify the data.") . '</a>'); break; } } if ($sig_only) { return; } $subpart = $imp_contents->getMIMEPart($sig_id); if (empty($subpart)) { try { $msg_data = $this->_impsmime->extractSignedContents($raw_text); $subpart = Horde_Mime_Part::parseMessage($msg_data, array('forcemime' => true)); } catch (Horde_Exception $e) { $status->addText($e->getMessage()); return null; } } return $subpart; }