summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/t_x509.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/t_x509.c')
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c150
1 files changed, 88 insertions, 62 deletions
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index b10fbbb992..42f4d498cf 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -58,21 +58,20 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "bn.h" 62#include <openssl/bn.h>
63#ifndef NO_RSA 63#ifndef NO_RSA
64#include "rsa.h" 64#include <openssl/rsa.h>
65#endif 65#endif
66#ifndef NO_DSA 66#ifndef NO_DSA
67#include "dsa.h" 67#include <openssl/dsa.h>
68#endif 68#endif
69#include "objects.h" 69#include <openssl/objects.h>
70#include "x509.h" 70#include <openssl/x509.h>
71#include <openssl/x509v3.h>
71 72
72#ifndef NO_FP_API 73#ifndef NO_FP_API
73int X509_print_fp(fp,x) 74int X509_print_fp(FILE *fp, X509 *x)
74FILE *fp;
75X509 *x;
76 { 75 {
77 BIO *b; 76 BIO *b;
78 int ret; 77 int ret;
@@ -89,9 +88,7 @@ X509 *x;
89 } 88 }
90#endif 89#endif
91 90
92int X509_print(bp,x) 91int X509_print(BIO *bp, X509 *x)
93BIO *bp;
94X509 *x;
95 { 92 {
96 long l; 93 long l;
97 int ret=0,i,j,n; 94 int ret=0,i,j,n;
@@ -99,7 +96,7 @@ X509 *x;
99 X509_CINF *ci; 96 X509_CINF *ci;
100 ASN1_INTEGER *bs; 97 ASN1_INTEGER *bs;
101 EVP_PKEY *pkey=NULL; 98 EVP_PKEY *pkey=NULL;
102 char *neg; 99 const char *neg;
103 X509_EXTENSION *ex; 100 X509_EXTENSION *ex;
104 ASN1_STRING *str=NULL; 101 ASN1_STRING *str=NULL;
105 102
@@ -146,9 +143,9 @@ X509 *x;
146 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err; 143 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err;
147 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err; 144 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err;
148 if (BIO_write(bp," Not Before: ",24) <= 0) goto err; 145 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
149 if (!ASN1_UTCTIME_print(bp,X509_get_notBefore(x))) goto err; 146 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
150 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; 147 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
151 if (!ASN1_UTCTIME_print(bp,X509_get_notAfter(x))) goto err; 148 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
152 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err; 149 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err;
153 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err; 150 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err;
154 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0) 151 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0)
@@ -158,6 +155,12 @@ X509 *x;
158 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err; 155 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
159 156
160 pkey=X509_get_pubkey(x); 157 pkey=X509_get_pubkey(x);
158 if (pkey == NULL)
159 {
160 BIO_printf(bp,"%12sUnable to load Public Key\n","");
161 ERR_print_errors(bp);
162 }
163 else
161#ifndef NO_RSA 164#ifndef NO_RSA
162 if (pkey->type == EVP_PKEY_RSA) 165 if (pkey->type == EVP_PKEY_RSA)
163 { 166 {
@@ -175,7 +178,9 @@ X509 *x;
175 } 178 }
176 else 179 else
177#endif 180#endif
178 BIO_printf(bp,"%12sDSA Public Key:\n",""); 181 BIO_printf(bp,"%12sUnknown Public Key:\n","");
182
183 EVP_PKEY_free(pkey);
179 184
180 n=X509_get_ext_count(x); 185 n=X509_get_ext_count(x);
181 if (n > 0) 186 if (n > 0)
@@ -183,7 +188,9 @@ X509 *x;
183 BIO_printf(bp,"%8sX509v3 extensions:\n",""); 188 BIO_printf(bp,"%8sX509v3 extensions:\n","");
184 for (i=0; i<n; i++) 189 for (i=0; i<n; i++)
185 { 190 {
191#if 0
186 int data_type,pack_type; 192 int data_type,pack_type;
193#endif
187 ASN1_OBJECT *obj; 194 ASN1_OBJECT *obj;
188 195
189 ex=X509_get_ext(x,i); 196 ex=X509_get_ext(x,i);
@@ -191,41 +198,11 @@ X509 *x;
191 obj=X509_EXTENSION_get_object(ex); 198 obj=X509_EXTENSION_get_object(ex);
192 i2a_ASN1_OBJECT(bp,obj); 199 i2a_ASN1_OBJECT(bp,obj);
193 j=X509_EXTENSION_get_critical(ex); 200 j=X509_EXTENSION_get_critical(ex);
194 if (BIO_printf(bp,": %s\n%16s",j?"critical":"","") <= 0) 201 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
195 goto err; 202 goto err;
196 203 if(!X509V3_EXT_print(bp, ex, 0, 16))
197 pack_type=X509v3_pack_type_by_OBJ(obj);
198 data_type=X509v3_data_type_by_OBJ(obj);
199
200 if (pack_type == X509_EXT_PACK_STRING)
201 {
202 if (X509v3_unpack_string(
203 &str,data_type,
204 X509_EXTENSION_get_data(ex)) == NULL)
205 {
206 /* hmm... */
207 goto err;
208 }
209 if ( (data_type == V_ASN1_IA5STRING) ||
210 (data_type == V_ASN1_PRINTABLESTRING) ||
211 (data_type == V_ASN1_T61STRING))
212 {
213 if (BIO_write(bp,(char *)str->data,
214 str->length) <= 0)
215 goto err;
216 }
217 else if (data_type == V_ASN1_BIT_STRING)
218 {
219 BIO_printf(bp,"0x");
220 for (j=0; j<str->length; j++)
221 {
222 BIO_printf(bp,"%02X",
223 str->data[j]);
224 }
225 }
226 }
227 else
228 { 204 {
205 BIO_printf(bp, "%16s", "");
229 ASN1_OCTET_STRING_print(bp,ex->value); 206 ASN1_OCTET_STRING_print(bp,ex->value);
230 } 207 }
231 if (BIO_write(bp,"\n",1) <= 0) goto err; 208 if (BIO_write(bp,"\n",1) <= 0) goto err;
@@ -253,9 +230,7 @@ err:
253 return(ret); 230 return(ret);
254 } 231 }
255 232
256int ASN1_STRING_print(bp,v) 233int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
257BIO *bp;
258ASN1_STRING *v;
259 { 234 {
260 int i,n; 235 int i,n;
261 char buf[80],*p;; 236 char buf[80],*p;;
@@ -284,15 +259,59 @@ ASN1_STRING *v;
284 return(1); 259 return(1);
285 } 260 }
286 261
287int ASN1_UTCTIME_print(bp,tm) 262int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
288BIO *bp; 263{
289ASN1_UTCTIME *tm; 264 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
265 if(tm->type == V_ASN1_GENERALIZEDTIME)
266 return ASN1_GENERALIZEDTIME_print(bp, tm);
267 BIO_write(bp,"Bad time value",14);
268 return(0);
269}
270
271static const char *mon[12]=
272 {
273 "Jan","Feb","Mar","Apr","May","Jun",
274 "Jul","Aug","Sep","Oct","Nov","Dec"
275 };
276
277int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
278 {
279 char *v;
280 int gmt=0;
281 int i;
282 int y=0,M=0,d=0,h=0,m=0,s=0;
283
284 i=tm->length;
285 v=(char *)tm->data;
286
287 if (i < 12) goto err;
288 if (v[i-1] == 'Z') gmt=1;
289 for (i=0; i<12; i++)
290 if ((v[i] > '9') || (v[i] < '0')) goto err;
291 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
292 M= (v[4]-'0')*10+(v[5]-'0');
293 if ((M > 12) || (M < 1)) goto err;
294 d= (v[6]-'0')*10+(v[7]-'0');
295 h= (v[8]-'0')*10+(v[9]-'0');
296 m= (v[10]-'0')*10+(v[11]-'0');
297 if ( (v[12] >= '0') && (v[12] <= '9') &&
298 (v[13] >= '0') && (v[13] <= '9'))
299 s= (v[12]-'0')*10+(v[13]-'0');
300
301 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
302 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
303 return(0);
304 else
305 return(1);
306err:
307 BIO_write(bp,"Bad time value",14);
308 return(0);
309 }
310
311int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
290 { 312 {
291 char *v; 313 char *v;
292 int gmt=0; 314 int gmt=0;
293 static char *mon[12]={
294 "Jan","Feb","Mar","Apr","May","Jun",
295 "Jul","Aug","Sep","Oct","Nov","Dec"};
296 int i; 315 int i;
297 int y=0,M=0,d=0,h=0,m=0,s=0; 316 int y=0,M=0,d=0,h=0,m=0,s=0;
298 317
@@ -324,10 +343,7 @@ err:
324 return(0); 343 return(0);
325 } 344 }
326 345
327int X509_NAME_print(bp,name,obase) 346int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
328BIO *bp;
329X509_NAME *name;
330int obase;
331 { 347 {
332 char *s,*c; 348 char *s,*c;
333 int ret=0,l,ll,i,first=1; 349 int ret=0,l,ll,i,first=1;
@@ -342,6 +358,7 @@ int obase;
342 c=s; 358 c=s;
343 for (;;) 359 for (;;)
344 { 360 {
361#ifndef CHARSET_EBCDIC
345 if ( ((*s == '/') && 362 if ( ((*s == '/') &&
346 ((s[1] >= 'A') && (s[1] <= 'Z') && ( 363 ((s[1] >= 'A') && (s[1] <= 'Z') && (
347 (s[2] == '=') || 364 (s[2] == '=') ||
@@ -349,6 +366,15 @@ int obase;
349 (s[3] == '=')) 366 (s[3] == '='))
350 ))) || 367 ))) ||
351 (*s == '\0')) 368 (*s == '\0'))
369#else
370 if ( ((*s == '/') &&
371 (isupper(s[1]) && (
372 (s[2] == '=') ||
373 (isupper(s[2]) &&
374 (s[3] == '='))
375 ))) ||
376 (*s == '\0'))
377#endif
352 { 378 {
353 if ((l <= 0) && !first) 379 if ((l <= 0) && !first)
354 { 380 {