## Use aclocal -I m4; automake --foreign
AUTOMAKE_OPTIONS = foreign
-EXTRA_PROGRAMS = madmutt_dotlock pgpringng pgpewrapng makedoc
+EXTRA_PROGRAMS = madmutt_dotlock makedoc
if BUILD_NNTP
NNTP_SUBDIR = nntp
BUILT_SOURCES = keymap_defs.h charset.gperf
DISTCLEANFILES = $(BUILT_SOURCES)
-bin_PROGRAMS = madmutt madmutt_dotlock pgpringng pgpewrapng smime_keysng
+bin_PROGRAMS = madmutt madmutt_dotlock smime_keysng
madmutt_SOURCES = $(BUILT_SOURCES) \
alias.c attach.c base64.c browser.c buffy.c charset.c commands.c \
compose.c copy.c editmsg.c init.c keymap.c lib.c \
recvattach.h handler.h thread.h globals.h init.h keymap.h \
mime.h mutt.h mutt_sasl.h pager.h protos.h \
sort.h mime.types autogen.sh remailer.c remailer.h browser.h state.h \
- lib.h extlib.c pgpewrap.c smime_keys.pl Madmuttrc.head Madmuttrc \
+ lib.h smime_keys.pl Madmuttrc.head Madmuttrc \
makedoc.c stamp-doc-rc README.SSL depcomp mutt_idna.h mutt_libesmtp.h
madmutt_dotlock_SOURCES = dotlock.c
madmutt_dotlock_LDADD = -Llib-lib -llib @LIBOBJS@
madmutt_dotlock_DEPENDENCIES = @LIBOBJS@ $(top_builddir)/lib-lib/liblib.a
-pgpringng_SOURCES = pgppubring.c lib.c extlib.c
-pgpringng_LDADD = @LIBOBJS@ $(INTLLIBS) \
- -Llib-lib -llib -Llib-hash -lhash -Llib-crypt -lcrypt
-pgpringng_DEPENDENCIES = @LIBOBJS@ $(INTLDEPS) \
- $(top_builddir)/lib-lib/liblib.a \
- $(top_builddir)/lib-hash/libhash.a
-
-pgpewrapng_SOURCES = pgpewrap.c
-pgpewrapng_LDADD =
-pgpewrapng_DEPENDENCIES =
-
CLEANFILES = stamp-doc-rc makedoc keymap_defs.h Madmuttrc
ACLOCAL_AMFLAGS = -I m4
AM_PATH_GPGME(,,[AC_MSG_ERROR(GPGME not found)])
MUTTLIBS="$MUTTLIBS $GPGME_LIBS"
AC_DEFINE(CRYPT_BACKEND_GPGME, 1, [Defined, if GPGME support is enabled])
- AM_CONDITIONAL(BUILD_GPGME, true)
else
- AM_CONDITIONAL(BUILD_GPGME, false)
+ AC_MSG_ERROR([could not find gpgme])
fi
])
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- * Some simple dummies, so we can reuse the routines from
- * lib.c in external programs.
- */
-
-#define WHERE
-#define _EXTLIB_C
-
-#include <lib-lib/lib-lib.h>
-#include "lib.h"
-
-void (*mutt_error)(const char *, ...)
- __attribute__((format(printf, 1, 2))) = mutt_nocurses_error;
-
-void mutt_exit (int code)
-{
- exit (code);
-}
** will be saved for later references. Also see ``$$record'',
** ``$$save_name'', ``$$force_name'' and ``$fcc-hook''.
*/
- {"crypt_use_gpgme", DT_BOOL, R_NONE, OPTCRYPTUSEGPGME, "no" },
- /*
- ** .pp
- ** This variable controls the use the GPGME enabled crypto backends.
- ** If it is \fIset\fP and Madmutt was build with gpgme support, the gpgme code for
- ** S/MIME and PGP will be used instead of the classic code.
- ** .pp
- ** \fBNote\fP: You need to use this option in your \fT.madmuttrc\fP configuration
- ** file as it won't have any effect when used interactively.
- */
{"crypt_autopgp", DT_BOOL, R_NONE, OPTCRYPTAUTOPGP, "yes" },
/*
** .pp
create_bindings (OpAlias, MENU_ALIAS);
create_bindings (OpPgp, MENU_PGP);
create_bindings (OpSmime, MENU_SMIME);
-
-#ifdef CRYPT_BACKEND_GPGME
create_bindings (OpPgp, MENU_KEY_SELECT_PGP);
create_bindings (OpSmime, MENU_KEY_SELECT_SMIME);
-#endif
-
create_bindings (OpMix, MENU_MIX);
km_bindkey ("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
return OpQuery;
case MENU_PGP:
return OpPgp;
-
-#ifdef CRYPT_BACKEND_GPGME
case MENU_KEY_SELECT_PGP:
return OpPgp;
case MENU_KEY_SELECT_SMIME:
return OpSmime;
-#endif
-
case MENU_MIX:
return OpMix;
}
MENU_QUERY,
MENU_PGP,
MENU_SMIME,
-
-#ifdef CRYPT_BACKEND_GPGME
MENU_KEY_SELECT_PGP,
MENU_KEY_SELECT_SMIME,
-#endif
-
MENU_MIX,
MENU_MAX
};
noinst_LIBRARIES = libcrypt.a
-if BUILD_GPGME
-GPGME_THINGS = crypt-gpgme.h crypt-gpgme.c crypt-mod-pgp-gpgme.c crypt-mod-smime-gpgme.c
-endif
+libcrypt_a_SOURCES = smime.h crypt.h crypt-mod.h \
+ smime.c crypt.c crypt-mod.c \
+ cryptglue.c \
+ crypt-gpgme.h crypt-gpgme.c crypt-mod-pgp-gpgme.c crypt-mod-smime-gpgme.c
-
-libcrypt_a_SOURCES = pgp.h pgplib.h pgppacket.h smime.h crypt.h crypt-mod.h \
- pgp.c pgplib.c pgppacket.c smime.c crypt.c crypt-mod.c \
- gnupgparse.c pgpinvoke.c pgpkey.c pgpmicalg.c \
- cryptglue.c crypt-mod-pgp-classic.c crypt-mod-smime-classic.c \
- $(GPGME_THINGS)
-
-noinst_HEADERS = pgp.h pgplib.h pgppacket.h smime.h crypt.h crypt-mod.h \
- crypt-gpgme.h
+noinst_HEADERS = smime.h crypt.h crypt-mod.h crypt-gpgme.h
-include $(top_builddir)/tools/cflags.mk
#include <lib-lib/lib-lib.h>
-#ifdef CRYPT_BACKEND_GPGME
-
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
{
return verify_sender (h, GPGME_PROTOCOL_CMS);
}
-
-#endif
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 2004 g10 Code GmbH
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- This is a crytpo module wrapping the classic pgp code.
- */
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "crypt-mod.h"
-#include "pgp.h"
-
-static void crypt_mod_pgp_void_passphrase (void)
-{
- pgp_void_passphrase ();
-}
-
-static int crypt_mod_pgp_valid_passphrase (void)
-{
- return pgp_valid_passphrase ();
-}
-
-static int crypt_mod_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c,
- BODY ** d)
-{
- return pgp_decrypt_mime (a, b, c, d);
-}
-static int crypt_mod_pgp_application_handler (BODY * m, STATE * s)
-{
- return pgp_application_pgp_handler (m, s);
-}
-
-static char *crypt_mod_pgp_findkeys (address_t * to, address_t * cc,
- address_t * bcc)
-{
- return pgp_findKeys (to, cc, bcc);
-}
-
-static BODY *crypt_mod_pgp_sign_message (BODY * a)
-{
- return pgp_sign_message (a);
-}
-
-static int crypt_mod_pgp_verify_one (BODY * sigbdy, STATE * s,
- const char *tempf)
-{
- return pgp_verify_one (sigbdy, s, tempf);
-}
-
-static int crypt_mod_pgp_send_menu (HEADER * msg, int *redraw)
-{
- return pgp_send_menu (msg, redraw);
-}
-
-static BODY *crypt_mod_pgp_encrypt_message (BODY * a, char *keylist, int sign)
-{
- return pgp_encrypt_message (a, keylist, sign);
-}
-
-static BODY *crypt_mod_pgp_make_key_attachment (char *tempf)
-{
- return pgp_make_key_attachment (tempf);
-}
-
-static int crypt_mod_pgp_check_traditional (FILE * fp, BODY * b,
- int tagged_only)
-{
- return pgp_check_traditional (fp, b, tagged_only);
-}
-
-static BODY *crypt_mod_pgp_traditional_encryptsign (BODY * a, int flags,
- char *keylist)
-{
- return pgp_traditional_encryptsign (a, flags, keylist);
-}
-
-static int crypt_mod_pgp_encrypted_handler (BODY * m, STATE * s)
-{
- return pgp_encrypted_handler (m, s);
-}
-
-static void crypt_mod_pgp_invoke_getkeys (address_t * addr)
-{
- pgp_invoke_getkeys (addr);
-}
-
-static void crypt_mod_pgp_invoke_import (const char *fname)
-{
- pgp_invoke_import (fname);
-}
-
-static void crypt_mod_pgp_extract_keys_from_attachment_list (FILE * fp,
- int tag,
- BODY * top)
-{
- pgp_extract_keys_from_attachment_list (fp, tag, top);
-}
-
-struct crypt_module_specs crypt_mod_pgp_classic = { APPLICATION_PGP,
- {
- NULL, /* init */
- crypt_mod_pgp_void_passphrase,
- crypt_mod_pgp_valid_passphrase,
- crypt_mod_pgp_decrypt_mime,
- crypt_mod_pgp_application_handler,
- crypt_mod_pgp_encrypted_handler,
- crypt_mod_pgp_findkeys,
- crypt_mod_pgp_sign_message,
- crypt_mod_pgp_verify_one,
- crypt_mod_pgp_send_menu,
-
- crypt_mod_pgp_encrypt_message,
- crypt_mod_pgp_make_key_attachment,
- crypt_mod_pgp_check_traditional,
- crypt_mod_pgp_traditional_encryptsign,
- crypt_mod_pgp_invoke_getkeys,
- crypt_mod_pgp_invoke_import,
- crypt_mod_pgp_extract_keys_from_attachment_list,
-
- NULL, /* smime_getkeys */
- NULL, /* smime_verify_sender */
- NULL, /* smime_build_smime_entity */
- NULL, /* smime_invoke_import */
- }
-};
#include <lib-lib/lib-lib.h>
-#ifdef CRYPT_BACKEND_GPGME
-
#include <lib-crypt/crypt-mod.h>
#include "crypt-gpgme.h"
NULL, /* smime_invoke_import */
}
};
-
-#endif
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 2004 g10 Code GmbH
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- This is a crytpo module wrapping the classic smime code.
- */
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "crypt-mod.h"
-#include "smime.h"
-
-static void crypt_mod_smime_void_passphrase (void)
-{
- smime_void_passphrase ();
-}
-
-static int crypt_mod_smime_valid_passphrase (void)
-{
- return smime_valid_passphrase ();
-}
-
-static int crypt_mod_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c,
- BODY ** d)
-{
- return smime_decrypt_mime (a, b, c, d);
-}
-static int crypt_mod_smime_application_handler (BODY * m, STATE * s)
-{
- return smime_application_smime_handler (m, s);
-}
-
-static char *crypt_mod_smime_findkeys (address_t * to, address_t * cc,
- address_t * bcc)
-{
- return smime_findKeys (to, cc, bcc);
-}
-
-static BODY *crypt_mod_smime_sign_message (BODY * a)
-{
- return smime_sign_message (a);
-}
-
-static int crypt_mod_smime_verify_one (BODY * sigbdy, STATE * s,
- const char *tempf)
-{
- return smime_verify_one (sigbdy, s, tempf);
-}
-
-static int crypt_mod_smime_send_menu (HEADER * msg, int *redraw)
-{
- return smime_send_menu (msg, redraw);
-}
-
-static void crypt_mod_smime_getkeys (ENVELOPE * env)
-{
- smime_getkeys (env);
-}
-
-static int crypt_mod_smime_verify_sender (HEADER * h)
-{
- return smime_verify_sender (h);
-}
-
-static BODY *crypt_mod_smime_build_smime_entity (BODY * a, char *certlist)
-{
- return smime_build_smime_entity (a, certlist);
-}
-
-static void crypt_mod_smime_invoke_import (char *infile, char *mailbox)
-{
- smime_invoke_import (infile, mailbox);
-}
-
-
-struct crypt_module_specs crypt_mod_smime_classic = { APPLICATION_SMIME,
- {
- NULL, /* init */
- crypt_mod_smime_void_passphrase,
- crypt_mod_smime_valid_passphrase,
- crypt_mod_smime_decrypt_mime,
- crypt_mod_smime_application_handler,
- NULL, /* encrypted_handler */
- crypt_mod_smime_findkeys,
- crypt_mod_smime_sign_message,
- crypt_mod_smime_verify_one,
- crypt_mod_smime_send_menu,
-
- NULL, /* pgp_encrypt_message */
- NULL, /* pgp_make_key_attachment */
- NULL, /* pgp_check_traditional */
- NULL, /* pgp_traditional_encryptsign */
- NULL, /* pgp_invoke_getkeys */
- NULL, /* pgp_invoke_import */
- NULL, /* pgp_extract_keys_from_attachment_list */
-
- crypt_mod_smime_getkeys,
- crypt_mod_smime_verify_sender,
- crypt_mod_smime_build_smime_entity,
- crypt_mod_smime_invoke_import,
- }
-};
#include <lib-lib/lib-lib.h>
-#ifdef CRYPT_BACKEND_GPGME
-
#include <lib-crypt/crypt-mod.h>
#include "crypt-gpgme.h"
NULL, /* smime_invoke_import */
}
};
-
-#endif
Generic
*/
-extern struct crypt_module_specs crypt_mod_pgp_classic;
-extern struct crypt_module_specs crypt_mod_smime_classic;
-
-#ifdef CRYPT_BACKEND_GPGME
extern struct crypt_module_specs crypt_mod_pgp_gpgme;
extern struct crypt_module_specs crypt_mod_smime_gpgme;
-#endif
void crypt_init (void)
{
- if (
-#ifdef CRYPT_BACKEND_GPGME
- (!option (OPTCRYPTUSEGPGME))
-#else
- 1
-#endif
- )
- crypto_module_register (&crypt_mod_pgp_classic);
-
- if (
-#ifdef CRYPT_BACKEND_GPGME
- (!option (OPTCRYPTUSEGPGME))
-#else
- 1
-#endif
- )
- crypto_module_register (&crypt_mod_smime_classic);
-
- if (option (OPTCRYPTUSEGPGME)) {
-#ifdef CRYPT_BACKEND_GPGME
crypto_module_register (&crypt_mod_pgp_gpgme);
crypto_module_register (&crypt_mod_smime_gpgme);
-#else
- mutt_message (_("\"crypt_use_gpgme\" set"
- " but not build with GPGME support."));
- if (mutt_any_key_to_continue (NULL) == -1)
- mutt_exit (1);
-#endif
- }
-
-#if defined CRYPT_BACKEND_CLASSIG_PGP || defined CRYPT_BACKEND_CLASSIG_SMIME || defined CRYPT_BACKEND_GPGME
- if (CRYPT_MOD_CALL_CHECK (PGP, init))
- (CRYPT_MOD_CALL (PGP, init)) ();
- if (CRYPT_MOD_CALL_CHECK (SMIME, init))
+ (CRYPT_MOD_CALL(PGP, init))();
(CRYPT_MOD_CALL (SMIME, init)) ();
-#endif
}
-
/* Show a message that a backend will be invoked. */
void crypt_invoke_message (int type)
{
mutt_message _("Invoking S/MIME...");
}
}
-\f
/*
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1998-2000 Werner Koch <werner.koch@guug.de>
- * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- * NOTE
- *
- * This code used to be the parser for GnuPG's output.
- *
- * Nowadays, we are using an external pubring lister with PGP which mimics
- * gpg's output format.
- *
- */
-
-#include <lib-lib/lib-lib.h>
-
-#include <lib-mime/mime.h>
-#include <lib-sys/unix.h>
-#include <lib-ui/curses.h>
-
-#include "pgp.h"
-#include "charset.h"
-
-/****************
- * Read the GNUPG keys. For now we read the complete keyring by
- * calling gnupg in a special mode.
- *
- * The output format of gpgm is colon delimited with these fields:
- * - record type ("pub","uid","sig","rev" etc.)
- * - trust info
- * - key length
- * - pubkey algo
- * - 16 hex digits with the long keyid.
- * - timestamp (1998-02-28)
- * - Local id
- * - ownertrust
- * - name
- * - signature class
- */
-
-/* decode the backslash-escaped user ids. */
-
-static char *_chs = 0;
-
-static void fix_uid (char *uid)
-{
- char *s, *d;
- iconv_t cd;
-
- for (s = d = uid; *s;) {
- if (*s == '\\' && *(s + 1) == 'x' && isxdigit ((unsigned char) *(s + 2))
- && isxdigit ((unsigned char) *(s + 3))) {
- *d++ = hexval (*(s + 2)) << 4 | hexval (*(s + 3));
- s += 4;
- }
- else
- *d++ = *s++;
- }
- *d = '\0';
-
- if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != MUTT_ICONV_ERROR) {
- int n = s - uid + 1; /* chars available in original buffer */
- char *buf;
- const char *ib;
- char *ob;
- ssize_t ibl, obl;
-
- buf = p_new(char, n + 1);
- ib = uid, ibl = d - uid + 1, ob = buf, obl = n;
- my_iconv(cd, &ib, &ibl, &ob, &obl);
- if (!ibl) {
- if (ob - buf < n) {
- memcpy (uid, buf, ob - buf);
- uid[ob - buf] = '\0';
- }
- else if (ob - buf == n && (buf[n] = 0, m_strlen(buf) < n))
- memcpy (uid, buf, n);
- }
- p_delete(&buf);
- iconv_close (cd);
- }
-}
-
-static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k)
-{
- pgp_uid_t *uid = NULL;
- int field = 0, is_uid = 0;
- char *pend, *p;
- int trust = 0;
- int flags = 0;
-
- *is_subkey = 0;
- if (!*buf)
- return NULL;
-
- for (p = buf; p; p = pend) {
- if ((pend = strchr (p, ':')))
- *pend++ = 0;
- field++;
- if (field > 1 && !*p)
- continue;
-
- switch (field) {
- case 1: /* record type */
- {
- if (!m_strcmp(p, "pub"));
- else if (!m_strcmp(p, "sub"))
- *is_subkey = 1;
- else if (!m_strcmp(p, "sec"));
- else if (!m_strcmp(p, "ssb"))
- *is_subkey = 1;
- else if (!m_strcmp(p, "uid"))
- is_uid = 1;
- else
- return NULL;
-
- if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB))))
- k = pgp_new_keyinfo();
-
- break;
- }
- case 2: /* trust info */
- {
- switch (*p) { /* look only at the first letter */
- case 'e':
- flags |= KEYFLAG_EXPIRED;
- break;
- case 'r':
- flags |= KEYFLAG_REVOKED;
- break;
- case 'd':
- flags |= KEYFLAG_DISABLED;
- break;
- case 'n':
- trust = 1;
- break;
- case 'm':
- trust = 2;
- break;
- case 'f':
- trust = 3;
- break;
- case 'u':
- trust = 3;
- break;
- }
-
- if (!is_uid && !(*is_subkey && option (OPTPGPIGNORESUB)))
- k->flags |= flags;
-
- break;
- }
- case 3: /* key length */
- {
- if (!(*is_subkey && option (OPTPGPIGNORESUB)))
- k->keylen = atoi (p); /* fixme: add validation checks */
- break;
- }
- case 4: /* pubkey algo */
- {
- if (!(*is_subkey && option (OPTPGPIGNORESUB))) {
- k->numalg = atoi (p);
- k->algorithm = pgp_pkalgbytype (atoi (p));
- }
- break;
- }
- case 5: /* 16 hex digits with the long keyid. */
- {
- if (!(*is_subkey && option (OPTPGPIGNORESUB)))
- m_strreplace(&k->keyid, p);
- break;
-
- }
- case 6: /* timestamp (1998-02-28) */
- {
- char tstr[11];
- struct tm st_time;
-
- if (!p)
- break;
- st_time.tm_sec = 0;
- st_time.tm_min = 0;
- st_time.tm_hour = 12;
- m_strcpy(tstr, sizeof(tstr), p);
- tstr[4] = '\0';
- st_time.tm_year = atoi (tstr) - 1900;
- tstr[7] = '\0';
- st_time.tm_mon = (atoi (tstr + 5)) - 1;
- st_time.tm_mday = atoi (tstr + 8);
- k->gen_time = mutt_mktime (&st_time, 0);
- break;
- }
- case 7: /* valid for n days */
- break;
- case 8: /* Local id */
- break;
- case 9: /* ownertrust */
- break;
- case 10: /* name */
- {
- if (!pend || !*p)
- break; /* empty field or no trailing colon */
-
- /* ignore user IDs on subkeys */
- if (!is_uid && (*is_subkey && option (OPTPGPIGNORESUB)))
- break;
-
- uid = p_new(pgp_uid_t, 1);
- fix_uid (p);
- uid->addr = m_strdup(p);
- uid->trust = trust;
- uid->flags |= flags;
- uid->parent = k;
- uid->next = k->address;
- k->address = uid;
-
- if (strstr (p, "ENCR"))
- k->flags |= KEYFLAG_PREFER_ENCRYPTION;
- if (strstr (p, "SIGN"))
- k->flags |= KEYFLAG_PREFER_SIGNING;
-
- break;
- }
- case 11: /* signature class */
- break;
- case 12: /* key capabilities */
- while (*p) {
- switch (*p++) {
- case 'D':
- flags |= KEYFLAG_DISABLED;
- break;
-
- case 'e':
- flags |= KEYFLAG_CANENCRYPT;
- break;
-
- case 's':
- flags |= KEYFLAG_CANSIGN;
- break;
- }
- }
-
- if (!is_uid && (!*is_subkey || !option (OPTPGPIGNORESUB)
- || !((flags & KEYFLAG_DISABLED)
- || (flags & KEYFLAG_REVOKED)
- || (flags & KEYFLAG_EXPIRED))))
- k->flags |= flags;
-
- break;
-
- default:
- break;
- }
- }
- return k;
-}
-
-pgp_key_t pgp_get_candidates (pgp_ring_t keyring, string_list_t * hints)
-{
- FILE *fp;
- pid_t thepid;
- char buf[LONG_STRING];
- pgp_key_t db = NULL, *kend, k = NULL, kk, mainkey = NULL;
- int is_sub;
- int devnull;
-
- if ((devnull = open ("/dev/null", O_RDWR)) == -1)
- return NULL;
-
- m_strreplace(&_chs, MCharset.charset);
-
- thepid = pgp_invoke_list_keys (NULL, &fp, NULL, -1, -1, devnull,
- keyring, hints);
- if (thepid == -1) {
- close (devnull);
- return NULL;
- }
-
- kend = &db;
- k = NULL;
- while (fgets (buf, sizeof (buf) - 1, fp)) {
- if (!(kk = parse_pub_line (buf, &is_sub, k)))
- continue;
-
- /* Only append kk to the list if it's new. */
- if (kk != k) {
- if (k)
- kend = &k->next;
- *kend = k = kk;
-
- if (is_sub) {
- pgp_uid_t **l;
-
- k->flags |= KEYFLAG_SUBKEY;
- k->parent = mainkey;
- for (l = &k->address; *l; l = &(*l)->next);
- *l = pgp_copy_uids (mainkey->address, k);
- }
- else
- mainkey = k;
- }
- }
-
- if (ferror (fp))
- mutt_perror ("fgets");
-
- m_fclose(&fp);
- mutt_wait_filter (thepid);
-
- close (devnull);
-
- return db;
-}
*/
#include "crypt.h"
-#include "pgplib.h"
-
/* prototypes */
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1997-2000 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/* This file contains the new pgp invocation code. Note that this
- * is almost entirely format based.
- */
-
-#include <lib-lib/lib-lib.h>
-
-#include <lib-sys/unix.h>
-#include <lib-mime/mime.h>
-#include <lib-ui/curses.h>
-
-#include "mutt_idna.h"
-#include "pgp.h"
-
-
-/*
- * The actual command line formatter.
- */
-
-struct pgp_command_context {
- short need_passphrase; /* %p */
- const char *fname; /* %f */
- const char *sig_fname; /* %s */
- const char *signas; /* %a */
- const char *ids; /* %r */
-};
-
-
-static const char *
-_mutt_fmt_pgp_command(char *dest, ssize_t destlen,
- char op, const char *src, const char *prefix,
- const char *ifstr, const char *elstr,
- anytype data, format_flag flags)
-{
- char fmt[16];
- struct pgp_command_context *cctx = data.ptr;
- int optional = (flags & M_FORMAT_OPTIONAL);
-
- switch (op) {
- case 'r':
- {
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, NONULL (cctx->ids));
- }
- else if (!cctx->ids)
- optional = 0;
- break;
- }
-
- case 'a':
- {
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, NONULL (cctx->signas));
- }
- else if (!cctx->signas)
- optional = 0;
- break;
- }
-
- case 's':
- {
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, NONULL (cctx->sig_fname));
- }
- else if (!cctx->sig_fname)
- optional = 0;
- break;
- }
-
- case 'f':
- {
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, NONULL (cctx->fname));
- }
- else if (!cctx->fname)
- optional = 0;
- break;
- }
-
- case 'p':
- {
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt,
- cctx->need_passphrase ? "PGPPASSFD=0" : "");
- }
- else if (!cctx->need_passphrase || pgp_use_gpg_agent ())
- optional = 0;
- break;
- }
- default:
- {
- *dest = '\0';
- break;
- }
- }
-
- if (flags & M_FORMAT_OPTIONAL)
- m_strformat(dest, destlen, 0, optional ? ifstr : elstr,
- _mutt_fmt_pgp_command, data, 0);
-
- return src;
-}
-
-static void
-mutt_pgp_command(char *d, ssize_t dlen, struct pgp_command_context *cctx,
- const char *fmt)
-{
- m_strformat(d, dlen, 0, fmt, _mutt_fmt_pgp_command, cctx, 0);
-}
-
-/*
- * Glue.
- */
-
-
-static pid_t pgp_invoke (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- short need_passphrase,
- const char *fname,
- const char *sig_fname,
- const char *signas,
- const char *ids, const char *format)
-{
- struct pgp_command_context cctx;
- char cmd[HUGE_STRING];
-
- p_clear(&cctx, 1);
-
- if (!format || !*format)
- return (pid_t) - 1;
-
- cctx.need_passphrase = need_passphrase;
- cctx.fname = fname;
- cctx.sig_fname = sig_fname;
- cctx.signas = signas;
- cctx.ids = ids;
-
- mutt_pgp_command (cmd, sizeof (cmd), &cctx, format);
-
- return mutt_create_filter_fd (cmd, pgpin, pgpout, pgperr,
- pgpinfd, pgpoutfd, pgperrfd);
-}
-
-
-/*
- * The exported interface.
- *
- * This is historic and may be removed at some point.
- *
- */
-
-
-pid_t pgp_invoke_decode (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname, short need_passphrase)
-{
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- need_passphrase, fname, NULL, NULL, NULL,
- PgpDecodeCommand);
-}
-
-pid_t pgp_invoke_verify (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname, const char *sig_fname)
-{
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 0, fname, sig_fname, NULL, NULL, PgpVerifyCommand);
-}
-
-pid_t pgp_invoke_decrypt (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname)
-{
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 1, fname, NULL, NULL, NULL, PgpDecryptCommand);
-}
-
-pid_t pgp_invoke_sign (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname)
-{
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 1, fname, NULL, PgpSignAs, NULL, PgpSignCommand);
-}
-
-
-pid_t pgp_invoke_encrypt (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname, const char *uids, int sign)
-{
- if (sign)
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 1, fname, NULL, PgpSignAs, uids,
- PgpEncryptSignCommand);
- else
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 0, fname, NULL, NULL, uids, PgpEncryptOnlyCommand);
-}
-
-pid_t pgp_invoke_traditional (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname, const char *uids, int flags)
-{
- if (flags & ENCRYPT)
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- flags & SIGN ? 1 : 0, fname, NULL, PgpSignAs, uids,
- flags & SIGN ? PgpEncryptSignCommand :
- PgpEncryptOnlyCommand);
- else
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 1, fname, NULL, PgpSignAs, NULL, PgpClearSignCommand);
-}
-
-
-void pgp_invoke_import (const char *fname)
-{
- char _fname[_POSIX_PATH_MAX + STRING];
- char cmd[HUGE_STRING];
- struct pgp_command_context cctx;
-
- p_clear(&cctx, 1);
-
- mutt_quote_filename (_fname, sizeof (_fname), fname);
- cctx.fname = _fname;
-
- mutt_pgp_command (cmd, sizeof (cmd), &cctx, PgpImportCommand);
- mutt_system (cmd);
-}
-
-void pgp_invoke_getkeys (address_t * addr)
-{
- char buff[LONG_STRING];
- char tmp[LONG_STRING];
- char cmd[HUGE_STRING];
- int devnull;
-
- char *personal;
-
- struct pgp_command_context cctx;
-
- if (!PgpGetkeysCommand)
- return;
-
- p_clear(&cctx, 1);
-
- personal = addr->personal;
- addr->personal = NULL;
-
- mutt_addrlist_to_local(addr);
- rfc822_addrcpy(tmp, sizeof(tmp), addr, 0);
- mutt_quote_filename(buff, sizeof(buff), tmp);
-
- addr->personal = personal;
-
- cctx.ids = buff;
-
- mutt_pgp_command (cmd, sizeof (cmd), &cctx, PgpGetkeysCommand);
-
- devnull = open ("/dev/null", O_RDWR);
-
- if (!isendwin ())
- mutt_message _("Fetching PGP key...");
-
- mutt_system (cmd);
-
- if (!isendwin ())
- mutt_clear_error ();
-
- close (devnull);
-}
-
-pid_t pgp_invoke_export (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *uids)
-{
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 0, NULL, NULL, NULL, uids, PgpExportCommand);
-}
-
-pid_t pgp_invoke_verify_key (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *uids)
-{
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 0, NULL, NULL, NULL, uids, PgpVerifyKeyCommand);
-}
-
-pid_t pgp_invoke_list_keys (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- pgp_ring_t keyring, string_list_t * hints)
-{
- char uids[HUGE_STRING];
- char tmpuids[HUGE_STRING];
- char quoted[HUGE_STRING];
-
- *uids = '\0';
-
- for (; hints; hints = hints->next) {
- mutt_quote_filename (quoted, sizeof (quoted), (char *) hints->data);
- snprintf (tmpuids, sizeof (tmpuids), "%s %s", uids, quoted);
- m_strcpy(uids, sizeof(uids), tmpuids);
- }
-
- return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
- 0, NULL, NULL, NULL, uids,
- keyring == PGP_SECRING ? PgpListSecringCommand :
- PgpListPubringCommand);
-}
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
- * Copyright (c) 1998,1999 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-#include <lib-lib/lib-lib.h>
-
-#include <lib-mime/mime.h>
-#include <lib-sys/unix.h>
-
-#include <lib-ui/curses.h>
-#include <lib-ui/enter.h>
-#include <lib-ui/menu.h>
-
-#include "recvattach.h"
-#include "pgp.h"
-#include "pager.h"
-#include "sort.h"
-
-struct pgp_cache {
- char *what;
- char *dflt;
- struct pgp_cache *next;
-};
-
-static struct pgp_cache *id_defaults = NULL;
-
-static char trust_flags[] = "?- +";
-
-static char *pgp_key_abilities (int flags)
-{
- static char buff[3];
-
- if (!(flags & KEYFLAG_CANENCRYPT))
- buff[0] = '-';
- else if (flags & KEYFLAG_PREFER_SIGNING)
- buff[0] = '.';
- else
- buff[0] = 'e';
-
- if (!(flags & KEYFLAG_CANSIGN))
- buff[1] = '-';
- else if (flags & KEYFLAG_PREFER_ENCRYPTION)
- buff[1] = '.';
- else
- buff[1] = 's';
-
- buff[2] = '\0';
-
- return buff;
-}
-
-static char pgp_flags (int flags)
-{
- if (flags & KEYFLAG_REVOKED)
- return 'R';
- else if (flags & KEYFLAG_EXPIRED)
- return 'X';
- else if (flags & KEYFLAG_DISABLED)
- return 'd';
- else if (flags & KEYFLAG_CRITICAL)
- return 'c';
- else
- return ' ';
-}
-
-static pgp_key_t pgp_principal_key (pgp_key_t key)
-{
- if (key->flags & KEYFLAG_SUBKEY && key->parent)
- return key->parent;
- else
- return key;
-}
-
-/*
- * Format an entry on the PGP key selection menu.
- *
- * %n number
- * %k key id %K key id of the principal key
- * %u user id
- * %a algorithm %A algorithm of the princ. key
- * %l length %L length of the princ. key
- * %f flags %F flags of the princ. key
- * %c capabilities %C capabilities of the princ. key
- * %t trust/validity of the key-uid association
- * %[...] date of key using strftime(3)
- */
-
-typedef struct pgp_entry {
- ssize_t num;
- pgp_uid_t *uid;
-} pgp_entry_t;
-
-static const char *
-pgp_entry_fmt (char *dest, ssize_t destlen, char op,
- const char *src, const char *prefix,
- const char *ifstr, const char *elstr,
- anytype data, format_flag flags)
-{
- char fmt[16];
- pgp_entry_t *entry;
- pgp_uid_t *uid;
- pgp_key_t key, pkey;
- int kflags = 0;
- int optional = (flags & M_FORMAT_OPTIONAL);
-
- entry = data.ptr;
- uid = entry->uid;
- key = uid->parent;
- pkey = pgp_principal_key (key);
-
- if (isupper ((unsigned char) op))
- key = pkey;
-
- kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS)
- | uid->flags;
-
- switch (ascii_tolower (op)) {
- case '[':
-
- {
- const char *cp;
- char buf2[STRING], *p;
- int do_locales;
- struct tm *tm;
- ssize_t len;
-
- p = dest;
-
- cp = src;
- if (*cp == '!') {
- do_locales = 0;
- cp++;
- }
- else
- do_locales = 1;
-
- len = destlen - 1;
- while (len > 0 && *cp != ']') {
- if (*cp == '%') {
- cp++;
- if (len >= 2) {
- *p++ = '%';
- *p++ = *cp;
- len -= 2;
- }
- else
- break; /* not enough space */
- cp++;
- }
- else {
- *p++ = *cp++;
- len--;
- }
- }
- *p = 0;
-
- if (do_locales && Locale)
- setlocale (LC_TIME, Locale);
-
- tm = localtime (&key->gen_time);
-
- strftime (buf2, sizeof (buf2), dest, tm);
-
- if (do_locales)
- setlocale (LC_TIME, "C");
-
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, buf2);
- if (len > 0)
- src = cp + 1;
- }
- break;
- case 'n':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
- snprintf (dest, destlen, fmt, entry->num);
- }
- break;
- case 'k':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, _pgp_keyid (key));
- }
- break;
- case 'u':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, uid->addr);
- }
- break;
- case 'a':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, key->algorithm);
- }
- break;
- case 'l':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
- snprintf (dest, destlen, fmt, key->keylen);
- }
- break;
- case 'f':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
- snprintf (dest, destlen, fmt, pgp_flags (kflags));
- }
- else if (!(kflags & (KEYFLAG_RESTRICTIONS)))
- optional = 0;
- break;
- case 'c':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- snprintf (dest, destlen, fmt, pgp_key_abilities (kflags));
- }
- else if (!(kflags & (KEYFLAG_ABILITIES)))
- optional = 0;
- break;
- case 't':
- if (!optional) {
- snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
- snprintf (dest, destlen, fmt, trust_flags[uid->trust & 0x03]);
- }
- else if (!(uid->trust & 0x03))
- /* undefined trust */
- optional = 0;
- break;
- default:
- *dest = '\0';
- }
-
- if (flags & M_FORMAT_OPTIONAL)
- m_strformat(dest, destlen, 0, optional ? ifstr : elstr,
- mutt_attach_fmt, data, 0);
- return src;
-}
-
-static void pgp_entry (char *s, ssize_t l, MUTTMENU * menu, int num)
-{
- pgp_uid_t **KeyTable = (pgp_uid_t **) menu->data;
- pgp_entry_t entry;
-
- entry.uid = KeyTable[num];
- entry.num = num + 1;
-
- m_strformat(s, l, COLS - SW, PgpEntryFormat, pgp_entry_fmt, &entry,
- option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0);
-}
-
-static int _pgp_compare_address (const void *a, const void *b)
-{
- int r;
-
- pgp_uid_t **s = (pgp_uid_t **) a;
- pgp_uid_t **t = (pgp_uid_t **) b;
-
- if ((r = m_strcasecmp((*s)->addr, (*t)->addr)))
- return r > 0;
- else
- return (m_strcasecmp(_pgp_keyid ((*s)->parent),
- _pgp_keyid ((*t)->parent)) > 0);
-}
-
-static int pgp_compare_address (const void *a, const void *b)
-{
- return ((PgpSortKeys & SORT_REVERSE) ? !_pgp_compare_address (a, b)
- : _pgp_compare_address (a, b));
-}
-
-
-
-static int _pgp_compare_keyid (const void *a, const void *b)
-{
- int r;
-
- pgp_uid_t **s = (pgp_uid_t **) a;
- pgp_uid_t **t = (pgp_uid_t **) b;
-
- if ((r = m_strcasecmp(_pgp_keyid ((*s)->parent),
- _pgp_keyid ((*t)->parent))))
- return r > 0;
- else
- return (m_strcasecmp((*s)->addr, (*t)->addr)) > 0;
-}
-
-static int pgp_compare_keyid (const void *a, const void *b)
-{
- return ((PgpSortKeys & SORT_REVERSE) ? !_pgp_compare_keyid (a, b)
- : _pgp_compare_keyid (a, b));
-}
-
-static int _pgp_compare_date (const void *a, const void *b)
-{
- int r;
- pgp_uid_t **s = (pgp_uid_t **) a;
- pgp_uid_t **t = (pgp_uid_t **) b;
-
- if ((r = ((*s)->parent->gen_time - (*t)->parent->gen_time)))
- return r > 0;
- return (m_strcasecmp((*s)->addr, (*t)->addr)) > 0;
-}
-
-static int pgp_compare_date (const void *a, const void *b)
-{
- return ((PgpSortKeys & SORT_REVERSE) ? !_pgp_compare_date (a, b)
- : _pgp_compare_date (a, b));
-}
-
-static int _pgp_compare_trust (const void *a, const void *b)
-{
- int r;
-
- pgp_uid_t **s = (pgp_uid_t **) a;
- pgp_uid_t **t = (pgp_uid_t **) b;
-
- if ((r = (((*s)->parent->flags & (KEYFLAG_RESTRICTIONS))
- - ((*t)->parent->flags & (KEYFLAG_RESTRICTIONS)))))
- return r > 0;
- if ((r = ((*s)->trust - (*t)->trust)))
- return r < 0;
- if ((r = ((*s)->parent->keylen - (*t)->parent->keylen)))
- return r < 0;
- if ((r = ((*s)->parent->gen_time - (*t)->parent->gen_time)))
- return r < 0;
- if ((r = m_strcasecmp((*s)->addr, (*t)->addr)))
- return r > 0;
- return (m_strcasecmp(_pgp_keyid ((*s)->parent),
- _pgp_keyid ((*t)->parent))) > 0;
-}
-
-static int pgp_compare_trust (const void *a, const void *b)
-{
- return ((PgpSortKeys & SORT_REVERSE) ? !_pgp_compare_trust (a, b)
- : _pgp_compare_trust (a, b));
-}
-
-static int pgp_key_is_valid (pgp_key_t k)
-{
- pgp_key_t pk = pgp_principal_key (k);
-
- if (k->flags & KEYFLAG_CANTUSE)
- return 0;
- if (pk->flags & KEYFLAG_CANTUSE)
- return 0;
-
- return 1;
-}
-
-static int pgp_id_is_strong (pgp_uid_t * uid)
-{
- if ((uid->trust & 3) < 3)
- return 0;
- /* else */
- return 1;
-}
-
-static int pgp_id_is_valid (pgp_uid_t * uid)
-{
- if (!pgp_key_is_valid (uid->parent))
- return 0;
- if (uid->flags & KEYFLAG_CANTUSE)
- return 0;
- /* else */
- return 1;
-}
-
-#define PGP_KV_VALID 1
-#define PGP_KV_ADDR 2
-#define PGP_KV_STRING 4
-#define PGP_KV_STRONGID 8
-
-#define PGP_KV_MATCH (PGP_KV_ADDR|PGP_KV_STRING)
-
-static int pgp_id_matches_addr (address_t * addr, address_t * u_addr,
- pgp_uid_t * uid)
-{
- int rv = 0;
-
- if (pgp_id_is_valid (uid))
- rv |= PGP_KV_VALID;
-
- if (pgp_id_is_strong (uid))
- rv |= PGP_KV_STRONGID;
-
- if (addr->mailbox && u_addr->mailbox
- && m_strcasecmp(addr->mailbox, u_addr->mailbox) == 0)
- rv |= PGP_KV_ADDR;
-
- if (addr->personal && u_addr->personal
- && m_strcasecmp(addr->personal, u_addr->personal) == 0)
- rv |= PGP_KV_STRING;
-
- return rv;
-}
-
-static pgp_key_t pgp_select_key (pgp_key_t keys, address_t * p, const char *s)
-{
- int keymax;
- pgp_uid_t **KeyTable;
- MUTTMENU *menu;
- int i, done = 0;
- char helpstr[STRING], buf[LONG_STRING], tmpbuf[STRING];
- char cmd[LONG_STRING], tempfile[_POSIX_PATH_MAX];
- FILE *fp, *devnull;
- pid_t thepid;
- pgp_key_t kp;
- pgp_uid_t *a;
- int (*f) (const void *, const void *);
-
- int unusable = 0;
-
- keymax = 0;
- KeyTable = NULL;
-
- for (i = 0, kp = keys; kp; kp = kp->next) {
- if (!option (OPTPGPSHOWUNUSABLE) && (kp->flags & KEYFLAG_CANTUSE)) {
- unusable = 1;
- continue;
- }
-
- for (a = kp->address; a; a = a->next) {
- if (!option (OPTPGPSHOWUNUSABLE) && (a->flags & KEYFLAG_CANTUSE)) {
- unusable = 1;
- continue;
- }
-
- if (i == keymax) {
- keymax += 5;
- p_realloc(&KeyTable, keymax);
- }
-
- KeyTable[i++] = a;
- }
- }
-
- if (!i && unusable) {
- mutt_error _("All matching keys are expired, revoked, or disabled.");
-
- mutt_sleep (1);
- return NULL;
- }
-
- switch (PgpSortKeys & SORT_MASK) {
- case SORT_DATE:
- f = pgp_compare_date;
- break;
- case SORT_KEYID:
- f = pgp_compare_keyid;
- break;
- case SORT_ADDRESS:
- f = pgp_compare_address;
- break;
- case SORT_TRUST:
- default:
- f = pgp_compare_trust;
- break;
- }
- qsort (KeyTable, i, sizeof (pgp_uid_t *), f);
-
- helpstr[0] = 0;
- mutt_make_help (buf, sizeof (buf), _("Exit "), MENU_PGP, OP_EXIT);
- m_strcat(helpstr, sizeof(helpstr), buf);
- mutt_make_help (buf, sizeof (buf), _("Select "), MENU_PGP,
- OP_GENERIC_SELECT_ENTRY);
- m_strcat(helpstr, sizeof(helpstr), buf);
- mutt_make_help (buf, sizeof (buf), _("Check key "), MENU_PGP,
- OP_VERIFY_KEY);
- m_strcat(helpstr, sizeof(helpstr), buf);
- mutt_make_help (buf, sizeof (buf), _("Help"), MENU_PGP, OP_HELP);
- m_strcat(helpstr, sizeof(helpstr), buf);
-
- menu = mutt_new_menu ();
- menu->max = i;
- menu->make_entry = pgp_entry;
- menu->menu = MENU_PGP;
- menu->help = helpstr;
- menu->data = KeyTable;
-
- if (p)
- snprintf (buf, sizeof (buf), _("PGP keys matching <%s>."), p->mailbox);
- else
- snprintf (buf, sizeof (buf), _("PGP keys matching \"%s\"."), s);
-
-
- menu->title = buf;
-
- kp = NULL;
-
- mutt_clear_error ();
-
- while (!done) {
- switch (mutt_menuLoop (menu)) {
-
- case OP_VERIFY_KEY:
-
- if ((devnull = fopen("/dev/null", "w")) == NULL) {
- mutt_perror (_("Can't open /dev/null"));
-
- break;
- }
-
- fp = m_tempfile (tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
- if (!fp) {
- m_fclose(&devnull);
- mutt_perror (_("Can't create temporary file"));
-
- break;
- }
-
- mutt_message _("Invoking PGP...");
-
- snprintf (tmpbuf, sizeof (tmpbuf), "0x%s",
- pgp_keyid (pgp_principal_key
- (KeyTable[menu->current]->parent)));
-
- if ((thepid = pgp_invoke_verify_key (NULL, NULL, NULL, -1,
- fileno (fp), fileno (devnull),
- tmpbuf)) == -1) {
- mutt_perror (_("Can't create filter"));
-
- unlink (tempfile);
- m_fclose(&fp);
- m_fclose(&devnull);
- }
-
- mutt_wait_filter (thepid);
- m_fclose(&fp);
- m_fclose(&devnull);
- mutt_clear_error ();
- snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"),
- pgp_keyid (pgp_principal_key
- (KeyTable[menu->current]->parent)));
- mutt_do_pager (cmd, tempfile, 0, NULL);
- menu->redraw = REDRAW_FULL;
-
- break;
-
- case OP_VIEW_ID:
-
- mutt_message ("%s", KeyTable[menu->current]->addr);
- break;
-
- case OP_GENERIC_SELECT_ENTRY:
-
-
- /* XXX make error reporting more verbose */
-
- if (option (OPTPGPCHECKTRUST))
- if (!pgp_key_is_valid (KeyTable[menu->current]->parent)) {
- mutt_error _("This key can't be used: expired/disabled/revoked.");
-
- break;
- }
-
- if (option (OPTPGPCHECKTRUST) &&
- (!pgp_id_is_valid (KeyTable[menu->current])
- || !pgp_id_is_strong (KeyTable[menu->current]))) {
- const char *q = "";
- char buff[LONG_STRING];
-
- if (KeyTable[menu->current]->flags & KEYFLAG_CANTUSE)
- q = N_("ID is expired/disabled/revoked.");
- else
- switch (KeyTable[menu->current]->trust & 0x03) {
- case 0:
- q = N_("ID has undefined validity.");
- break;
- case 1:
- q = N_("ID is not valid.");
- break;
- case 2:
- q = N_("ID is only marginally valid.");
- break;
- }
-
- snprintf (buff, sizeof (buff),
- _("%s Do you really want to use the key?"), _(q));
-
- if (mutt_yesorno (buff, M_NO) != M_YES) {
- mutt_clear_error ();
- break;
- }
- }
-
-# if 0
- kp = pgp_principal_key (KeyTable[menu->current]->parent);
-# else
- kp = KeyTable[menu->current]->parent;
-# endif
- done = 1;
- break;
-
- case OP_EXIT:
-
- kp = NULL;
- done = 1;
- break;
- }
- }
-
- mutt_menuDestroy (&menu);
- p_delete(&KeyTable);
-
- set_option (OPTNEEDREDRAW);
-
- return (kp);
-}
-
-pgp_key_t pgp_ask_for_key (char *tag, char *whatfor,
- short abilities, pgp_ring_t keyring)
-{
- pgp_key_t key;
- char resp[STRING];
- struct pgp_cache *l = NULL;
-
- mutt_clear_error ();
-
- resp[0] = 0;
- if (whatfor) {
-
- for (l = id_defaults; l; l = l->next)
- if (!m_strcasecmp(whatfor, l->what)) {
- m_strcpy(resp, sizeof(resp), NONULL(l->dflt));
- break;
- }
- }
-
-
- for (;;) {
- resp[0] = 0;
- if (mutt_get_field (tag, resp, sizeof (resp), M_CLEAR) != 0)
- return NULL;
-
- if (whatfor) {
- if (l)
- m_strreplace(&l->dflt, resp);
- else {
- l = p_new(struct pgp_cache, 1);
- l->next = id_defaults;
- id_defaults = l;
- l->what = m_strdup(whatfor);
- l->dflt = m_strdup(resp);
- }
- }
-
- if ((key = pgp_getkeybystr (resp, abilities, keyring)))
- return key;
-
- BEEP ();
- }
- /* not reached */
-}
-
-/* generate a public key attachment */
-
-BODY *pgp_make_key_attachment (char *tempf)
-{
- BODY *att;
- char buff[LONG_STRING];
- char tempfb[_POSIX_PATH_MAX], tmp[STRING];
- FILE *tempfp;
- FILE *devnull;
- struct stat sb;
- pid_t thepid;
- pgp_key_t key;
-
- unset_option (OPTPGPCHECKTRUST);
-
- key =
- pgp_ask_for_key (_("Please enter the key ID: "), NULL, 0, PGP_PUBRING);
-
- if (!key)
- return NULL;
-
- snprintf (tmp, sizeof (tmp), "0x%s", pgp_keyid (pgp_principal_key (key)));
- pgp_free_key (&key);
-
- if (!tempf) {
- tempfp = m_tempfile (tempfb, sizeof(tempfb), NONULL(MCore.tmpdir), NULL);
- tempf = tempfb;
- } else {
- tempfp = safe_fopen(tempf, "a");
- }
-
- if (!tempfp) {
- mutt_perror (_("Can't create temporary file"));
- return NULL;
- }
-
- if ((devnull = fopen("/dev/null", "w")) == NULL) {
- mutt_perror (_("Can't open /dev/null"));
-
- m_fclose(&tempfp);
- if (tempf == tempfb)
- unlink (tempf);
- return NULL;
- }
-
- mutt_message _("Invoking pgp...");
-
-
- if ((thepid =
- pgp_invoke_export (NULL, NULL, NULL, -1,
- fileno (tempfp), fileno (devnull), tmp)) == -1) {
- mutt_perror (_("Can't create filter"));
-
- unlink (tempf);
- m_fclose(&tempfp);
- m_fclose(&devnull);
- return NULL;
- }
-
- mutt_wait_filter (thepid);
-
- m_fclose(&tempfp);
- m_fclose(&devnull);
-
- att = body_new();
- att->filename = m_strdup(tempf);
- att->unlink = 1;
- att->use_disp = 0;
- att->type = TYPEAPPLICATION;
- att->subtype = m_strdup("pgp-keys");
- snprintf (buff, sizeof (buff), _("PGP Key %s."), tmp);
- att->description = m_strdup(buff);
- mutt_update_encoding (att);
-
- stat (tempf, &sb);
- att->length = sb.st_size;
-
- return att;
-}
-
-static string_list_t *pgp_add_string_to_hints (string_list_t * hints, const char *str)
-{
- char *scratch;
- char *t;
-
- if ((scratch = m_strdup(str)) == NULL)
- return hints;
-
- for (t = strtok (scratch, " ,.:\"()<>\n"); t;
- t = strtok (NULL, " ,.:\"()<>\n")) {
- if (m_strlen(t) > 3)
- hints = mutt_add_list (hints, t);
- }
-
- p_delete(&scratch);
- return hints;
-}
-
-static pgp_key_t *pgp_get_lastp (pgp_key_t p)
-{
- for (; p; p = p->next)
- if (!p->next)
- return &p->next;
-
- return NULL;
-}
-
-pgp_key_t pgp_getkeybyaddr (address_t * a, short abilities, pgp_ring_t keyring)
-{
- address_t *r, *p;
- string_list_t *hints = NULL;
-
- int weak = 0;
- int invalid = 0;
- int multi = 0;
- int this_key_has_strong;
- int this_key_has_weak;
- int this_key_has_invalid;
- int match;
-
- pgp_key_t keys, k, kn;
- pgp_key_t the_valid_key = NULL;
- pgp_key_t matches = NULL;
- pgp_key_t *last = &matches;
- pgp_uid_t *q;
-
- if (a && a->mailbox)
- hints = pgp_add_string_to_hints (hints, a->mailbox);
- if (a && a->personal)
- hints = pgp_add_string_to_hints (hints, a->personal);
-
- mutt_message (_("Looking for keys matching \"%s\"..."), a->mailbox);
- keys = pgp_get_candidates (keyring, hints);
-
- string_list_wipe(&hints);
-
- if (!keys)
- return NULL;
-
- for (k = keys; k; k = kn) {
- kn = k->next;
-
- if (abilities && !(k->flags & abilities)) {
- continue;
- }
-
- this_key_has_weak = 0; /* weak but valid match */
- this_key_has_invalid = 0; /* invalid match */
- this_key_has_strong = 0; /* strong and valid match */
- match = 0; /* any match */
-
- for (q = k->address; q; q = q->next) {
- r = rfc822_parse_adrlist (NULL, q->addr);
-
- for (p = r; p; p = p->next) {
- int validity = pgp_id_matches_addr (a, p, q);
-
- if (validity & PGP_KV_MATCH) /* something matches */
- match = 1;
-
- /* is this key a strong candidate? */
- if ((validity & PGP_KV_VALID) && (validity & PGP_KV_STRONGID)
- && (validity & PGP_KV_ADDR)) {
- if (the_valid_key && the_valid_key != k)
- multi = 1;
- the_valid_key = k;
- this_key_has_strong = 1;
- }
- else if ((validity & PGP_KV_MATCH) && !(validity & PGP_KV_VALID))
- this_key_has_invalid = 1;
- else if ((validity & PGP_KV_MATCH)
- && (!(validity & PGP_KV_STRONGID)
- || !(validity & PGP_KV_ADDR)))
- this_key_has_weak = 1;
- }
-
- address_list_wipe(&r);
- }
-
- if (match && !this_key_has_strong && this_key_has_invalid)
- invalid = 1;
- if (match && !this_key_has_strong && this_key_has_weak)
- weak = 1;
-
- if (match) {
- *last = pgp_principal_key (k);
- kn = pgp_remove_key (&keys, *last);
- last = pgp_get_lastp (k);
- }
- }
-
- pgp_free_key (&keys);
-
- if (matches) {
- if (the_valid_key && !multi /* && !weak
- && !(invalid && option (OPTPGPSHOWUNUSABLE)) */ ) {
- /*
- * There was precisely one strong match on a valid ID.
- *
- * Proceed without asking the user.
- */
- pgp_remove_key (&matches, the_valid_key);
- pgp_free_key (&matches);
- k = the_valid_key;
- }
- else {
- /*
- * Else: Ask the user.
- */
- if ((k = pgp_select_key (matches, a, NULL)))
- pgp_remove_key (&matches, k);
- pgp_free_key (&matches);
- }
-
- return k;
- }
-
- return NULL;
-}
-
-pgp_key_t pgp_getkeybystr (const char *p, short abilities, pgp_ring_t keyring)
-{
- string_list_t *hints = NULL;
- pgp_key_t keys;
- pgp_key_t matches = NULL;
- pgp_key_t *last = &matches;
- pgp_key_t k, kn;
- pgp_uid_t *a;
- short match;
-
- mutt_message (_("Looking for keys matching \"%s\"..."), p);
-
- hints = pgp_add_string_to_hints (hints, p);
- keys = pgp_get_candidates (keyring, hints);
- string_list_wipe(&hints);
-
- if (!keys)
- return NULL;
-
-
- for (k = keys; k; k = kn) {
- kn = k->next;
- if (abilities && !(k->flags & abilities))
- continue;
-
- match = 0;
-
- for (a = k->address; a; a = a->next) {
- if (!*p || m_strcasecmp(p, pgp_keyid (k)) == 0
- || (!m_strncasecmp(p, "0x", 2)
- && !m_strcasecmp(p + 2, pgp_keyid (k)))
- || (option (OPTPGPLONGIDS) && !m_strncasecmp(p, "0x", 2)
- && !m_strcasecmp(p + 2, k->keyid + 8))
- || m_stristr(a->addr, p)) {
- match = 1;
- break;
- }
- }
-
- if (match) {
- *last = pgp_principal_key (k);
- kn = pgp_remove_key (&keys, *last);
- last = pgp_get_lastp (k);
- }
- }
-
- pgp_free_key (&keys);
-
- if (matches) {
- if ((k = pgp_select_key (matches, NULL, p)))
- pgp_remove_key (&matches, k);
-
- pgp_free_key (&matches);
- return k;
- }
-
- return NULL;
-}
-
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1997-2000 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/* Generally useful, pgp-related functions. */
-
-#include <lib-lib/lib-lib.h>
-
-#include "lib.h"
-#include "pgplib.h"
-
-const char *pgp_pkalgbytype (unsigned char type)
-{
- switch (type) {
- case 1:
- return "RSA";
- case 2:
- return "RSA";
- case 3:
- return "RSA";
- case 16:
- return "ElG";
- case 17:
- return "DSA";
- case 20:
- return "ElG";
- default:
- return "unk";
- }
-}
-
-short pgp_canencrypt (unsigned char type)
-{
- switch (type) {
- case 1:
- case 2:
- case 16:
- case 20:
- return 1;
- default:
- return 0;
- }
-}
-
-short pgp_cansign (unsigned char type)
-{
- switch (type) {
- case 1:
- case 3:
- case 17:
- case 20:
- return 1;
- default:
- return 0;
- }
-}
-
-/* return values:
-
- * 1 = sign only
- * 2 = encrypt only
- * 3 = both
- */
-
-short pgp_get_abilities (unsigned char type)
-{
- return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
-}
-
-static void pgp_free_sig (pgp_sig_t ** sigp)
-{
- pgp_sig_t *sp, *q;
-
- if (!sigp || !*sigp)
- return;
-
- for (sp = *sigp; sp; sp = q) {
- q = sp->next;
- p_delete(&sp);
- }
-
- *sigp = NULL;
-}
-
-static void pgp_free_uid (pgp_uid_t ** upp)
-{
- pgp_uid_t *up, *q;
-
- if (!upp || !*upp)
- return;
- for (up = *upp; up; up = q) {
- q = up->next;
- pgp_free_sig (&up->sigs);
- p_delete(&up->addr);
- p_delete(&up);
- }
-
- *upp = NULL;
-}
-
-pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent)
-{
- pgp_uid_t *l = NULL;
- pgp_uid_t **lp = &l;
-
- for (; up; up = up->next) {
- *lp = p_new(pgp_uid_t, 1);
- (*lp)->trust = up->trust;
- (*lp)->flags = up->flags;
- (*lp)->addr = m_strdup(up->addr);
- (*lp)->parent = parent;
- lp = &(*lp)->next;
- }
-
- return l;
-}
-
-static void _pgp_free_key (pgp_key_t * kpp)
-{
- pgp_key_t kp;
-
- if (!kpp || !*kpp)
- return;
-
- kp = *kpp;
-
- pgp_free_uid (&kp->address);
- p_delete(&kp->keyid);
- p_delete(kpp);
-}
-
-pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
-{
- pgp_key_t *last;
- pgp_key_t p, q, r;
-
- if (!klist || !*klist || !key)
- return NULL;
-
- if (key->parent && key->parent != key)
- key = key->parent;
-
- last = klist;
- for (p = *klist; p && p != key; p = p->next)
- last = &p->next;
-
- if (!p)
- return NULL;
-
- for (q = p->next, r = p; q && q->parent == p; q = q->next)
- r = q;
-
- if (r)
- r->next = NULL;
-
- *last = q;
- return q;
-}
-
-void pgp_free_key (pgp_key_t * kpp)
-{
- pgp_key_t p, q, r;
-
- if (!kpp || !*kpp)
- return;
-
- if ((*kpp)->parent && (*kpp)->parent != *kpp)
- *kpp = (*kpp)->parent;
-
- /* Order is important here:
- *
- * - First free all children.
- * - If we are an orphan (i.e., our parent was not in the key list),
- * free our parent.
- * - free ourselves.
- */
-
- for (p = *kpp; p; p = q) {
- for (q = p->next; q && q->parent == p; q = r) {
- r = q->next;
- _pgp_free_key (&q);
- }
- if (p->parent)
- _pgp_free_key (&p->parent);
-
- _pgp_free_key (&p);
- }
-
- *kpp = NULL;
-}
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
- * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-#include "crypt.h"
-
-typedef struct pgp_signature {
- struct pgp_signature *next;
- unsigned char sigtype;
- unsigned long sid1;
- unsigned long sid2;
-} pgp_sig_t;
-
-struct pgp_keyinfo {
- char *keyid;
- struct pgp_uid *address;
- int flags;
- short keylen;
- time_t gen_time;
- int numalg;
- const char *algorithm;
- struct pgp_keyinfo *parent;
- struct pgp_signature *sigs;
- struct pgp_keyinfo *next;
-
- short fp_len; /* length of fingerprint.
- * 20 for sha-1, 16 for md5.
- */
- unsigned char fingerprint[20]; /* large enough to hold SHA-1 and RIPEMD160
- hashes (20 bytes), MD5 hashes just use the
- first 16 bytes */
-};
-
-/* Note, that pgp_key_t is now pointer and declared in crypt.h */
-
-typedef struct pgp_uid {
- char *addr;
- short trust;
- int flags;
- struct pgp_keyinfo *parent;
- struct pgp_uid *next;
- struct pgp_signature *sigs;
-} pgp_uid_t;
-
-enum pgp_version {
- PGP_V2,
- PGP_V3,
- PGP_GPG,
- PGP_UNKNOWN
-};
-
-/* prototypes */
-
-const char *pgp_pkalgbytype (unsigned char);
-
-pgp_key_t pgp_remove_key (pgp_key_t *, pgp_key_t);
-pgp_uid_t *pgp_copy_uids (pgp_uid_t *, pgp_key_t);
-
-short pgp_canencrypt (unsigned char);
-short pgp_cansign (unsigned char);
-short pgp_get_abilities (unsigned char);
-
-void pgp_free_key (pgp_key_t * kpp);
-
-#define pgp_new_keyinfo() xmalloc(sizeof *((pgp_key_t)0))
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/* This module peeks at a PGP signature and figures out the hash
- * algorithm.
- */
-
-#include <lib-lib/lib-lib.h>
-
-#include <lib-mime/mime.h>
-#include <lib-ui/curses.h>
-
-#include "handler.h"
-#include "pgp.h"
-#include "pgppacket.h"
-#include "charset.h"
-
-
-static struct {
- short id;
- const char *name;
-} HashAlgorithms[] = {
- {
- 1, "pgp-md5"}, {
- 2, "pgp-sha1"}, {
- 3, "pgp-ripemd160"}, {
- 5, "pgp-md2"}, {
- 6, "pgp-tiger192"}, {
- 7, "pgp-haval-5-160"}, {
- 8, "pgp-sha256"}, {
- 9, "pgp-sha384"}, {
- 10, "pgp-sha512"}, {
- -1, NULL}
-};
-
-static const char *pgp_hash_to_micalg (short id)
-{
- int i;
-
- for (i = 0; HashAlgorithms[i].id >= 0; i++)
- if (HashAlgorithms[i].id == id)
- return HashAlgorithms[i].name;
- return "x-unknown";
-}
-
-static void pgp_dearmor (FILE * in, FILE * out)
-{
- char line[HUGE_STRING];
- off_t start;
- off_t end;
- char *r;
-
- STATE state;
-
- p_clear(&state, 1);
- state.fpin = in;
- state.fpout = out;
-
- /* find the beginning of ASCII armor */
-
- while ((r = fgets (line, sizeof (line), in)) != NULL) {
- if (!m_strncmp (line, "-----BEGIN", 10))
- break;
- }
- if (r == NULL) {
- return;
- }
-
- /* skip the armor header */
-
- while ((r = fgets (line, sizeof (line), in)) != NULL) {
- r = vskipspaces(r);
- if (!*r)
- break;
- }
- if (r == NULL) {
- return;
- }
-
- /* actual data starts here */
- start = ftello (in);
-
- /* find the checksum */
-
- while ((r = fgets (line, sizeof (line), in)) != NULL) {
- if (*line == '=' || !m_strncmp (line, "-----END", 8))
- break;
- }
- if (r == NULL) {
- return;
- }
-
- if ((end = ftello (in) - m_strlen(line)) < start) {
- return;
- }
-
- if (fseeko (in, start, SEEK_SET) == -1) {
- return;
- }
-
- mutt_decode_base64 (&state, end - start, 0, MUTT_ICONV_ERROR);
-}
-
-static short pgp_mic_from_packet (unsigned char *p, size_t len)
-{
- /* is signature? */
- if ((p[0] & 0x3f) != PT_SIG) {
- return -1;
- }
-
- if (len >= 18 && p[1] == 3)
- /* version 3 signature */
- return (short) p[17];
- else if (len >= 5 && p[1] == 4)
- /* version 4 signature */
- return (short) p[4];
- else {
- return -1;
- }
-}
-
-static short pgp_find_hash (const char *fname)
-{
- FILE *in = NULL;
- FILE *out = NULL;
-
- char tempfile[_POSIX_PATH_MAX];
-
- unsigned char *p;
- size_t l;
-
- short rv = -1;
-
- out = m_tempfile (tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
- if (!out) {
- mutt_perror (_("Can't create temporary file"));
- goto bye;
- }
- unlink (tempfile);
-
- if ((in = fopen (fname, "r")) == NULL) {
- mutt_perror (_("Can't create temporary file"));
- goto bye;
- }
-
- pgp_dearmor (in, out);
- rewind (out);
-
- if ((p = pgp_read_packet (out, &l)) != NULL) {
- rv = pgp_mic_from_packet (p, l);
- }
-
-bye:
-
- m_fclose(&in);
- m_fclose(&out);
- pgp_release_packet ();
- return rv;
-}
-
-const char *pgp_micalg (const char *fname)
-{
- return pgp_hash_to_micalg (pgp_find_hash (fname));
-}
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-#include <lib-lib/lib-lib.h>
-#include <lib-hash/hash.h>
-
-#include "lib.h"
-#include "pgplib.h"
-#include "pgppacket.h"
-
-#define CHUNKSIZE 1024
-
-static unsigned char *pbuf = NULL;
-static size_t plen = 0;
-
-static int read_material (size_t material, size_t * used, FILE * fp)
-{
- if (*used + material >= plen) {
- p_realloc(&pbuf, plen = *used + material + CHUNKSIZE);
- }
-
- if (fread (pbuf + *used, 1, material, fp) < material) {
- perror ("fread");
- return -1;
- }
-
- *used += material;
- return 0;
-}
-
-unsigned char *pgp_read_packet (FILE * fp, size_t * len)
-{
- size_t used = 0;
- off_t startpos;
- unsigned char ctb;
- unsigned char b;
- size_t material;
-
- startpos = ftello (fp);
-
- if (!plen) {
- pbuf = p_new(unsigned char, plen = CHUNKSIZE);
- }
-
- if (fread (&ctb, 1, 1, fp) < 1) {
- if (!feof (fp))
- perror ("fread");
- goto bail;
- }
-
- if (!(ctb & 0x80)) {
- goto bail;
- }
-
- if (ctb & 0x40) { /* handle PGP 5.0 packets. */
- int partial = 0;
-
- pbuf[0] = ctb;
- used++;
-
- do {
- if (fread (&b, 1, 1, fp) < 1) {
- perror ("fread");
- goto bail;
- }
-
- if (b < 192) {
- material = b;
- partial = 0;
- /* material -= 1; */
- }
- else if (192 <= b && b <= 223) {
- material = (b - 192) * 256;
- if (fread (&b, 1, 1, fp) < 1) {
- perror ("fread");
- goto bail;
- }
- material += b + 192;
- partial = 0;
- /* material -= 2; */
- }
- else if (b < 255) {
- material = 1 << (b & 0x1f);
- partial = 1;
- /* material -= 1; */
- }
- else
- /* b == 255 */
- {
- unsigned char buf[4];
-
- if (fread (buf, 4, 1, fp) < 1) {
- perror ("fread");
- goto bail;
- }
- /*assert( sizeof(material) >= 4 ); */
- material = buf[0] << 24;
- material |= buf[1] << 16;
- material |= buf[2] << 8;
- material |= buf[3];
- partial = 0;
- /* material -= 5; */
- }
-
- if (read_material (material, &used, fp) == -1)
- goto bail;
-
- }
- while (partial);
- }
- else
- /* Old-Style PGP */
- {
- int bytes = 0;
-
- pbuf[0] = 0x80 | ((ctb >> 2) & 0x0f);
- used++;
-
- switch (ctb & 0x03) {
- case 0:
- {
- if (fread (&b, 1, 1, fp) < 1) {
- perror ("fread");
- goto bail;
- }
-
- material = b;
- break;
- }
-
- case 1:
- bytes = 2;
-
- case 2:
- {
- int i;
-
- if (!bytes)
- bytes = 4;
-
- material = 0;
-
- for (i = 0; i < bytes; i++) {
- if (fread (&b, 1, 1, fp) < 1) {
- perror ("fread");
- goto bail;
- }
-
- material = (material << 8) + b;
- }
- break;
- }
-
- default:
- goto bail;
- }
-
- if (read_material (material, &used, fp) == -1)
- goto bail;
- }
-
- if (len)
- *len = used;
-
- return pbuf;
-
-bail:
-
- fseeko (fp, startpos, SEEK_SET);
- return NULL;
-}
-
-void pgp_release_packet (void)
-{
- plen = 0;
- p_delete(&pbuf);
-}
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- * Definitions for a rudimentary PGP packet parser which is shared
- * by mutt proper and the PGP public key ring lister.
- */
-
-#ifndef _PGPPACKET_H
-# define _PGPPACKET_H
-
-enum packet_tags {
- PT_RES0 = 0, /* reserved */
- PT_ESK, /* Encrypted Session Key */
- PT_SIG, /* Signature Packet */
- PT_CESK, /* Conventionally Encrypted Session Key Packet */
- PT_OPS, /* One-Pass Signature Packet */
- PT_SECKEY, /* Secret Key Packet */
- PT_PUBKEY, /* Public Key Packet */
- PT_SUBSECKEY, /* Secret Subkey Packet */
- PT_COMPRESSED, /* Compressed Data Packet */
- PT_SKE, /* Symmetrically Encrypted Data Packet */
- PT_MARKER, /* Marker Packet */
- PT_LITERAL, /* Literal Data Packet */
- PT_TRUST, /* Trust Packet */
- PT_NAME, /* Name Packet */
- PT_SUBKEY, /* Subkey Packet */
- PT_RES15, /* Reserved */
- PT_COMMENT /* Comment Packet */
-};
-
-unsigned char *pgp_read_packet (FILE * fp, size_t * len);
-void pgp_release_packet (void);
-
-#endif
#include <gnutls/gnutls.h>
#endif
-#ifdef CRYPT_BACKEND_GPGME
#include <gpgme.h>
-#endif
#ifdef USE_SSL
#include <openssl/opensslv.h>
printf (" %s\n",OPENSSL_VERSION_TEXT);
#endif
-#ifdef CRYPT_BACKEND_GPGME
printf (" gpgme %s\n", GPGME_VERSION);
-#endif
-
puts (_("Compile Options:"));
puts (
);
puts (
-#ifdef CRYPT_BACKEND_GPGME
"+CRYPT_BACKEND_GPGME "
-#else
- "-CRYPT_BACKEND_GPGME "
-#endif
"\n "
#ifdef ENABLE_NLS
"+ENABLE_NLS "
OPTXMAILTO, /* 1 if $edit_header is forcebly set */
OPTXTERMSETTITLES,
- OPTCRYPTUSEGPGME,
-
/* PGP options */
OPTCRYPTAUTOSIGN,
+++ /dev/null
-/*
- * C version by Wessel Dankers <wsl@fruit.eu.org>
- *
- * This code is in the public domain.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-static void print_usage (const char *progname)
-{
- fprintf (stderr, "Command line usage: %s [flags] -- prefix [recipients]\n",
- progname);
- exit (1);
-}
-
-int main (int argc, char **argv)
-{
- char **opts, **opt, *pfx;
- int i;
-
- if (argc <= 1) {
- print_usage (argv[0]);
- }
-
- opts = malloc((2 * argc + 1) * sizeof (*opts));
- if (!opts) {
- perror (argv[0]);
- exit (2);
- }
-
- if (argc < 2) {
- fprintf (stderr,
- "Command line usage: %s [flags] -- prefix [recipients]\n",
- argv[0]);
- return 1;
- }
-
- opt = opts;
- *opt++ = argv[1];
- pfx = NULL;
-
- for (i = 2; i < argc;) {
- if (!strcmp (argv[i], "--")) {
- i += 2;
- if (i > argc) {
- print_usage (argv[0]);
- }
- pfx = argv[i - 1];
- }
- if (pfx)
- *opt++ = pfx;
- *opt++ = argv[i++];
- }
- *opt = NULL;
-
- execvp (opts[0], opts);
- perror (argv[0]);
- return 2;
-}
+++ /dev/null
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1997-2001 Thomas Roessler <roessler@does-not-exist.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- * This is a "simple" PGP key ring dumper.
- *
- * The output format is supposed to be compatible to the one GnuPG
- * emits and Mutt expects.
- *
- * Note that the code of this program could be considerably less
- * complex, but most of it was taken from mutt's second generation
- * key ring parser.
- *
- * You can actually use this to put together some fairly general
- * PGP key management applications.
- *
- */
-
-#include <lib-lib/lib-lib.h>
-
-#include <lib-hash/hash.h>
-
-#ifdef HAVE_GETOPT_H
-# include <getopt.h>
-#else
-extern char *optarg;
-extern int optind;
-#endif
-
-short Umask; /* dirty hack because we need Umask in lib.c but don't want globals.h there */
-
-#include "lib.h"
-#include <lib-crypt/pgplib.h>
-#include <lib-crypt/pgppacket.h>
-
-#define MD5_DIGEST_LENGTH 16
-
-#ifdef HAVE_FGETPOS
-#define FGETPOS(fp,pos) fgetpos((fp),&(pos))
-#define FSETPOS(fp,pos) fsetpos((fp),&(pos))
-#else
-#define FGETPOS(fp,pos) pos=ftello((fp));
-#define FSETPOS(fp,pos) fseeko((fp),(pos),SEEK_SET)
-#endif
-
-
-static short dump_signatures = 0;
-static short dump_fingerprints = 0;
-
-
-static void pgpring_find_candidates (char *ringfile, const char *hints[],
- int nhints);
-static void pgpring_dump_keyblock (pgp_key_t p);
-
-int main (int argc, char *const argv[])
-{
- int c;
-
- short version = 2;
- short secring = 0;
-
- const char *_kring = NULL;
- char *env_pgppath, *env_home;
-
- char pgppath[_POSIX_PATH_MAX];
- char kring[_POSIX_PATH_MAX];
-
- while ((c = getopt (argc, argv, "f25sk:S")) != EOF) {
- switch (c) {
- case 'S':
- {
- dump_signatures = 1;
- break;
- }
-
- case 'f':
- {
- dump_fingerprints = 1;
- break;
- }
-
- case 'k':
- {
- _kring = optarg;
- break;
- }
-
- case '2':
- case '5':
- {
- version = c - '0';
- break;
- }
-
- case 's':
- {
- secring = 1;
- break;
- }
-
- default:
- {
- fprintf (stderr,
- "usage: %s [-k <key ring> | [-2 | -5] [ -s] [-S] [-f]] [hints]\n",
- argv[0]);
- exit (1);
- }
- }
- }
-
- if (_kring)
- m_strcpy(kring, sizeof(kring), _kring);
- else {
- if ((env_pgppath = getenv ("PGPPATH")))
- m_strcpy(pgppath, sizeof(pgppath), env_pgppath);
- else if ((env_home = getenv ("HOME")))
- snprintf (pgppath, sizeof (pgppath), "%s/.pgp", env_home);
- else {
- fprintf (stderr, "%s: Can't determine your PGPPATH.\n", argv[0]);
- exit (1);
- }
-
- if (secring)
- snprintf (kring, sizeof (kring), "%s/secring.%s", pgppath,
- version == 2 ? "pgp" : "skr");
- else
- snprintf (kring, sizeof (kring), "%s/pubring.%s", pgppath,
- version == 2 ? "pgp" : "pkr");
- }
-
- pgpring_find_candidates (kring, (const char **) argv + optind,
- argc - optind);
-
- return 0;
-}
-
-
-/* The actual key ring parser */
-
-static void pgp_make_pgp2_fingerprint (unsigned char *buff,
- unsigned char *digest)
-{
-
- MD5_CTX context;
- unsigned int size = 0;
-
-
- MD5Init (&context);
-
- size = (buff[0] << 8) + buff[1];
- size = ((size + 7) / 8);
- buff = &buff[2];
-
- MD5Update (&context, buff, size);
- buff = &buff[size];
-
- size = (buff[0] << 8) + buff[1];
- size = ((size + 7) / 8);
- buff = &buff[2];
-
- MD5Update (&context, buff, size);
-
- MD5Final (digest, &context);
-
-} /* pgp_make_pgp2_fingerprint() */
-
-static pgp_key_t pgp_parse_pgp2_key (unsigned char *buff, size_t l)
-{
- pgp_key_t p;
- unsigned char alg;
- unsigned char digest[MD5_DIGEST_LENGTH];
- size_t expl;
- unsigned long id;
- time_t gen_time = 0;
- unsigned short exp_days = 0;
- size_t j;
- int i, k;
- unsigned char scratch[LONG_STRING];
-
- if (l < 12)
- return NULL;
-
- p = pgp_new_keyinfo ();
-
- for (i = 0, j = 2; i < 4; i++)
- gen_time = (gen_time << 8) + buff[j++];
-
- p->gen_time = gen_time;
-
- for (i = 0; i < 2; i++)
- exp_days = (exp_days << 8) + buff[j++];
-
- if (exp_days && time (NULL) > gen_time + exp_days * 24 * 3600)
- p->flags |= KEYFLAG_EXPIRED;
-
- alg = buff[j++];
-
- p->numalg = alg;
- p->algorithm = pgp_pkalgbytype (alg);
- p->flags |= pgp_get_abilities (alg);
-
- if (dump_fingerprints) {
- /* j now points to the key material, which we need for the fingerprint */
- p->fp_len = MD5_DIGEST_LENGTH;
- pgp_make_pgp2_fingerprint (&buff[j], digest);
- memcpy (p->fingerprint, digest, MD5_DIGEST_LENGTH);
- }
- else /* just to be usre */
- p_clear(p->fingerprint, MD5_DIGEST_LENGTH);
-
- expl = 0;
- for (i = 0; i < 2; i++)
- expl = (expl << 8) + buff[j++];
-
- p->keylen = expl;
-
- expl = (expl + 7) / 8;
- if (expl < 4)
- goto bailout;
-
-
- j += expl - 8;
-
- for (k = 0; k < 2; k++) {
- for (id = 0, i = 0; i < 4; i++)
- id = (id << 8) + buff[j++];
-
- snprintf ((char *) scratch + k * 8, sizeof (scratch) - k * 8,
- "%08lX", id);
- }
-
- p->keyid = m_strdup((char *) scratch);
-
- return p;
-
-bailout:
-
- p_delete(&p);
- return NULL;
-}
-
-static void pgp_make_pgp3_fingerprint (unsigned char *buff, size_t l,
- unsigned char *digest)
-{
- unsigned char dummy;
- SHA1_CTX context;
-
- SHA1_Init (&context);
-
- dummy = buff[0] & 0x3f;
-
- if (dummy == PT_SUBSECKEY || dummy == PT_SUBKEY || dummy == PT_SECKEY)
- dummy = PT_PUBKEY;
-
- dummy = (dummy << 2) | 0x81;
- SHA1_Update (&context, &dummy, 1);
- dummy = ((l - 1) >> 8) & 0xff;
- SHA1_Update (&context, &dummy, 1);
- dummy = (l - 1) & 0xff;
- SHA1_Update (&context, &dummy, 1);
- SHA1_Update (&context, buff + 1, l - 1);
- SHA1_Final (digest, &context);
-
-}
-
-static void skip_bignum (unsigned char *buff, size_t l, size_t j,
- size_t * toff, size_t n)
-{
- size_t len;
-
- do {
- len = (buff[j] << 8) + buff[j + 1];
- j += (len + 7) / 8 + 2;
- }
- while (j <= l && --n > 0);
-
- if (toff)
- *toff = j;
-}
-
-
-static pgp_key_t pgp_parse_pgp3_key (unsigned char *buff, size_t l)
-{
- pgp_key_t p;
- unsigned char alg;
- unsigned char digest[SHA_DIGEST_LENGTH];
- unsigned char scratch[LONG_STRING];
- time_t gen_time = 0;
- unsigned long id;
- int i, k;
- short len;
- size_t j;
-
- p = pgp_new_keyinfo ();
- j = 2;
-
- for (i = 0; i < 4; i++)
- gen_time = (gen_time << 8) + buff[j++];
-
- p->gen_time = gen_time;
-
- alg = buff[j++];
-
- p->numalg = alg;
- p->algorithm = pgp_pkalgbytype (alg);
- p->flags |= pgp_get_abilities (alg);
-
- if (alg == 17)
- skip_bignum (buff, l, j, &j, 3);
- else if (alg == 16 || alg == 20)
- skip_bignum (buff, l, j, &j, 2);
-
- len = (buff[j] << 8) + buff[j + 1];
- p->keylen = len;
-
-
- if (alg >= 1 && alg <= 3)
- skip_bignum (buff, l, j, &j, 2);
- else if (alg == 17 || alg == 16 || alg == 20)
- skip_bignum (buff, l, j, &j, 1);
-
- pgp_make_pgp3_fingerprint (buff, j, digest);
- p->fp_len = SHA_DIGEST_LENGTH;
-
- for (k = 0; k < 2; k++) {
- for (id = 0, i = SHA_DIGEST_LENGTH - 8 + k * 4;
- i < SHA_DIGEST_LENGTH + (k - 1) * 4; i++)
- id = (id << 8) + digest[i];
-
- snprintf ((char *) scratch + k * 8, sizeof (scratch) - k * 8, "%08lX",
- id);
- }
-
- p->keyid = m_strdup((char *) scratch);
-
- return p;
-}
-
-static pgp_key_t pgp_parse_keyinfo (unsigned char *buff, size_t l)
-{
- if (!buff || l < 2)
- return NULL;
-
- switch (buff[1]) {
- case 2:
- case 3:
- return pgp_parse_pgp2_key (buff, l);
- case 4:
- return pgp_parse_pgp3_key (buff, l);
- default:
- return NULL;
- }
-}
-
-static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l,
- pgp_key_t p, pgp_sig_t * s)
-{
- unsigned char sigtype;
- time_t sig_gen_time;
- unsigned long signerid1;
- unsigned long signerid2;
- size_t j;
- int i;
-
- if (l < 22)
- return -1;
-
- j = 3;
- sigtype = buff[j++];
-
- sig_gen_time = 0;
- for (i = 0; i < 4; i++)
- sig_gen_time = (sig_gen_time << 8) + buff[j++];
-
- signerid1 = signerid2 = 0;
- for (i = 0; i < 4; i++)
- signerid1 = (signerid1 << 8) + buff[j++];
-
- for (i = 0; i < 4; i++)
- signerid2 = (signerid2 << 8) + buff[j++];
-
-
- if (sigtype == 0x20 || sigtype == 0x28)
- p->flags |= KEYFLAG_REVOKED;
-
- if (s) {
- s->sigtype = sigtype;
- s->sid1 = signerid1;
- s->sid2 = signerid2;
- }
-
- return 0;
-}
-
-static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l,
- pgp_key_t p, pgp_sig_t * s)
-{
- unsigned char sigtype;
- unsigned char pkalg;
- unsigned char hashalg;
- unsigned char skt;
- time_t sig_gen_time = -1;
- long validity = -1;
- long key_validity = -1;
- unsigned long signerid1 = 0;
- unsigned long signerid2 = 0;
- size_t ml;
- size_t j;
- int i;
- short ii;
- short have_critical_spks = 0;
-
- if (l < 7)
- return -1;
-
- j = 2;
-
- sigtype = buff[j++];
- pkalg = buff[j++];
- hashalg = buff[j++];
-
- for (ii = 0; ii < 2; ii++) {
- size_t skl;
- size_t nextone;
-
- ml = (buff[j] << 8) + buff[j + 1];
- j += 2;
-
- if (j + ml > l)
- break;
-
- nextone = j;
- while (ml) {
- j = nextone;
- skl = buff[j++];
- if (!--ml)
- break;
-
- if (skl >= 192) {
- skl = (skl - 192) * 256 + buff[j++] + 192;
- if (!--ml)
- break;
- }
-
- if ((int) ml - (int) skl < 0)
- break;
- ml -= skl;
-
- nextone = j + skl;
- skt = buff[j++];
-
- switch (skt & 0x7f) {
- case 2: /* creation time */
- {
- if (skl < 4)
- break;
- sig_gen_time = 0;
- for (i = 0; i < 4; i++)
- sig_gen_time = (sig_gen_time << 8) + buff[j++];
-
- break;
- }
- case 3: /* expiration time */
- {
- if (skl < 4)
- break;
- validity = 0;
- for (i = 0; i < 4; i++)
- validity = (validity << 8) + buff[j++];
- break;
- }
- case 9: /* key expiration time */
- {
- if (skl < 4)
- break;
- key_validity = 0;
- for (i = 0; i < 4; i++)
- key_validity = (key_validity << 8) + buff[j++];
- break;
- }
- case 16: /* issuer key ID */
- {
- if (skl < 8)
- break;
- signerid2 = signerid1 = 0;
- for (i = 0; i < 4; i++)
- signerid1 = (signerid1 << 8) + buff[j++];
- for (i = 0; i < 4; i++)
- signerid2 = (signerid2 << 8) + buff[j++];
-
- break;
- }
- case 10: /* CMR key */
- break;
- case 4: /* exportable */
- case 5: /* trust */
- case 6: /* regexp */
- case 7: /* revocable */
- case 11: /* Pref. symm. alg. */
- case 12: /* revocation key */
- case 20: /* notation data */
- case 21: /* pref. hash */
- case 22: /* pref. comp.alg. */
- case 23: /* key server prefs. */
- case 24: /* pref. key server */
- default:
- {
- if (skt & 0x80)
- have_critical_spks = 1;
- }
- }
- }
- j = nextone;
- }
-
- if (sigtype == 0x20 || sigtype == 0x28)
- p->flags |= KEYFLAG_REVOKED;
- if (key_validity != -1 && time (NULL) > p->gen_time + key_validity)
- p->flags |= KEYFLAG_EXPIRED;
- if (have_critical_spks)
- p->flags |= KEYFLAG_CRITICAL;
-
- if (s) {
- s->sigtype = sigtype;
- s->sid1 = signerid1;
- s->sid2 = signerid2;
- }
-
-
- return 0;
-
-}
-
-
-static int pgp_parse_sig (unsigned char *buff, size_t l,
- pgp_key_t p, pgp_sig_t * sig)
-{
- if (!buff || l < 2 || !p)
- return -1;
-
- switch (buff[1]) {
- case 2:
- case 3:
- return pgp_parse_pgp2_sig (buff, l, p, sig);
- case 4:
- return pgp_parse_pgp3_sig (buff, l, p, sig);
- default:
- return -1;
- }
-}
-
-/* parse one key block, including all subkeys. */
-
-static pgp_key_t pgp_parse_keyblock (FILE * fp)
-{
- unsigned char *buff;
- unsigned char pt = 0;
- unsigned char last_pt;
- size_t l;
- short err = 0;
-
-#ifdef HAVE_FGETPOS
- fpos_t pos;
-#else
- off_t pos;
-#endif
-
- pgp_key_t root = NULL;
- pgp_key_t *last = &root;
- pgp_key_t p = NULL;
- pgp_uid_t *uid = NULL;
- pgp_uid_t **addr = NULL;
- pgp_sig_t **lsig = NULL;
-
- FGETPOS (fp, pos);
-
- while (!err && (buff = pgp_read_packet (fp, &l)) != NULL) {
- last_pt = pt;
- pt = buff[0] & 0x3f;
-
- /* check if we have read the complete key block. */
-
- if ((pt == PT_SECKEY || pt == PT_PUBKEY) && root) {
- FSETPOS (fp, pos);
- return root;
- }
-
- switch (pt) {
- case PT_SECKEY:
- case PT_PUBKEY:
- case PT_SUBKEY:
- case PT_SUBSECKEY:
- {
- if (!(*last = p = pgp_parse_keyinfo (buff, l))) {
- err = 1;
- break;
- }
-
- last = &p->next;
- addr = &p->address;
- lsig = &p->sigs;
-
- if (pt == PT_SUBKEY || pt == PT_SUBSECKEY) {
- p->flags |= KEYFLAG_SUBKEY;
- if (p != root) {
- p->parent = root;
- p->address = pgp_copy_uids (root->address, p);
- while (*addr)
- addr = &(*addr)->next;
- }
- }
-
- if (pt == PT_SECKEY || pt == PT_SUBSECKEY)
- p->flags |= KEYFLAG_SECRET;
-
- break;
- }
-
- case PT_SIG:
- {
- if (lsig) {
- pgp_sig_t *signature = p_new(pgp_sig_t, 1);
-
- *lsig = signature;
- lsig = &signature->next;
-
- pgp_parse_sig (buff, l, p, signature);
- }
- break;
- }
-
- case PT_TRUST:
- {
- if (p && (last_pt == PT_SECKEY || last_pt == PT_PUBKEY ||
- last_pt == PT_SUBKEY || last_pt == PT_SUBSECKEY)) {
- if (buff[1] & 0x20) {
- p->flags |= KEYFLAG_DISABLED;
- }
- }
- else if (last_pt == PT_NAME && uid) {
- uid->trust = buff[1];
- }
- break;
- }
- case PT_NAME:
- {
- char *chr;
-
-
- if (!addr)
- break;
-
- chr = p_dupstr(buff + 1, l - 1);
-
- *addr = uid = p_new(pgp_uid_t, 1); /* XXX */
- uid->addr = chr;
- uid->parent = p;
- uid->trust = 0;
- addr = &uid->next;
- lsig = &uid->sigs;
-
- /* the following tags are generated by
- * pgp 2.6.3in.
- */
-
- if (strstr (chr, "ENCR"))
- p->flags |= KEYFLAG_PREFER_ENCRYPTION;
- if (strstr (chr, "SIGN"))
- p->flags |= KEYFLAG_PREFER_SIGNING;
-
- break;
- }
- }
-
- FGETPOS (fp, pos);
- }
-
- if (err)
- pgp_free_key (&root);
-
- return root;
-}
-
-static int pgpring_string_matches_hint (const char *s, const char *hints[],
- int nhints)
-{
- int i;
-
- if (!hints || !nhints)
- return 1;
-
- for (i = 0; i < nhints; i++) {
- if (m_stristr(s, hints[i]) != NULL)
- return 1;
- }
-
- return 0;
-}
-
-/*
- * Go through the key ring file and look for keys with
- * matching IDs.
- */
-
-static void pgpring_find_candidates (char *ringfile, const char *hints[],
- int nhints)
-{
- FILE *rfp;
-
-#ifdef HAVE_FGETPOS
- fpos_t pos, keypos;
-#else
- off_t pos, keypos;
-#endif
-
- unsigned char *buff = NULL;
- unsigned char pt = 0;
- size_t l = 0;
-
- short err = 0;
-
- if ((rfp = fopen (ringfile, "r")) == NULL) {
- char *error_buf;
- size_t error_buf_len;
-
- error_buf_len = sizeof ("fopen: ") - 1 + m_strlen(ringfile) + 1;
- error_buf = p_new(char, error_buf_len);
- snprintf (error_buf, error_buf_len, "fopen: %s", ringfile);
- perror (error_buf);
- p_delete(&error_buf);
- return;
- }
-
- FGETPOS (rfp, pos);
- FGETPOS (rfp, keypos);
-
- while (!err && (buff = pgp_read_packet (rfp, &l)) != NULL) {
- pt = buff[0] & 0x3f;
-
- if (l < 1)
- continue;
-
- if ((pt == PT_SECKEY) || (pt == PT_PUBKEY)) {
- keypos = pos;
- }
- else if (pt == PT_NAME) {
- char *tmp = p_dupstr(buff + 1, l - 1);
-
- /* mutt_decode_utf8_string (tmp, chs); */
-
- if (pgpring_string_matches_hint (tmp, hints, nhints)) {
- pgp_key_t p;
-
- FSETPOS (rfp, keypos);
-
- /* Not bailing out here would lead us into an endless loop. */
-
- if ((p = pgp_parse_keyblock (rfp)) == NULL)
- err = 1;
-
- pgpring_dump_keyblock (p);
- pgp_free_key (&p);
- }
-
- p_delete(&tmp);
- }
-
- FGETPOS (rfp, pos);
- }
- m_fclose(&rfp);
-}
-
-static void print_userid (const char *id)
-{
- for (; id && *id; id++) {
- if (*id >= ' ' && *id <= 'z' && *id != ':')
- putchar (*id);
- else
- printf ("\\x%02x", (*id) & 0xff);
- }
-}
-
-static void print_fingerprint (pgp_key_t p)
-{
- int i = 0;
-
- printf ("fpr:::::::::");
- for (i = 0; i < p->fp_len; i++)
- printf ("%02X", p->fingerprint[i]);
- printf (":\n");
-
-} /* print_fingerprint() */
-
-
-static void pgpring_dump_signatures (pgp_sig_t * sig)
-{
- for (; sig; sig = sig->next) {
- if (sig->sigtype == 0x10 || sig->sigtype == 0x11 ||
- sig->sigtype == 0x12 || sig->sigtype == 0x13)
- printf ("sig::::%08lX%08lX::::::%X:\n",
- sig->sid1, sig->sid2, sig->sigtype);
- else if (sig->sigtype == 0x20)
- printf ("rev::::%08lX%08lX::::::%X:\n",
- sig->sid1, sig->sid2, sig->sigtype);
- }
-}
-
-
-static char gnupg_trustletter (int t)
-{
- switch (t) {
- case 1:
- return 'n';
- case 2:
- return 'm';
- case 3:
- return 'f';
- }
- return 'q';
-}
-
-static void pgpring_dump_keyblock (pgp_key_t p)
-{
- pgp_uid_t *uid;
- short first;
- struct tm *tp;
- time_t t;
-
- for (; p; p = p->next) {
- first = 1;
-
- if (p->flags & KEYFLAG_SECRET) {
- if (p->flags & KEYFLAG_SUBKEY)
- printf ("ssb:");
- else
- printf ("sec:");
- }
- else {
- if (p->flags & KEYFLAG_SUBKEY)
- printf ("sub:");
- else
- printf ("pub:");
- }
-
- if (p->flags & KEYFLAG_REVOKED)
- putchar ('r');
- if (p->flags & KEYFLAG_EXPIRED)
- putchar ('e');
- if (p->flags & KEYFLAG_DISABLED)
- putchar ('d');
-
- for (uid = p->address; uid; uid = uid->next, first = 0) {
- if (!first) {
- printf ("uid:%c::::::::", gnupg_trustletter (uid->trust));
- print_userid (uid->addr);
- printf (":\n");
- }
- else {
- if (p->flags & KEYFLAG_SECRET)
- putchar ('u');
- else
- putchar (gnupg_trustletter (uid->trust));
-
- t = p->gen_time;
- tp = gmtime (&t);
-
- printf (":%d:%d:%s:%04d-%02d-%02d::::", p->keylen, p->numalg,
- p->keyid, 1900 + tp->tm_year, tp->tm_mon + 1, tp->tm_mday);
-
- print_userid (uid->addr);
- printf ("::");
-
- if (pgp_canencrypt (p->numalg))
- putchar ('e');
- if (pgp_cansign (p->numalg))
- putchar ('s');
- if (p->flags & KEYFLAG_DISABLED)
- putchar ('D');
- printf (":\n");
-
- if (dump_fingerprints)
- print_fingerprint (p);
- }
-
- if (dump_signatures) {
- if (first)
- pgpring_dump_signatures (p->sigs);
- pgpring_dump_signatures (uid->sigs);
- }
- }
- }
-}