diff options
| author | tb <> | 2025-11-27 08:26:32 +0000 |
|---|---|---|
| committer | tb <> | 2025-11-27 08:26:32 +0000 |
| commit | e301ef23b53cd30d97d07468d49ce25c85bdea3e (patch) | |
| tree | 4a3759942fd81e9b281f6cc1c2a68f8c93a97187 /src | |
| parent | 9c2fb2d749c8780ed1220475b6050f4dbebf9d0a (diff) | |
| download | openbsd-e301ef23b53cd30d97d07468d49ce25c85bdea3e.tar.gz openbsd-e301ef23b53cd30d97d07468d49ce25c85bdea3e.tar.bz2 openbsd-e301ef23b53cd30d97d07468d49ce25c85bdea3e.zip | |
openssl pkcs12: stop reaching into ASN1_STRING
Buy a t: rename hex_prin() to hex_print() and accept an ASN1_STRING so that
we only need to use accessors once. Also avoid a printf %s NULL.
ok kenjiro
Diffstat (limited to 'src')
| -rw-r--r-- | src/usr.bin/openssl/pkcs12.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/usr.bin/openssl/pkcs12.c b/src/usr.bin/openssl/pkcs12.c index efd6d59163..d29a12ce60 100644 --- a/src/usr.bin/openssl/pkcs12.c +++ b/src/usr.bin/openssl/pkcs12.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: pkcs12.c,v 1.30 2025/06/07 08:33:58 tb Exp $ */ | 1 | /* $OpenBSD: pkcs12.c,v 1.31 2025/11/27 08:26:32 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -88,7 +88,6 @@ static int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bags, char *pass, | |||
| 88 | int passlen, int options, char *pempass); | 88 | int passlen, int options, char *pempass); |
| 89 | static int print_attribs(BIO *out, const STACK_OF(X509_ATTRIBUTE) *attrlst, | 89 | static int print_attribs(BIO *out, const STACK_OF(X509_ATTRIBUTE) *attrlst, |
| 90 | const char *name); | 90 | const char *name); |
| 91 | static void hex_prin(BIO *out, unsigned char *buf, int len); | ||
| 92 | static int alg_print(BIO *x, const X509_ALGOR *alg); | 91 | static int alg_print(BIO *x, const X509_ALGOR *alg); |
| 93 | static int set_pbe(BIO *err, int *ppbe, const char *str); | 92 | static int set_pbe(BIO *err, int *ppbe, const char *str); |
| 94 | 93 | ||
| @@ -1021,6 +1020,17 @@ alg_print(BIO *x, const X509_ALGOR *alg) | |||
| 1021 | return 1; | 1020 | return 1; |
| 1022 | } | 1021 | } |
| 1023 | 1022 | ||
| 1023 | static void | ||
| 1024 | hex_print(BIO *out, const ASN1_STRING *str) | ||
| 1025 | { | ||
| 1026 | const unsigned char *buf = ASN1_STRING_get0_data(str); | ||
| 1027 | int len = ASN1_STRING_length(str); | ||
| 1028 | int i; | ||
| 1029 | |||
| 1030 | for (i = 0; i < len; i++) | ||
| 1031 | BIO_printf(out, "%02X ", buf[i]); | ||
| 1032 | } | ||
| 1033 | |||
| 1024 | /* Generalised attribute print: handle PKCS#8 and bag attributes */ | 1034 | /* Generalised attribute print: handle PKCS#8 and bag attributes */ |
| 1025 | static void | 1035 | static void |
| 1026 | print_attribute(BIO *out, const ASN1_TYPE *av) | 1036 | print_attribute(BIO *out, const ASN1_TYPE *av) |
| @@ -1030,21 +1040,19 @@ print_attribute(BIO *out, const ASN1_TYPE *av) | |||
| 1030 | switch (av->type) { | 1040 | switch (av->type) { |
| 1031 | case V_ASN1_BMPSTRING: | 1041 | case V_ASN1_BMPSTRING: |
| 1032 | value = OPENSSL_uni2asc( | 1042 | value = OPENSSL_uni2asc( |
| 1033 | av->value.bmpstring->data, | 1043 | ASN1_STRING_get0_data(av->value.bmpstring), |
| 1034 | av->value.bmpstring->length); | 1044 | ASN1_STRING_length(av->value.bmpstring)); |
| 1035 | BIO_printf(out, "%s\n", value); | 1045 | BIO_printf(out, "%s\n", value != NULL ? value : "(null)"); |
| 1036 | free(value); | 1046 | free(value); |
| 1037 | break; | 1047 | break; |
| 1038 | 1048 | ||
| 1039 | case V_ASN1_OCTET_STRING: | 1049 | case V_ASN1_OCTET_STRING: |
| 1040 | hex_prin(out, av->value.octet_string->data, | 1050 | hex_print(out, av->value.octet_string); |
| 1041 | av->value.octet_string->length); | ||
| 1042 | BIO_printf(out, "\n"); | 1051 | BIO_printf(out, "\n"); |
| 1043 | break; | 1052 | break; |
| 1044 | 1053 | ||
| 1045 | case V_ASN1_BIT_STRING: | 1054 | case V_ASN1_BIT_STRING: |
| 1046 | hex_prin(out, av->value.bit_string->data, | 1055 | hex_print(out, av->value.bit_string); |
| 1047 | av->value.bit_string->length); | ||
| 1048 | BIO_printf(out, "\n"); | 1056 | BIO_printf(out, "\n"); |
| 1049 | break; | 1057 | break; |
| 1050 | 1058 | ||
| @@ -1096,15 +1104,6 @@ print_attribs(BIO *out, const STACK_OF(X509_ATTRIBUTE) *attrlst, | |||
| 1096 | return 1; | 1104 | return 1; |
| 1097 | } | 1105 | } |
| 1098 | 1106 | ||
| 1099 | static void | ||
| 1100 | hex_prin(BIO *out, unsigned char *buf, int len) | ||
| 1101 | { | ||
| 1102 | int i; | ||
| 1103 | |||
| 1104 | for (i = 0; i < len; i++) | ||
| 1105 | BIO_printf(out, "%02X ", buf[i]); | ||
| 1106 | } | ||
| 1107 | |||
| 1108 | static int | 1107 | static int |
| 1109 | set_pbe(BIO *err, int *ppbe, const char *str) | 1108 | set_pbe(BIO *err, int *ppbe, const char *str) |
| 1110 | { | 1109 | { |
