@@ -66,7 +66,7 @@ if(window.rcmail) {
66
66
if ( rcmail . env . action === "compose" ) {
67
67
rcmail . env . compose_commands . push ( 'open-key-manager' ) ;
68
68
rcmail . addEventListener ( "beforesend" , function ( e ) { if ( ! beforeSend ( ) ) { return false ; } } ) ;
69
- $ ( "#composebuttons" ) . prepend ( "<input id='openpgpjs_encrypt' type='checkbox' checked='checked' /> " + rcmail . gettext ( 'encrypt' , 'rc_openpgpjs' ) + " <input id='openpgpjs_sign' type='checkbox' disabled='disabled ' /> " + rcmail . gettext ( 'sign' , 'rc_openpgpjs' ) + "" ) ;
69
+ $ ( "#composebuttons" ) . prepend ( "<input id='openpgpjs_encrypt' type='checkbox' /> " + rcmail . gettext ( 'encrypt' , 'rc_openpgpjs' ) + " <input id='openpgpjs_sign' type='checkbox' checked='checked ' /> " + rcmail . gettext ( 'sign' , 'rc_openpgpjs' ) + "" ) ;
70
70
} else if ( rcmail . env . action === 'show' || rcmail . env . action === "preview" ) {
71
71
processReceived ( ) ;
72
72
}
@@ -81,9 +81,14 @@ if(window.rcmail) {
81
81
return ;
82
82
}
83
83
84
+ // msg[0].type: 2 == signed only
85
+ // msg[0].type: 3 == encrypted only
86
+
84
87
showKeyInfo ( msg ) ;
85
88
86
- // Successfully parsed OpenPGP message
89
+ // TODO fix signature verification
90
+ if ( msg [ 0 ] . type === 2 ) return ;
91
+
87
92
if ( ! openpgp . keyring . hasPrivateKey ( ) ) {
88
93
rcmail . display_message ( rcmail . gettext ( 'no_key_imported' , 'rc_openpgpjs' ) , "error" ) ;
89
94
return false ;
@@ -198,54 +203,14 @@ if(window.rcmail) {
198
203
199
204
$ ( '#key_select_error' ) . addClass ( "hidden" ) ;
200
205
$ ( '#openpgpjs_key_select' ) . dialog ( 'close' ) ;
201
- }
202
-
203
- function sign ( encrypt ) {
204
- if ( this . passphrase === "" && openpgp . keyring . privateKeys . length > 0 )
205
- {
206
- $ ( "#openpgpjs_key_select" ) . dialog ( 'open' ) ;
207
- return false ;
208
- } else if ( ! encrypt && openpgp . keyring . privateKeys . length === 0 ) {
209
- alert ( rcmail . gettext ( 'no_keys' , 'rc_openpgpjs' ) ) ;
210
- return false ;
211
- } else if ( openpgp . keyring . privateKeys . length === 0 || openpgp . keyring . publicKeys . length === 0 ) {
212
- alert ( rcmail . gettext ( 'no_keys' , 'rc_openpgpjs' ) ) ;
213
- return false ;
214
- }
215
206
216
- passobj = JSON . parse ( this . passphrase ) ;
217
- var keyid = openpgp . keyring . privateKeys [ passobj . id ] . obj . getKeyId ( ) ;
218
- var privkey_armored = openpgp . keyring . getPrivateKeyForKeyId ( keyid ) [ 0 ] . key . armored ;
219
- var priv_key = openpgp . read_privateKey ( privkey_armored ) ;
220
-
221
- if ( ! priv_key [ 0 ] . decryptSecretMPIs ( passobj . passphrase ) ) {
222
- alert ( rcmail . gettext ( 'incorrect_pass' , 'rc_openpgpjs' ) ) ;
223
- }
224
-
225
- if ( ! encrypt ) {
226
- signed = openpgp . write_signed_message ( priv_key [ 0 ] , $ ( "textarea#composebody" ) . val ( ) ) ;
227
- if ( signed ) {
228
- return signed ;
229
- }
230
- }
231
-
232
- var pubkeys = new Array ( ) ;
233
- var recipients = $ ( "#_to" ) . val ( ) . split ( "," ) ;
234
-
235
- for ( var i = 0 ; i < recipients . length ; i ++ ) {
236
- var recipient = recipients [ i ] . replace ( / ( .+ ?< ) / , '' ) . replace ( / > / , '' ) ;
237
- var pubkey = openpgp . keyring . getPublicKeyForAddress ( recipient ) ;
238
- pubkeys . push ( pubkey [ 0 ] . obj ) ;
239
- // TODO: For some reason signing can only be made with one recipient pubkey, gotta investigate
240
- break ;
241
- }
242
-
243
- signed = openpgp . write_signed_and_encrypted_message ( priv_key [ 0 ] , pubkey [ 0 ] . obj , $ ( "textarea#composebody" ) . val ( ) ) ;
244
- if ( signed ) {
245
- return signed ;
246
- }
247
-
248
- return false ;
207
+ // This is required when sending emails and private keys are required for
208
+ // sending an email (when signing a message). These lines makes the client
209
+ // jump right back into beforeSend() allowing key sign and message send to
210
+ // be made as soon as the passphrase is correct and available.
211
+ if ( typeof ( this . sendmail ) !== "undefined" ) {
212
+ rcmail . command ( 'send' , '' , this , event )
213
+ }
249
214
}
250
215
251
216
function fetchRecipientPubkeys ( ) {
@@ -287,16 +252,16 @@ if(window.rcmail) {
287
252
}
288
253
289
254
function beforeSend ( ) {
290
- if ( ! $ ( "#openpgpjs_encrypt" ) . is ( ":checked" ) &&
291
- ! $ ( "#openpgpjs_sign" ) . is ( "checked" ) ) {
292
- return true ;
293
- }
255
+ if ( ! $ ( "#openpgpjs_encrypt" ) . is ( ":checked" ) &&
256
+ ! $ ( "#openpgpjs_sign" ) . is ( ": checked" ) ) {
257
+ return true ;
258
+ }
294
259
295
260
if ( typeof ( this . finished_treating ) !== "undefined" ) {
296
261
return true ;
297
262
}
298
263
299
- // Only encrypt, don't sign
264
+ // Encrypt only
300
265
if ( $ ( "#openpgpjs_encrypt" ) . is ( ":checked" ) &&
301
266
! $ ( "#openpgpjs_sign" ) . is ( ":checked" ) ) {
302
267
// Fetch recipient pubkeys
@@ -311,9 +276,43 @@ if(window.rcmail) {
311
276
this . finished_treating = 1 ;
312
277
return true ;
313
278
}
279
+ }
280
+
281
+ // Sign only
282
+ if ( $ ( "#openpgpjs_sign" ) . is ( ":checked" ) &&
283
+ ! $ ( "#openpgpjs_encrypt" ) . is ( ":checked" ) ) {
284
+
285
+ if ( this . passphrase === "" &&
286
+ openpgp . keyring . privateKeys . length > 0 ) {
287
+ this . sendmail = true ; // Global var to notify set_passphrase
288
+ $ ( "#openpgpjs_key_select" ) . dialog ( 'open' ) ;
289
+ return false ;
290
+ }
291
+
292
+ if ( openpgp . keyring . privateKeys . length === 0 ) {
293
+ alert ( rcmail . gettext ( 'no_keys' , 'rc_openpgpjs' ) ) ;
294
+ return false ;
295
+ }
296
+
297
+ var passobj = JSON . parse ( this . passphrase ) ;
298
+ var keyid = openpgp . keyring . privateKeys [ passobj . id ] . obj . getKeyId ( ) ;
299
+ var privkey_armored = openpgp . keyring . getPrivateKeyForKeyId ( keyid ) [ 0 ] . key . armored ;
300
+ var privkey = openpgp . read_privateKey ( privkey_armored ) ;
301
+
302
+ if ( ! privkey [ 0 ] . decryptSecretMPIs ( passobj . passphrase ) ) {
303
+ alert ( "WRONG PASS" ) ;
304
+ }
305
+
306
+ signed = openpgp . write_signed_message ( privkey [ 0 ] , "hej" ) ;
307
+
308
+ if ( signed ) {
309
+ $ ( "textarea#composebody" ) . val ( signed ) ;
310
+ return true ;
311
+ }
314
312
315
313
return false ;
316
314
}
315
+
317
316
return false ;
318
317
}
319
318
0 commit comments