}
else if (choice == M_YES)
{
- snprintf (key,mutt_strlen(key), fields[1]);
+ snprintf (key,mutt_strlen(key)+1, fields[1]);
ask = 0;
break;
}
if (key)
{
- key[mutt_strlen(key)+1] = 0;
+ key[mutt_strlen(key)+1] = '\0';
key[mutt_strlen(key)] = '\n';
}
void _smime_getkeys (char *mailbox)
{
- char *k = smime_get_field_from_db (mailbox, NULL, 0, 0); /* XXX - or sohuld we ask? */
+ char *k = smime_get_field_from_db (mailbox, NULL, 0, 1);
char buf[STRING];
if (!k)
NONULL(SmimeCertificates), k);
if (mutt_strcasecmp (k, SmimeSignAs))
- {
- endwin ();
- mutt_clear_error ();
- snprintf (buf, sizeof (buf), _("This message seems to require key"
- " %s. (Any key to continue)"), k);
- mutt_any_key_to_continue (buf);
- endwin ();
smime_void_passphrase ();
- }
safe_free ((void **) &k);
return;
if (ret == -1)
{
- mutt_copy_stream (fperr, stdout);
mutt_endwin(NULL);
- mutt_error (_("Alert: No mailbox specified in certificate.\n"));
+ mutt_copy_stream (fperr, stdout);
+ mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
ret = 1;
}
else if (!ret)
- {
- mutt_endwin(NULL);
- mutt_error (_("Alert: Certificate does *NOT* belong to \"%s\".\n"), mailbox);
ret = 1;
- }
else ret = 0;
if(copy && buffer && num)
-static int smime_compare_fingerprint (char *certificate, char *hashval, char *dest)
+
+/* Add a certificate and update index file (externally). */
+
+void smime_invoke_import (char *infile, char *mailbox)
{
- FILE *fpout = NULL, *fperr = NULL;
- char tmpfname[_POSIX_PATH_MAX];
- char md5New[STRING], md5Old[STRING];
- pid_t thepid;
+ char tmpfname[_POSIX_PATH_MAX], *certfile = NULL, buf[STRING];
+ FILE *smimein=NULL, *fpout = NULL, *fperr = NULL;
+ pid_t thepid=-1;
mutt_mktemp (tmpfname);
if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
{
mutt_perror (tmpfname);
- return -1;
+ return;
}
mutt_unlink (tmpfname);
{
fclose (fperr);
mutt_perror (tmpfname);
- return -1;
+ return;
}
mutt_unlink (tmpfname);
- /* fingerprint the certificate to add */
- if ((thepid = smime_invoke (NULL, NULL, NULL,
- -1, fileno (fpout), fileno (fperr),
- certificate, NULL, NULL, NULL, NULL, NULL,
- SmimeFingerprintCertCommand))== -1)
- {
- mutt_message (_("Error: unable to create OpenSSL subprocess!"));
- fclose (fperr);
- fclose (fpout);
- return -1;
- }
-
- mutt_wait_filter (thepid);
-
- fflush (fpout);
- rewind (fpout);
- fflush (fperr);
- rewind (fperr);
- if (!(fgets (md5New, sizeof (md5New), fpout)))
- {
- mutt_copy_stream (fperr, stdout);
- fclose (fpout);
- fclose (fperr);
- return -1;
- }
+ buf[0] = '\0';
+ if (option (OPTASKCERTLABEL))
+ mutt_get_field ("Label for certificate:", buf, sizeof (buf), 0);
- /* fingerprint the certificate already installed */
- if ((thepid = smime_invoke (NULL, NULL, NULL,
- -1, fileno (fpout), fileno (fperr),
- dest, NULL, NULL, NULL, NULL, NULL,
- SmimeFingerprintCertCommand))== -1)
+ mutt_endwin (NULL);
+ if ((certfile = smime_extract_certificate(infile)))
{
- mutt_message (_("Error: unable to create OpenSSL subprocess!"));
- fclose (fperr);
- fclose (fpout);
- return -1;
- }
-
- mutt_wait_filter (thepid);
+ mutt_endwin (NULL);
- fflush (fpout);
- rewind (fpout);
- fflush (fperr);
- rewind (fperr);
-
- if (!(fgets (md5Old, sizeof (md5Old), fpout)))
- {
- mutt_copy_stream (fperr, stdout);
- fclose (fpout);
- fclose (fperr);
- return -1;
- }
-
- fclose (fpout);
- fclose (fperr);
-
- return ((mutt_strcasecmp (md5Old, md5New) == 0));
-}
-
-
-/* Add a certificate and update index file. */
-
-static int smime_add_certificate (char *certificate, char *mailbox)
-{
- FILE *fpin = NULL, *fpout = NULL, *fperr = NULL;
- char tmpfname[_POSIX_PATH_MAX], dest[_POSIX_PATH_MAX];
- char buf[LONG_STRING], hashval[STRING], *tmpKey;
- struct stat info;
- int i = 0, certExists=0;
- pid_t thepid;
-
- mutt_mktemp (tmpfname);
- if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
- {
- mutt_perror (tmpfname);
- return 1;
- }
- mutt_unlink (tmpfname);
-
- mutt_mktemp (tmpfname);
- if ((fpout = safe_fopen (tmpfname, "w+")) == NULL)
- {
- fclose (fperr);
- mutt_perror (tmpfname);
- return 1;
- }
- mutt_unlink (tmpfname);
-
- /*
- OpenSSl can create a hash value of the certificate's subject.
- This and a concatenated integer make up the certificate's
- 'unique id' and also its filename.
- */
+ if ((thepid = smime_invoke (&smimein, NULL, NULL,
+ -1, fileno(fpout), fileno(fperr),
+ certfile, NULL, NULL, NULL, NULL, NULL,
+ SmimeImportCertCommand))== -1)
+ {
+ mutt_message (_("Error: unable to create OpenSSL subprocess!"));
+ return;
+ }
+ fputs (buf, smimein);
+ fputc ('\n', smimein);
+ fclose(smimein);
- mutt_endwin (NULL);
+ mutt_wait_filter (thepid);
- if ((thepid = smime_invoke (NULL, NULL, NULL,
- -1, fileno (fpout), fileno (fperr),
- certificate, NULL, NULL, NULL, NULL, NULL,
- SmimeHashCertCommand))== -1)
- {
- mutt_message (_("Error: unable to create OpenSSL subprocess!"));
- fclose (fperr);
- fclose (fpout);
- return 1;
+ mutt_unlink (certfile);
+ safe_free((void **)&certfile);
}
- mutt_wait_filter (thepid);
-
fflush (fpout);
rewind (fpout);
fflush (fperr);
rewind (fperr);
- if (!(fgets (hashval, sizeof (hashval), fpout)))
- {
- mutt_copy_stream (fperr, stdout);
- fclose (fpout);
- fclose (fperr);
- return 1;
- }
+ mutt_copy_stream (fpout, stdout);
+ mutt_copy_stream (fperr, stdout);
+
fclose (fpout);
fclose (fperr);
- *(hashval+mutt_strlen(hashval)-1) = '\0';
-
- while (1)
- {
- snprintf (dest, sizeof (dest), "%s/%s.%d", NONULL(SmimeCertificates),
- hashval, i);
-
- if (stat (dest, &info))
- break;
- else { /* check wether this certificate already exists. */
- if((certExists = smime_compare_fingerprint (certificate, hashval, dest)) == 1)
- {
- break;
- }
- else
- {
- if(!certExists)
- i++;
- else /* some error: abort. */
- return 1;
- }
- }
- }
-
- if(!certExists)
- {
- if ((fpout = safe_fopen (dest, "w+")) == NULL)
- {
- mutt_perror (dest);
- return 1;
- }
-
- if ((fpin = safe_fopen (certificate, "r")) == NULL)
- {
- mutt_perror (certificate);
- fclose (fpout);
- mutt_unlink (dest);
- return 1;
- }
-
- mutt_copy_stream (fpin, fpout);
- fclose (fpout);
- fclose (fpin);
- }
-
-
- /*
- Now check if the mailbox is already found with the certificate's
- hash value and/or md5 fingerprint.
- */
-
- tmpKey = smime_get_field_from_db (mailbox, NULL, 1, 0); /* _always_ public! */
-
- /* check if hash is identical => same certificate! */
- /* perhaps we should ask for permission to overwrite ? */
- /* what about revoked certificates anyway ? */
-
- if (tmpKey && !mutt_strncmp (tmpKey, hashval, mutt_strlen (hashval)))
- {
- mutt_message (_("Certificate \"%s\" exists for \"%s\"."), hashval, mailbox);
- return 0;
- }
-
- /* doesn't exist or is a new one, so append to index. */
- snprintf (tmpfname, sizeof (tmpfname), "%s/.index",
- NONULL(SmimeCertificates)); /* _always_ public: we don't add keys here */
-
- if (!stat (tmpfname, &info))
- {
- if ((fpout = safe_fopen (tmpfname, "a")) == NULL)
- {
- mutt_perror (tmpfname);
- mutt_unlink (dest);
- return 1;
- }
- /*
- ? = unknown issuer, - = unassigned label,
- v = undefined trust settings (else we wouldn't have got that far).
- */
- snprintf (buf, sizeof (buf), "%s %s.%d - ? u\n", mailbox, hashval, i);
- fputs (buf, fpout);
- fclose (fpout);
-
- mutt_message (_("Successfully added certificate \"%s\" for \"%s\". "), hashval, mailbox);
- }
-
- return 0;
-}
-
-
-
-void smime_invoke_import (char *infile, char *mailbox)
-{
- char *certfile = NULL, **addrList=0;
- int i, addrCount=0, ret = 0;
- certfile = smime_extract_signer_certificate(infile);
-
- if (certfile)
- {
- i = smime_handle_cert_email (certfile, mailbox, 1, &addrList, &addrCount);
-
- mutt_unlink(certfile);
-
- if (i)
- {
- mutt_message _("Certificate *NOT* added.");
- return;
- }
- if ((certfile = smime_extract_certificate(infile)))
- {
- for (i = 0; i < addrCount; i++)
- {
- /* perhaps we shouldn't abort completley ? */
-
- if(!ret)
- ret = smime_add_certificate (certfile, addrList[i]);
-
- safe_free((void **)&(addrList[i]));
- }
- mutt_unlink (certfile);
- safe_free((void **)&certfile);
- safe_free((void **)&addrList);
- }
- if(!ret)
- return;
- }
-
- if(isendwin())
- {
- mutt_any_key_to_continue(NULL);
- mutt_message _("Certificate *NOT* added.");
- }
- return;
}
{
mutt_unlink(tempfname);
if (smime_handle_cert_email (certfile, mbox, 0, NULL, NULL))
- mutt_any_key_to_continue(NULL);
+ {
+ if(isendwin())
+ mutt_any_key_to_continue(NULL);
+ }
else
retval = 0;
mutt_unlink(certfile);
/*
- * Copyright (C) 2001 Oliver Ehli <elmy@acm.org>
+ * Copyright (C) 2001,2002 Oliver Ehli <elmy@acm.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
WHERE char *SmimeGetSignerCertCommand;
WHERE char *SmimePk7outCommand;
WHERE char *SmimeGetCertCommand;
-WHERE char *SmimeHashCertCommand;
-WHERE char *SmimeFingerprintCertCommand;
+WHERE char *SmimeImportCertCommand;
WHERE char *SmimeGetCertEmailCommand;
int mutt_is_application_smime (BODY *);
+int smime_decrypt_mime (FILE *, FILE **, BODY *, BODY **);
+void smime_application_smime_handler (BODY *, STATE *);
-int smime_decrypt_mime (FILE *, FILE **, BODY *, BODY **);
-void smime_application_smime_handler (BODY *, STATE *);
+BODY* smime_sign_message (BODY *);
-int smime_verify_sender(HEADER *);
+BODY* smime_build_smime_entity (BODY *, char *);
+int smime_verify_one(BODY *, STATE *, const char *);
+int smime_verify_sender(HEADER *);
-char *smime_get_field_from_db (char *, char *, short, short);
-char* smime_ask_for_key (char *, char *, short);
-
-void smime_getkeys (ENVELOPE *);
+char* smime_get_field_from_db (char *, char *, short, short);
-/* private ? */
+void smime_getkeys (ENVELOPE *);
-void smime_invoke_import (char *, char *);
+char* smime_ask_for_key (char *, char *, short);
-int smime_verify_one(BODY *, STATE *, const char *);
-BODY *smime_sign_message (BODY *);
+void smime_invoke_import (char *, char *);
-BODY *smime_build_smime_entity (BODY *, char *);
#endif