提交 f5eac85e 编写于 作者: D Dr. Stephen Henson

Add new -out option to asn1parse to allow the parsed data to be output.

Fixed -strparse option: it didn't work if used more than once (this was due
to the d2i_ASN1_TYPE call parsing a freed buffer). On Win32 the file wincrypt.h
#define's X509_NAME and PKCS7_SIGNER_INFO causing clashes so these are #undef'ed
上级 d53ff9ab
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
Changes between 0.9.2b and 0.9.3 Changes between 0.9.2b and 0.9.3
*) New option -out to asn1parse to allow the parsed structure to be
output to a file. This is most useful when combined with the -strparse
option to examine the output of things like OCTET STRINGS.
[Steve Henson]
*) Make SSL library a little more fool-proof by not requiring any longer *) Make SSL library a little more fool-proof by not requiring any longer
that SSL_set_{accept,connect}_state be called before that SSL_set_{accept,connect}_state be called before
SSL_{accept,connect} may be used (SSL_set_..._state is omitted SSL_{accept,connect} may be used (SSL_set_..._state is omitted
......
...@@ -85,9 +85,9 @@ int MAIN(int argc, char **argv) ...@@ -85,9 +85,9 @@ int MAIN(int argc, char **argv)
int i,badops=0,offset=0,ret=1,j; int i,badops=0,offset=0,ret=1,j;
unsigned int length=0; unsigned int length=0;
long num,tmplen; long num,tmplen;
BIO *in=NULL,*out=NULL,*b64=NULL; BIO *in=NULL,*out=NULL,*b64=NULL, *derout = NULL;
int informat,indent=0; int informat,indent=0;
char *infile=NULL,*str=NULL,*prog,*oidfile=NULL; char *infile=NULL,*str=NULL,*prog,*oidfile=NULL, *derfile=NULL;
unsigned char *tmpbuf; unsigned char *tmpbuf;
BUF_MEM *buf=NULL; BUF_MEM *buf=NULL;
STACK *osk=NULL; STACK *osk=NULL;
...@@ -121,6 +121,11 @@ int MAIN(int argc, char **argv) ...@@ -121,6 +121,11 @@ int MAIN(int argc, char **argv)
if (--argc < 1) goto bad; if (--argc < 1) goto bad;
infile= *(++argv); infile= *(++argv);
} }
else if (strcmp(*argv,"-out") == 0)
{
if (--argc < 1) goto bad;
derfile= *(++argv);
}
else if (strcmp(*argv,"-i") == 0) else if (strcmp(*argv,"-i") == 0)
{ {
indent=1; indent=1;
...@@ -170,6 +175,7 @@ bad: ...@@ -170,6 +175,7 @@ bad:
BIO_printf(bio_err," -strparse offset\n"); BIO_printf(bio_err," -strparse offset\n");
BIO_printf(bio_err," a series of these can be used to 'dig' into multiple\n"); BIO_printf(bio_err," a series of these can be used to 'dig' into multiple\n");
BIO_printf(bio_err," ASN1 blob wrappings\n"); BIO_printf(bio_err," ASN1 blob wrappings\n");
BIO_printf(bio_err," -out filename output DER encoding to file\n");
goto end; goto end;
} }
...@@ -206,6 +212,14 @@ bad: ...@@ -206,6 +212,14 @@ bad:
} }
} }
if (derfile) {
if(!(derout = BIO_new_file(derfile, "wb"))) {
BIO_printf(bio_err,"problems opening %s\n",derfile);
ERR_print_errors(bio_err);
goto end;
}
}
if ((buf=BUF_MEM_new()) == NULL) goto end; if ((buf=BUF_MEM_new()) == NULL) goto end;
if (!BUF_MEM_grow(buf,BUFSIZ*8)) goto end; /* Pre-allocate :-) */ if (!BUF_MEM_grow(buf,BUFSIZ*8)) goto end; /* Pre-allocate :-) */
...@@ -239,6 +253,7 @@ bad: ...@@ -239,6 +253,7 @@ bad:
tmplen=num; tmplen=num;
for (i=0; i<sk_num(osk); i++) for (i=0; i<sk_num(osk); i++)
{ {
ASN1_TYPE *atmp;
j=atoi(sk_value(osk,i)); j=atoi(sk_value(osk,i));
if (j == 0) if (j == 0)
{ {
...@@ -247,7 +262,10 @@ bad: ...@@ -247,7 +262,10 @@ bad:
} }
tmpbuf+=j; tmpbuf+=j;
tmplen-=j; tmplen-=j;
if (d2i_ASN1_TYPE(&at,&tmpbuf,tmplen) == NULL) atmp = at;
at = d2i_ASN1_TYPE(NULL,&tmpbuf,tmplen);
ASN1_TYPE_free(atmp);
if(!at)
{ {
BIO_printf(bio_err,"Error parsing structure\n"); BIO_printf(bio_err,"Error parsing structure\n");
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
...@@ -262,6 +280,13 @@ bad: ...@@ -262,6 +280,13 @@ bad:
} }
if (length == 0) length=(unsigned int)num; if (length == 0) length=(unsigned int)num;
if(derout) {
if(BIO_write(derout, str + offset, length) != length) {
BIO_printf(bio_err, "Error writing output\n");
ERR_print_errors(bio_err);
goto end;
}
}
if (!ASN1_parse(out,(unsigned char *)&(str[offset]),length,indent)) if (!ASN1_parse(out,(unsigned char *)&(str[offset]),length,indent))
{ {
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
...@@ -269,6 +294,7 @@ bad: ...@@ -269,6 +294,7 @@ bad:
} }
ret=0; ret=0;
end: end:
BIO_free(derout);
if (in != NULL) BIO_free(in); if (in != NULL) BIO_free(in);
if (out != NULL) BIO_free(out); if (out != NULL) BIO_free(out);
if (b64 != NULL) BIO_free(b64); if (b64 != NULL) BIO_free(b64);
......
...@@ -98,6 +98,9 @@ extern "C" { ...@@ -98,6 +98,9 @@ extern "C" {
#ifdef WIN32 #ifdef WIN32
#define get_last_sys_error() GetLastError() #define get_last_sys_error() GetLastError()
#define clear_sys_error() SetLastError(0) #define clear_sys_error() SetLastError(0)
/* These are defined in wincrypt.h and can cause problems */
#undef X509_NAME
#undef PKCS7_SIGNER_INFO
#if !defined(WINNT) #if !defined(WINNT)
#define WIN_CONSOLE_BUG #define WIN_CONSOLE_BUG
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册