summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c6
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c4
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c9
-rw-r--r--src/lib/libcrypto/asn1/t_req.c260
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c6
5 files changed, 167 insertions, 118 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index ed0bdfbde1..e0265f69d2 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -120,6 +120,12 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
120 unsigned char *p,*s; 120 unsigned char *p,*s;
121 int i; 121 int i;
122 122
123 if (len < 1)
124 {
125 i=ASN1_R_STRING_TOO_SHORT;
126 goto err;
127 }
128
123 if ((a == NULL) || ((*a) == NULL)) 129 if ((a == NULL) || ((*a) == NULL))
124 { 130 {
125 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); 131 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
index 8dab29dca1..7ddb7662f1 100644
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -544,7 +544,7 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
544{ 544{
545 ASN1_STRING stmp, *str = &stmp; 545 ASN1_STRING stmp, *str = &stmp;
546 int mbflag, type, ret; 546 int mbflag, type, ret;
547 if(!*out || !in) return -1; 547 if(!in) return -1;
548 type = in->type; 548 type = in->type;
549 if((type < 0) || (type > 30)) return -1; 549 if((type < 0) || (type > 30)) return -1;
550 mbflag = tag2nbyte[type]; 550 mbflag = tag2nbyte[type];
@@ -553,6 +553,6 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
553 stmp.data = NULL; 553 stmp.data = NULL;
554 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); 554 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
555 if(ret < 0) return ret; 555 if(ret < 0) return ret;
556 if(out) *out = stmp.data; 556 *out = stmp.data;
557 return stmp.length; 557 return stmp.length;
558} 558}
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index 422685a3b4..0638870ab7 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <limits.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include <openssl/asn1.h> 62#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h> 63#include <openssl/asn1_mac.h>
@@ -124,7 +125,7 @@ int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
124 (int)(omax+ *pp)); 125 (int)(omax+ *pp));
125 126
126#endif 127#endif
127 if (*plength > (omax - (*pp - p))) 128 if (*plength > (omax - (p - *pp)))
128 { 129 {
129 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); 130 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
130 /* Set this so that even if things are not long enough 131 /* Set this so that even if things are not long enough
@@ -141,7 +142,7 @@ err:
141static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) 142static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
142 { 143 {
143 unsigned char *p= *pp; 144 unsigned char *p= *pp;
144 long ret=0; 145 unsigned long ret=0;
145 int i; 146 int i;
146 147
147 if (max-- < 1) return(0); 148 if (max-- < 1) return(0);
@@ -170,10 +171,10 @@ static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
170 else 171 else
171 ret=i; 172 ret=i;
172 } 173 }
173 if (ret < 0) 174 if (ret > LONG_MAX)
174 return 0; 175 return 0;
175 *pp=p; 176 *pp=p;
176 *rl=ret; 177 *rl=(long)ret;
177 return(1); 178 return(1);
178 } 179 }
179 180
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index 848c29a2dd..739f272ecf 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -82,7 +82,7 @@ int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
82 } 82 }
83#endif 83#endif
84 84
85int X509_REQ_print(BIO *bp, X509_REQ *x) 85int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag)
86 { 86 {
87 unsigned long l; 87 unsigned long l;
88 int i; 88 int i;
@@ -92,143 +92,185 @@ int X509_REQ_print(BIO *bp, X509_REQ *x)
92 STACK_OF(X509_ATTRIBUTE) *sk; 92 STACK_OF(X509_ATTRIBUTE) *sk;
93 STACK_OF(X509_EXTENSION) *exts; 93 STACK_OF(X509_EXTENSION) *exts;
94 char str[128]; 94 char str[128];
95 char mlch = ' ';
96 int nmindent = 0;
97
98 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
99 mlch = '\n';
100 nmindent = 12;
101 }
102
103 if(nmflags == X509_FLAG_COMPAT)
104 nmindent = 16;
105
95 106
96 ri=x->req_info; 107 ri=x->req_info;
97 sprintf(str,"Certificate Request:\n"); 108 if(!(cflag & X509_FLAG_NO_HEADER))
98 if (BIO_puts(bp,str) <= 0) goto err;
99 sprintf(str,"%4sData:\n","");
100 if (BIO_puts(bp,str) <= 0) goto err;
101
102 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
103 l=0;
104 for (i=0; i<ri->version->length; i++)
105 { l<<=8; l+=ri->version->data[i]; }
106 sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l);
107 if (BIO_puts(bp,str) <= 0) goto err;
108 sprintf(str,"%8sSubject: ","");
109 if (BIO_puts(bp,str) <= 0) goto err;
110
111 X509_NAME_print(bp,ri->subject,16);
112 sprintf(str,"\n%8sSubject Public Key Info:\n","");
113 if (BIO_puts(bp,str) <= 0) goto err;
114 i=OBJ_obj2nid(ri->pubkey->algor->algorithm);
115 sprintf(str,"%12sPublic Key Algorithm: %s\n","",
116 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
117 if (BIO_puts(bp,str) <= 0) goto err;
118
119 pkey=X509_REQ_get_pubkey(x);
120#ifndef OPENSSL_NO_RSA
121 if (pkey != NULL && pkey->type == EVP_PKEY_RSA)
122 { 109 {
123 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", 110 if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
124 BN_num_bits(pkey->pkey.rsa->n)); 111 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
125 RSA_print(bp,pkey->pkey.rsa,16);
126 } 112 }
127 else 113 if(!(cflag & X509_FLAG_NO_VERSION))
128#endif
129#ifndef OPENSSL_NO_DSA
130 if (pkey != NULL && pkey->type == EVP_PKEY_DSA)
131 { 114 {
132 BIO_printf(bp,"%12sDSA Public Key:\n",""); 115 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
133 DSA_print(bp,pkey->pkey.dsa,16); 116 l=0;
117 for (i=0; i<ri->version->length; i++)
118 { l<<=8; l+=ri->version->data[i]; }
119 sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l);
120 if (BIO_puts(bp,str) <= 0) goto err;
134 } 121 }
135 else 122 if(!(cflag & X509_FLAG_NO_SUBJECT))
136#endif 123 {
137 BIO_printf(bp,"%12sUnknown Public Key:\n",""); 124 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
125 if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
126 if (BIO_write(bp,"\n",1) <= 0) goto err;
127 }
128 if(!(cflag & X509_FLAG_NO_PUBKEY))
129 {
130 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
131 goto err;
132 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
133 goto err;
134 if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
135 goto err;
136 if (BIO_puts(bp, "\n") <= 0)
137 goto err;
138 138
139 if (pkey != NULL) 139 pkey=X509_REQ_get_pubkey(x);
140 EVP_PKEY_free(pkey); 140 if (pkey == NULL)
141 {
142 BIO_printf(bp,"%12sUnable to load Public Key\n","");
143 ERR_print_errors(bp);
144 }
145 else
146#ifndef OPENSSL_NO_RSA
147 if (pkey->type == EVP_PKEY_RSA)
148 {
149 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
150 BN_num_bits(pkey->pkey.rsa->n));
151 RSA_print(bp,pkey->pkey.rsa,16);
152 }
153 else
154#endif
155#ifndef OPENSSL_NO_DSA
156 if (pkey->type == EVP_PKEY_DSA)
157 {
158 BIO_printf(bp,"%12sDSA Public Key:\n","");
159 DSA_print(bp,pkey->pkey.dsa,16);
160 }
161 else
162#endif
163 BIO_printf(bp,"%12sUnknown Public Key:\n","");
141 164
142 /* may not be */ 165 EVP_PKEY_free(pkey);
143 sprintf(str,"%8sAttributes:\n",""); 166 }
144 if (BIO_puts(bp,str) <= 0) goto err;
145 167
146 sk=x->req_info->attributes; 168 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
147 if (sk_X509_ATTRIBUTE_num(sk) == 0)
148 { 169 {
149 sprintf(str,"%12sa0:00\n",""); 170 /* may not be */
171 sprintf(str,"%8sAttributes:\n","");
150 if (BIO_puts(bp,str) <= 0) goto err; 172 if (BIO_puts(bp,str) <= 0) goto err;
151 } 173
152 else 174 sk=x->req_info->attributes;
153 { 175 if (sk_X509_ATTRIBUTE_num(sk) == 0)
154 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
155 { 176 {
156 ASN1_TYPE *at; 177 sprintf(str,"%12sa0:00\n","");
157 X509_ATTRIBUTE *a;
158 ASN1_BIT_STRING *bs=NULL;
159 ASN1_TYPE *t;
160 int j,type=0,count=1,ii=0;
161
162 a=sk_X509_ATTRIBUTE_value(sk,i);
163 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
164 continue;
165 sprintf(str,"%12s","");
166 if (BIO_puts(bp,str) <= 0) goto err; 178 if (BIO_puts(bp,str) <= 0) goto err;
167 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) 179 }
180 else
168 { 181 {
169 if (a->single) 182 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
170 { 183 {
171 t=a->value.single; 184 ASN1_TYPE *at;
172 type=t->type; 185 X509_ATTRIBUTE *a;
173 bs=t->value.bit_string; 186 ASN1_BIT_STRING *bs=NULL;
174 } 187 ASN1_TYPE *t;
175 else 188 int j,type=0,count=1,ii=0;
189
190 a=sk_X509_ATTRIBUTE_value(sk,i);
191 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
192 continue;
193 sprintf(str,"%12s","");
194 if (BIO_puts(bp,str) <= 0) goto err;
195 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
176 { 196 {
177 ii=0; 197 if (a->single)
178 count=sk_ASN1_TYPE_num(a->value.set); 198 {
199 t=a->value.single;
200 type=t->type;
201 bs=t->value.bit_string;
202 }
203 else
204 {
205 ii=0;
206 count=sk_ASN1_TYPE_num(a->value.set);
179get_next: 207get_next:
180 at=sk_ASN1_TYPE_value(a->value.set,ii); 208 at=sk_ASN1_TYPE_value(a->value.set,ii);
181 type=at->type; 209 type=at->type;
182 bs=at->value.asn1_string; 210 bs=at->value.asn1_string;
211 }
212 }
213 for (j=25-j; j>0; j--)
214 if (BIO_write(bp," ",1) != 1) goto err;
215 if (BIO_puts(bp,":") <= 0) goto err;
216 if ( (type == V_ASN1_PRINTABLESTRING) ||
217 (type == V_ASN1_T61STRING) ||
218 (type == V_ASN1_IA5STRING))
219 {
220 if (BIO_write(bp,(char *)bs->data,bs->length)
221 != bs->length)
222 goto err;
223 BIO_puts(bp,"\n");
224 }
225 else
226 {
227 BIO_puts(bp,"unable to print attribute\n");
228 }
229 if (++ii < count) goto get_next;
183 } 230 }
184 } 231 }
185 for (j=25-j; j>0; j--) 232 }
186 if (BIO_write(bp," ",1) != 1) goto err; 233 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
187 if (BIO_puts(bp,":") <= 0) goto err; 234 {
188 if ( (type == V_ASN1_PRINTABLESTRING) || 235 exts = X509_REQ_get_extensions(x);
189 (type == V_ASN1_T61STRING) || 236 if(exts)
190 (type == V_ASN1_IA5STRING)) 237 {
238 BIO_printf(bp,"%8sRequested Extensions:\n","");
239 for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
191 { 240 {
192 if (BIO_write(bp,(char *)bs->data,bs->length) 241 ASN1_OBJECT *obj;
193 != bs->length) 242 X509_EXTENSION *ex;
243 int j;
244 ex=sk_X509_EXTENSION_value(exts, i);
245 if (BIO_printf(bp,"%12s","") <= 0) goto err;
246 obj=X509_EXTENSION_get_object(ex);
247 i2a_ASN1_OBJECT(bp,obj);
248 j=X509_EXTENSION_get_critical(ex);
249 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
194 goto err; 250 goto err;
195 BIO_puts(bp,"\n"); 251 if(!X509V3_EXT_print(bp, ex, 0, 16))
196 } 252 {
197 else 253 BIO_printf(bp, "%16s", "");
198 { 254 M_ASN1_OCTET_STRING_print(bp,ex->value);
199 BIO_puts(bp,"unable to print attribute\n"); 255 }
256 if (BIO_write(bp,"\n",1) <= 0) goto err;
200 } 257 }
201 if (++ii < count) goto get_next; 258 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
202 } 259 }
203 } 260 }
204 261
205 exts = X509_REQ_get_extensions(x); 262 if(!(cflag & X509_FLAG_NO_SIGDUMP))
206 if(exts) { 263 {
207 BIO_printf(bp,"%8sRequested Extensions:\n",""); 264 if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
208 for (i=0; i<sk_X509_EXTENSION_num(exts); i++) {
209 ASN1_OBJECT *obj;
210 X509_EXTENSION *ex;
211 int j;
212 ex=sk_X509_EXTENSION_value(exts, i);
213 if (BIO_printf(bp,"%12s","") <= 0) goto err;
214 obj=X509_EXTENSION_get_object(ex);
215 i2a_ASN1_OBJECT(bp,obj);
216 j=X509_EXTENSION_get_critical(ex);
217 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
218 goto err;
219 if(!X509V3_EXT_print(bp, ex, 0, 16)) {
220 BIO_printf(bp, "%16s", "");
221 M_ASN1_OCTET_STRING_print(bp,ex->value);
222 }
223 if (BIO_write(bp,"\n",1) <= 0) goto err;
224 } 265 }
225 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
226 }
227
228 if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
229 266
230 return(1); 267 return(1);
231err: 268err:
232 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); 269 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
233 return(0); 270 return(0);
234 } 271 }
272
273int X509_REQ_print(BIO *bp, X509_REQ *x)
274 {
275 return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
276 }
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index 0fc1f421e2..f87c08793a 100644
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -913,10 +913,10 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *i
913 ctx->ptag = ptag; 913 ctx->ptag = ptag;
914 ctx->hdrlen = p - q; 914 ctx->hdrlen = p - q;
915 ctx->valid = 1; 915 ctx->valid = 1;
916 /* If definite length, length + header can't exceed total 916 /* If definite length, and no error, length +
917 * amount of data available. 917 * header can't exceed total amount of data available.
918 */ 918 */
919 if(!(i & 1) && ((plen + ctx->hdrlen) > len)) { 919 if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
920 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); 920 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);
921 asn1_tlc_clear(ctx); 921 asn1_tlc_clear(ctx);
922 return 0; 922 return 0;