gpgme_signature_t current_sig;
int did_prepare_new_sig;
int only_newsig_seen;
+ int plaintext_seen;
} *op_data_t;
}
+/* Parse an error status line and if SET_STATUS is true update the
+ result status as appropriate. With SET_STATUS being false, only
+ check for an error. */
static gpgme_error_t
-parse_error (gpgme_signature_t sig, char *args)
+parse_error (gpgme_signature_t sig, char *args, int set_status)
{
gpgme_error_t err;
char *where = strchr (args, ' ');
err = _gpgme_map_gnupg_error (which);
- if (!strcmp (where, "verify.findkey"))
+ if (!strcmp (where, "proc_pkt.plaintext")
+ && gpg_err_code (err) == GPG_ERR_BAD_DATA)
+ {
+ /* This indicates a double plaintext. The only solid way to
+ handle this is by failing the oepration. */
+ return gpg_error (GPG_ERR_BAD_DATA);
+ }
+ else if (!set_status)
+ ;
+ else if (!strcmp (where, "verify.findkey"))
sig->status = err;
else if (!strcmp (where, "verify.keyusage")
&& gpg_err_code (err) == GPG_ERR_WRONG_KEY_USAGE)
case GPGME_STATUS_ERROR:
opd->only_newsig_seen = 0;
- /* The error status is informational, so we don't return an
- error code if we are not ready to process this status. */
- return sig ? parse_error (sig, args) : 0;
+ /* Some error stati are informational, so we don't return an
+ error code if we are not ready to process this status. */
+ return parse_error (sig, args, !!sig );
case GPGME_STATUS_EOF:
if (sig && !opd->did_prepare_new_sig)
break;
case GPGME_STATUS_PLAINTEXT:
+ if (++opd->only_newsig_seen > 1)
+ return gpg_error (GPG_ERR_BAD_DATA);
err = _gpgme_parse_plaintext (args, &opd->result.file_name);
if (err)
return err;
successful verify operation in R_STAT (if non-null). The creation
time stamp of the signature is returned in R_CREATED (if non-null).
The function returns a string containing the fingerprint. */
-const char *gpgme_get_sig_status (gpgme_ctx_t ctx, int idx,
- _gpgme_sig_stat_t *r_stat, time_t *r_created)
+const char *
+gpgme_get_sig_status (gpgme_ctx_t ctx, int idx,
+ _gpgme_sig_stat_t *r_stat, time_t *r_created)
{
gpgme_verify_result_t result;
gpgme_signature_t sig;
number of the signature after a successful verify operation. WHAT
is an attribute where GPGME_ATTR_EXPIRE is probably the most useful
one. WHATIDX is to be passed as 0 for most attributes . */
-unsigned long gpgme_get_sig_ulong_attr (gpgme_ctx_t ctx, int idx,
- _gpgme_attr_t what, int whatidx)
+unsigned long
+gpgme_get_sig_ulong_attr (gpgme_ctx_t ctx, int idx,
+ _gpgme_attr_t what, int whatidx)
{
gpgme_verify_result_t result;
gpgme_signature_t sig;
}
-const char *gpgme_get_sig_string_attr (gpgme_ctx_t ctx, int idx,
- _gpgme_attr_t what, int whatidx)
+const char *
+gpgme_get_sig_string_attr (gpgme_ctx_t ctx, int idx,
+ _gpgme_attr_t what, int whatidx)
{
gpgme_verify_result_t result;
gpgme_signature_t sig;
"=Crq6\n"
"-----END PGP MESSAGE-----\n";
+/* A message with a prepended but unsigned plaintext packet. */
+static const char double_plaintext_sig[] =
+"-----BEGIN PGP MESSAGE-----\n"
+"\n"
+"rDRiCmZvb2Jhci50eHRF4pxNVGhpcyBpcyBteSBzbmVha3kgcGxhaW50ZXh0IG1l\n"
+"c3NhZ2UKowGbwMvMwCSoW1RzPCOz3IRxTWISa6JebnG666MFD1wzSzJSixQ81XMV\n"
+"UlITUxTyixRyKxXKE0uSMxQyEosVikvyCwpSU/S4FNCArq6Ce1F+aXJGvoJvYlGF\n"
+"erFCTmJxiUJ5flFKMVeHGwuDIBMDGysTyA4GLk4BmO036xgWzMgzt9V85jCtfDFn\n"
+"UqVooWlGXHwNw/xg/fVzt9VNbtjtJ/fhUqYo0/LyCGEA\n"
+"=6+AK\n"
+"-----END PGP MESSAGE-----\n";
+
+
+
static void
check_result (gpgme_verify_result_t result, unsigned int summary, char *fpr,
check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
GPG_ERR_NO_ERROR, 0);
+
+ /* Checking an invalid message. */
+ gpgme_data_release (sig);
+ gpgme_data_release (text);
+ err = gpgme_data_new_from_mem (&sig, double_plaintext_sig,
+ strlen (double_plaintext_sig), 0);
+ fail_if_err (err);
+ err = gpgme_data_new (&text);
+ fail_if_err (err);
+ err = gpgme_op_verify (ctx, sig, NULL, text);
+ if (gpg_err_code (err) != GPG_ERR_BAD_DATA)
+ {
+ fprintf (stderr, "%s:%i: Double plaintext message not detected\n",
+ __FILE__, __LINE__);
+ exit (1);
+ }
+
gpgme_data_release (sig);
gpgme_data_release (text);
gpgme_release (ctx);