Changeset 5439:d8bbdcd01ec4

Show
Ignore:
Timestamp:
2008-07-01 17:57:37 (3 months ago)
Author:
Brendan Cully <brendan@…>
Branch:
HEAD
Message:

Stub in a gpgme version of extract-keys. It doesn't currently work
right because apparently while gpg on the command line can parse a
whole message, we'll have to do it for gpgme. I really wonder about
the 'ME' part of GPGME sometimes.

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5437 r5439  
    1 2008-07-01 13:32 -0700  Brendan Cully  <brendan@kublai.com>  (17525e17fa7b) 
     12008-07-01 17:20 -0700  Brendan Cully  <brendan@kublai.com>  (8e2438ec5909) 
     2 
     3        * crypt-gpgme.c, lib.c, lib.h: Support displaying application/pgp-keys 
     4        with GPGME. This was pretty convoluted because GPGME provides no way 
     5        to examine a key block without importing it. This code creates a 
     6        temporary GPG home in which to import the key in order to display 
     7        it. 
     8 
     9        * crypt-gpgme.c, handler.c, pgp.c: Handle DONTHANDLEPGPKEYS in 
     10        handler instead of crypto modules. This lets gpgme and classic pgp 
     11        share a bit of logic, and unbreaks key extraction at least for 
     12        classic PGP. 
    213 
    314        * copy.c: Bail out of copy if decryption is requested but the desired 
  • crypt-gpgme.c

    r5438 r5439  
    18391839} 
    18401840 
    1841 static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp) 
     1841static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun) 
    18421842{ 
    18431843  /* there's no side-effect free way to view key data in GPGME, 
     
    18571857  int rc = -1; 
    18581858 
    1859   snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", Tempdir); 
    1860   if (!mkdtemp (tmpdir)) 
    1861   { 
    1862     dprint (1, (debugfile, "Error creating temporary GPGME home\n")); 
    1863     return rc; 
    1864   } 
    1865  
    18661859  if ((err = gpgme_new (&tmpctx)) != GPG_ERR_NO_ERROR) 
    18671860  { 
    18681861    dprint (1, (debugfile, "Error creating GPGME context\n")); 
    1869     goto err_tmpdir; 
     1862    return rc; 
    18701863  } 
    1871  
    1872   engineinfo = gpgme_ctx_get_engine_info (tmpctx); 
    1873   while (engineinfo && engineinfo->protocol != GPGME_PROTOCOL_OpenPGP) 
    1874     engineinfo = engineinfo->next; 
    1875   if (!engineinfo) 
     1864   
     1865  if (dryrun) 
    18761866  { 
    1877     dprint (1, (debugfile, "Error finding GPGME PGP engine\n")); 
    1878     goto err_ctx; 
    1879   } 
    1880    
    1881   err = gpgme_ctx_set_engine_info (tmpctx, GPGME_PROTOCOL_OpenPGP, 
    1882                                    engineinfo->file_name, tmpdir); 
    1883   if (err != GPG_ERR_NO_ERROR) 
    1884   { 
    1885     dprint (1, (debugfile, "Error setting GPGME context home\n")); 
    1886     goto err_ctx; 
     1867    snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", Tempdir); 
     1868    if (!mkdtemp (tmpdir)) 
     1869    { 
     1870      dprint (1, (debugfile, "Error creating temporary GPGME home\n")); 
     1871      goto err_ctx; 
     1872    } 
     1873 
     1874    engineinfo = gpgme_ctx_get_engine_info (tmpctx); 
     1875    while (engineinfo && engineinfo->protocol != GPGME_PROTOCOL_OpenPGP) 
     1876      engineinfo = engineinfo->next; 
     1877    if (!engineinfo) 
     1878    { 
     1879      dprint (1, (debugfile, "Error finding GPGME PGP engine\n")); 
     1880      goto err_tmpdir; 
     1881    } 
     1882 
     1883    err = gpgme_ctx_set_engine_info (tmpctx, GPGME_PROTOCOL_OpenPGP, 
     1884                                     engineinfo->file_name, tmpdir); 
     1885    if (err != GPG_ERR_NO_ERROR) 
     1886    { 
     1887      dprint (1, (debugfile, "Error setting GPGME context home\n")); 
     1888      goto err_tmpdir; 
     1889    } 
    18871890  } 
    18881891 
     
    18901893  { 
    18911894    dprint (1, (debugfile, "Error importing key\n")); 
    1892     goto err_ctx; 
     1895    goto err_tmpdir; 
    18931896  } 
    18941897 
     
    18981901  { 
    18991902    mutt_perror (tmpfile); 
    1900     goto err_ctx; 
     1903    goto err_tmpdir; 
    19011904  } 
    19021905  unlink (tmpfile); 
     
    19451948    *fp = NULL; 
    19461949  } 
     1950err_tmpdir: 
     1951  if (dryrun) 
     1952    mutt_rmtree (tmpdir); 
    19471953err_ctx: 
    19481954  gpgme_release (tmpctx); 
    1949 err_tmpdir: 
    1950   mutt_rmtree (tmpdir); 
    19511955 
    19521956  return rc; 
     
    20332037  } 
    20342038  return rv; 
     2039} 
     2040 
     2041/* TODO: looks like this won't work and we'll have to fully parse the 
     2042 * message file. GPGME makes life hard yet again. */ 
     2043void pgp_gpgme_invoke_import (const char *fname) 
     2044{ 
     2045  gpgme_data_t keydata; 
     2046  gpgme_error_t err; 
     2047  FILE* in; 
     2048  FILE* out; 
     2049  long outlen; 
     2050 
     2051  if (!(in = safe_fopen (fname, "r"))) 
     2052    return; 
     2053  if ((err = gpgme_data_new_from_stream (&keydata, in)) != GPG_ERR_NO_ERROR) 
     2054  { 
     2055    dprint (1, (debugfile, "error converting key file into data object\n")); 
     2056    return; 
     2057  } 
     2058  fclose (in); 
     2059 
     2060  if (!pgp_gpgme_extract_keys (keydata, &out, 0)) 
     2061  { 
     2062    /* display import results */ 
     2063    outlen = ftell (out); 
     2064    fseek (out, 0, SEEK_SET); 
     2065    mutt_copy_bytes (out, stdout, outlen); 
     2066    fclose (out); 
     2067  } 
     2068  else 
     2069    printf (_("Error extracting key data!\n")); 
    20352070} 
    20362071 
     
    21802215          if (pgp_keyblock) 
    21812216          { 
    2182             pgp_gpgme_extract_keys (armored_data, &pgpout); 
     2217            pgp_gpgme_extract_keys (armored_data, &pgpout, 1); 
    21832218          } 
    21842219          else if (!clearsign || (s->flags & M_VERIFY)) 
  • crypt-gpgme.h

    r4917 r5439  
    3535 
    3636int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only); 
     37void pgp_gpgme_invoke_import (const char* fname); 
    3738 
    3839int pgp_gpgme_application_handler (BODY *m, STATE *s); 
  • crypt-mod-pgp-gpgme.c

    r4917 r5439  
    6666} 
    6767 
     68static void crypt_mod_pgp_invoke_import (const char *fname) 
     69{ 
     70  pgp_gpgme_invoke_import (fname); 
     71} 
     72 
    6873static char *crypt_mod_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) 
    6974{ 
     
    118123      NULL,                     /* pgp_traditional_encryptsign  */ 
    119124      NULL, /* pgp_invoke_getkeys  */ 
    120       NULL, /* pgp_invoke_import  */ 
     125      crypt_mod_pgp_invoke_import, 
    121126      NULL, /* pgp_extract_keys_from_attachment_list  */ 
    122127