Merge branch 'attach-pgp-key' of https://github.com/guitarmanusa/roundcubemail-1 into guitarmanusa-attach-pgp-key
| | |
| | | // Enable encrypting all messages by default |
| | | $config['enigma_encrypt_all'] = false; |
| | | |
| | | // Enable signing all messages by default |
| | | $config['enigma_attach_pubkey'] = false; |
| | | |
| | | // Default for how long to store private key passwords (in minutes). |
| | | // When set to 0 passwords will be stored for the whole session. |
| | | $config['enigma_password_time'] = 5; |
| | |
| | | ); |
| | | } |
| | | |
| | | if (!isset($no_override['enigma_attach_pubkey'])) { |
| | | if (!$p['current']) { |
| | | $p['blocks']['main']['content'] = true; |
| | | return $p; |
| | | } |
| | | |
| | | $field_id = 'rcmfd_enigma_attach_pubkey'; |
| | | $input = new html_checkbox(array( |
| | | 'name' => '_enigma_attach_pubkey', |
| | | 'id' => $field_id, |
| | | 'value' => 1, |
| | | )); |
| | | |
| | | $p['blocks']['main']['options']['enigma_encrypt_all'] = array( |
| | | 'title' => html::label($field_id, $this->gettext('attachpubkeydefault')), |
| | | 'content' => $input->show($this->rc->config->get('enigma_attach_pubkey') ? 1 : 0), |
| | | ); |
| | | } |
| | | |
| | | if (!isset($no_override['enigma_password_time'])) { |
| | | if (!$p['current']) { |
| | | $p['blocks']['main']['content'] = true; |
| | |
| | | 'enigma_encryption' => (bool) rcube_utils::get_input_value('_enigma_encryption', rcube_utils::INPUT_POST), |
| | | 'enigma_sign_all' => (bool) rcube_utils::get_input_value('_enigma_sign_all', rcube_utils::INPUT_POST), |
| | | 'enigma_encrypt_all' => (bool) rcube_utils::get_input_value('_enigma_encrypt_all', rcube_utils::INPUT_POST), |
| | | 'enigma_attach_pubkey' => (bool) rcube_utils::get_input_value('_enigma_attach_pubkey', rcube_utils::INPUT_POST), |
| | | 'enigma_password_time' => intval(rcube_utils::get_input_value('_enigma_password_time', rcube_utils::INPUT_POST)), |
| | | ); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public function pubkey_for_attach($email) |
| | | { |
| | | try { |
| | | $pubkey = $this->gpg->exportPublicKey($email, true); |
| | | return $pubkey; |
| | | } |
| | | catch (Exception $e) { |
| | | return $this->get_error_from_exception($e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Converts Crypt_GPG exception into Enigma's error object |
| | | * |
| | |
| | | return $result; |
| | | } |
| | | |
| | | function get_gpg_pubkey_for_attach($email) |
| | | { |
| | | $this->load_pgp_driver(); |
| | | $result = $this->pgp_driver->pubkey_for_attach($email); |
| | | |
| | | if ($result instanceof enigma_error) { |
| | | rcube::raise_error(array( |
| | | 'code' => 600, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Enigma plugin: " . $result->getMessage() |
| | | ), true, false); |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | function get_keyID($email) |
| | | { |
| | | $this->load_pgp_driver(); |
| | | $result = $this->pgp_driver->get_keyID($email); |
| | | |
| | | if ($result instanceof enigma_error) { |
| | | rcube::raise_error(array( |
| | | 'code' => 600, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Enigma plugin: " . $result->getMessage() |
| | | ), true, false); |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | /** |
| | | * Find PGP private/public key |
| | | * |
| | |
| | | $menu->add(null, $chbox->show($this->rc->config->get('enigma_encrypt_all') ? 1 : 0, |
| | | array('name' => '_enigma_encrypt', 'id' => 'enigmaencryptopt'))); |
| | | |
| | | $menu->add(null, html::label(array('for' => 'enigmaattachpubkeyopt'), |
| | | rcube::Q($this->enigma->gettext('attachpubkeymsg')))); |
| | | $menu->add(null, $chbox->show($this->rc->config->get('enigma_attach_pubkey') ? 1 : 0, |
| | | array('name' => '_enigma_attachpubkey', 'id' => 'enigmaattachpubkeyopt'))); |
| | | |
| | | $menu = html::div(array('id' => 'enigmamenu', 'class' => 'popupmenu'), $menu->show()); |
| | | |
| | | // Options menu contents |
| | |
| | | } |
| | | |
| | | /** |
| | | * Handle message_ready hook (encryption/signing) |
| | | * Handle message_ready hook (encryption/signing/attach public key) |
| | | */ |
| | | function message_ready($p) |
| | | { |
| | | $savedraft = !empty($_POST['_draft']) && empty($_GET['_saveonly']); |
| | | |
| | | if (!$savedraft && rcube_utils::get_input_value('_enigma_attachpubkey', rcube_utils::INPUT_POST)) { |
| | | $p = $this->attach_public($p); |
| | | } |
| | | |
| | | if (!$savedraft && rcube_utils::get_input_value('_enigma_sign', rcube_utils::INPUT_POST)) { |
| | | $this->enigma->load_engine(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Add sender's public key (PGP). |
| | | */ |
| | | function attach_public($p) |
| | | { |
| | | // get sender's PGP pubkey for attachment |
| | | $this->enigma->load_engine(); |
| | | $key = $this->enigma->engine->list_keys($p['message']->headers()['From']); |
| | | $keyID = $key[0]->subkeys[0]->get_short_id(); |
| | | $pubkey_armor = $this->enigma->engine->get_gpg_pubkey_for_attach($p['message']->headers()['From']); |
| | | |
| | | if(!$pubkey_armor instanceof enigma_error) { |
| | | $p['message']->addAttachment($pubkey_armor, 'application/pgp-keys', "0x$keyID.asc", false); |
| | | } |
| | | |
| | | return $p; |
| | | } |
| | | |
| | | /** |
| | | * Handler for message_compose_body hook |
| | | * Display error when the message cannot be encrypted |
| | | * and provide a way to try again with a password. |
| | |
| | | $labels['supportdecryption'] = 'Enable message decryption'; |
| | | $labels['signdefault'] = 'Sign all messages by default'; |
| | | $labels['encryptdefault'] = 'Encrypt all messages by default'; |
| | | $labels['attachpubkeydefault'] = 'Attach my public PGP key by default'; |
| | | $labels['passwordtime'] = 'Keep private key passwords for'; |
| | | $labels['nminutes'] = '$m minute(s)'; |
| | | $labels['wholesession'] = 'the whole session'; |
| | |
| | | $labels['enterkeypasstitle'] = 'Enter key passphrase'; |
| | | $labels['enterkeypass'] = 'A passphrase is needed to unlock the secret key ($keyid) for user: $user.'; |
| | | $labels['arialabelkeyexportoptions'] = 'Keys export options'; |
| | | $labels['attachpubkeymsg'] = 'Attach my public key'; |
| | | |
| | | $messages = array(); |
| | | $messages['sigvalid'] = 'Verified signature from $sender.'; |