enabled() public static method

Return whether PGP support is current enabled in IMP.
public static enabled ( ) : boolean
return boolean True if PGP support is enabled.
Exemplo n.º 1
0
Arquivo: Ui.php Projeto: horde/horde
 /**
  * Return a list of valid encrypt HTML option tags.
  *
  * @param string $default      The default encrypt option.
  * @param boolean $returnList  Whether to return a hash with options
  *                             instead of the options tag.
  *
  * @return mixed  The list of option tags. This is empty if no encryption
  *                is available.
  */
 public function encryptList($default = null, $returnList = false)
 {
     global $injector, $prefs;
     if (is_null($default)) {
         $default = $prefs->getValue('default_encrypt');
     }
     $enc_opts = array();
     $output = '';
     if (IMP_Pgp::enabled()) {
         $enc_opts += $injector->getInstance('IMP_Pgp')->encryptList();
     }
     if (IMP_Smime::enabled()) {
         $enc_opts += $injector->getInstance('IMP_Smime')->encryptList();
     }
     if (!empty($enc_opts)) {
         $enc_opts = array_merge(array(IMP::ENCRYPT_NONE => _("None")), $enc_opts);
     }
     if ($returnList) {
         return $enc_opts;
     }
     foreach ($enc_opts as $key => $val) {
         $output .= '<option value="' . $key . '"' . ($default == $key ? ' selected="selected"' : '') . '>' . $val . "</option>\n";
     }
     return $output;
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     global $page_output, $prefs, $registry;
     $this->_files[] = new Horde_Script_File_JsDir('compose.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('draghandler.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('editor.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('imp.js', 'imp');
     if (!$prefs->isLocked('default_encrypt') && (IMP_Pgp::enabled() || IMP_Smime::enabled())) {
         $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
         $this->_files[] = new Horde_Script_File_JsDir('passphrase.js', 'imp');
     }
     if (!IMP_Compose::canHtmlCompose()) {
         return;
     }
     switch ($registry->getView()) {
         case $registry::VIEW_BASIC:
         case $registry::VIEW_DYNAMIC:
             $this->_files[] = new Horde_Script_File_JsDir('ckeditor/imageupload.js', 'imp');
             $this->_files[] = new Horde_Script_File_JsDir('ckeditor/images.js', 'imp');
             $page_output->addInlineJsVars(array('ImpCkeditorImgs.related_attr' => IMP_Compose::RELATED_ATTR));
             $js = new Horde_Script_File_JsDir('ckeditor/pasteattachment.js', 'imp');
             $upload_url = $registry->getServiceLink('ajax', 'imp')->url . 'addAttachmentCkeditor';
             $page_output->addInlineScript(array('if (window.CKEDITOR) { CKEDITOR.on("loaded", function(e) {' . 'CKEDITOR.plugins.addExternal("pasteattachment", "' . $js->url->url . '", "");' . 'CKEDITOR.config.filebrowserImageUploadUrl = "' . $upload_url . '";' . '}); };'), true);
             break;
     }
 }
Exemplo n.º 3
0
 /**
  */
 protected function _compose($base, $view, $args)
 {
     global $injector, $registry, $page_output, $prefs;
     $view->title = $args['title'];
     /* Load Identity. */
     $identity = $injector->getInstance('IMP_Identity');
     $selected_identity = intval($identity->getDefault());
     /* Generate identities list. */
     $this->_addIdentityJs();
     if (IMP_Compose::canHtmlCompose()) {
         $view->compose_html = !empty($args['show_editor']);
         $view->rte = true;
         $page_output->addScriptPackage('IMP_Script_Package_Editor');
         $page_output->addScriptFile('external/base64.js');
     }
     /* Create list for sent-mail selection. */
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS) && !$prefs->isLocked('save_sent_mail')) {
         $view->save_sent_mail = true;
         $view->save_sent_mail_select = !$prefs->isLocked(IMP_Mailbox::MBOX_SENT);
     }
     $view->drafts = $imp_imap->access(IMP_Imap::ACCESS_DRAFTS) && ($draft = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS)) && !$draft->readonly;
     $view->compose_link = $registry->getServiceLink('ajax', 'imp')->url . 'addAttachment';
     $view->resume = !empty($args['resume']);
     $view->is_template = !empty($args['template']);
     $view->read_receipt_set = strcasecmp($prefs->getValue('request_mdn'), 'always') === 0;
     $view->user = $registry->getAuth();
     if (IMP_Compose::canUploadAttachment()) {
         $view->attach = true;
         $view->max_size = IMP_Compose::maxAttachmentSize();
         $view->save_attach_set = strcasecmp($prefs->getValue('save_attachments'), 'always') === 0;
     } else {
         $view->attach = false;
     }
     if ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')) {
         $view->pgp_pubkey = $prefs->getValue('pgp_attach_pubkey');
     }
     if ($registry->hasMethod('contacts/ownVCard')) {
         $view->vcard_attach = true;
     }
     $view->priority = $prefs->getValue('set_priority');
     if (!$prefs->isLocked('default_encrypt') && (IMP_Pgp::enabled() || IMP_Smime::enabled())) {
         $view->encrypt = $prefs->getValue('default_encrypt');
     }
     $from_list = array();
     foreach ($identity->getSelectList() as $id => $from) {
         $from_list[] = array('label' => $from, 'sel' => $id == $selected_identity, 'val' => $id);
     }
     $view->from_list = $from_list;
     $view->signature = $identity->hasSignature(true);
     $view->sigExpanded = $prefs->getValue('signature_expanded');
 }
Exemplo n.º 4
0
 /**
  * Parse signed data.
  *
  * @param boolean $sig_only  Only do signature checking?
  *
  * @return mixed  See self::_getEmbeddedMimeParts().
  */
 protected function _parseSignedData($sig_only = false)
 {
     $iterator = $this->_mimepart->partIterator();
     $iterator->rewind();
     if (!($curr = $iterator->current())) {
         return null;
     }
     $base_id = $curr->getMimeId();
     $iterator->next();
     if (!($curr = $iterator->current())) {
         // application/pkcs-7-mime might be the base part.
         // See RFC 5751 3.4.2
         $data_id = $base_id;
     } else {
         $data_id = $curr->getMimeId();
     }
     $id_ob = new Horde_Mime_Id($data_id);
     $sig_id = $id_ob->idArithmetic($id_ob::ID_NEXT);
     /* Initialize inline data. */
     $status = new IMP_Mime_Status($this->_mimepart, _("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 (!IMP_Smime::enabled()) {
         $status->addText(_("S/MIME support is not enabled so the digital signature is unable to be verified."));
         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);
             }
             if (!is_array($sig_result->email)) {
                 $sig_result->email = array($sig_result->email);
             }
             $email = implode(', ', $sig_result->email);
             $cache->smime[$base_id]['wrap'] = 'mimePartWrapValid';
             $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($email), array('jstext' => _("View certificate details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE, 'view_smime_key' => 1)))));
                 foreach ($sig_result->email as $single_email) {
                     try {
                         $this->_impsmime->getPublicKey($single_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>');
                         break;
                     }
                 }
             } 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 {
         $status->addMimeAction('smimeVerifyMsg', _("Click to verify the data."));
     }
     if ($sig_only) {
         return;
     }
     if (!($subpart = $imp_contents->getMimePart($sig_id))) {
         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;
 }
Exemplo n.º 5
0
 /**
  * Encrypt an outgoing message.
  *
  * @param Horde_Mime_Part $msg             Outgoing message.
  * @param integer $encrypt                 Encryption type.
  * @param Horde_Mail_Rfc822_List $recip    Recipient list.
  * @param Horde_Mail_Rfc822_Address $from  Sending address.
  *
  * @return Horde_Mime_Part $msg  Processed outgoing message.
  */
 protected function _encryptMessage(Horde_Mime_Part $msg, $encrypt, Horde_Mail_Rfc822_List $recip, Horde_Mail_Rfc822_Address $from)
 {
     global $injector;
     /* Add personal address to encrypted message. */
     switch ($encrypt) {
         case IMP_Pgp::ENCRYPT:
         case IMP_Pgp::SIGNENC:
         case IMP_Pgp::SYM_ENCRYPT:
         case IMP_Pgp::SYM_SIGNENC:
         case IMP_Smime::ENCRYPT:
         case IMP_Smime::SIGNENC:
             $recip2 = clone $recip;
             $recip2->add($from);
             break;
     }
     switch ($encrypt) {
         case IMP_Pgp::ENCRYPT:
         case IMP_Pgp::SIGN:
         case IMP_Pgp::SIGNENC:
         case IMP_Pgp::SYM_ENCRYPT:
         case IMP_Pgp::SYM_SIGNENC:
             if (IMP_Pgp::enabled()) {
                 break;
             }
             $imp_pgp = $injector->getInstance('IMP_Pgp');
             switch ($encrypt) {
                 case IMP_Pgp::SIGN:
                 case IMP_Pgp::SIGNENC:
                 case IMP_Pgp::SYM_SIGNENC:
                     /* Check to see if we have the user's passphrase yet. */
                     $passphrase = $imp_pgp->getPassphrase('personal');
                     if (empty($passphrase)) {
                         $e = new IMP_Compose_Exception(_("PGP: Need passphrase for personal private key."));
                         $e->encrypt = 'pgp_passphrase_dialog';
                         throw $e;
                     }
                     break;
                 case IMP_Pgp::SYM_ENCRYPT:
                 case IMP_Pgp::SYM_SIGNENC:
                     /* Check to see if we have the user's symmetric passphrase
                      * yet. */
                     $symmetric_passphrase = $imp_pgp->getPassphrase('symmetric', 'imp_compose_' . $this->_cacheid);
                     if (empty($symmetric_passphrase)) {
                         $e = new IMP_Compose_Exception(_("PGP: Need passphrase to encrypt your message with."));
                         $e->encrypt = 'pgp_symmetric_passphrase_dialog';
                         throw $e;
                     }
                     break;
             }
             /* Do the encryption/signing requested. */
             try {
                 switch ($encrypt) {
                     case IMP_Pgp::SIGN:
                         $msg2 = $imp_pgp->signMimePart($msg);
                         $this->_setMetadata('encrypt_sign', true);
                         return $msg2;
                     case IMP_Pgp::ENCRYPT:
                     case IMP_Pgp::SYM_ENCRYPT:
                         return $imp_pgp->encryptMimePart($msg, $recip2, $encrypt == IMP_Pgp::SYM_ENCRYPT ? $symmetric_passphrase : null);
                     case IMP_Pgp::SIGNENC:
                     case IMP_Pgp::SYM_SIGNENC:
                         return $imp_pgp->signAndEncryptMimePart($msg, $recip2, $encrypt == IMP_Pgp::SYM_SIGNENC ? $symmetric_passphrase : null);
                         break;
                 }
             } catch (Horde_Exception $e) {
                 throw new IMP_Compose_Exception(_("PGP Error: ") . $e->getMessage(), $e->getCode());
             }
             break;
         case IMP_Smime::ENCRYPT:
         case IMP_Smime::SIGN:
         case IMP_Smime::SIGNENC:
             if (!IMP_Smime::enabled()) {
                 break;
             }
             $imp_smime = $injector->getInstance('IMP_Smime');
             /* Check to see if we have the user's passphrase yet. */
             switch ($encrypt) {
                 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."));
                         $e->encrypt = 'smime_passphrase_dialog';
                         throw $e;
                     }
                     break;
             }
             /* Do the encryption/signing requested. */
             try {
                 switch ($encrypt) {
                     case IMP_Smime::SIGN:
                         $msg2 = $imp_smime->signMimePart($msg);
                         $this->_setMetadata('encrypt_sign', true);
                         return $msg2;
                     case IMP_Smime::ENCRYPT:
                         return $imp_smime->encryptMimePart($msg, $recip2);
                     case IMP_Smime::SIGNENC:
                         return $imp_smime->signAndEncryptMimePart($msg, $recip2);
                 }
             } catch (Horde_Exception $e) {
                 throw new IMP_Compose_Exception(_("S/MIME Error: ") . $e->getMessage(), $e->getCode());
             }
             break;
     }
     return $msg;
 }