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

New function X509_signature_print() to remove some duplicate

code from certificate, CRL and request printing routines.
parent 06db4253
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3,6 +3,10 @@

 Changes between 0.9.6 and 0.9.7  [xx XXX 2000]

  *) New function X509_signature_print() to remove duplication in some
     print routines.
     [Steve Henson]

  *) Add a special meaning when SET OF and SEQUENCE OF flags are both
     set (this was treated exactly the same as SET OF previously). This
     is used to reorder the STACK representing the structure to match the
+1 −14
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@ int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
int X509_CRL_print(BIO *out, X509_CRL *x)
{
	char buf[256];
	unsigned char *s;
	STACK_OF(X509_REVOKED) *rev;
	X509_REVOKED *r;
	long l;
@@ -131,19 +130,7 @@ int X509_CRL_print(BIO *out, X509_CRL *x)
		for(j = 0; j < X509_REVOKED_get_ext_count(r); j++)
				ext_print(out, X509_REVOKED_get_ext(r, j));
	}

	i=OBJ_obj2nid(x->sig_alg->algorithm);
	BIO_printf(out,"    Signature Algorithm: %s",
				(i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));

	s = x->signature->data;
	n = x->signature->length;
	for (i=0; i<n; i++, s++)
	{
		if ((i%18) == 0) BIO_write(out,"\n        ",9);
		BIO_printf(out,"%02x%s",*s, ((i+1) == n)?"":":");
	}
	BIO_write(out,"\n",1);
	X509_signature_print(out, x->sig_alg, x->signature);

	return 1;

+2 −19
Original line number Diff line number Diff line
@@ -85,8 +85,7 @@ int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
int X509_REQ_print(BIO *bp, X509_REQ *x)
	{
	unsigned long l;
	int i,n;
	char *s;
	int i;
	const char *neg;
	X509_REQ_INFO *ri;
	EVP_PKEY *pkey;
@@ -226,24 +225,8 @@ get_next:
		sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
	}

	i=OBJ_obj2nid(x->sig_alg->algorithm);
	sprintf(str,"%4sSignature Algorithm: %s","",
		(i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
	if (BIO_puts(bp,str) <= 0) goto err;
	if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;

	n=x->signature->length;
	s=(char *)x->signature->data;
	for (i=0; i<n; i++)
		{
		if ((i%18) == 0)
			{
			sprintf(str,"\n%8s","");
			if (BIO_puts(bp,str) <= 0) goto err;
			}
		sprintf(str,"%02x%s",(unsigned char)s[i],((i+1) == n)?"":":");
		if (BIO_puts(bp,str) <= 0) goto err;
		}
	if (BIO_puts(bp,"\n") <= 0) goto err;
	return(1);
err:
	X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
+22 −15
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
	{
	long l;
	int ret=0,i,j,n;
	char *m=NULL,*s, mlch = ' ';
	char *m=NULL,mlch = ' ';
	int nmindent = 0;
	X509_CINF *ci;
	ASN1_INTEGER *bs;
@@ -256,20 +256,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)

	if(!(cflag & X509_FLAG_NO_SIGDUMP))
		{
		i=OBJ_obj2nid(x->sig_alg->algorithm);
		if (BIO_printf(bp,"%4sSignature Algorithm: %s","",
			(i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;

		n=x->signature->length;
		s=(char *)x->signature->data;
		for (i=0; i<n; i++)
			{
			if ((i%18) == 0)
				if (BIO_write(bp,"\n        ",9) <= 0) goto err;
			if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
				((i+1) == n)?"":":") <= 0) goto err;
			}
		if (BIO_write(bp,"\n",1) != 1) goto err;
		if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err;
		}
	if(!(cflag & X509_FLAG_NO_AUX))
		{
@@ -332,6 +319,26 @@ err:
	return(0);
	}

int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
{
	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_printf(bp,"%02x%s",s[i],
				((i+1) == n)?"":":") <= 0) return 0;
		}
	if (BIO_write(bp,"\n",1) != 1) return 0;
	return 1;
}

int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
	{
	int i,n;
+2 −0
Original line number Diff line number Diff line
@@ -711,6 +711,8 @@ int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);

int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);

int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig);

int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);