diff options
| author | Carson Fleming <[email protected]> | 2025-01-02 01:06:13 -0800 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2025-01-02 01:06:13 -0800 |
| commit | cbdfa29d284a2402ef814d71b988e3afe02d8878 (patch) | |
| tree | 42406ff111a1cfe3f638e169d906a39b04a55061 /keys.js | |
| parent | 387e6f45dd081f927ddb3c8028bda54a17a9fe2e (diff) | |
| download | rc-inbox-settings-cbdfa29d284a2402ef814d71b988e3afe02d8878.tar.gz | |
add client-side key generation
Diffstat (limited to 'keys.js')
| -rw-r--r-- | keys.js | 49 |
1 files changed, 27 insertions, 22 deletions
@@ -13,7 +13,7 @@ window.rcmail && window.rcmail.addEventListener('init', function() { .focus(); } - rcmail.register_command('plugin.inbox_keys_generate', () => rcmail.inbox_keys_generate(), false); + rcmail.register_command('plugin.inbox_keys_generate', () => rcmail.inbox_keys_generate(), true); rcmail.register_command('plugin.inbox_keys_import', () => rcmail.inbox_keys_import(), true); rcmail.register_command('plugin.inbox_keys_delete', () => rcmail.inbox_keys_delete(), false); } @@ -24,8 +24,31 @@ rcube_webmail.prototype.inbox_keys_select = function(list) { }; rcube_webmail.prototype.inbox_keys_generate = function() { - // TODO: generate the key client-side and post it to the import endpoint, - // TODO: then redirect the client to download the generated private key + var userIDs = [], passphrase; + var comment = 'Generated ' + (new Date()).toLocaleDateString(); + var generating_message = this.display_message( + this.get_label('inbox_settings.generating_key'), 'loading'); + openpgp.generateKey( + { + type: 'ecc', + curve: 'curve25519', + userIDs, + passphrase, + format: 'armored' + }).then(generated => { + this.hide_message(generating_message); + var lock = this.display_message( + this.get_label('inbox_settings.importing_key'), 'loading'); + this.addEventListener('responseafter', () => { + location.href = + 'data:application/pgp-keys;base64,' + btoa(generated.privateKey); + this.reload(2000); + }); + this.http_post( + 'plugin.inbox_keys_import', + {import: true, key_data: generated.publicKey, comment}, + lock); + }); }; rcube_webmail.prototype.inbox_keys_import = function() { @@ -42,25 +65,7 @@ rcube_webmail.prototype.inbox_keys_delete = function() { function(_evt, ref) { var lock = ref.display_message( ref.get_label('inbox_settings.deleting_key', 'loading')); - ref.addEventListener('responseafter', () => ref.reload(3000)); + ref.addEventListener('responseafter', () => ref.reload(2000)); ref.http_post('plugin.inbox_keys_delete', {keys}, lock); }); }; - -rcube_webmail.prototype.inbox_keys_loadframe = function(url) { - var win; - if (win = this.get_frame_window(this.env.contentframe)) { - if (!url) { - if (win.location && win.location.href.indexOf(this.env.blankpage) < 0) { - win.location.href = this.env.blankpage; - } - if (this.env.frame_lock) { - this.set_busy(false, null, this.env.frame_lock); - } - return; - } - - this.env.frame_lock = this.set_busy(true, 'loading'); - win.location.href = this.env.comm_path + '&_framed=1' + url; - } -}; |
