Commit fa1ba589 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Add algorithm specific signature printing. An individual ASN1 method can

now print out signatures instead of the standard hex dump.

More complex signatures (e.g. PSS) can print out more meaningful information.

Sample DSA version included that prints out the signature parameters r, s.

[Note EVP_PKEY_ASN1_METHOD is an application opaque structure so adding
 new fields in the middle has no compatibility issues]
parent 8c4ce7ba
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -4,6 +4,14 @@

 Changes between 1.0.0 and 1.1.0  [xx XXX xxxx]

   *) Add algorithm specific signature printing. An individual ASN1 method
      can now print out signatures instead of the standard hex dump. 

      More complex signatures (e.g. PSS) can print out more meaningful
      information. Include DSA version that prints out the signature
      parameters r, s.
     [Steve Henson]

  *) Add -trusted_first option which attempts to find certificates in the
     trusted store even if an untrusted chain is also supplied.
     [Steve Henson]
+2 −2
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ typedef struct asn1_object_st
 */
#define ASN1_STRING_FLAG_MSTRING 0x040 
/* This is the base type that holds just about everything :-) */
typedef struct asn1_string_st
struct asn1_string_st
	{
	int length;
	int type;
@@ -245,7 +245,7 @@ typedef struct asn1_string_st
	 * input data has a non-zero 'unused bits' value, it will be
	 * handled correctly */
	long flags;
	} ASN1_STRING;
	};

/* ASN1_ENCODING structure: this is used to save the received
 * encoding of an ASN1 type. This is useful to get round
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,9 @@ struct evp_pkey_asn1_method_st
	int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
	int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
							ASN1_PCTX *pctx);
	int (*sig_print)(BIO *out,
			 const X509_ALGOR *sigalg, const ASN1_STRING *sig,
					 int indent, ASN1_PCTX *pctx);

	void (*pkey_free)(EVP_PKEY *pkey);
	int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2);
+28 −5
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include "asn1_locl.h"

#ifndef OPENSSL_NO_FP_API
int X509_print_fp(FILE *fp, X509 *x)
@@ -286,26 +287,48 @@ err:
	return(0);
	}

int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
{
	unsigned char *s;
	const unsigned char *s;
	int i, n;
	if (BIO_puts(bp,"    Signature Algorithm: ") <= 0) return 0;
	if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;

	n=sig->length;
	s=sig->data;
	for (i=0; i<n; i++)
		{
		if ((i%18) == 0)
			if (BIO_write(bp,"\n        ",9) <= 0) return 0;
			if (BIO_write(bp,"\n",1) <= 0) return 0;
			if (BIO_indent(bp, indent, indent) <= 0) return 0;
			if (BIO_printf(bp,"%02x%s",s[i],
				((i+1) == n)?"":":") <= 0) return 0;
		}
	if (BIO_write(bp,"\n",1) != 1) return 0;

	return 1;
}

int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
{
	int sig_nid;
	if (BIO_puts(bp,"    Signature Algorithm: ") <= 0) return 0;
	if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;

	sig_nid = OBJ_obj2nid(sigalg->algorithm);
	if (sig_nid != NID_undef)
		{
		int pkey_nid, dig_nid;
		const EVP_PKEY_ASN1_METHOD *ameth;
		if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid))
			{
			ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
			if (ameth && ameth->sig_print)
				return ameth->sig_print(bp, sigalg, sig, 9, 0);
			}
		}

	return X509_signature_dump(bp, sig, 9);
}

int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
	{
	int i,n;
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ const EVP_PKEY_ASN1_METHOD cmac_asn1_meth =

	cmac_size,
	0,
	0,0,0,0,0,0,
	0,0,0,0,0,0,0,

	cmac_key_free,
	0,
Loading