Browse Source

Do not assume the signature uses SHA-1.

Use information provided by GpgME about the hash algorithm used
in the signature instead of assuming it is always SHA-1 (it will
probably never by SHA-1 anymore...).
tags/fmail-0.1.1^2
Damien Goutte-Gattat 2 years ago
parent
commit
a14bfb88d3
1 changed files with 31 additions and 2 deletions
  1. +31
    -2
      src/fmail.c

+ 31
- 2
src/fmail.c View File

@@ -319,10 +319,35 @@ initialize_gpgme(void)
return ctx;
}

static const char *
hash_algo_to_string(gpgme_hash_algo_t algo)
{
switch ( algo ) {
case GPGME_MD_MD5: return "pgp-md5";
case GPGME_MD_SHA1: return "pgp-sha1";
case GPGME_MD_RMD160: return "pgp-ripemd160";
case GPGME_MD_MD2: return "pgp-md2";
case GPGME_MD_TIGER: return "pgp-tiger192";
case GPGME_MD_HAVAL: return "php-haval-5-160";
case GPGME_MD_SHA256: return "pgp-sha256";
case GPGME_MD_SHA384: return "pgp-sha384";
case GPGME_MD_SHA512: return "pgp-sha512";
case GPGME_MD_SHA224: return "pgp-sha224";
case GPGME_MD_MD4: return "pgp-md4";
case GPGME_MD_CRC32: return "pgp-crc32";
case GPGME_MD_CRC32_RFC1510: return "pgp-crc32-rfc1510";
case GPGME_MD_CRC24_RFC2440: return "pgp-crc24-rfc2440";
case GPGME_MD_NONE: return "";
}

return ""; /* FIXME: What to do here? */
}

static void
sign_stream(gpgme_ctx_t ctx, FILE *in, FILE *out)
{
gpgme_data_t gin, gout;
gpgme_sign_result_t result;
char boundary[32], buffer[512];
int n;

@@ -330,15 +355,19 @@ sign_stream(gpgme_ctx_t ctx, FILE *in, FILE *out)
gpgme_data_new(&gout);

gpgme_op_sign(ctx, gin, gout, GPGME_SIG_MODE_DETACH);
result = gpgme_op_sign_result(ctx);
result->signatures->hash_algo;

generate_boundary(boundary, sizeof(boundary));
fprintf(out, "Content-Type: multipart/signed;\r\n"
" boundary=\"%s\";\r\n"
" protocol=\"application/pgp-signature\";\r\n"
" micalg=pgp-sha1\r\n"
" micalg=%s\r\n"
"\r\n"
"--%s\r\n",
boundary, boundary);
boundary,
hash_algo_to_string(result->signatures->hash_algo),
boundary);

fseek(in, 0, SEEK_SET);
while ( (n = fread(buffer, 1, sizeof(buffer), in)) > 0 )


Loading…
Cancel
Save