Skip to content

Commit 225fe37

Browse files
committed
ASN.1 OIDs and sum: Change algorithm for sum
New sum algorithm has no clashes at this time. Old algorithm enabled by defining: WOLFSSL_OLD_OID_SUM. New oid_sum.h file generated with scripts/asn1_oid_sum.pl. Added bunch of OID names into asn1 example.
1 parent 3919491 commit 225fe37

File tree

19 files changed

+20634
-612
lines changed

19 files changed

+20634
-612
lines changed

.github/workflows/codespell.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
check_filenames: true
2424
check_hidden: true
2525
# Add comma separated list of words that occur multiple times that should be ignored (sorted alphabetically, case sensitive)
26-
ignore_words_list: adin,aNULL,brunch,carryIn,chainG,ciph,cLen,cliKs,dout,haveA,inCreated,inOut,inout,larg,LEAPYEAR,Merget,optionA,parm,parms,repid,rIn,userA,ser,siz,te,Te
26+
ignore_words_list: adin,aNULL,brunch,carryIn,chainG,ciph,cLen,cliKs,dout,haveA,inCreated,inOut,inout,larg,LEAPYEAR,Merget,optionA,parm,parms,repid,rIn,userA,ser,siz,te,Te,
2727
# The exclude_file contains lines of code that should be ignored. This is useful for individual lines which have non-words that can safely be ignored.
2828
exclude_file: '.codespellexcludelines'
2929
# To skip files entirely from being processed, add it to the following list:
30-
skip: '*.cproject,*.der,*.mtpj,*.pem,*.vcxproj,.git,*.launch,*.scfg,*.revoked'
30+
skip: '*.cproject,*.der,*.mtpj,*.pem,*.vcxproj,.git,*.launch,*.scfg,*.revoked,dumpasn1.cfg,oid_names.h'

examples/asn1/asn1.c

+45-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#if defined(WOLFSSL_ASN_PRINT) && !defined(NO_FILESYSTEM)
3636

37+
#include "oid_names.h"
38+
3739
/* Increment allocated data by this much. */
3840
#define DATA_INC_LEN 256
3941

@@ -50,6 +52,20 @@ static Asn1PrintOptions opts;
5052
/* ASN.1 parsing state. */
5153
static Asn1 asn1;
5254

55+
static const char* asn1App_OidToName(unsigned char* oid, word32 len)
56+
{
57+
int i;
58+
59+
for (i = 0; i < asn1App_oid_names_len; i++) {
60+
if ((len == asn1App_oid_name[i].len) &&
61+
(XMEMCMP(oid, asn1App_oid_name[i].oid, len) == 0)) {
62+
return asn1App_oid_name[i].name;
63+
}
64+
}
65+
66+
return NULL;
67+
}
68+
5369
/* Read the contents of a file into a dynamically allocated buffer.
5470
*
5571
* Uses realloc as input may be stdin.
@@ -65,9 +81,10 @@ static int asn1App_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
6581
int ret = 0;
6682
word32 len = 0;
6783
size_t read_len;
68-
/* Allocate a minimum amount. */
69-
unsigned char* data = (unsigned char*)XMALLOC(DATA_INC_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER);
84+
unsigned char* data;
7085

86+
/* Allocate a minimum amount. */
87+
data = (unsigned char*)XMALLOC(DATA_INC_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER);
7188
if (data != NULL) {
7289
/* Read more data. */
7390
while ((read_len = fread(data + len, 1, DATA_INC_LEN, fp)) != 0) {
@@ -87,7 +104,8 @@ static int asn1App_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
87104
}
88105

89106
/* Make space for more data to be added to buffer. */
90-
p = (unsigned char*)XREALLOC(data, len + DATA_INC_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER);
107+
p = (unsigned char*)XREALLOC(data, len + DATA_INC_LEN, NULL,
108+
DYNAMIC_TYPE_TMP_BUFFER);
91109
if (p == NULL) {
92110
/* Reallocation failed - free current buffer. */
93111
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@@ -299,6 +317,7 @@ const char* usage[] = {
299317
" -B, --base64 file contents are Base64 encoded",
300318
#endif
301319
" -d, --dump show all ASN.1 item data as a hex dump",
320+
" -D, --der file format is DER",
302321
" -h, --headers show all ASN.1 item headers as a hex dump",
303322
" -i, --indent indent tag name with depth",
304323
" -l, --length LEN display length bytes of data",
@@ -340,6 +359,7 @@ int main(int argc, char* argv[])
340359
int file_format = FORMAT_DER;
341360
word32 indent = 0;
342361
int pem_skip = 0;
362+
int format_set = 0;
343363

344364
/* Reset options. */
345365
(void)wc_Asn1PrintOptions_Init(&opts);
@@ -365,6 +385,11 @@ int main(int argc, char* argv[])
365385
(strcmp(argv[0], "--dump") == 0)) {
366386
wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_SHOW_DATA, 1);
367387
}
388+
else if ((strcmp(argv[0], "-D") == 0) ||
389+
(strcmp(argv[0], "--der") == 0)) {
390+
file_format = FORMAT_DER;
391+
format_set = 1;
392+
}
368393
/* Dump ASN.1 item headers. */
369394
else if ((strcmp(argv[0], "-h") == 0) ||
370395
(strcmp(argv[0], "--headers") == 0)) {
@@ -421,6 +446,7 @@ int main(int argc, char* argv[])
421446
else if ((strcmp(argv[0], "-p") == 0) ||
422447
(strcmp(argv[0], "--pem") == 0)) {
423448
file_format = FORMAT_PEM;
449+
format_set = 1;
424450
}
425451
#endif
426452
/* Skip a number of PEM blocks. */
@@ -451,10 +477,25 @@ int main(int argc, char* argv[])
451477
return 1;
452478
}
453479
else {
480+
int nameLen;
481+
454482
if (fp != stdin) {
455483
fprintf(stderr, "At most one input file can be supplied.\n");
456484
return 1;
457485
}
486+
487+
if (!format_set) {
488+
nameLen = (int)XSTRLEN(argv[0]);
489+
if (nameLen > 3) {
490+
if (XMEMCMP(argv[0] + nameLen - 4, ".pem", 4) == 0) {
491+
file_format = FORMAT_PEM;
492+
}
493+
else if (XMEMCMP(argv[0] + nameLen - 4, ".der", 4) == 0) {
494+
file_format = FORMAT_DER;
495+
}
496+
}
497+
}
498+
458499
/* Name of file to read. */
459500
fp = fopen(argv[0], "r");
460501
if (fp == NULL) {
@@ -472,6 +513,7 @@ int main(int argc, char* argv[])
472513

473514
(void)wc_Asn1_Init(&asn1);
474515
(void)wc_Asn1_SetFile(&asn1, stdout);
516+
(void)wc_Asn1_SetOidToNameCb(&asn1, asn1App_OidToName);
475517

476518
/* Process file based on type. */
477519
if (file_format == FORMAT_DER) {

0 commit comments

Comments
 (0)