Try to parse inner structure of an octet string (limited to CONS SEQ right now)
This commit is contained in:
@@ -41,9 +41,8 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <der.h>
|
#include <der.h>
|
||||||
|
|
||||||
RCSID("$Id$");
|
|
||||||
|
|
||||||
static int indent_flag = 1;
|
static int indent_flag = 1;
|
||||||
|
static int inner_flag = 0;
|
||||||
|
|
||||||
static unsigned long indefinite_form_loop;
|
static unsigned long indefinite_form_loop;
|
||||||
static unsigned long indefinite_form_loop_max = 10000;
|
static unsigned long indefinite_form_loop_max = 10000;
|
||||||
@@ -167,17 +166,39 @@ loop (unsigned char *buf, size_t len, int indent)
|
|||||||
}
|
}
|
||||||
case UT_OctetString : {
|
case UT_OctetString : {
|
||||||
heim_octet_string str;
|
heim_octet_string str;
|
||||||
int i;
|
size_t i;
|
||||||
unsigned char *uc;
|
|
||||||
|
|
||||||
ret = der_get_octet_string (buf, length, &str, NULL);
|
ret = der_get_octet_string (buf, length, &str, NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
errx (1, "der_get_octet_string: %s", error_message (ret));
|
errx (1, "der_get_octet_string: %s", error_message (ret));
|
||||||
printf ("(length %lu), ", (unsigned long)length);
|
printf ("(length %lu), ", (unsigned long)length);
|
||||||
uc = (unsigned char *)str.data;
|
|
||||||
for (i = 0; i < min(16,length); ++i)
|
if (inner_flag) {
|
||||||
printf ("%02x", uc[i]);
|
Der_class class;
|
||||||
printf ("\n");
|
Der_type type;
|
||||||
|
unsigned int tag;
|
||||||
|
|
||||||
|
ret = der_get_tag(str.data, str.length,
|
||||||
|
&class, &type, &tag, &sz);
|
||||||
|
if (ret || sz > str.length ||
|
||||||
|
type != CONS || tag != UT_Sequence)
|
||||||
|
goto just_an_octet_string;
|
||||||
|
|
||||||
|
printf("{\n");
|
||||||
|
loop (str.data, str.length, indent + 2);
|
||||||
|
for (i = 0; i < indent; ++i)
|
||||||
|
printf (" ");
|
||||||
|
printf ("}\n");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
unsigned char *uc;
|
||||||
|
|
||||||
|
just_an_octet_string:
|
||||||
|
uc = (unsigned char *)str.data;
|
||||||
|
for (i = 0; i < min(16,length); ++i)
|
||||||
|
printf ("%02x", uc[i]);
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
free (str.data);
|
free (str.data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -295,6 +316,7 @@ static int version_flag;
|
|||||||
static int help_flag;
|
static int help_flag;
|
||||||
struct getargs args[] = {
|
struct getargs args[] = {
|
||||||
{ "indent", 0, arg_negative_flag, &indent_flag },
|
{ "indent", 0, arg_negative_flag, &indent_flag },
|
||||||
|
{ "inner", 0, arg_flag, &inner_flag, "try to parse inner structures of OCTET STRING" },
|
||||||
{ "version", 0, arg_flag, &version_flag },
|
{ "version", 0, arg_flag, &version_flag },
|
||||||
{ "help", 0, arg_flag, &help_flag }
|
{ "help", 0, arg_flag, &help_flag }
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user