[gmime] Parse the hash algo used by each signer



commit 1d2de6c3c4065768fdc52d39395e4bf39aaf3735
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Mon Nov 22 20:32:11 2010 -0500

    Parse the hash algo used by each signer
    
    2010-11-22  Jeffrey Stedfast  <fejj novell com>
    
    	Fixes bug #635492.
    
    	* gmime/gmime-gpg-context.c (gpg_hash_from_id): New function
    	mapping the numeric hash id's that gpg uses to GMimeCryptoHash
    	ids.
    	(gpg_ctx_parse_signer_info): Extract the hash algorithm used by
    	the signer.
    	(gpg_ctx_parse_status): Updated to use gpg_hash_from_id().
    
    	* gmime/gmime-crypto-context.c (g_mime_signer_set_hash): New
    	function to set the hash algorithm used by the signer.
    	(g_mime_signer_get_hash): New function to get the hash algorithm
    	used by the signer.

 ChangeLog                         |   16 +++++++++++
 docs/reference/gmime-sections.txt |    2 +
 gmime/gmime-crypto-context.c      |   33 ++++++++++++++++++++++++
 gmime/gmime-crypto-context.h      |    9 +++++-
 gmime/gmime-gpg-context.c         |   51 ++++++++++++++++++++++++++-----------
 5 files changed, 94 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 04ec850..f998884 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2010-11-22  Jeffrey Stedfast  <fejj novell com>
 
+	Fixes bug #635492.
+
+	* gmime/gmime-gpg-context.c (gpg_hash_from_id): New function
+	mapping the numeric hash id's that gpg uses to GMimeCryptoHash
+	ids.
+	(gpg_ctx_parse_signer_info): Extract the hash algorithm used by
+	the signer.
+	(gpg_ctx_parse_status): Updated to use gpg_hash_from_id().
+
+	* gmime/gmime-crypto-context.c (g_mime_signer_set_hash): New
+	function to set the hash algorithm used by the signer.
+	(g_mime_signer_get_hash): New function to get the hash algorithm
+	used by the signer.
+
+2010-11-22  Jeffrey Stedfast  <fejj novell com>
+
 	Fixes bug #635491.
 
 	* gmime/gmime-crypto-context.[c,h]: Renamed from
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index cedbd92..9469150 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -1165,6 +1165,8 @@ g_mime_signer_get_errors
 g_mime_signer_set_errors
 g_mime_signer_get_trust
 g_mime_signer_set_trust
+g_mime_signer_get_hash
+g_mime_signer_set_hash
 g_mime_signer_get_issuer_serial
 g_mime_signer_set_issuer_serial
 g_mime_signer_get_issuer_name
diff --git a/gmime/gmime-crypto-context.c b/gmime/gmime-crypto-context.c
index dde39a9..75b87ea 100644
--- a/gmime/gmime-crypto-context.c
+++ b/gmime/gmime-crypto-context.c
@@ -610,6 +610,39 @@ g_mime_signer_get_trust (const GMimeSigner *signer)
 
 
 /**
+ * g_mime_signer_set_hash:
+ * @signer: a #GMimeSigner
+ * @hash: a #GMimeCryptoHash
+ *
+ * Set the hash algorithm used by the signer.
+ **/
+void
+g_mime_signer_set_hash (GMimeSigner *signer, GMimeCryptoHash hash)
+{
+	g_return_if_fail (signer != NULL);
+	
+	signer->hash = hash;
+}
+
+
+/**
+ * g_mime_signer_get_hash:
+ * @signer: a #GMimeSigner
+ *
+ * Get the hash algorithm used by the signer.
+ *
+ * Returns: the hash algorithm used by the signer.
+ **/
+GMimeCryptoHash
+g_mime_signer_get_hash (const GMimeSigner *signer)
+{
+	g_return_val_if_fail (signer != NULL, GMIME_CRYPTO_HASH_DEFAULT);
+	
+	return signer->hash;
+}
+
+
+/**
  * g_mime_signer_set_issuer_serial:
  * @signer: a #GMimeSigner
  * @issuer_serial: signer's issuer serial
diff --git a/gmime/gmime-crypto-context.h b/gmime/gmime-crypto-context.h
index 4113dc5..71e347e 100644
--- a/gmime/gmime-crypto-context.h
+++ b/gmime/gmime-crypto-context.h
@@ -247,8 +247,9 @@ typedef enum {
  * @errors: A bitfield of #GMimeSignerError values.
  * @trust: A #GMimeSignerTrust.
  * @unused: Unused expansion bits for future use; ignore this.
- * @issuer_serial: The issuer of the certificate if known.
- * @issuer_name: The issuer of the certificate if known.
+ * @hash: The hash algorithm used by the signer, if known.
+ * @issuer_serial: The issuer of the certificate, if known.
+ * @issuer_name: The issuer of the certificate, if known.
  * @fingerprint: A hex string representing the signer's fingerprint.
  * @sig_created: The creation date of the signature.
  * @sig_expires: The expiration date of the signature.
@@ -266,6 +267,7 @@ struct _GMimeSigner {
 	unsigned int errors:4;    /* bitfield of GMimeSignerError's */
 	unsigned int trust:3;     /* GMimeSignerTrust */
 	unsigned int unused:21;   /* unused expansion bits */
+	GMimeCryptoHash hash;
 	char *issuer_serial;
 	char *issuer_name;
 	char *fingerprint;
@@ -293,6 +295,9 @@ GMimeSignerError g_mime_signer_get_errors (const GMimeSigner *signer);
 void g_mime_signer_set_trust (GMimeSigner *signer, GMimeSignerTrust trust);
 GMimeSignerTrust g_mime_signer_get_trust (const GMimeSigner *signer);
 
+void g_mime_signer_set_hash (GMimeSigner *signer, GMimeCryptoHash hash);
+GMimeCryptoHash g_mime_signer_get_hash (const GMimeSigner *signer);
+
 void g_mime_signer_set_issuer_serial (GMimeSigner *signer, const char *issuer_serial);
 const char *g_mime_signer_get_issuer_serial (const GMimeSigner *signer);
 
diff --git a/gmime/gmime-gpg-context.c b/gmime/gmime-gpg-context.c
index 9622317..44673a6 100644
--- a/gmime/gmime-gpg-context.c
+++ b/gmime/gmime-gpg-context.c
@@ -235,7 +235,6 @@ gpg_hash_name (GMimeCryptoContext *ctx, GMimeCryptoHash hash)
 	}
 }
 
-
 enum _GpgCtxMode {
 	GPG_CTX_MODE_SIGN,
 	GPG_CTX_MODE_VERIFY,
@@ -548,6 +547,24 @@ gpg_hash_str (GMimeCryptoHash hash)
 	}
 }
 
+static GMimeCryptoHash
+gpg_hash_from_id (int id)
+{
+	switch (id) {
+	case 1: return GMIME_CRYPTO_HASH_MD5;
+	case 2: return GMIME_CRYPTO_HASH_SHA1;
+	case 3:	return GMIME_CRYPTO_HASH_RIPEMD160;
+	case 5: return GMIME_CRYPTO_HASH_MD2; /* ? */
+	case 6: return GMIME_CRYPTO_HASH_TIGER192; /* ? */
+	case 7: return GMIME_CRYPTO_HASH_HAVAL5160; /* ? */
+	case 8: return GMIME_CRYPTO_HASH_SHA256;
+	case 9: return GMIME_CRYPTO_HASH_SHA384;
+	case 10: return GMIME_CRYPTO_HASH_SHA512;
+	case 11: return GMIME_CRYPTO_HASH_SHA224;
+	default: return GMIME_CRYPTO_HASH_DEFAULT;
+	}
+}
+
 static char **
 gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, int secret_fd, char ***strv)
 {
@@ -896,6 +913,22 @@ gpg_ctx_parse_signer_info (struct _GpgCtx *gpg, char *status)
 		/* the fourth token is the signature expiration date (or 0 for never) */
 		signer->sig_expires = strtoul (status, NULL, 10);
 		
+		/* the fifth token is unknown 0 */
+		status = next_token (status, NULL);
+		
+		/* the sixth token is unknown 4 */
+		status = next_token (status, NULL);
+		
+		/* the seventh token is unknown 0 */
+		status = next_token (status, NULL);
+		
+		/* the eighth token is the public-key algorithm id */
+		status = next_token (status, NULL);
+		
+		/* the nineth token is the hash algorithm id */
+		status = next_token (status, NULL);
+		signer->hash = gpg_hash_from_id (strtol (status, NULL, 10));
+		
 		/* ignore the rest... */
 	} else if (!strncmp (status, "TRUST_", 6)) {
 		status += 6;
@@ -1125,23 +1158,11 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 			/* skip the next single-char token ("D" for detached) */
 			status = next_token (status, NULL);
 			
-			/* skip the public-key algo token */
+			/* skip the public-key algorithm id token */
 			status = next_token (status, NULL);
 			
 			/* this token is the hash algorithm used */
-			switch (strtol (status, NULL, 10)) {
-			case 1: gpg->hash = GMIME_CRYPTO_HASH_MD5; break;
-			case 2: gpg->hash = GMIME_CRYPTO_HASH_SHA1; break;
-			case 3:	gpg->hash = GMIME_CRYPTO_HASH_RIPEMD160; break;
-			case 5: gpg->hash = GMIME_CRYPTO_HASH_MD2; break; /* ? */
-			case 6: gpg->hash = GMIME_CRYPTO_HASH_TIGER192; break; /* ? */
-			case 7: gpg->hash = GMIME_CRYPTO_HASH_HAVAL5160; break; /* ? */
-			case 8: gpg->hash = GMIME_CRYPTO_HASH_SHA256; break;
-			case 9: gpg->hash = GMIME_CRYPTO_HASH_SHA384; break;
-			case 10: gpg->hash = GMIME_CRYPTO_HASH_SHA512; break;
-			case 11: gpg->hash = GMIME_CRYPTO_HASH_SHA224; break;
-			default: break;
-			}
+			gpg->hash = gpg_hash_from_id (strtol (status, NULL, 10));
 			break;
 		case GPG_CTX_MODE_VERIFY:
 			gpg_ctx_parse_signer_info (gpg, status);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]