Changeset 5439:d8bbdcd01ec4
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r5437
|
r5439
|
|
| 1 | | 2008-07-01 13:32 -0700 Brendan Cully <brendan@kublai.com> (17525e17fa7b) |
| | 1 | 2008-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. |
| 2 | 13 | |
| 3 | 14 | * copy.c: Bail out of copy if decryption is requested but the desired |
-
|
r5438
|
r5439
|
|
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | | static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp) |
| | 1841 | static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun) |
| 1842 | 1842 | { |
| 1843 | 1843 | /* there's no side-effect free way to view key data in GPGME, |
| … |
… |
|
| 1857 | 1857 | int rc = -1; |
| 1858 | 1858 | |
| 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 | | |
| 1866 | 1859 | if ((err = gpgme_new (&tmpctx)) != GPG_ERR_NO_ERROR) |
| 1867 | 1860 | { |
| 1868 | 1861 | dprint (1, (debugfile, "Error creating GPGME context\n")); |
| 1869 | | goto err_tmpdir; |
| | 1862 | return rc; |
| 1870 | 1863 | } |
| 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) |
| 1876 | 1866 | { |
| 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 | } |
| 1887 | 1890 | } |
| 1888 | 1891 | |
| … |
… |
|
| 1890 | 1893 | { |
| 1891 | 1894 | dprint (1, (debugfile, "Error importing key\n")); |
| 1892 | | goto err_ctx; |
| | 1895 | goto err_tmpdir; |
| 1893 | 1896 | } |
| 1894 | 1897 | |
| … |
… |
|
| 1898 | 1901 | { |
| 1899 | 1902 | mutt_perror (tmpfile); |
| 1900 | | goto err_ctx; |
| | 1903 | goto err_tmpdir; |
| 1901 | 1904 | } |
| 1902 | 1905 | unlink (tmpfile); |
| … |
… |
|
| 1945 | 1948 | *fp = NULL; |
| 1946 | 1949 | } |
| | 1950 | err_tmpdir: |
| | 1951 | if (dryrun) |
| | 1952 | mutt_rmtree (tmpdir); |
| 1947 | 1953 | err_ctx: |
| 1948 | 1954 | gpgme_release (tmpctx); |
| 1949 | | err_tmpdir: |
| 1950 | | mutt_rmtree (tmpdir); |
| 1951 | 1955 | |
| 1952 | 1956 | return rc; |
| … |
… |
|
| 2033 | 2037 | } |
| 2034 | 2038 | 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. */ |
| | 2043 | void 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")); |
| 2035 | 2070 | } |
| 2036 | 2071 | |
| … |
… |
|
| 2180 | 2215 | if (pgp_keyblock) |
| 2181 | 2216 | { |
| 2182 | | pgp_gpgme_extract_keys (armored_data, &pgpout); |
| | 2217 | pgp_gpgme_extract_keys (armored_data, &pgpout, 1); |
| 2183 | 2218 | } |
| 2184 | 2219 | else if (!clearsign || (s->flags & M_VERIFY)) |
-
|
r4917
|
r5439
|
|
| 35 | 35 | |
| 36 | 36 | int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only); |
| | 37 | void pgp_gpgme_invoke_import (const char* fname); |
| 37 | 38 | |
| 38 | 39 | int pgp_gpgme_application_handler (BODY *m, STATE *s); |
-
|
r4917
|
r5439
|
|
| 66 | 66 | } |
| 67 | 67 | |
| | 68 | static void crypt_mod_pgp_invoke_import (const char *fname) |
| | 69 | { |
| | 70 | pgp_gpgme_invoke_import (fname); |
| | 71 | } |
| | 72 | |
| 68 | 73 | static char *crypt_mod_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) |
| 69 | 74 | { |
| … |
… |
|
| 118 | 123 | NULL, /* pgp_traditional_encryptsign */ |
| 119 | 124 | NULL, /* pgp_invoke_getkeys */ |
| 120 | | NULL, /* pgp_invoke_import */ |
| | 125 | crypt_mod_pgp_invoke_import, |
| 121 | 126 | NULL, /* pgp_extract_keys_from_attachment_list */ |
| 122 | 127 | |