summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509v3/v3_prn.c
diff options
context:
space:
mode:
authorjsing <>2014-05-26 12:10:11 +0000
committerjsing <>2014-05-26 12:10:11 +0000
commit0995a92809472b446ca1bf18277538657c614595 (patch)
tree1adbb75e5e24e4d93c2bd12fb748f9eb26f2d739 /src/lib/libcrypto/x509v3/v3_prn.c
parent1918fecccdef550d51f6267a095575731f873b2b (diff)
downloadopenbsd-0995a92809472b446ca1bf18277538657c614595.tar.gz
openbsd-0995a92809472b446ca1bf18277538657c614595.tar.bz2
openbsd-0995a92809472b446ca1bf18277538657c614595.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_prn.c')
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c168
1 files changed, 96 insertions, 72 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
index 565937af47..3874ded51c 100644
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ b/src/lib/libcrypto/x509v3/v3_prn.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -64,139 +64,163 @@
64 64
65/* Extension printing routines */ 65/* Extension printing routines */
66 66
67static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported); 67static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag,
68 int indent, int supported);
68 69
69/* Print out a name+value stack */ 70/* Print out a name+value stack */
70 71
71void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml) 72void
73X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
72{ 74{
73 int i; 75 int i;
74 CONF_VALUE *nval; 76 CONF_VALUE *nval;
75 if(!val) return; 77
76 if(!ml || !sk_CONF_VALUE_num(val)) { 78 if (!val)
79 return;
80 if (!ml || !sk_CONF_VALUE_num(val)) {
77 BIO_printf(out, "%*s", indent, ""); 81 BIO_printf(out, "%*s", indent, "");
78 if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n"); 82 if (!sk_CONF_VALUE_num(val))
83 BIO_puts(out, "<EMPTY>\n");
79 } 84 }
80 for(i = 0; i < sk_CONF_VALUE_num(val); i++) { 85 for (i = 0; i < sk_CONF_VALUE_num(val); i++) {
81 if(ml) BIO_printf(out, "%*s", indent, ""); 86 if (ml)
82 else if(i > 0) BIO_printf(out, ", "); 87 BIO_printf(out, "%*s", indent, "");
83 nval = sk_CONF_VALUE_value(val, i); 88 else if (i > 0) BIO_printf(out, ", ");
84 if(!nval->name) BIO_puts(out, nval->value); 89 nval = sk_CONF_VALUE_value(val, i);
85 else if(!nval->value) BIO_puts(out, nval->name); 90 if (!nval->name)
86 else BIO_printf(out, "%s:%s", nval->name, nval->value); 91 BIO_puts(out, nval->value);
87 if(ml) BIO_puts(out, "\n"); 92 else if (!nval->value)
93 BIO_puts(out, nval->name);
94 else
95 BIO_printf(out, "%s:%s", nval->name, nval->value);
96 if (ml)
97 BIO_puts(out, "\n");
88 } 98 }
89} 99}
90 100
91/* Main routine: print out a general extension */ 101/* Main routine: print out a general extension */
92 102
93int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent) 103int
104X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent)
94{ 105{
95 void *ext_str = NULL; 106 void *ext_str = NULL;
96 char *value = NULL; 107 char *value = NULL;
97 const unsigned char *p; 108 const unsigned char *p;
98 const X509V3_EXT_METHOD *method; 109 const X509V3_EXT_METHOD *method;
99 STACK_OF(CONF_VALUE) *nval = NULL; 110 STACK_OF(CONF_VALUE) *nval = NULL;
100 int ok = 1; 111 int ok = 1;
101 112
102 if(!(method = X509V3_EXT_get(ext))) 113 if (!(method = X509V3_EXT_get(ext)))
103 return unknown_ext_print(out, ext, flag, indent, 0); 114 return unknown_ext_print(out, ext, flag, indent, 0);
104 p = ext->value->data; 115 p = ext->value->data;
105 if(method->it) ext_str = ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it)); 116 if (method->it)
106 else ext_str = method->d2i(NULL, &p, ext->value->length); 117 ext_str = ASN1_item_d2i(NULL, &p, ext->value->length,
118 ASN1_ITEM_ptr(method->it));
119 else
120 ext_str = method->d2i(NULL, &p, ext->value->length);
107 121
108 if(!ext_str) return unknown_ext_print(out, ext, flag, indent, 1); 122 if (!ext_str)
123 return unknown_ext_print(out, ext, flag, indent, 1);
109 124
110 if(method->i2s) { 125 if (method->i2s) {
111 if(!(value = method->i2s(method, ext_str))) { 126 if (!(value = method->i2s(method, ext_str))) {
112 ok = 0; 127 ok = 0;
113 goto err; 128 goto err;
114 } 129 }
115 BIO_printf(out, "%*s%s", indent, "", value); 130 BIO_printf(out, "%*s%s", indent, "", value);
116 } else if(method->i2v) { 131 } else if (method->i2v) {
117 if(!(nval = method->i2v(method, ext_str, NULL))) { 132 if (!(nval = method->i2v(method, ext_str, NULL))) {
118 ok = 0; 133 ok = 0;
119 goto err; 134 goto err;
120 } 135 }
121 X509V3_EXT_val_prn(out, nval, indent, 136 X509V3_EXT_val_prn(out, nval, indent,
122 method->ext_flags & X509V3_EXT_MULTILINE); 137 method->ext_flags & X509V3_EXT_MULTILINE);
123 } else if(method->i2r) { 138 } else if (method->i2r) {
124 if(!method->i2r(method, ext_str, out, indent)) ok = 0; 139 if (!method->i2r(method, ext_str, out, indent))
125 } else ok = 0; 140 ok = 0;
126 141 } else
127 err: 142 ok = 0;
128 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); 143
129 if(value) free(value); 144err:
130 if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it)); 145 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
131 else method->ext_free(ext_str); 146 if (value)
132 return ok; 147 free(value);
148 if (method->it)
149 ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));
150 else
151 method->ext_free(ext_str);
152 return ok;
133} 153}
134 154
135int X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent) 155int
156X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts,
157 unsigned long flag, int indent)
136{ 158{
137 int i, j; 159 int i, j;
138 160
139 if(sk_X509_EXTENSION_num(exts) <= 0) return 1; 161 if (sk_X509_EXTENSION_num(exts) <= 0)
162 return 1;
140 163
141 if(title) 164 if (title) {
142 { 165 BIO_printf(bp, "%*s%s:\n",indent, "", title);
143 BIO_printf(bp,"%*s%s:\n",indent, "", title);
144 indent += 4; 166 indent += 4;
145 } 167 }
146 168
147 for (i=0; i<sk_X509_EXTENSION_num(exts); i++) 169 for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
148 {
149 ASN1_OBJECT *obj; 170 ASN1_OBJECT *obj;
150 X509_EXTENSION *ex; 171 X509_EXTENSION *ex;
151 ex=sk_X509_EXTENSION_value(exts, i); 172 ex = sk_X509_EXTENSION_value(exts, i);
152 if (indent && BIO_printf(bp,"%*s",indent, "") <= 0) return 0; 173 if (indent && BIO_printf(bp, "%*s",indent, "") <= 0)
153 obj=X509_EXTENSION_get_object(ex);
154 i2a_ASN1_OBJECT(bp,obj);
155 j=X509_EXTENSION_get_critical(ex);
156 if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0)
157 return 0; 174 return 0;
158 if(!X509V3_EXT_print(bp, ex, flag, indent + 4)) 175 obj = X509_EXTENSION_get_object(ex);
159 { 176 i2a_ASN1_OBJECT(bp, obj);
177 j = X509_EXTENSION_get_critical(ex);
178 if (BIO_printf(bp, ": %s\n",j?"critical":"") <= 0)
179 return 0;
180 if (!X509V3_EXT_print(bp, ex, flag, indent + 4)) {
160 BIO_printf(bp, "%*s", indent + 4, ""); 181 BIO_printf(bp, "%*s", indent + 4, "");
161 M_ASN1_OCTET_STRING_print(bp,ex->value); 182 M_ASN1_OCTET_STRING_print(bp, ex->value);
162 }
163 if (BIO_write(bp,"\n",1) <= 0) return 0;
164 } 183 }
184 if (BIO_write(bp, "\n",1) <= 0)
185 return 0;
186 }
165 return 1; 187 return 1;
166} 188}
167 189
168static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported) 190static int
191unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag,
192 int indent, int supported)
169{ 193{
170 switch(flag & X509V3_EXT_UNKNOWN_MASK) { 194 switch (flag & X509V3_EXT_UNKNOWN_MASK) {
171 195 case X509V3_EXT_DEFAULT:
172 case X509V3_EXT_DEFAULT:
173 return 0; 196 return 0;
174 197 case X509V3_EXT_ERROR_UNKNOWN:
175 case X509V3_EXT_ERROR_UNKNOWN: 198 if (supported)
176 if(supported)
177 BIO_printf(out, "%*s<Parse Error>", indent, ""); 199 BIO_printf(out, "%*s<Parse Error>", indent, "");
178 else 200 else
179 BIO_printf(out, "%*s<Not Supported>", indent, ""); 201 BIO_printf(out, "%*s<Not Supported>", indent, "");
180 return 1; 202 return 1;
181 203 case X509V3_EXT_PARSE_UNKNOWN:
182 case X509V3_EXT_PARSE_UNKNOWN: 204 return ASN1_parse_dump(out,
183 return ASN1_parse_dump(out, 205 ext->value->data, ext->value->length, indent, -1);
184 ext->value->data, ext->value->length, indent, -1); 206 case X509V3_EXT_DUMP_UNKNOWN:
185 case X509V3_EXT_DUMP_UNKNOWN: 207 return BIO_dump_indent(out, (char *)ext->value->data,
186 return BIO_dump_indent(out, (char *)ext->value->data, ext->value->length, indent); 208 ext->value->length, indent);
187 209 default:
188 default:
189 return 1; 210 return 1;
190 } 211 }
191} 212}
192 213
193 214
194#ifndef OPENSSL_NO_FP_API 215#ifndef OPENSSL_NO_FP_API
195int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent) 216int
217X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
196{ 218{
197 BIO *bio_tmp; 219 BIO *bio_tmp;
198 int ret; 220 int ret;
199 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0; 221
222 if (!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE)))
223 return 0;
200 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent); 224 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
201 BIO_free(bio_tmp); 225 BIO_free(bio_tmp);
202 return ret; 226 return ret;