Added -strictpem parameter to enable processing of PEM files with data prior to the BEGIN marker
This commit is contained in:
parent
487dac87e3
commit
6b5c1d940b
@ -80,6 +80,9 @@
|
|||||||
#undef PROG
|
#undef PROG
|
||||||
#define PROG asn1parse_main
|
#define PROG asn1parse_main
|
||||||
|
|
||||||
|
/* Minimum buffer size to be used */
|
||||||
|
#define MIN_BUFFER 256
|
||||||
|
|
||||||
int MAIN(int, char **);
|
int MAIN(int, char **);
|
||||||
|
|
||||||
static int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf);
|
static int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf);
|
||||||
@ -90,7 +93,7 @@ int MAIN(int argc, char **argv)
|
|||||||
unsigned int length=0;
|
unsigned int length=0;
|
||||||
long num,tmplen;
|
long num,tmplen;
|
||||||
BIO *in=NULL,*out=NULL,*b64=NULL, *derout = NULL;
|
BIO *in=NULL,*out=NULL,*b64=NULL, *derout = NULL;
|
||||||
int informat,indent=0, noout = 0, dump = 0;
|
int informat,indent=0, noout = 0, dump = 0, strictpem = 0;
|
||||||
char *infile=NULL,*str=NULL,*prog,*oidfile=NULL, *derfile=NULL;
|
char *infile=NULL,*str=NULL,*prog,*oidfile=NULL, *derfile=NULL;
|
||||||
char *genstr=NULL, *genconf=NULL;
|
char *genstr=NULL, *genconf=NULL;
|
||||||
unsigned char *tmpbuf;
|
unsigned char *tmpbuf;
|
||||||
@ -181,6 +184,11 @@ int MAIN(int argc, char **argv)
|
|||||||
if (--argc < 1) goto bad;
|
if (--argc < 1) goto bad;
|
||||||
genconf= *(++argv);
|
genconf= *(++argv);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(*argv,"-strictpem") == 0)
|
||||||
|
{
|
||||||
|
strictpem = 1;
|
||||||
|
informat = FORMAT_PEM;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BIO_printf(bio_err,"unknown option %s\n",*argv);
|
BIO_printf(bio_err,"unknown option %s\n",*argv);
|
||||||
@ -211,6 +219,8 @@ bad:
|
|||||||
BIO_printf(bio_err," ASN1 blob wrappings\n");
|
BIO_printf(bio_err," ASN1 blob wrappings\n");
|
||||||
BIO_printf(bio_err," -genstr str string to generate ASN1 structure from\n");
|
BIO_printf(bio_err," -genstr str string to generate ASN1 structure from\n");
|
||||||
BIO_printf(bio_err," -genconf file file to generate ASN1 structure from\n");
|
BIO_printf(bio_err," -genconf file file to generate ASN1 structure from\n");
|
||||||
|
BIO_printf(bio_err," -strictpem do not attempt base64 decode outside PEM markers (-inform \n");
|
||||||
|
BIO_printf(bio_err," will be ignored)\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +272,7 @@ bad:
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)<MIN_BUFFER?MIN_BUFFER:(BUFSIZ*8))) goto end; /* Pre-allocate :-) */
|
||||||
|
|
||||||
if (genstr || genconf)
|
if (genstr || genconf)
|
||||||
{
|
{
|
||||||
@ -281,6 +291,38 @@ bad:
|
|||||||
{
|
{
|
||||||
BIO *tmp;
|
BIO *tmp;
|
||||||
|
|
||||||
|
if(strictpem)
|
||||||
|
{
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
/* Read a line */
|
||||||
|
i=BIO_gets(in,buf->data,MIN_BUFFER-1);
|
||||||
|
|
||||||
|
if (i <= 0)
|
||||||
|
{
|
||||||
|
BIO_printf(bio_err, "Error: Cannot find start line\n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip trailing spaces etc */
|
||||||
|
do
|
||||||
|
i--;
|
||||||
|
while ((i >= 0) && (buf->data[i] <= ' '));
|
||||||
|
|
||||||
|
buf->data[++i]='\0';
|
||||||
|
|
||||||
|
/* Check if we have a PEM BEGIN marker */
|
||||||
|
if (strncmp(buf->data,"-----BEGIN ",11) == 0)
|
||||||
|
{
|
||||||
|
if (strncmp(&(buf->data[i-5]),"-----",5) != 0)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ((b64=BIO_new(BIO_f_base64())) == NULL)
|
if ((b64=BIO_new(BIO_f_base64())) == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
BIO_push(b64,in);
|
BIO_push(b64,in);
|
||||||
|
@ -18,6 +18,7 @@ B<openssl> B<asn1parse>
|
|||||||
[B<-strparse offset>]
|
[B<-strparse offset>]
|
||||||
[B<-genstr string>]
|
[B<-genstr string>]
|
||||||
[B<-genconf file>]
|
[B<-genconf file>]
|
||||||
|
[B<-strictpem>]
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
@ -78,6 +79,13 @@ B<asn1>. The encoded data is passed through the ASN1 parser and printed out as
|
|||||||
though it came from a file, the contents can thus be examined and written to a
|
though it came from a file, the contents can thus be examined and written to a
|
||||||
file using the B<out> option.
|
file using the B<out> option.
|
||||||
|
|
||||||
|
=item B<-strictpem>
|
||||||
|
|
||||||
|
If this option is used then B<-inform> will be ignored. Without this option any
|
||||||
|
data in a PEM format input file will be treated as base64 encoded and processed
|
||||||
|
whether it has the normal PEM BEGIN and END markers or not. This option will
|
||||||
|
ignore any data prior to the start of the BEGIN marker in a PEM file.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head2 OUTPUT
|
=head2 OUTPUT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user