diff options
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_prn.c')
| -rw-r--r-- | src/lib/libcrypto/x509v3/v3_prn.c | 112 |
1 files changed, 105 insertions, 7 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c index dc20c6bdba..aeaf6170fe 100644 --- a/src/lib/libcrypto/x509v3/v3_prn.c +++ b/src/lib/libcrypto/x509v3/v3_prn.c | |||
| @@ -64,6 +64,8 @@ | |||
| 64 | 64 | ||
| 65 | /* Extension printing routines */ | 65 | /* Extension printing routines */ |
| 66 | 66 | ||
| 67 | static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported); | ||
| 68 | |||
| 67 | /* Print out a name+value stack */ | 69 | /* Print out a name+value stack */ |
| 68 | 70 | ||
| 69 | void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml) | 71 | void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml) |
| @@ -81,29 +83,65 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml) | |||
| 81 | nval = sk_CONF_VALUE_value(val, i); | 83 | nval = sk_CONF_VALUE_value(val, i); |
| 82 | if(!nval->name) BIO_puts(out, nval->value); | 84 | if(!nval->name) BIO_puts(out, nval->value); |
| 83 | else if(!nval->value) BIO_puts(out, nval->name); | 85 | else if(!nval->value) BIO_puts(out, nval->name); |
| 86 | #ifndef CHARSET_EBCDIC | ||
| 84 | else BIO_printf(out, "%s:%s", nval->name, nval->value); | 87 | else BIO_printf(out, "%s:%s", nval->name, nval->value); |
| 88 | #else | ||
| 89 | else { | ||
| 90 | int len; | ||
| 91 | char *tmp; | ||
| 92 | len = strlen(nval->value)+1; | ||
| 93 | tmp = OPENSSL_malloc(len); | ||
| 94 | if (tmp) | ||
| 95 | { | ||
| 96 | ascii2ebcdic(tmp, nval->value, len); | ||
| 97 | BIO_printf(out, "%s:%s", nval->name, tmp); | ||
| 98 | OPENSSL_free(tmp); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | #endif | ||
| 85 | if(ml) BIO_puts(out, "\n"); | 102 | if(ml) BIO_puts(out, "\n"); |
| 86 | } | 103 | } |
| 87 | } | 104 | } |
| 88 | 105 | ||
| 89 | /* Main routine: print out a general extension */ | 106 | /* Main routine: print out a general extension */ |
| 90 | 107 | ||
| 91 | int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent) | 108 | int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent) |
| 92 | { | 109 | { |
| 93 | char *ext_str = NULL, *value = NULL; | 110 | void *ext_str = NULL; |
| 111 | char *value = NULL; | ||
| 94 | unsigned char *p; | 112 | unsigned char *p; |
| 95 | X509V3_EXT_METHOD *method; | 113 | X509V3_EXT_METHOD *method; |
| 96 | STACK_OF(CONF_VALUE) *nval = NULL; | 114 | STACK_OF(CONF_VALUE) *nval = NULL; |
| 97 | int ok = 1; | 115 | int ok = 1; |
| 98 | if(!(method = X509V3_EXT_get(ext))) return 0; | 116 | if(!(method = X509V3_EXT_get(ext))) |
| 117 | return unknown_ext_print(out, ext, flag, indent, 0); | ||
| 99 | p = ext->value->data; | 118 | p = ext->value->data; |
| 100 | if(!(ext_str = method->d2i(NULL, &p, ext->value->length))) return 0; | 119 | if(method->it) ext_str = ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it)); |
| 120 | else ext_str = method->d2i(NULL, &p, ext->value->length); | ||
| 121 | |||
| 122 | if(!ext_str) return unknown_ext_print(out, ext, flag, indent, 1); | ||
| 123 | |||
| 101 | if(method->i2s) { | 124 | if(method->i2s) { |
| 102 | if(!(value = method->i2s(method, ext_str))) { | 125 | if(!(value = method->i2s(method, ext_str))) { |
| 103 | ok = 0; | 126 | ok = 0; |
| 104 | goto err; | 127 | goto err; |
| 105 | } | 128 | } |
| 129 | #ifndef CHARSET_EBCDIC | ||
| 106 | BIO_printf(out, "%*s%s", indent, "", value); | 130 | BIO_printf(out, "%*s%s", indent, "", value); |
| 131 | #else | ||
| 132 | { | ||
| 133 | int len; | ||
| 134 | char *tmp; | ||
| 135 | len = strlen(value)+1; | ||
| 136 | tmp = OPENSSL_malloc(len); | ||
| 137 | if (tmp) | ||
| 138 | { | ||
| 139 | ascii2ebcdic(tmp, value, len); | ||
| 140 | BIO_printf(out, "%*s%s", indent, "", tmp); | ||
| 141 | OPENSSL_free(tmp); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | #endif | ||
| 107 | } else if(method->i2v) { | 145 | } else if(method->i2v) { |
| 108 | if(!(nval = method->i2v(method, ext_str, NULL))) { | 146 | if(!(nval = method->i2v(method, ext_str, NULL))) { |
| 109 | ok = 0; | 147 | ok = 0; |
| @@ -117,12 +155,72 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent) | |||
| 117 | 155 | ||
| 118 | err: | 156 | err: |
| 119 | sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); | 157 | sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); |
| 120 | if(value) Free(value); | 158 | if(value) OPENSSL_free(value); |
| 121 | method->ext_free(ext_str); | 159 | if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it)); |
| 160 | else method->ext_free(ext_str); | ||
| 122 | return ok; | 161 | return ok; |
| 123 | } | 162 | } |
| 124 | 163 | ||
| 125 | #ifndef NO_FP_API | 164 | int X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent) |
| 165 | { | ||
| 166 | int i, j; | ||
| 167 | |||
| 168 | if(sk_X509_EXTENSION_num(exts) <= 0) return 1; | ||
| 169 | |||
| 170 | if(title) | ||
| 171 | { | ||
| 172 | BIO_printf(bp,"%*s%s:\n",indent, "", title); | ||
| 173 | indent += 4; | ||
| 174 | } | ||
| 175 | |||
| 176 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | ||
| 177 | { | ||
| 178 | ASN1_OBJECT *obj; | ||
| 179 | X509_EXTENSION *ex; | ||
| 180 | ex=sk_X509_EXTENSION_value(exts, i); | ||
| 181 | if (BIO_printf(bp,"%*s",indent, "") <= 0) return 0; | ||
| 182 | obj=X509_EXTENSION_get_object(ex); | ||
| 183 | i2a_ASN1_OBJECT(bp,obj); | ||
| 184 | j=X509_EXTENSION_get_critical(ex); | ||
| 185 | if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0) | ||
| 186 | return 0; | ||
| 187 | if(!X509V3_EXT_print(bp, ex, flag, 12)) | ||
| 188 | { | ||
| 189 | BIO_printf(bp, "%*s", indent + 4, ""); | ||
| 190 | M_ASN1_OCTET_STRING_print(bp,ex->value); | ||
| 191 | } | ||
| 192 | if (BIO_write(bp,"\n",1) <= 0) return 0; | ||
| 193 | } | ||
| 194 | return 1; | ||
| 195 | } | ||
| 196 | |||
| 197 | static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported) | ||
| 198 | { | ||
| 199 | switch(flag & X509V3_EXT_UNKNOWN_MASK) { | ||
| 200 | |||
| 201 | case X509V3_EXT_DEFAULT: | ||
| 202 | return 0; | ||
| 203 | |||
| 204 | case X509V3_EXT_ERROR_UNKNOWN: | ||
| 205 | if(supported) | ||
| 206 | BIO_printf(out, "%*s<Parse Error>", indent, ""); | ||
| 207 | else | ||
| 208 | BIO_printf(out, "%*s<Not Supported>", indent, ""); | ||
| 209 | return 1; | ||
| 210 | |||
| 211 | case X509V3_EXT_PARSE_UNKNOWN: | ||
| 212 | return ASN1_parse_dump(out, | ||
| 213 | ext->value->data, ext->value->length, indent, -1); | ||
| 214 | case X509V3_EXT_DUMP_UNKNOWN: | ||
| 215 | return BIO_dump_indent(out, (char *)ext->value->data, ext->value->length, indent); | ||
| 216 | |||
| 217 | default: | ||
| 218 | return 1; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | |||
| 223 | #ifndef OPENSSL_NO_FP_API | ||
| 126 | int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent) | 224 | int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent) |
| 127 | { | 225 | { |
| 128 | BIO *bio_tmp; | 226 | BIO *bio_tmp; |
