@@ -35,11 +35,11 @@ static EVP_PKEY * acert_read_pubkey(const char * file);
3535static int acert_print (X509_ACERT * x509 );
3636static EVP_PKEY * acert_read_x509_pubkey (const char * cert );
3737static int acert_test_api_misc (X509_ACERT * x509 );
38- #if defined(USE_WOLFSSL ) && defined( PUBLIC_ASN )
38+ #if defined(USE_WOLFSSL )
3939static int acert_parse_attr (const X509_ACERT * x509 );
4040static void acert_dump_hex (const char * what , const byte * data ,
4141 size_t len );
42- #endif /* if USE_WOLFSSL && PUBLIC_ASN */
42+ #endif /* if USE_WOLFSSL */
4343
4444static int dump = 0 ;
4545static int parse = 0 ;
@@ -233,15 +233,15 @@ acert_do_test(const char * file,
233233 goto end_acert_do_test ;
234234 }
235235
236- #if defined(USE_WOLFSSL ) && defined( PUBLIC_ASN )
236+ #if defined(USE_WOLFSSL )
237237 rc = acert_parse_attr (x509 );
238238
239239 if (rc ) {
240240 printf ("error: acert_parse_attr returned: %d\n" , rc );
241241 fail = 1 ;
242242 goto end_acert_do_test ;
243243 }
244- #endif /* if USE_WOLFSSL && PUBLIC_ASN */
244+ #endif /* if USE_WOLFSSL */
245245
246246 if (cert ) {
247247 pkey = acert_read_x509_pubkey (cert );
@@ -433,9 +433,9 @@ acert_test_api_misc(X509_ACERT * x509)
433433 return rc ;
434434}
435435
436- #if defined(USE_WOLFSSL ) && defined( PUBLIC_ASN )
437- /* Given an x509, retrieves the raw attributes buffer and
438- * length, and then parses it.
436+ #if defined(USE_WOLFSSL )
437+ /* Given an x509 acert, retrieve the raw attributes buffer and
438+ * length, and then parses it a little .
439439 *
440440 * Returns 0 on success.
441441 * Returns < 0 on error.
@@ -447,12 +447,13 @@ acert_parse_attr(const X509_ACERT * x509)
447447 word32 attr_len = 0 ;
448448 word32 idx = 0 ;
449449 word32 max_idx = 0 ;
450- int seq_len = 0 ;
450+ byte tag ;
451451 int rc = 0 ;
452+ int len = 0 ;
452453
453454 rc = wolfSSL_X509_ACERT_get_attr_buf (x509 , & attr , & attr_len );
454455
455- if (rc != 0 ) {
456+ if (rc != SSL_SUCCESS ) {
456457 printf ("error: wolfSSL_X509_ACERT_get_attr_buf returned: %d\n" , rc );
457458 return -1 ;
458459 }
@@ -472,18 +473,28 @@ acert_parse_attr(const X509_ACERT * x509)
472473
473474 max_idx = attr_len ;
474475
475- seq_len = GetSequence (attr + idx , & idx , & seq_len , max_idx );
476+ rc = GetASNTag (attr + idx , & idx , & tag , max_idx );
476477
477- if (seq_len <= 0 ) {
478- printf ("error: GetSequence (%p, %d, %d, %d) returned: %d\n" , attr ,
479- idx , seq_len , max_idx , seq_len );
478+ if (rc < 0 ) {
479+ printf ("error: GetASNTag (%p, %d, %d, %d) returned: %d\n" , attr + idx ,
480+ idx , tag , max_idx , tag );
480481 return -1 ;
481482 }
482- else {
483- printf ("info: GetSequence(%p, %d, %d, %d) returned: %d\n" , attr ,
484- idx , seq_len , max_idx , seq_len );
483+
484+ printf ("info: GetASNTag(%p, %d, %d, %d): found tag: 0x%0x\n" , attr + idx ,
485+ idx , tag , max_idx , tag );
486+
487+ len = GetLength (attr + idx , & idx , & len , max_idx );
488+
489+ if (len <= 0 ) {
490+ printf ("error: GetLength(%p, %d, %d, %d) returned: %d\n" , attr + idx ,
491+ idx , len , max_idx , len );
492+ return -1 ;
485493 }
486494
495+ printf ("info: GetLength(%p, %d, %d, %d) returned: %d\n" , attr + idx ,
496+ idx , len , max_idx , len );
497+
487498 return rc ;
488499}
489500
@@ -494,6 +505,21 @@ acert_parse_attr(const X509_ACERT * x509)
494505#define BOLDYELLOW "\033[1m\033[33m"
495506#define RESET "\033[0m"
496507
508+ static void
509+ acert_print_data (const byte * data ,
510+ size_t i ,
511+ size_t j )
512+ {
513+ if (isprint (data [i + 2 + j ])) {
514+ printf ("%c" , data [i + 2 + j ]);
515+ }
516+ else {
517+ printf ("." );
518+ }
519+
520+ return ;
521+ }
522+
497523/* Dump data as hex, with some pretty color coding.
498524 * Kind of a silly work in progress, for debugging use.
499525 * */
@@ -571,13 +597,7 @@ acert_dump_hex(const char * what,
571597 printf (BOLDGREEN "0x%02x " RESET , data [i + 1 ]);
572598
573599 for (size_t j = 0 ; j < seq_len ; ++ j ) {
574- if (isalnum (data [i + 2 + j ])) {
575- printf ("%c" , data [i + 2 + j ]);
576- }
577- else {
578- //printf("%d", data[i + 2 + j]);
579- printf ("." );
580- }
600+ acert_print_data (data , i , j );
581601 }
582602 printf ("\n" );
583603 }
@@ -597,6 +617,7 @@ acert_dump_hex(const char * what,
597617
598618 for (size_t j = 0 ; j < str_len ; ++ j ) {
599619 printf ("%c" , data [i + 2 + j ]);
620+ acert_print_data (data , i , j );
600621 }
601622
602623 printf ("\n" );
@@ -607,7 +628,7 @@ acert_dump_hex(const char * what,
607628
608629 return ;
609630}
610- #endif /* if USE_WOLFSSL && PUBLIC_ASN */
631+ #endif /* if USE_WOLFSSL */
611632
612633/* Reads and print pubkey certificate.
613634 * */
0 commit comments