/[gpgoe]/trunk/src/OECrypto.c
ViewVC logotype

Diff of /trunk/src/OECrypto.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by twoaday, Sun Mar 26 10:39:09 2006 UTC revision 10 by twoaday, Mon Mar 27 12:47:50 2006 UTC
# Line 34  enum { Line 34  enum {
34      PGP_CLEARSIG     =  2,            PGP_CLEARSIG     =  2,      
35      PGP_SIG          =  4,      PGP_SIG          =  4,
36      PGP_KEY          =  8,      PGP_KEY          =  8,
     PGP_DASH_ESCAPED = 32  
37  };  };
38    
39    
40  /* Move the keyboard focus to the message window to copy  /* Move the keyboard focus to the message window
41     the text to the clipboard. */     to copy the text to the clipboard. */
42  static void  static void
43  set_focus (HWND main)  set_focus (HWND main)
44  {        {      
# Line 73  window_get_message (HWND main_hwnd) Line 72  window_get_message (HWND main_hwnd)
72      SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_SELECTALL, 0), 0);      SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_SELECTALL, 0), 0);
73      SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_COPY, 0), 0);      SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_COPY, 0), 0);
74    
75        /* even so SendMessage() should wait, we wait for safety reasons. */
76      Sleep (200);      Sleep (200);
77        return get_clip_text (NULL);
     return get_clip_text (NULL);;  
78  }  }
79    
80    
# Line 189  parse_recipients (plugin_ctx_t ctx, reci Line 188  parse_recipients (plugin_ctx_t ctx, reci
188  }  }
189    
190    
191  /* Fill in the key part of the recipient list if possible. */  /* Fill in the key part of the recipient list @addrs if possible. */
192  static int  static int
193  get_keys_from_addresses (recip_list_t addrs)  get_keys_from_addresses (recip_list_t addrs)
194  {  {
# Line 216  get_keys_from_addresses (recip_list_t ad Line 215  get_keys_from_addresses (recip_list_t ad
215          err = gpgme_op_keylist_next (ctx, &pk);          err = gpgme_op_keylist_next (ctx, &pk);
216          if (err)          if (err)
217              break;              break;
218            /* do not add invalid keys. */
219          if (pk->disabled || pk->expired || pk->revoked)          if (pk->disabled || pk->expired || pk->revoked)
220              continue;              continue;
221          fnd = find_recipient (addrs, pk);          fnd = find_recipient (addrs, pk);
# Line 246  map_gpgme_data (gpgme_data_t out, char * Line 246  map_gpgme_data (gpgme_data_t out, char *
246  }  }
247    
248    
   
   
   
249  /* Try to extract the needed key information and retrieve  /* Try to extract the needed key information and retrieve
250     the keys if possible. */     the keys if possible. */
251  static gpgme_error_t  static gpgme_error_t
# Line 268  get_keys (plugin_ctx_t ctx, recip_list_t Line 265  get_keys (plugin_ctx_t ctx, recip_list_t
265          rcount += parse_recipients (ctx, &addrs, ctx->bcc);          rcount += parse_recipients (ctx, &addrs, ctx->bcc);
266    
267      nkeys = get_keys_from_addresses (addrs);      nkeys = get_keys_from_addresses (addrs);
268        /* at least some keys were not found, so we offer to select them. */
269      if (nkeys != rcount) {      if (nkeys != rcount) {
270          ctx->rset = addrs;          ctx->rset = addrs;
271          rcount = DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_ENCRYPT,          rcount = DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_ENCRYPT,
# Line 289  get_keys (plugin_ctx_t ctx, recip_list_t Line 287  get_keys (plugin_ctx_t ctx, recip_list_t
287  }  }
288    
289    
290  /* For this function we think that the clipboard contains the data which  /* Encrypt the given message @r_msg with the recipients from the
291     should be encrypted.     To, Cc, Bcc fields. In case that a recipient was not found
292     After all recipient headers are converted to valid GPG recipients the     use the recipient dialog so the user can select the missing keys. */
    message is encrypted. In the case that the OE recipients are not  
    available in the GPG keyring, an keylist is shown. */  
293  static gpgme_error_t  static gpgme_error_t
294  encrypt_msg (plugin_ctx_t ctx, char **r_msg)  encrypt_msg (plugin_ctx_t ctx, char **r_msg)
295  {  {
# Line 302  encrypt_msg (plugin_ctx_t ctx, char **r_ Line 298  encrypt_msg (plugin_ctx_t ctx, char **r_
298      gpgme_ctx_t gctx = NULL;      gpgme_ctx_t gctx = NULL;
299      gpgme_data_t in = NULL, out = NULL;      gpgme_data_t in = NULL, out = NULL;
300      recip_list_t list = NULL;      recip_list_t list = NULL;
301      int ec = 0, nkeys=0;      int nkeys=0;
302      char *msg = *r_msg;      char *msg = *r_msg;
303    
304      assert (ctx);      assert (ctx);
305    
306      ec = get_keys (ctx, &list, &keys, &nkeys);      err = get_keys (ctx, &list, &keys, &nkeys);
307      if (ec)      if (err)
308          return ec;          return err;
309    
310      err = gpgme_new (&gctx);      err = gpgme_new (&gctx);
311      if (!err)      if (!err)
# Line 319  encrypt_msg (plugin_ctx_t ctx, char **r_ Line 315  encrypt_msg (plugin_ctx_t ctx, char **r_
315      if (!err) {      if (!err) {
316          gpgme_set_armor (gctx, 1);          gpgme_set_armor (gctx, 1);
317          gpgme_set_textmode (gctx, 1);          gpgme_set_textmode (gctx, 1);
318          err = gpgme_op_encrypt (gctx, keys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);          err = gpgme_op_encrypt (gctx, keys,
319                                    GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
320      }      }
321    
322      gpgme_release (gctx);      gpgme_release (gctx);
# Line 327  encrypt_msg (plugin_ctx_t ctx, char **r_ Line 324  encrypt_msg (plugin_ctx_t ctx, char **r_
324      release_recipient (list);      release_recipient (list);
325      free (keys);      free (keys);
326    
327      if (err) {      if (err)
328          gpgme_data_release (out);          gpgme_data_release (out);
329          return err;      else
330      }          map_gpgme_data (out, r_msg);
331        return err;
     map_gpgme_data (out, r_msg);  
     return 0;  
332  }  }
333    
334    
335    /* Sign the message given in @r_msg with the GPG default key. */
336  static gpgme_error_t  static gpgme_error_t
337  sign_msg (plugin_ctx_t ctx, char **r_msg)  sign_msg (plugin_ctx_t ctx, char **r_msg)
338  {  {
# Line 361  sign_msg (plugin_ctx_t ctx, char **r_msg Line 357  sign_msg (plugin_ctx_t ctx, char **r_msg
357      gpgme_data_release (in);      gpgme_data_release (in);
358      free_pass_cb (cb_val);      free_pass_cb (cb_val);
359    
360      if (err) {      if (err)
361          gpgme_data_release (out);          gpgme_data_release (out);
362          return err;      else
363      }          map_gpgme_data (out, r_msg);
   
     map_gpgme_data (out, r_msg);  
364    
365      return 0;      return err;
366  }  }
367    
368    
369    /* Sign and encrypt the message @r_msg. */
370  static gpgme_error_t  static gpgme_error_t
371  sign_encrypt_msg (plugin_ctx_t ctx, char **r_msg)  sign_encrypt_msg (plugin_ctx_t ctx, char **r_msg)
372  {  {
# Line 408  sign_encrypt_msg (plugin_ctx_t ctx, char Line 403  sign_encrypt_msg (plugin_ctx_t ctx, char
403      free (keys);      free (keys);
404      free_pass_cb (cb_val);      free_pass_cb (cb_val);
405    
406      if (err) {      if (err)
407          gpgme_data_release (out);          gpgme_data_release (out);
408          return err;      else
409      }          map_gpgme_data (out, r_msg);
410        return err;
     map_gpgme_data (out, r_msg);  
     return 0;  
411  }  }
412    
413    
# Line 443  verify_msg (plugin_ctx_t ctx, char **r_m Line 436  verify_msg (plugin_ctx_t ctx, char **r_m
436    
437      gpgme_release (gctx);      gpgme_release (gctx);
438      gpgme_data_release (sig);      gpgme_data_release (sig);
439      map_gpgme_data (out, r_msg);      
440        if (!err)
441            map_gpgme_data (out, r_msg);
442        else
443            gpgme_data_release (out);
444      return err;      return err;
445  }  }
446    
# Line 487  store_decrypt_info (char *buf, size_t bu Line 483  store_decrypt_info (char *buf, size_t bu
483  }  }
484    
485    
486  /* For this function we think that the clipboard contains the data which  /* Decrypt the message @r_msg. If the type @type is actually a signature,
487     should be encrypted.     the verify function is called instead of decryption. */
    Actually the functions can differ between the various PGP messages.  
    In the case encrypted data is detected, it tries to decrypt it  
    with a passphrase callback which is equal to the signing procedure.  
    The other possibility is that the data is a clearsigned signature.  
    Then the signature is verified and the status is shown. */  
488  static gpgme_error_t  static gpgme_error_t
489  decrypt_msg (plugin_ctx_t ctx, char **r_msg, int type)  decrypt_msg (plugin_ctx_t ctx, char **r_msg, int type)
490  {  {
# Line 501  decrypt_msg (plugin_ctx_t ctx, char **r_ Line 492  decrypt_msg (plugin_ctx_t ctx, char **r_
492      gpgme_data_t in = NULL, out = NULL;      gpgme_data_t in = NULL, out = NULL;
493      gpgme_error_t err;      gpgme_error_t err;
494      gpgme_verify_result_t res;      gpgme_verify_result_t res;
       
495      pass_cb_t cb_val;      pass_cb_t cb_val;
496      char *msg = *r_msg;      char *msg = *r_msg;
     char *p;  
     size_t len;  
497    
498      if ((type & PGP_SIG) || (type & PGP_CLEARSIG))      if ((type & PGP_SIG) || (type & PGP_CLEARSIG))
499          return verify_msg (ctx, r_msg);          return verify_msg (ctx, r_msg);
# Line 534  decrypt_msg (plugin_ctx_t ctx, char **r_ Line 522  decrypt_msg (plugin_ctx_t ctx, char **r_
522      gpgme_data_release (in);      gpgme_data_release (in);
523      free_pass_cb (cb_val);      free_pass_cb (cb_val);
524            
525      if (err) {      if (err)
526          gpgme_data_release (out);          gpgme_data_release (out);
527          return err;      else
528      }          map_gpgme_data (out, r_msg);
   
     p = gpgme_data_release_and_get_mem (out, &len);  
     free_if_alloc (msg);  
     *r_msg = xcalloc (1, len+1);  
     memcpy (*r_msg, p, len);  
     gpgme_free (p);  
529    
530      return 0;      return err;
531  }  }
532    
533    
# Line 573  gpgme_error_t Line 555  gpgme_error_t
555  oe_handle_mail (plugin_ctx_t ctx)  oe_handle_mail (plugin_ctx_t ctx)
556  {  {
557      gpgme_error_t rc = 0;      gpgme_error_t rc = 0;
558      char *msg = NULL;      char *msg;
559      int msg_type = 0;      int msg_type = 0;
560    
561      assert (ctx);      assert (ctx);

Legend:
Removed from v.6  
changed lines
  Added in v.10

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26