summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/t_req.c
diff options
context:
space:
mode:
authorjsing <>2014-04-18 13:14:31 +0000
committerjsing <>2014-04-18 13:14:31 +0000
commit48839e33a53ed2d6e54cb31ec1a93635e0a4dc60 (patch)
treef569441b32f0a3293eba8921ed58e2489986006c /src/lib/libcrypto/asn1/t_req.c
parent8a0112534d8764e81ead87d96bc29f9f7087f881 (diff)
downloadopenbsd-48839e33a53ed2d6e54cb31ec1a93635e0a4dc60.tar.gz
openbsd-48839e33a53ed2d6e54cb31ec1a93635e0a4dc60.tar.bz2
openbsd-48839e33a53ed2d6e54cb31ec1a93635e0a4dc60.zip
More KNF.
Diffstat (limited to 'src/lib/libcrypto/asn1/t_req.c')
-rw-r--r--src/lib/libcrypto/asn1/t_req.c220
1 files changed, 121 insertions, 99 deletions
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index 4457f5291e..331440bed5 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -71,23 +71,26 @@
71#endif 71#endif
72 72
73#ifndef OPENSSL_NO_FP_API 73#ifndef OPENSSL_NO_FP_API
74int X509_REQ_print_fp(FILE *fp, X509_REQ *x) 74int
75X509_REQ_print_fp(FILE *fp, X509_REQ *x)
75{ 76{
76 BIO *b; 77 BIO *b;
77 int ret; 78 int ret;
78 79
79 if ((b=BIO_new(BIO_s_file())) == NULL) { 80 if ((b = BIO_new(BIO_s_file())) == NULL) {
80 X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); 81 X509err(X509_F_X509_REQ_PRINT_FP, ERR_R_BUF_LIB);
81 return(0); 82 return (0);
82 } 83 }
83 BIO_set_fp(b,fp,BIO_NOCLOSE); 84 BIO_set_fp(b, fp, BIO_NOCLOSE);
84 ret=X509_REQ_print(b, x); 85 ret = X509_REQ_print(b, x);
85 BIO_free(b); 86 BIO_free(b);
86 return(ret); 87 return (ret);
87} 88}
88#endif 89#endif
89 90
90int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) 91int
92X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
93 unsigned long cflag)
91{ 94{
92 unsigned long l; 95 unsigned long l;
93 int i; 96 int i;
@@ -99,49 +102,55 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long
99 char mlch = ' '; 102 char mlch = ' ';
100 int nmindent = 0; 103 int nmindent = 0;
101 104
102 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { 105 if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
103 mlch = '\n'; 106 mlch = '\n';
104 nmindent = 12; 107 nmindent = 12;
105 } 108 }
106 109
107 if(nmflags == X509_FLAG_COMPAT) 110 if (nmflags == X509_FLAG_COMPAT)
108 nmindent = 16; 111 nmindent = 16;
109 112
113 ri = x->req_info;
114 if (!(cflag & X509_FLAG_NO_HEADER)) {
115 if (BIO_write(bp, "Certificate Request:\n", 21) <= 0)
116 goto err;
117 if (BIO_write(bp, " Data:\n", 10) <= 0)
110 118
111 ri=x->req_info; 119 goto err;
112 if(!(cflag & X509_FLAG_NO_HEADER)) {
113 if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
114 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
115 } 120 }
116 if(!(cflag & X509_FLAG_NO_VERSION)) { 121 if (!(cflag & X509_FLAG_NO_VERSION)) {
117 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; 122 neg = (ri->version->type == V_ASN1_NEG_INTEGER) ? "-" : "";
118 l=0; 123 l = 0;
119 for (i=0; i<ri->version->length; i++) { 124 for (i = 0; i < ri->version->length; i++) {
120 l<<=8; l+=ri->version->data[i]; 125 l <<= 8;
126 l += ri->version->data[i];
121 } 127 }
122 if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, 128 if (BIO_printf(bp, "%8sVersion: %s%lu (%s0x%lx)\n", "", neg,
123 l) <= 0) 129 l, neg, l) <= 0)
124 goto err; 130 goto err;
131 }
132 if (!(cflag & X509_FLAG_NO_SUBJECT)) {
133 if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
134 goto err;
135 if (X509_NAME_print_ex(bp, ri->subject, nmindent, nmflags) < 0)
136 goto err;
137 if (BIO_write(bp, "\n", 1) <= 0)
138 goto err;
125 } 139 }
126 if(!(cflag & X509_FLAG_NO_SUBJECT)) 140 if (!(cflag & X509_FLAG_NO_PUBKEY)) {
127 { 141 if (BIO_write(bp, " Subject Public Key Info:\n",
128 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; 142 33) <= 0)
129 if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
130 if (BIO_write(bp,"\n",1) <= 0) goto err;
131 }
132 if(!(cflag & X509_FLAG_NO_PUBKEY)) {
133 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
134 goto err; 143 goto err;
135 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) 144 if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
136 goto err; 145 goto err;
137 if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0) 146 if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
138 goto err; 147 goto err;
139 if (BIO_puts(bp, "\n") <= 0) 148 if (BIO_puts(bp, "\n") <= 0)
140 goto err; 149 goto err;
141 150
142 pkey=X509_REQ_get_pubkey(x); 151 pkey = X509_REQ_get_pubkey(x);
143 if (pkey == NULL) { 152 if (pkey == NULL) {
144 BIO_printf(bp,"%12sUnable to load Public Key\n",""); 153 BIO_printf(bp, "%12sUnable to load Public Key\n", "");
145 ERR_print_errors(bp); 154 ERR_print_errors(bp);
146 } else { 155 } else {
147 EVP_PKEY_print_public(bp, pkey, 16, NULL); 156 EVP_PKEY_print_public(bp, pkey, 16, NULL);
@@ -149,95 +158,108 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long
149 } 158 }
150 } 159 }
151 160
152 if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) { 161 if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
153 /* may not be */ 162 /* may not be */
154 if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) 163 if (BIO_printf(bp, "%8sAttributes:\n", "") <= 0)
155 goto err; 164 goto err;
156 165
157 sk=x->req_info->attributes; 166 sk = x->req_info->attributes;
158 if (sk_X509_ATTRIBUTE_num(sk) == 0) { 167 if (sk_X509_ATTRIBUTE_num(sk) == 0) {
159 if(BIO_printf(bp,"%12sa0:00\n","") <= 0) 168 if (BIO_printf(bp, "%12sa0:00\n", "") <= 0)
160 goto err; 169 goto err;
161 } else { 170 } else {
162 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) { 171 for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
163 ASN1_TYPE *at; 172 ASN1_TYPE *at;
164 X509_ATTRIBUTE *a; 173 X509_ATTRIBUTE *a;
165 ASN1_BIT_STRING *bs=NULL; 174 ASN1_BIT_STRING *bs = NULL;
166 ASN1_TYPE *t; 175 ASN1_TYPE *t;
167 int j,type=0,count=1,ii=0; 176 int j, type = 0, count = 1, ii = 0;
168 177
169 a=sk_X509_ATTRIBUTE_value(sk,i); 178 a = sk_X509_ATTRIBUTE_value(sk, i);
170 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) 179 if (X509_REQ_extension_nid(
171 continue; 180 OBJ_obj2nid(a->object)))
172 if(BIO_printf(bp,"%12s","") <= 0) 181 continue;
173 goto err; 182 if (BIO_printf(bp, "%12s", "") <= 0)
174 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) { 183 goto err;
175 if (a->single) { 184 if ((j = i2a_ASN1_OBJECT(bp, a->object)) > 0) {
176 t=a->value.single; 185 if (a->single) {
177 type=t->type; 186 t = a->value.single;
178 bs=t->value.bit_string; 187 type = t->type;
179 } else { 188 bs = t->value.bit_string;
180 ii=0; 189 } else {
181 count=sk_ASN1_TYPE_num(a->value.set); 190 ii = 0;
191 count = sk_ASN1_TYPE_num(
192 a->value.set);
182get_next: 193get_next:
183 at=sk_ASN1_TYPE_value(a->value.set,ii); 194 at = sk_ASN1_TYPE_value(
184 type=at->type; 195 a->value.set, ii);
185 bs=at->value.asn1_string; 196 type = at->type;
197 bs = at->value.asn1_string;
198 }
186 } 199 }
187 } 200 for (j = 25 - j; j > 0; j--)
188 for (j=25-j; j>0; j--) 201 if (BIO_write(bp, " ", 1) != 1)
189 if (BIO_write(bp," ",1) != 1) goto err;
190 if (BIO_puts(bp,":") <= 0) goto err;
191 if ( (type == V_ASN1_PRINTABLESTRING) ||
192 (type == V_ASN1_T61STRING) ||
193 (type == V_ASN1_IA5STRING)) {
194 if (BIO_write(bp,(char *)bs->data,bs->length)
195 != bs->length)
196 goto err; 202 goto err;
197 BIO_puts(bp,"\n"); 203 if (BIO_puts(bp, ":") <= 0)
204 goto err;
205 if ((type == V_ASN1_PRINTABLESTRING) ||
206 (type == V_ASN1_T61STRING) ||
207 (type == V_ASN1_IA5STRING)) {
208 if (BIO_write(bp, (char *)bs->data,
209 bs->length) != bs->length)
210 goto err;
211 BIO_puts(bp, "\n");
198 } else { 212 } else {
199 BIO_puts(bp,"unable to print attribute\n"); 213 BIO_puts(bp,
214 "unable to print attribute\n");
200 } 215 }
201 if (++ii < count) goto get_next; 216 if (++ii < count)
217 goto get_next;
202 } 218 }
203 } 219 }
204 } 220 }
205 if(!(cflag & X509_FLAG_NO_EXTENSIONS)) { 221 if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
206 exts = X509_REQ_get_extensions(x); 222 exts = X509_REQ_get_extensions(x);
207 if(exts) { 223 if (exts) {
208 BIO_printf(bp,"%8sRequested Extensions:\n",""); 224 BIO_printf(bp, "%8sRequested Extensions:\n", "");
209 for (i=0; i<sk_X509_EXTENSION_num(exts); i++) { 225 for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
210 ASN1_OBJECT *obj; 226 ASN1_OBJECT *obj;
211 X509_EXTENSION *ex; 227 X509_EXTENSION *ex;
212 int j; 228 int j;
213 ex=sk_X509_EXTENSION_value(exts, i); 229 ex = sk_X509_EXTENSION_value(exts, i);
214 if (BIO_printf(bp,"%12s","") <= 0) goto err; 230 if (BIO_printf(bp, "%12s", "") <= 0)
215 obj=X509_EXTENSION_get_object(ex); 231 goto err;
216 i2a_ASN1_OBJECT(bp,obj); 232 obj = X509_EXTENSION_get_object(ex);
217 j=X509_EXTENSION_get_critical(ex); 233 i2a_ASN1_OBJECT(bp, obj);
218 if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) 234 j = X509_EXTENSION_get_critical(ex);
235 if (BIO_printf(bp, ": %s\n",
236 j ? "critical" : "") <= 0)
219 goto err; 237 goto err;
220 if(!X509V3_EXT_print(bp, ex, cflag, 16)) { 238 if (!X509V3_EXT_print(bp, ex, cflag, 16)) {
221 BIO_printf(bp, "%16s", ""); 239 BIO_printf(bp, "%16s", "");
222 M_ASN1_OCTET_STRING_print(bp,ex->value); 240 M_ASN1_OCTET_STRING_print(bp, ex->value);
223 } 241 }
224 if (BIO_write(bp,"\n",1) <= 0) goto err; 242 if (BIO_write(bp, "\n", 1) <= 0)
243 goto err;
225 } 244 }
226 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); 245 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
227 } 246 }
228 } 247 }
229 248
230 if(!(cflag & X509_FLAG_NO_SIGDUMP)) { 249 if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
231 if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; 250 if (!X509_signature_print(bp, x->sig_alg, x->signature))
251 goto err;
232 } 252 }
233 253
234 return(1); 254 return (1);
255
235err: 256err:
236 X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); 257 X509err(X509_F_X509_REQ_PRINT_EX, ERR_R_BUF_LIB);
237 return(0); 258 return (0);
238} 259}
239 260
240int X509_REQ_print(BIO *bp, X509_REQ *x) 261int
262X509_REQ_print(BIO *bp, X509_REQ *x)
241{ 263{
242 return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); 264 return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
243} 265}