diff options
author | tedu <> | 2014-04-18 00:58:49 +0000 |
---|---|---|
committer | tedu <> | 2014-04-18 00:58:49 +0000 |
commit | a1df5b66c7ad477a535e56a504d8da47e1998cfa (patch) | |
tree | b216ca6fba673789f2c494699c4cf41d23337bfa /src/lib/libcrypto/asn1/t_req.c | |
parent | 07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (diff) | |
download | openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.gz openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.bz2 openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.zip |
lob a few more knf grenades in here to soften things up.
Diffstat (limited to 'src/lib/libcrypto/asn1/t_req.c')
-rw-r--r-- | src/lib/libcrypto/asn1/t_req.c | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c index a863543898..4457f5291e 100644 --- a/src/lib/libcrypto/asn1/t_req.c +++ b/src/lib/libcrypto/asn1/t_req.c | |||
@@ -76,8 +76,7 @@ int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | |||
76 | BIO *b; | 76 | BIO *b; |
77 | int ret; | 77 | int ret; |
78 | 78 | ||
79 | if ((b=BIO_new(BIO_s_file())) == NULL) | 79 | if ((b=BIO_new(BIO_s_file())) == NULL) { |
80 | { | ||
81 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); | 80 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); |
82 | return(0); | 81 | return(0); |
83 | } | 82 | } |
@@ -110,17 +109,16 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
110 | 109 | ||
111 | 110 | ||
112 | ri=x->req_info; | 111 | ri=x->req_info; |
113 | if(!(cflag & X509_FLAG_NO_HEADER)) | 112 | if(!(cflag & X509_FLAG_NO_HEADER)) { |
114 | { | ||
115 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; | 113 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; |
116 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 114 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
117 | } | 115 | } |
118 | if(!(cflag & X509_FLAG_NO_VERSION)) | 116 | if(!(cflag & X509_FLAG_NO_VERSION)) { |
119 | { | ||
120 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | 117 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; |
121 | l=0; | 118 | l=0; |
122 | for (i=0; i<ri->version->length; i++) | 119 | for (i=0; i<ri->version->length; i++) { |
123 | { l<<=8; l+=ri->version->data[i]; } | 120 | l<<=8; l+=ri->version->data[i]; |
121 | } | ||
124 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, | 122 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, |
125 | l) <= 0) | 123 | l) <= 0) |
126 | goto err; | 124 | goto err; |
@@ -131,8 +129,7 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
131 | if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; | 129 | if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; |
132 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 130 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
133 | } | 131 | } |
134 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | 132 | if(!(cflag & X509_FLAG_NO_PUBKEY)) { |
135 | { | ||
136 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 133 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) |
137 | goto err; | 134 | goto err; |
138 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 135 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) |
@@ -143,34 +140,26 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
143 | goto err; | 140 | goto err; |
144 | 141 | ||
145 | pkey=X509_REQ_get_pubkey(x); | 142 | pkey=X509_REQ_get_pubkey(x); |
146 | if (pkey == NULL) | 143 | if (pkey == NULL) { |
147 | { | ||
148 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 144 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); |
149 | ERR_print_errors(bp); | 145 | ERR_print_errors(bp); |
150 | } | 146 | } else { |
151 | else | ||
152 | { | ||
153 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 147 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
154 | EVP_PKEY_free(pkey); | 148 | EVP_PKEY_free(pkey); |
155 | } | 149 | } |
156 | } | 150 | } |
157 | 151 | ||
158 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | 152 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) { |
159 | { | ||
160 | /* may not be */ | 153 | /* may not be */ |
161 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) | 154 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) |
162 | goto err; | 155 | goto err; |
163 | 156 | ||
164 | sk=x->req_info->attributes; | 157 | sk=x->req_info->attributes; |
165 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | 158 | if (sk_X509_ATTRIBUTE_num(sk) == 0) { |
166 | { | ||
167 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) | 159 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) |
168 | goto err; | 160 | goto err; |
169 | } | 161 | } else { |
170 | else | 162 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) { |
171 | { | ||
172 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
173 | { | ||
174 | ASN1_TYPE *at; | 163 | ASN1_TYPE *at; |
175 | X509_ATTRIBUTE *a; | 164 | X509_ATTRIBUTE *a; |
176 | ASN1_BIT_STRING *bs=NULL; | 165 | ASN1_BIT_STRING *bs=NULL; |
@@ -182,16 +171,12 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
182 | continue; | 171 | continue; |
183 | if(BIO_printf(bp,"%12s","") <= 0) | 172 | if(BIO_printf(bp,"%12s","") <= 0) |
184 | goto err; | 173 | goto err; |
185 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | 174 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) { |
186 | { | 175 | if (a->single) { |
187 | if (a->single) | ||
188 | { | ||
189 | t=a->value.single; | 176 | t=a->value.single; |
190 | type=t->type; | 177 | type=t->type; |
191 | bs=t->value.bit_string; | 178 | bs=t->value.bit_string; |
192 | } | 179 | } else { |
193 | else | ||
194 | { | ||
195 | ii=0; | 180 | ii=0; |
196 | count=sk_ASN1_TYPE_num(a->value.set); | 181 | count=sk_ASN1_TYPE_num(a->value.set); |
197 | get_next: | 182 | get_next: |
@@ -205,29 +190,23 @@ get_next: | |||
205 | if (BIO_puts(bp,":") <= 0) goto err; | 190 | if (BIO_puts(bp,":") <= 0) goto err; |
206 | if ( (type == V_ASN1_PRINTABLESTRING) || | 191 | if ( (type == V_ASN1_PRINTABLESTRING) || |
207 | (type == V_ASN1_T61STRING) || | 192 | (type == V_ASN1_T61STRING) || |
208 | (type == V_ASN1_IA5STRING)) | 193 | (type == V_ASN1_IA5STRING)) { |
209 | { | ||
210 | if (BIO_write(bp,(char *)bs->data,bs->length) | 194 | if (BIO_write(bp,(char *)bs->data,bs->length) |
211 | != bs->length) | 195 | != bs->length) |
212 | goto err; | 196 | goto err; |
213 | BIO_puts(bp,"\n"); | 197 | BIO_puts(bp,"\n"); |
214 | } | 198 | } else { |
215 | else | ||
216 | { | ||
217 | BIO_puts(bp,"unable to print attribute\n"); | 199 | BIO_puts(bp,"unable to print attribute\n"); |
218 | } | 200 | } |
219 | if (++ii < count) goto get_next; | 201 | if (++ii < count) goto get_next; |
220 | } | 202 | } |
221 | } | 203 | } |
222 | } | 204 | } |
223 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) | 205 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) { |
224 | { | ||
225 | exts = X509_REQ_get_extensions(x); | 206 | exts = X509_REQ_get_extensions(x); |
226 | if(exts) | 207 | if(exts) { |
227 | { | ||
228 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | 208 | BIO_printf(bp,"%8sRequested Extensions:\n",""); |
229 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | 209 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) { |
230 | { | ||
231 | ASN1_OBJECT *obj; | 210 | ASN1_OBJECT *obj; |
232 | X509_EXTENSION *ex; | 211 | X509_EXTENSION *ex; |
233 | int j; | 212 | int j; |
@@ -238,8 +217,7 @@ get_next: | |||
238 | j=X509_EXTENSION_get_critical(ex); | 217 | j=X509_EXTENSION_get_critical(ex); |
239 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) | 218 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) |
240 | goto err; | 219 | goto err; |
241 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) | 220 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) { |
242 | { | ||
243 | BIO_printf(bp, "%16s", ""); | 221 | BIO_printf(bp, "%16s", ""); |
244 | M_ASN1_OCTET_STRING_print(bp,ex->value); | 222 | M_ASN1_OCTET_STRING_print(bp,ex->value); |
245 | } | 223 | } |
@@ -249,8 +227,7 @@ get_next: | |||
249 | } | 227 | } |
250 | } | 228 | } |
251 | 229 | ||
252 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | 230 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) { |
253 | { | ||
254 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | 231 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; |
255 | } | 232 | } |
256 | 233 | ||