/* Enigma Plugin */ window.rcmail && rcmail.addEventListener('init', function(evt) { if (rcmail.env.task == 'settings') { if (rcmail.gui_objects.keyslist) { rcmail.keys_list = new rcube_list_widget(rcmail.gui_objects.keyslist, {multiselect:true, draggable:false, keyboard:false}); rcmail.keys_list .addEventListener('select', function(o) { rcmail.enigma_keylist_select(o); }) .addEventListener('keypress', function(o) { rcmail.enigma_keylist_keypress(o); }) .init() .focus(); rcmail.enigma_list(); rcmail.register_command('firstpage', function(props) { return rcmail.enigma_list_page('first'); }); rcmail.register_command('previouspage', function(props) { return rcmail.enigma_list_page('previous'); }); rcmail.register_command('nextpage', function(props) { return rcmail.enigma_list_page('next'); }); rcmail.register_command('lastpage', function(props) { return rcmail.enigma_list_page('last'); }); } if (rcmail.env.action == 'plugin.enigmakeys') { rcmail.register_command('search', function(props) {return rcmail.enigma_search(props); }, true); rcmail.register_command('reset-search', function(props) {return rcmail.enigma_search_reset(props); }, true); rcmail.register_command('plugin.enigma-import', function() { rcmail.enigma_import(); }, true); rcmail.register_command('plugin.enigma-import-search', function() { rcmail.enigma_import_search(); }, true); rcmail.register_command('plugin.enigma-key-export', function() { rcmail.enigma_export(); }); rcmail.register_command('plugin.enigma-key-export-selected', function() { rcmail.enigma_export(true); }); rcmail.register_command('plugin.enigma-key-import', function() { rcmail.enigma_key_import(); }, true); rcmail.register_command('plugin.enigma-key-delete', function(props) { return rcmail.enigma_delete(); }); rcmail.register_command('plugin.enigma-key-create', function(props) { return rcmail.enigma_key_create(); }, true); rcmail.register_command('plugin.enigma-key-save', function(props) { return rcmail.enigma_key_create_save(); }, true); rcmail.addEventListener('responseafterplugin.enigmakeys', function() { rcmail.enable_command('plugin.enigma-key-export', rcmail.env.rowcount > 0); }); if (rcmail.gui_objects.importform) { // make sure Enter key in search input starts searching // instead of submitting the form $('#rcmimportsearch').keydown(function(e) { if (e.which == 13) { rcmail.enigma_import_search(); return false; } }); $('input[type="button"]:first').focus(); } } } else if (rcmail.env.task == 'mail') { if (rcmail.env.action == 'compose') { rcmail.addEventListener('beforesend', function(props) { rcmail.enigma_beforesend_handler(props); }) .addEventListener('beforesavedraft', function(props) { rcmail.enigma_beforesavedraft_handler(props); }); $('input,label', $('#enigmamenu')).mouseup(function(e) { // don't close the menu on mouse click inside e.stopPropagation(); }); $('a.button.enigma').prop('tabindex', $('#messagetoolbar > a:first').prop('tabindex')); } $.each(['encrypt', 'sign'], function() { if (rcmail.env['enigma_force_' + this]) $('[name="_enigma_' + this + '"]').prop('checked', true); }); if (rcmail.env.enigma_password_request) { rcmail.enigma_password_request(rcmail.env.enigma_password_request); } } }); /*********************************************************/ /********* Enigma Settings/Keys/Certs UI *********/ /*********************************************************/ // Display key(s) import form rcube_webmail.prototype.enigma_key_import = function() { this.enigma_loadframe('&_action=plugin.enigmakeys&_a=import'); }; // Display key(s) generation form rcube_webmail.prototype.enigma_key_create = function() { this.enigma_loadframe('&_action=plugin.enigmakeys&_a=create'); }; // Generate key(s) and submit them rcube_webmail.prototype.enigma_key_create_save = function() { var options, lock, users = [], password = $('#key-pass').val(), confirm = $('#key-pass-confirm').val(), size = $('#key-size').val(); $('[name="identity[]"]:checked').each(function() { users.push(this.value); }); // validate the form if (!password || !confirm) return alert(this.get_label('enigma.formerror')); if (password != confirm) return alert(this.get_label('enigma.passwordsdiffer')); if (!users.length) return alert(this.get_label('enigma.noidentselected')); // generate keys // use OpenPGP.js if browser supports required features if (window.openpgp && window.crypto && (window.crypto.getRandomValues || window.crypto.subtle)) { lock = this.set_busy(true, 'enigma.keygenerating'); options = { numBits: size, userId: users, passphrase: password }; openpgp.generateKeyPair(options).then(function(keypair) { // success var post = {_a: 'import', _keys: keypair.privateKeyArmored, _generated: 1, _passwd: password, _keyid: keypair.key.primaryKey.fingerprint}; // send request to server rcmail.http_post('plugin.enigmakeys', post, lock); }, function(error) { // failure rcmail.set_busy(false, null, lock); rcmail.display_message(rcmail.get_label('enigma.keygenerateerror'), 'error'); }); } else { rcmail.display_message(rcmail.get_label('enigma.keygennosupport'), 'error'); } }; // Action executed after successful key generation and import rcube_webmail.prototype.enigma_key_create_success = function() { parent.rcmail.enigma_list(1); }; // Delete key(s) rcube_webmail.prototype.enigma_delete = function() { var keys = this.keys_list.get_selection(); if (!keys.length || !confirm(this.get_label('enigma.keyremoveconfirm'))) return; var lock = this.display_message(this.get_label('enigma.keyremoving'), 'loading'), post = {_a: 'delete', _keys: keys}; // send request to server this.http_post('plugin.enigmakeys', post, lock); }; // Export key(s) rcube_webmail.prototype.enigma_export = function(selected) { var priv = false, list = this.keys_list, keys = selected ? list.get_selection().join(',') : '*', args = {_keys: keys}; if (!keys.length) return; // find out whether selected keys are private if (keys == '*') priv = true; else $.each(list.get_selection(), function() { flags = $(list.rows[this].obj).data('flags'); if (flags && flags.indexOf('p') >= 0) { priv = true; return false; } }); // ask the user about including private key in the export if (priv) return this.show_popup_dialog( this.get_label('enigma.keyexportprompt'), this.get_label('enigma.exportkeys'), [{ text: this.get_label('enigma.onlypubkeys'), click: function(e) { rcmail.enigma_export_submit(args); $(this).remove(); } }, { text: this.get_label('enigma.withprivkeys'), click: function(e) { args._priv = 1; rcmail.enigma_export_submit(args); $(this).remove(); } }], {width: 400} ); this.enigma_export_submit(args); }; // Sumbitting request for key(s) export // Done this way to handle password input rcube_webmail.prototype.enigma_export_submit = function(data) { var id = 'keyexport-' + new Date().getTime(), form = $('