merge crypt back into $top_builddir :)
authorPierre Habouzit <madcoder@debian.org>
Wed, 4 Apr 2007 23:46:14 +0000 (01:46 +0200)
committerPierre Habouzit <madcoder@debian.org>
Wed, 4 Apr 2007 23:46:14 +0000 (01:46 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
28 files changed:
Makefile.am
attach.c
commands.c
compose.c
configure.ac
copy.c
crypt.c [moved from lib-crypt/crypt-gpgme.c with 91% similarity]
crypt.h [moved from lib-crypt/crypt.h with 91% similarity]
handler.c
headers.c
hook.c
init.c
keymap.c
lib-crypt/Makefile.am [deleted file]
lib-crypt/crypt.c [deleted file]
lib-mime/crypt.c
lib-mx/mx.c
lib-ui/curs_main.c
lib-ui/hdrline.c
main.c
nntp/nntp.c
pager.c
pattern.c
pop/pop.c
postpone.c
recvattach.c
send.c
sendlib.c

index c6ab853..2e155df 100644 (file)
@@ -9,7 +9,7 @@ NNTP_SUBDIR = nntp
 endif
 
 SUBDIRS = tools intl m4 po $(XXXXXXXXXXXX_doc) apidoc contrib \
-         lib-lua lib-mime lib-lib lib-mx lib-crypt lib-hash lib-sys lib-ui \
+         lib-lua lib-mime lib-lib lib-mx lib-hash lib-sys lib-ui \
          pop imap $(NNTP_SUBDIR)
 
 BUILT_SOURCES = keymap_defs.h charset.gperf
@@ -18,14 +18,13 @@ DISTCLEANFILES = $(BUILT_SOURCES)
 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 \
+       compose.c copy.c crypt.c editmsg.c init.c keymap.c lib.c \
        flags.c from.c handler.c headers.c help.c hook.c \
        main.c muttlib.c mutt_idna.c pager.c pattern.c postpone.c recvattach.c recvcmd.c \
        score.c send.c sendlib.c sort.c state.c thread.c account.c remailer.c
 
 madmutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \
                $(top_builddir)/lib-mime/libmime.a \
-               $(top_builddir)/lib-crypt/libcrypt.a \
                $(top_builddir)/lib-mx/libmx.a \
                $(top_builddir)/imap/libimap.a \
                $(top_builddir)/pop/libpop.a \
@@ -42,7 +41,6 @@ madmutt_DEPENDENCIES = \
                       @MUTT_LIB_OBJECTS@ @LIBOBJS@ \
                       $(top_builddir)/lib-lib/liblib.a \
                       $(top_builddir)/lib-mime/libmime.a \
-                      $(top_builddir)/lib-crypt/libcrypt.a \
                       $(top_builddir)/lib-hash/libhash.a \
                       $(top_builddir)/lib-sys/libsys.a \
                       $(top_builddir)/lib-ui/libui.a \
@@ -74,7 +72,7 @@ EXTRA_madmutt_SOURCES = \
 
 EXTRA_DIST = config.rpath  COPYRIGHT GPL OPS TODO \
        configure account.h alias.h attach.h recvattach.h handler.h thread.h \
-       buffy.h charset.h copy.h dotlock.h functions.def gen_defs \
+       buffy.h charset.h copy.h crypt.c dotlock.h functions.def gen_defs \
        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 \
index db791f5..1750e26 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -22,7 +22,7 @@
 #include "keymap.h"
 #include "pager.h"
 #include "copy.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 
 int mutt_get_tmp_attachment (BODY * a)
 {
index f5b4d43..4e810c9 100644 (file)
@@ -28,7 +28,7 @@
 #include "sort.h"
 #include "copy.h"
 #include "pager.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 #include "mutt_idna.h"
 #include <sys/types.h>
 #include <sys/stat.h>
index a5f7094..d8e0694 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -15,7 +15,6 @@
 
 #include <lib-sys/unix.h>
 #include <lib-mime/mime.h>
-#include <lib-crypt/crypt.h>
 
 #include <lib-ui/curses.h>
 #include <lib-ui/enter.h>
@@ -24,6 +23,7 @@
 
 #include "mutt.h"
 #include "alias.h"
+#include "crypt.h"
 #include "mutt_idna.h"
 #include "attach.h"
 #include "recvattach.h"
index f3d2183..0300fa7 100644 (file)
@@ -745,7 +745,6 @@ AC_OUTPUT(Makefile
           lib-lib/Makefile
           lib-lua/Makefile
           lib-mime/Makefile
-          lib-crypt/Makefile
           lib-hash/Makefile
           lib-mx/Makefile
           lib-sys/Makefile
diff --git a/copy.c b/copy.c
index 8e8f96f..c3299f0 100644 (file)
--- a/copy.c
+++ b/copy.c
 #include <lib-lib/lib-lib.h>
 
 #include <lib-mime/mime.h>
+#include <lib-ui/curses.h>
 #include <lib-mx/mx.h>
 
 #include "mutt.h"
 #include "handler.h"
 #include "copy.h"
-#include <lib-crypt/crypt.h>
-#include <lib-ui/curses.h>
+#include "crypt.h"
 #include "mutt_idna.h"
 
 static int address_header_decode (char **str);
similarity index 91%
rename from lib-crypt/crypt-gpgme.c
rename to crypt.c
index 5bd3173..b22d616 100644 (file)
+++ b/crypt.c
@@ -19,6 +19,7 @@
 #include <lib-ui/curses.h>
 #include <lib-ui/enter.h>
 #include <lib-ui/menu.h>
+#include <lib-mx/mx.h>
 
 #include "crypt.h"
 
@@ -3907,3 +3908,387 @@ void crypt_smime_getkeys (ENVELOPE * env)
 {
 }
 
+/***************************************************************************/
+
+void crypt_invoke_message (int type)
+{
+    if (type & APPLICATION_PGP) {
+        mutt_message _("Invoking PGP...");
+    }
+    else if (type & APPLICATION_SMIME) {
+        mutt_message _("Invoking S/MIME...");
+    }
+}
+
+int mutt_protect (HEADER * msg, char *keylist)
+{
+  BODY *pbody = NULL, *tmp_pbody = NULL;
+  BODY *tmp_smime_pbody = NULL;
+  BODY *tmp_pgp_pbody = NULL;
+  int flags = msg->security;
+
+  if (!isendwin ())
+    mutt_endwin (NULL);
+
+  tmp_smime_pbody = msg->content;
+  tmp_pgp_pbody = msg->content;
+
+  if (msg->security & SIGN) {
+    if (msg->security & APPLICATION_SMIME) {
+      if (!(tmp_pbody = crypt_smime_sign_message (msg->content)))
+        return -1;
+      pbody = tmp_smime_pbody = tmp_pbody;
+    }
+
+    if ((msg->security & APPLICATION_PGP)
+        && (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG))) {
+      if (!(tmp_pbody = crypt_pgp_sign_message (msg->content)))
+        return -1;
+
+      flags &= ~SIGN;
+      pbody = tmp_pgp_pbody = tmp_pbody;
+    }
+
+    if ((msg->security & APPLICATION_SMIME)
+        && (msg->security & APPLICATION_PGP)) {
+      /* here comes the draft ;-) */
+    }
+  }
+
+
+  if (msg->security & ENCRYPT) {
+    if ((msg->security & APPLICATION_SMIME)) {
+      if (!(tmp_pbody = crypt_smime_build_smime_entity (tmp_smime_pbody,
+                                                        keylist))) {
+        /* signed ? free it! */
+        return (-1);
+      }
+      /* free tmp_body if messages was signed AND encrypted ... */
+      if (tmp_smime_pbody != msg->content && tmp_smime_pbody != tmp_pbody) {
+        /* detatch and dont't delete msg->content,
+           which tmp_smime_pbody->parts after signing. */
+        tmp_smime_pbody->parts = tmp_smime_pbody->parts->next;
+        msg->content->next = NULL;
+        body_list_wipe(&tmp_smime_pbody);
+      }
+      pbody = tmp_pbody;
+    }
+
+    if ((msg->security & APPLICATION_PGP)) {
+      if (!(pbody = crypt_pgp_encrypt_message (tmp_pgp_pbody, keylist,
+                                               flags & SIGN))) {
+
+        /* did we perform a retainable signature? */
+        if (flags != msg->security) {
+          /* remove the outer multipart layer */
+          tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody);
+          /* get rid of the signature */
+          body_list_wipe(&tmp_pgp_pbody->next);
+        }
+
+        return (-1);
+      }
+
+      /* destroy temporary signature envelope when doing retainable 
+       * signatures.
+
+       */
+      if (flags != msg->security) {
+        tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody);
+        body_list_wipe(&tmp_pgp_pbody->next);
+      }
+    }
+  }
+
+  if (pbody)
+    msg->content = pbody;
+
+  return 0;
+}
+
+
+int crypt_query (BODY * m)
+{
+  int t = 0;
+
+  if (!m)
+    return 0;
+
+  if (m->type == TYPEAPPLICATION) {
+    t |= mutt_is_application_pgp (m);
+
+    t |= mutt_is_application_smime (m);
+    if (t && m->goodsig)
+      t |= GOODSIGN;
+    if (t && m->badsig)
+      t |= BADSIGN;
+  }
+  else if (m->type == TYPETEXT) {
+    t |= mutt_is_application_pgp (m);
+    if (t && m->goodsig)
+      t |= GOODSIGN;
+  }
+
+  if (m->type == TYPEMULTIPART) {
+    t |= mutt_is_multipart_encrypted (m);
+    t |= mutt_is_multipart_signed (m);
+
+    if (t && m->goodsig)
+      t |= GOODSIGN;
+  }
+
+  if (m->type == TYPEMULTIPART || m->type == TYPEMESSAGE) {
+    BODY *p;
+    int u, v, w;
+
+    u = m->parts ? ~0 : 0;      /* Bits set in all parts */
+    w = 0;                      /* Bits set in any part  */
+
+    for (p = m->parts; p; p = p->next) {
+      v = crypt_query (p);
+      u &= v;
+      w |= v;
+    }
+    t |= u | (w & ~GOODSIGN);
+
+    if ((w & GOODSIGN) && !(u & GOODSIGN))
+      t |= PARTSIGN;
+  }
+
+  return t;
+}
+
+
+static void crypt_write_signed(BODY * a, STATE * s, FILE *fp)
+{
+    int c;
+    short hadcr;
+    size_t bytes;
+
+    fseeko (s->fpin, a->hdr_offset, 0);
+    bytes = a->length + a->offset - a->hdr_offset;
+    hadcr = 0;
+    while (bytes > 0) {
+        if ((c = fgetc (s->fpin)) == EOF)
+            break;
+
+        bytes--;
+
+        if (c == '\r')
+            hadcr = 1;
+        else {
+            if (c == '\n' && !hadcr)
+                fputc ('\r', fp);
+
+            hadcr = 0;
+        }
+        fputc (c, fp);
+    }
+}
+
+
+
+void convert_to_7bit (BODY * a)
+{
+  while (a) {
+    if (a->type == TYPEMULTIPART) {
+      if (a->encoding != ENC7BIT) {
+        a->encoding = ENC7BIT;
+        convert_to_7bit (a->parts);
+      } else {
+        convert_to_7bit (a->parts);
+      }
+    }
+    else if (a->type == TYPEMESSAGE &&
+             m_strcasecmp(a->subtype, "delivery-status")) {
+      if (a->encoding != ENC7BIT)
+        mutt_message_to_7bit (a, NULL);
+    }
+    else if (a->encoding == ENC8BIT)
+      a->encoding = ENCQUOTEDPRINTABLE;
+    else if (a->encoding == ENCBINARY)
+      a->encoding = ENCBASE64;
+    else if (a->content && a->encoding != ENCBASE64 &&
+             (a->content->from || a->content->space))
+      a->encoding = ENCQUOTEDPRINTABLE;
+    a = a->next;
+  }
+}
+
+
+static void extract_keys_aux(FILE *fpout, HEADER *h)
+{
+    mutt_parse_mime_message (Context, h);
+
+    rewind(fpout);
+    if (h->security & APPLICATION_PGP) {
+        mutt_copy_message(fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0);
+        fflush (fpout);
+
+        mutt_endwin (_("Trying to extract PGP keys...\n"));
+    }
+
+    if (h->security & APPLICATION_SMIME) {
+        if (h->security & ENCRYPT)
+            mutt_copy_message (fpout, Context, h, M_CM_NOHEADER
+                               | M_CM_DECODE_CRYPT | M_CM_DECODE_SMIME, 0);
+        else
+            mutt_copy_message(fpout, Context, h, 0, 0);
+        fflush (fpout);
+
+        mutt_message (_("Trying to extract S/MIME certificates...\n"));
+    }
+
+    rewind(fpout);
+    crypt_invoke_import(fpout, h->security & APPLICATION_SMIME);
+}
+
+void crypt_extract_keys_from_messages(HEADER * h)
+{
+    FILE *tmpfp = tmpfile();
+    if (!tmpfp) {
+        mutt_error(_("Could not create temporary file"));
+        return;
+    }
+
+    set_option(OPTDONTHANDLEPGPKEYS);
+    if (!h) {
+        int i;
+        for (i = 0; i < Context->vcount; i++) {
+            if (!Context->hdrs[Context->v2r[i]]->tagged)
+                continue;
+            extract_keys_aux(tmpfp, Context->hdrs[Context->v2r[i]]);
+        }
+    } else {
+        extract_keys_aux(tmpfp, h);
+    }
+    unset_option(OPTDONTHANDLEPGPKEYS);
+    m_fclose(&tmpfp);
+
+    if (isendwin())
+        mutt_any_key_to_continue(NULL);
+}
+
+
+
+static void crypt_fetch_signatures (BODY ***signatures, BODY * a, int *n)
+{
+  for (; a; a = a->next) {
+    if (a->type == TYPEMULTIPART)
+      crypt_fetch_signatures (signatures, a->parts, n);
+    else {
+      if ((*n % 5) == 0)
+        p_realloc(signatures, *n + 6);
+
+      (*signatures)[(*n)++] = a;
+    }
+  }
+}
+
+
+/*
+ * This routine verifies a  "multipart/signed"  body.
+ */
+
+int mutt_signed_handler (BODY * a, STATE * s)
+{
+  unsigned major, minor;
+  char *protocol;
+  int rc, i, goodsig = 1, sigcnt = 0;
+  BODY *b = a;
+
+  protocol = parameter_getval(a->parameter, "protocol");
+  a = a->parts;
+
+  switch (mime_which_token(protocol, -1)) {
+    case MIME_APPLICATION_PGP_SIGNATURE:
+      major = TYPEAPPLICATION;
+      minor = MIME_PGP_SIGNATURE;
+      break;
+    case MIME_APPLICATION_X_PKCS7_SIGNATURE:
+      major = TYPEAPPLICATION;
+      minor = MIME_X_PKCS7_SIGNATURE;
+      break;
+    case MIME_APPLICATION_PKCS7_SIGNATURE:
+      major = TYPEAPPLICATION;
+      minor = MIME_PKCS7_SIGNATURE;
+      break;
+    case MIME_MULTIPART_MIXED:
+      major = TYPEMULTIPART;
+      minor = MIME_MIXED;
+      break;
+
+    default:
+      state_printf(s, _("[-- Error: "
+                        "Unknown multipart/signed protocol %s! --]\n\n"),
+                    protocol);
+      return mutt_body_handler (a, s);
+  }
+
+  /* consistency check */
+  if (!(a && a->next && a->next->type == major &&
+        mime_which_token(a->next->subtype, -1) == minor))
+  {
+    state_attach_puts(_("[-- Error: "
+                        "Inconsistent multipart/signed structure! --]\n\n"),
+                      s);
+    return mutt_body_handler (a, s);
+  }
+
+  if (s->flags & M_DISPLAY) {
+    BODY **sigs = NULL;
+
+    crypt_fetch_signatures (&sigs, a->next, &sigcnt);
+    if (sigcnt) {
+      FILE *tmpfp = tmpfile();
+
+      if (!tmpfp) {
+          mutt_error(_("Could not create temporary file"));
+      } else {
+        crypt_write_signed(a, s, tmpfp);
+        rewind(tmpfp);
+        for (i = 0; i < sigcnt; i++) {
+          if (sigs[i]->type == TYPEAPPLICATION) {
+            int subtype;
+
+            switch ((subtype = mime_which_token(sigs[i]->subtype, -1))) {
+              case MIME_PGP_SIGNATURE:
+              case MIME_X_PKCS7_SIGNATURE:
+              case MIME_PKCS7_SIGNATURE:
+                if (crypt_verify_one(sigs[i], s, tmpfp, subtype != MIME_PGP_SIGNATURE) != 0)
+                  goodsig = 0;
+
+                m_fclose(&tmpfp);
+                continue;
+
+              default:
+                break;
+            }
+          }
+
+          state_printf(s, _("[-- Warning: "
+                            "We can't verify %s/%s signatures. --]\n\n"),
+                       TYPE (sigs[i]), sigs[i]->subtype);
+        }
+      }
+
+      b->goodsig = goodsig;
+      b->badsig  = !goodsig;
+
+      /* Now display the signed body */
+      state_attach_puts(_("[-- The following data is signed --]\n\n"), s);
+
+      p_delete(&sigs);
+    } else {
+      state_attach_puts(_("[-- Warning: Can't find any signatures. --]\n\n"),
+                        s);
+    }
+  }
+
+  rc = mutt_body_handler (a, s);
+
+  if (s->flags & M_DISPLAY && sigcnt)
+    state_attach_puts (_("\n[-- End of signed data --]\n"), s);
+
+  return (rc);
+}
similarity index 91%
rename from lib-crypt/crypt.h
rename to crypt.h
index 8d394ca..12acc61 100644 (file)
+++ b/crypt.h
 #include <lib-mime/mime.h>
 #include "state.h"
 
-/* FIXME: They should be pointer to anonymous structures for better
-   information hiding. */
-
-
 #define ENCRYPT    (1 << 0)
 #define SIGN       (1 << 1)
 #define GOODSIGN   (1 << 2)
 
 #define PGPENCRYPT  (APPLICATION_PGP | ENCRYPT)
 #define PGPSIGN     (APPLICATION_PGP | SIGN)
-#define PGPGOODSIGN (APPLICATION_PGP | GOODSIGN)
 #define PGPKEY      (APPLICATION_PGP | KEYBLOCK)
 #define PGPINLINE   (APPLICATION_PGP | INLINE)
 
 #define SMIMEENCRYPT  (APPLICATION_SMIME | ENCRYPT)
 #define SMIMESIGN     (APPLICATION_SMIME | SIGN)
-#define SMIMEGOODSIGN (APPLICATION_SMIME | GOODSIGN)
-#define SMIMEBADSIGN  (APPLICATION_SMIME | BADSIGN)
 #define SMIMEOPAQUE   (APPLICATION_SMIME | SIGNOPAQUE)
 
 #define KEYFLAG_CANSIGN                (1 <<  0)
 
 #define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN|KEYFLAG_CANENCRYPT|KEYFLAG_PREFER_ENCRYPTION|KEYFLAG_PREFER_SIGNING)
 
-enum pgp_ring {
-  PGP_PUBRING,
-  PGP_SECRING
-};
-typedef enum pgp_ring pgp_ring_t;
-
-
-struct pgp_keyinfo;
-typedef struct pgp_keyinfo *pgp_key_t;
-
-
-
-/* Some prototypes -- old crypt.h. */
-
-int mutt_protect (HEADER *, char *);
-
-int mutt_signed_handler (BODY *, STATE *);
-
-int mutt_parse_crypt_hdr (char *, int);
-
-void convert_to_7bit (BODY *);
-
-
 /*-- new API --*/
 
 void crypt_invoke_import(FILE *stream, int smime);
@@ -98,6 +68,11 @@ int crypt_verify_one(BODY *, STATE *s, FILE *fp, int smime);
 
 /*-- crypt.c --*/
 
+int mutt_protect (HEADER *, char *);
+int mutt_signed_handler (BODY *, STATE *);
+int mutt_parse_crypt_hdr (char *, int);
+void convert_to_7bit (BODY *);
+
 /* Check out the type of encryption used and set the cached status
    values if there are any. */
 int crypt_query (BODY * m);
index abe7f65..28739c1 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -22,7 +22,7 @@
 #include "keymap.h"
 #include "copy.h"
 #include "charset.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 #include "state.h"
 #include "attach.h"
 #include "lib.h"
index cd3362b..a067025 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -12,7 +12,7 @@
 
 #include "mutt.h"
 #include "alias.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 #include "mutt_idna.h"
 
 void mutt_edit_headers(const char *body,
diff --git a/hook.c b/hook.c
index 7361bba..315a1c1 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -12,9 +12,9 @@
 #include <lib-ui/curses.h>
 #include <lib-mx/mx.h>
 #include <lib-mx/compress.h>
-#include <lib-crypt/crypt.h>
 
 #include "alias.h"
+#include "crypt.h"
 #include "pattern.h"
 
 typedef struct hook_t {
diff --git a/init.c b/init.c
index fb2f8a6..0a4d827 100644 (file)
--- a/init.c
+++ b/init.c
 #include <lib-ui/curses.h>
 #include <lib-ui/history.h>
 #include <lib-mx/mx.h>
-#include <lib-crypt/crypt.h>
 
 #include "mutt.h"
 #include "keymap.h"
+#include "crypt.h"
 #include "charset.h"
 #include "thread.h"
 #include "mutt_idna.h"
index ffbdc93..ab8ad63 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -14,7 +14,7 @@
 
 #include "mutt.h"
 #include "keymap.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 
 #define MUTT_FUNCTIONS_VALUES
 #include "functions.def"
diff --git a/lib-crypt/Makefile.am b/lib-crypt/Makefile.am
deleted file mode 100644 (file)
index 5e591e6..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-noinst_LIBRARIES = libcrypt.a
-
-libcrypt_a_SOURCES = crypt.h crypt.c crypt-gpgme.c
-
-noinst_HEADERS     = crypt.h
-
--include $(top_builddir)/tools/cflags.mk
diff --git a/lib-crypt/crypt.c b/lib-crypt/crypt.c
deleted file mode 100644 (file)
index 60349cf..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
- * Copyright (C) 1998-2000 Thomas Roessler <roessler@does-not-exist.org>
- * Copyright (C) 2001  Thomas Roessler <roessler@does-not-exist.org>
- *                     Oliver Ehli <elmy@acm.org>
- * Copyright (C) 2003  Werner Koch <wk@gnupg.org>
- * Copyright (C) 2002, 2003, 2004 g10 Code GmbH
- */
-/*
- * Copyright © 2006 Pierre Habouzit
- */
-
-#include <lib-lib/lib-lib.h>
-
-#include <lib-mime/mime.h>
-#include <lib-ui/curses.h>
-#include <lib-mx/mx.h>
-
-#include "alias.h"
-#include "handler.h"
-#include "copy.h"
-#include "crypt.h"
-
-void crypt_invoke_message (int type)
-{
-    if (type & APPLICATION_PGP) {
-        mutt_message _("Invoking PGP...");
-    }
-    else if (type & APPLICATION_SMIME) {
-        mutt_message _("Invoking S/MIME...");
-    }
-}
-
-int mutt_protect (HEADER * msg, char *keylist)
-{
-  BODY *pbody = NULL, *tmp_pbody = NULL;
-  BODY *tmp_smime_pbody = NULL;
-  BODY *tmp_pgp_pbody = NULL;
-  int flags = msg->security;
-
-  if (!isendwin ())
-    mutt_endwin (NULL);
-
-  tmp_smime_pbody = msg->content;
-  tmp_pgp_pbody = msg->content;
-
-  if (msg->security & SIGN) {
-    if (msg->security & APPLICATION_SMIME) {
-      if (!(tmp_pbody = crypt_smime_sign_message (msg->content)))
-        return -1;
-      pbody = tmp_smime_pbody = tmp_pbody;
-    }
-
-    if ((msg->security & APPLICATION_PGP)
-        && (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG))) {
-      if (!(tmp_pbody = crypt_pgp_sign_message (msg->content)))
-        return -1;
-
-      flags &= ~SIGN;
-      pbody = tmp_pgp_pbody = tmp_pbody;
-    }
-
-    if ((msg->security & APPLICATION_SMIME)
-        && (msg->security & APPLICATION_PGP)) {
-      /* here comes the draft ;-) */
-    }
-  }
-
-
-  if (msg->security & ENCRYPT) {
-    if ((msg->security & APPLICATION_SMIME)) {
-      if (!(tmp_pbody = crypt_smime_build_smime_entity (tmp_smime_pbody,
-                                                        keylist))) {
-        /* signed ? free it! */
-        return (-1);
-      }
-      /* free tmp_body if messages was signed AND encrypted ... */
-      if (tmp_smime_pbody != msg->content && tmp_smime_pbody != tmp_pbody) {
-        /* detatch and dont't delete msg->content,
-           which tmp_smime_pbody->parts after signing. */
-        tmp_smime_pbody->parts = tmp_smime_pbody->parts->next;
-        msg->content->next = NULL;
-        body_list_wipe(&tmp_smime_pbody);
-      }
-      pbody = tmp_pbody;
-    }
-
-    if ((msg->security & APPLICATION_PGP)) {
-      if (!(pbody = crypt_pgp_encrypt_message (tmp_pgp_pbody, keylist,
-                                               flags & SIGN))) {
-
-        /* did we perform a retainable signature? */
-        if (flags != msg->security) {
-          /* remove the outer multipart layer */
-          tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody);
-          /* get rid of the signature */
-          body_list_wipe(&tmp_pgp_pbody->next);
-        }
-
-        return (-1);
-      }
-
-      /* destroy temporary signature envelope when doing retainable 
-       * signatures.
-
-       */
-      if (flags != msg->security) {
-        tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody);
-        body_list_wipe(&tmp_pgp_pbody->next);
-      }
-    }
-  }
-
-  if (pbody)
-    msg->content = pbody;
-
-  return 0;
-}
-
-
-int crypt_query (BODY * m)
-{
-  int t = 0;
-
-  if (!m)
-    return 0;
-
-  if (m->type == TYPEAPPLICATION) {
-    t |= mutt_is_application_pgp (m);
-
-    t |= mutt_is_application_smime (m);
-    if (t && m->goodsig)
-      t |= GOODSIGN;
-    if (t && m->badsig)
-      t |= BADSIGN;
-  }
-  else if (m->type == TYPETEXT) {
-    t |= mutt_is_application_pgp (m);
-    if (t && m->goodsig)
-      t |= GOODSIGN;
-  }
-
-  if (m->type == TYPEMULTIPART) {
-    t |= mutt_is_multipart_encrypted (m);
-    t |= mutt_is_multipart_signed (m);
-
-    if (t && m->goodsig)
-      t |= GOODSIGN;
-  }
-
-  if (m->type == TYPEMULTIPART || m->type == TYPEMESSAGE) {
-    BODY *p;
-    int u, v, w;
-
-    u = m->parts ? ~0 : 0;      /* Bits set in all parts */
-    w = 0;                      /* Bits set in any part  */
-
-    for (p = m->parts; p; p = p->next) {
-      v = crypt_query (p);
-      u &= v;
-      w |= v;
-    }
-    t |= u | (w & ~GOODSIGN);
-
-    if ((w & GOODSIGN) && !(u & GOODSIGN))
-      t |= PARTSIGN;
-  }
-
-  return t;
-}
-
-
-static void crypt_write_signed(BODY * a, STATE * s, FILE *fp)
-{
-    int c;
-    short hadcr;
-    size_t bytes;
-
-    fseeko (s->fpin, a->hdr_offset, 0);
-    bytes = a->length + a->offset - a->hdr_offset;
-    hadcr = 0;
-    while (bytes > 0) {
-        if ((c = fgetc (s->fpin)) == EOF)
-            break;
-
-        bytes--;
-
-        if (c == '\r')
-            hadcr = 1;
-        else {
-            if (c == '\n' && !hadcr)
-                fputc ('\r', fp);
-
-            hadcr = 0;
-        }
-        fputc (c, fp);
-    }
-}
-
-
-
-void convert_to_7bit (BODY * a)
-{
-  while (a) {
-    if (a->type == TYPEMULTIPART) {
-      if (a->encoding != ENC7BIT) {
-        a->encoding = ENC7BIT;
-        convert_to_7bit (a->parts);
-      } else {
-        convert_to_7bit (a->parts);
-      }
-    }
-    else if (a->type == TYPEMESSAGE &&
-             m_strcasecmp(a->subtype, "delivery-status")) {
-      if (a->encoding != ENC7BIT)
-        mutt_message_to_7bit (a, NULL);
-    }
-    else if (a->encoding == ENC8BIT)
-      a->encoding = ENCQUOTEDPRINTABLE;
-    else if (a->encoding == ENCBINARY)
-      a->encoding = ENCBASE64;
-    else if (a->content && a->encoding != ENCBASE64 &&
-             (a->content->from || a->content->space))
-      a->encoding = ENCQUOTEDPRINTABLE;
-    a = a->next;
-  }
-}
-
-
-static void extract_keys_aux(FILE *fpout, HEADER *h)
-{
-    mutt_parse_mime_message (Context, h);
-
-    rewind(fpout);
-    if (h->security & APPLICATION_PGP) {
-        mutt_copy_message(fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0);
-        fflush (fpout);
-
-        mutt_endwin (_("Trying to extract PGP keys...\n"));
-    }
-
-    if (h->security & APPLICATION_SMIME) {
-        if (h->security & ENCRYPT)
-            mutt_copy_message (fpout, Context, h, M_CM_NOHEADER
-                               | M_CM_DECODE_CRYPT | M_CM_DECODE_SMIME, 0);
-        else
-            mutt_copy_message(fpout, Context, h, 0, 0);
-        fflush (fpout);
-
-        mutt_message (_("Trying to extract S/MIME certificates...\n"));
-    }
-
-    rewind(fpout);
-    crypt_invoke_import(fpout, h->security & APPLICATION_SMIME);
-}
-
-void crypt_extract_keys_from_messages(HEADER * h)
-{
-    FILE *tmpfp = tmpfile();
-    if (!tmpfp) {
-        mutt_error(_("Could not create temporary file"));
-        return;
-    }
-
-    set_option(OPTDONTHANDLEPGPKEYS);
-    if (!h) {
-        int i;
-        for (i = 0; i < Context->vcount; i++) {
-            if (!Context->hdrs[Context->v2r[i]]->tagged)
-                continue;
-            extract_keys_aux(tmpfp, Context->hdrs[Context->v2r[i]]);
-        }
-    } else {
-        extract_keys_aux(tmpfp, h);
-    }
-    unset_option(OPTDONTHANDLEPGPKEYS);
-    m_fclose(&tmpfp);
-
-    if (isendwin())
-        mutt_any_key_to_continue(NULL);
-}
-
-
-
-static void crypt_fetch_signatures (BODY ***signatures, BODY * a, int *n)
-{
-  for (; a; a = a->next) {
-    if (a->type == TYPEMULTIPART)
-      crypt_fetch_signatures (signatures, a->parts, n);
-    else {
-      if ((*n % 5) == 0)
-        p_realloc(signatures, *n + 6);
-
-      (*signatures)[(*n)++] = a;
-    }
-  }
-}
-
-
-/*
- * This routine verifies a  "multipart/signed"  body.
- */
-
-int mutt_signed_handler (BODY * a, STATE * s)
-{
-  unsigned major, minor;
-  char *protocol;
-  int rc, i, goodsig = 1, sigcnt = 0;
-  BODY *b = a;
-
-  protocol = parameter_getval(a->parameter, "protocol");
-  a = a->parts;
-
-  switch (mime_which_token(protocol, -1)) {
-    case MIME_APPLICATION_PGP_SIGNATURE:
-      major = TYPEAPPLICATION;
-      minor = MIME_PGP_SIGNATURE;
-      break;
-    case MIME_APPLICATION_X_PKCS7_SIGNATURE:
-      major = TYPEAPPLICATION;
-      minor = MIME_X_PKCS7_SIGNATURE;
-      break;
-    case MIME_APPLICATION_PKCS7_SIGNATURE:
-      major = TYPEAPPLICATION;
-      minor = MIME_PKCS7_SIGNATURE;
-      break;
-    case MIME_MULTIPART_MIXED:
-      major = TYPEMULTIPART;
-      minor = MIME_MIXED;
-      break;
-
-    default:
-      state_printf(s, _("[-- Error: "
-                        "Unknown multipart/signed protocol %s! --]\n\n"),
-                    protocol);
-      return mutt_body_handler (a, s);
-  }
-
-  /* consistency check */
-  if (!(a && a->next && a->next->type == major &&
-        mime_which_token(a->next->subtype, -1) == minor))
-  {
-    state_attach_puts(_("[-- Error: "
-                        "Inconsistent multipart/signed structure! --]\n\n"),
-                      s);
-    return mutt_body_handler (a, s);
-  }
-
-  if (s->flags & M_DISPLAY) {
-    BODY **sigs = NULL;
-
-    crypt_fetch_signatures (&sigs, a->next, &sigcnt);
-    if (sigcnt) {
-      FILE *tmpfp = tmpfile();
-
-      if (!tmpfp) {
-          mutt_error(_("Could not create temporary file"));
-      } else {
-        crypt_write_signed(a, s, tmpfp);
-        rewind(tmpfp);
-        for (i = 0; i < sigcnt; i++) {
-          if (sigs[i]->type == TYPEAPPLICATION) {
-            int subtype;
-
-            switch ((subtype = mime_which_token(sigs[i]->subtype, -1))) {
-              case MIME_PGP_SIGNATURE:
-              case MIME_X_PKCS7_SIGNATURE:
-              case MIME_PKCS7_SIGNATURE:
-                if (crypt_verify_one(sigs[i], s, tmpfp, subtype != MIME_PGP_SIGNATURE) != 0)
-                  goodsig = 0;
-
-                m_fclose(&tmpfp);
-                continue;
-
-              default:
-                break;
-            }
-          }
-
-          state_printf(s, _("[-- Warning: "
-                            "We can't verify %s/%s signatures. --]\n\n"),
-                       TYPE (sigs[i]), sigs[i]->subtype);
-        }
-      }
-
-      b->goodsig = goodsig;
-      b->badsig  = !goodsig;
-
-      /* Now display the signed body */
-      state_attach_puts(_("[-- The following data is signed --]\n\n"), s);
-
-      p_delete(&sigs);
-    } else {
-      state_attach_puts(_("[-- Warning: Can't find any signatures. --]\n\n"),
-                        s);
-    }
-  }
-
-  rc = mutt_body_handler (a, s);
-
-  if (s->flags & M_DISPLAY && sigcnt)
-    state_attach_puts (_("\n[-- End of signed data --]\n"), s);
-
-  return (rc);
-}
index 7c55f2b..af64a2c 100644 (file)
@@ -32,9 +32,8 @@
 
 #include <lib-lib/lib-lib.h>
 
-#include <lib-crypt/crypt.h>
-
 #include "mime.h"
+#include "crypt.h"
 
 int mutt_is_multipart_signed(BODY * b)
 {
index b6fcfc1..b58a621 100644 (file)
@@ -16,9 +16,9 @@
 #include <lib-sys/unix.h>
 #include <lib-mime/mime.h>
 #include <lib-ui/sidebar.h>
-#include <lib-crypt/crypt.h>
 
 #include "mutt.h"
+#include "crypt.h"
 #include "pattern.h"
 #include "buffy.h"
 #include "mx.h"
index bf3c5a1..4893833 100644 (file)
 
 #include <lib-ui/sidebar.h>
 #include <lib-mx/mx.h>
-#include <lib-crypt/crypt.h>
-
 #include <pop/pop.h>
 
 #include "curses.h"
 #include "menu.h"
 
 #include "mutt.h"
+#include "crypt.h"
 #include "pattern.h"
 #include "alias.h"
 #include "sort.h"
index 24aa3de..50049ef 100644 (file)
 #include <lib-mime/mime.h>
 #include <lib-ui/curses.h>
 #include <lib-mx/mx.h>
-#include <lib-crypt/crypt.h>
 
 #include "mutt.h"
 #include "alias.h"
+#include "crypt.h"
 #include "sort.h"
 #include "thread.h"
 #include "charset.h"
diff --git a/main.c b/main.c
index a02ecbc..4a1fe59 100644 (file)
--- a/main.c
+++ b/main.c
 #include <lib-sys/mutt_signal.h>
 #include <lib-mime/mime.h>
 #include <lib-ui/curses.h>
-#include <lib-crypt/crypt.h>
 #include <lib-mx/mx.h>
 
 #include "mutt.h"
+#include "crypt.h"
 #include "alias.h"
 #include "buffy.h"
 #include "sort.h"
index b7d83ea..bd1fcf0 100644 (file)
@@ -20,8 +20,7 @@
 #include "sort.h"
 #include "nntp.h"
 #include "buffy.h"
-
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 
 #define WANT_LISTGROUP_COMMAND          0
 
diff --git a/pager.c b/pager.c
index be51928..348e679 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -12,7 +12,6 @@
  */
 
 #include <lib-lib/lib-lib.h>
-#include <lib-crypt/crypt.h>
 
 #include <lib-ui/curses.h>
 #include <lib-ui/enter.h>
@@ -21,6 +20,7 @@
 #include <lib-mx/mx.h>
 
 #include "mutt.h"
+#include "crypt.h"
 #include "alias.h"
 #include "keymap.h"
 #include "sort.h"
index 8d0e4ba..6bcda21 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -10,7 +10,6 @@
 #include <lib-lib/lib-lib.h>
 
 #include <lib-mime/mime.h>
-#include <lib-crypt/crypt.h>
 #include <lib-ui/enter.h>
 #include <lib-ui/curses.h>
 #include <lib-mx/mx.h>
@@ -18,6 +17,7 @@
 
 #include "pattern.h"
 #include "alias.h"
+#include "crypt.h"
 #include "handler.h"
 #include "keymap.h"
 #include "copy.h"
index 0db1cec..a09e1fc 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -14,7 +14,7 @@
 
 #include "mutt.h"
 #include "pop.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 
 /* write line to file */
 static int fetch_message (char *line, void *file)
index 7f5aff1..485b44f 100644 (file)
@@ -23,7 +23,7 @@
 #include "handler.h"
 #include "sort.h"
 #include "thread.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 
 #include <imap/imap.h>
 
index ef8fc18..e2fbd41 100644 (file)
@@ -17,9 +17,9 @@
 #include <lib-ui/enter.h>
 #include <lib-ui/menu.h>
 #include <lib-mx/mx.h>
-#include <lib-crypt/crypt.h>
 
 #include "mutt.h"
+#include "crypt.h"
 #include "handler.h"
 #include "recvattach.h"
 #include "attach.h"
diff --git a/send.c b/send.c
index 2da13d7..67f0d7c 100644 (file)
--- a/send.c
+++ b/send.c
@@ -19,7 +19,7 @@
 #include "alias.h"
 #include "keymap.h"
 #include "copy.h"
-#include <lib-crypt/crypt.h>
+#include "crypt.h"
 #include "mutt_idna.h"
 #include "attach.h"
 
index 152862b..328aa2b 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
 #include <lib-ui/curses.h>
 #include <lib-mx/mx.h>
 
-#include <lib-crypt/crypt.h>
-
 #include "mutt.h"
 #include "handler.h"
+#include "crypt.h"
 #include "recvattach.h"
 #include "copy.h"
 #include "pager.h"