summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/objects/obj_dat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/objects/obj_dat.c')
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c269
1 files changed, 172 insertions, 97 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 34866ebbd2..d47b874399 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -59,23 +59,29 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <ctype.h> 60#include <ctype.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "lhash.h" 62#include <openssl/lhash.h>
63#include "asn1.h" 63#include <openssl/asn1.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66/* obj_dat.h is generated from objects.h by obj_dat.pl */ 66/* obj_dat.h is generated from objects.h by obj_dat.pl */
67#ifndef NO_OBJECT
67#include "obj_dat.h" 68#include "obj_dat.h"
69#else
70/* You will have to load all the objects needed manually in the application */
71#define NUM_NID 0
72#define NUM_SN 0
73#define NUM_LN 0
74#define NUM_OBJ 0
75static unsigned char lvalues[1];
76static ASN1_OBJECT nid_objs[1];
77static ASN1_OBJECT *sn_objs[1];
78static ASN1_OBJECT *ln_objs[1];
79static ASN1_OBJECT *obj_objs[1];
80#endif
68 81
69#ifndef NOPROTO
70static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); 82static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
71static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); 83static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
72static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); 84static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
73#else
74static int sn_cmp();
75static int ln_cmp();
76static int obj_cmp();
77#endif
78
79#define ADDED_DATA 0 85#define ADDED_DATA 0
80#define ADDED_SNAME 1 86#define ADDED_SNAME 1
81#define ADDED_LNAME 2 87#define ADDED_LNAME 2
@@ -90,18 +96,13 @@ typedef struct added_obj_st
90static int new_nid=NUM_NID; 96static int new_nid=NUM_NID;
91static LHASH *added=NULL; 97static LHASH *added=NULL;
92 98
93static int sn_cmp(ap,bp) 99static int sn_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
94ASN1_OBJECT **ap;
95ASN1_OBJECT **bp;
96 { return(strcmp((*ap)->sn,(*bp)->sn)); } 100 { return(strcmp((*ap)->sn,(*bp)->sn)); }
97 101
98static int ln_cmp(ap,bp) 102static int ln_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
99ASN1_OBJECT **ap;
100ASN1_OBJECT **bp;
101 { return(strcmp((*ap)->ln,(*bp)->ln)); } 103 { return(strcmp((*ap)->ln,(*bp)->ln)); }
102 104
103static unsigned long add_hash(ca) 105static unsigned long add_hash(ADDED_OBJ *ca)
104ADDED_OBJ *ca;
105 { 106 {
106 ASN1_OBJECT *a; 107 ASN1_OBJECT *a;
107 int i; 108 int i;
@@ -134,8 +135,7 @@ ADDED_OBJ *ca;
134 return(ret); 135 return(ret);
135 } 136 }
136 137
137static int add_cmp(ca,cb) 138static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb)
138ADDED_OBJ *ca,*cb;
139 { 139 {
140 ASN1_OBJECT *a,*b; 140 ASN1_OBJECT *a,*b;
141 int i; 141 int i;
@@ -163,36 +163,35 @@ ADDED_OBJ *ca,*cb;
163 default: 163 default:
164 abort(); 164 abort();
165 } 165 }
166 return(1); /* should not get here */
166 } 167 }
167 168
168static int init_added() 169static int init_added(void)
169 { 170 {
170 if (added != NULL) return(1); 171 if (added != NULL) return(1);
171 added=lh_new(add_hash,add_cmp); 172 added=lh_new(add_hash,add_cmp);
172 return(added != NULL); 173 return(added != NULL);
173 } 174 }
174 175
175static void cleanup1(a) 176static void cleanup1(ADDED_OBJ *a)
176ADDED_OBJ *a;
177 { 177 {
178 a->obj->nid=0; 178 a->obj->nid=0;
179 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| 179 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
180 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS; 180 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
181 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
181 } 182 }
182 183
183static void cleanup2(a) 184static void cleanup2(ADDED_OBJ *a)
184ADDED_OBJ *a;
185 { a->obj->nid++; } 185 { a->obj->nid++; }
186 186
187static void cleanup3(a) 187static void cleanup3(ADDED_OBJ *a)
188ADDED_OBJ *a;
189 { 188 {
190 if (--a->obj->nid == 0) 189 if (--a->obj->nid == 0)
191 ASN1_OBJECT_free(a->obj); 190 ASN1_OBJECT_free(a->obj);
192 Free(a); 191 Free(a);
193 } 192 }
194 193
195void OBJ_cleanup() 194void OBJ_cleanup(void)
196 { 195 {
197 if (added == NULL) return; 196 if (added == NULL) return;
198 added->down_load=0; 197 added->down_load=0;
@@ -203,8 +202,7 @@ void OBJ_cleanup()
203 added=NULL; 202 added=NULL;
204 } 203 }
205 204
206int OBJ_new_nid(num) 205int OBJ_new_nid(int num)
207int num;
208 { 206 {
209 int i; 207 int i;
210 208
@@ -213,8 +211,7 @@ int num;
213 return(i); 211 return(i);
214 } 212 }
215 213
216int OBJ_add_object(obj) 214int OBJ_add_object(ASN1_OBJECT *obj)
217ASN1_OBJECT *obj;
218 { 215 {
219 ASN1_OBJECT *o; 216 ASN1_OBJECT *o;
220 ADDED_OBJ *ao[4],*aop; 217 ADDED_OBJ *ao[4],*aop;
@@ -247,7 +244,9 @@ ASN1_OBJECT *obj;
247 Free(aop); 244 Free(aop);
248 } 245 }
249 } 246 }
250 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); 247 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
248 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
249
251 return(o->nid); 250 return(o->nid);
252err: 251err:
253 for (i=ADDED_DATA; i<=ADDED_NID; i++) 252 for (i=ADDED_DATA; i<=ADDED_NID; i++)
@@ -256,8 +255,7 @@ err:
256 return(NID_undef); 255 return(NID_undef);
257 } 256 }
258 257
259ASN1_OBJECT *OBJ_nid2obj(n) 258ASN1_OBJECT *OBJ_nid2obj(int n)
260int n;
261 { 259 {
262 ADDED_OBJ ad,*adp; 260 ADDED_OBJ ad,*adp;
263 ASN1_OBJECT ob; 261 ASN1_OBJECT ob;
@@ -289,8 +287,7 @@ int n;
289 } 287 }
290 } 288 }
291 289
292char *OBJ_nid2sn(n) 290const char *OBJ_nid2sn(int n)
293int n;
294 { 291 {
295 ADDED_OBJ ad,*adp; 292 ADDED_OBJ ad,*adp;
296 ASN1_OBJECT ob; 293 ASN1_OBJECT ob;
@@ -322,8 +319,7 @@ int n;
322 } 319 }
323 } 320 }
324 321
325char *OBJ_nid2ln(n) 322const char *OBJ_nid2ln(int n)
326int n;
327 { 323 {
328 ADDED_OBJ ad,*adp; 324 ADDED_OBJ ad,*adp;
329 ASN1_OBJECT ob; 325 ASN1_OBJECT ob;
@@ -355,8 +351,7 @@ int n;
355 } 351 }
356 } 352 }
357 353
358int OBJ_obj2nid(a) 354int OBJ_obj2nid(ASN1_OBJECT *a)
359ASN1_OBJECT *a;
360 { 355 {
361 ASN1_OBJECT **op; 356 ASN1_OBJECT **op;
362 ADDED_OBJ ad,*adp; 357 ADDED_OBJ ad,*adp;
@@ -380,45 +375,126 @@ ASN1_OBJECT *a;
380 return((*op)->nid); 375 return((*op)->nid);
381 } 376 }
382 377
383int OBJ_txt2nid(s) 378/* Convert an object name into an ASN1_OBJECT
384char *s; 379 * if "noname" is not set then search for short and long names first.
380 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
381 * it can be used with any objects, not just registered ones.
382 */
383
384ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
385 { 385 {
386 int ret; 386 int nid = NID_undef;
387 ASN1_OBJECT *op=NULL;
388 unsigned char *buf,*p;
389 int i, j;
387 390
388 ret=OBJ_sn2nid(s); 391 if(!no_name) {
389 if (ret == NID_undef) 392 if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
390 { 393 ((nid = OBJ_ln2nid(s)) != NID_undef) )
391 ret=OBJ_ln2nid(s); 394 return OBJ_nid2obj(nid);
392 if (ret == NID_undef) 395 }
393 {
394 ASN1_OBJECT *op=NULL;
395 unsigned char *buf,*p;
396 int i;
397 396
398 i=a2d_ASN1_OBJECT(NULL,0,s,-1); 397 /* Work out size of content octets */
399 if (i <= 0) 398 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
400 { 399 if (i <= 0) {
401 /* clear the error */ 400 /* Clear the error */
402 ERR_get_error(); 401 ERR_get_error();
403 return(0); 402 return NULL;
404 } 403 }
404 /* Work out total size */
405 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
406
407 if((buf=(unsigned char *)Malloc(j)) == NULL) return NULL;
408
409 p = buf;
410 /* Write out tag+length */
411 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
412 /* Write out contents */
413 a2d_ASN1_OBJECT(p,i,s,-1);
414
415 p=buf;
416 op=d2i_ASN1_OBJECT(NULL,&p,i);
417 Free(buf);
418 return op;
419 }
420
421int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name)
422{
423 int i,idx=0,n=0,len,nid;
424 unsigned long l;
425 unsigned char *p;
426 const char *s;
427 char tbuf[32];
428
429 if (buf_len <= 0) return(0);
430
431 if ((a == NULL) || (a->data == NULL)) {
432 buf[0]='\0';
433 return(0);
434 }
405 435
406 if ((buf=(unsigned char *)Malloc(i)) == NULL) 436 nid=OBJ_obj2nid(a);
407 return(NID_undef); 437 if ((nid == NID_undef) || no_name) {
408 a2d_ASN1_OBJECT(buf,i,s,-1); 438 len=a->length;
409 p=buf; 439 p=a->data;
410 op=d2i_ASN1_OBJECT(NULL,&p,i); 440
411 if (op == NULL) return(NID_undef); 441 idx=0;
412 ret=OBJ_obj2nid(op); 442 l=0;
413 ASN1_OBJECT_free(op); 443 while (idx < a->length) {
414 Free(buf); 444 l|=(p[idx]&0x7f);
445 if (!(p[idx] & 0x80)) break;
446 l<<=7L;
447 idx++;
448 }
449 idx++;
450 i=(int)(l/40);
451 if (i > 2) i=2;
452 l-=(long)(i*40);
453
454 sprintf(tbuf,"%d.%lu",i,l);
455 i=strlen(tbuf);
456 strncpy(buf,tbuf,buf_len);
457 buf_len-=i;
458 buf+=i;
459 n+=i;
460
461 l=0;
462 for (; idx<len; idx++) {
463 l|=p[idx]&0x7f;
464 if (!(p[idx] & 0x80)) {
465 sprintf(tbuf,".%lu",l);
466 i=strlen(tbuf);
467 if (buf_len > 0)
468 strncpy(buf,tbuf,buf_len);
469 buf_len-=i;
470 buf+=i;
471 n+=i;
472 l=0;
415 } 473 }
474 l<<=7L;
416 } 475 }
417 return(ret); 476 } else {
477 s=OBJ_nid2ln(nid);
478 if (s == NULL)
479 s=OBJ_nid2sn(nid);
480 strncpy(buf,s,buf_len);
481 n=strlen(s);
418 } 482 }
483 buf[buf_len-1]='\0';
484 return(n);
485}
419 486
420int OBJ_ln2nid(s) 487int OBJ_txt2nid(char *s)
421char *s; 488{
489 ASN1_OBJECT *obj;
490 int nid;
491 obj = OBJ_txt2obj(s, 0);
492 nid = OBJ_obj2nid(obj);
493 ASN1_OBJECT_free(obj);
494 return nid;
495}
496
497int OBJ_ln2nid(const char *s)
422 { 498 {
423 ASN1_OBJECT o,*oo= &o,**op; 499 ASN1_OBJECT o,*oo= &o,**op;
424 ADDED_OBJ ad,*adp; 500 ADDED_OBJ ad,*adp;
@@ -437,8 +513,7 @@ char *s;
437 return((*op)->nid); 513 return((*op)->nid);
438 } 514 }
439 515
440int OBJ_sn2nid(s) 516int OBJ_sn2nid(const char *s)
441char *s;
442 { 517 {
443 ASN1_OBJECT o,*oo= &o,**op; 518 ASN1_OBJECT o,*oo= &o,**op;
444 ADDED_OBJ ad,*adp; 519 ADDED_OBJ ad,*adp;
@@ -457,9 +532,7 @@ char *s;
457 return((*op)->nid); 532 return((*op)->nid);
458 } 533 }
459 534
460static int obj_cmp(ap, bp) 535static int obj_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
461ASN1_OBJECT **ap;
462ASN1_OBJECT **bp;
463 { 536 {
464 int j; 537 int j;
465 ASN1_OBJECT *a= *ap; 538 ASN1_OBJECT *a= *ap;
@@ -470,12 +543,7 @@ ASN1_OBJECT **bp;
470 return(memcmp(a->data,b->data,a->length)); 543 return(memcmp(a->data,b->data,a->length));
471 } 544 }
472 545
473char *OBJ_bsearch(key,base,num,size,cmp) 546char *OBJ_bsearch(char *key, char *base, int num, int size, int (*cmp)())
474char *key;
475char *base;
476int num;
477int size;
478int (*cmp)();
479 { 547 {
480 int l,h,i,c; 548 int l,h,i,c;
481 char *p; 549 char *p;
@@ -495,14 +563,24 @@ int (*cmp)();
495 else 563 else
496 return(p); 564 return(p);
497 } 565 }
566#ifdef CHARSET_EBCDIC
567/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
568 * I don't have perl (yet), we revert to a *LINEAR* search
569 * when the object wasn't found in the binary search.
570 */
571 for (i=0; i<num; ++i) {
572 p= &(base[i*size]);
573 if ((*cmp)(key,p) == 0)
574 return p;
575 }
576#endif
498 return(NULL); 577 return(NULL);
499 } 578 }
500 579
501int OBJ_create_objects(in) 580int OBJ_create_objects(BIO *in)
502BIO *in;
503 { 581 {
504 MS_STATIC char buf[512]; 582 MS_STATIC char buf[512];
505 int i,num= -1; 583 int i,num=0;
506 char *o,*s,*l=NULL; 584 char *o,*s,*l=NULL;
507 585
508 for (;;) 586 for (;;)
@@ -511,26 +589,26 @@ BIO *in;
511 i=BIO_gets(in,buf,512); 589 i=BIO_gets(in,buf,512);
512 if (i <= 0) return(num); 590 if (i <= 0) return(num);
513 buf[i-1]='\0'; 591 buf[i-1]='\0';
514 if (!isalnum(buf[0])) return(num); 592 if (!isalnum((unsigned char)buf[0])) return(num);
515 o=s=buf; 593 o=s=buf;
516 while (isdigit(*s) || (*s == '.')) 594 while (isdigit((unsigned char)*s) || (*s == '.'))
517 s++; 595 s++;
518 if (*s != '\0') 596 if (*s != '\0')
519 { 597 {
520 *(s++)='\0'; 598 *(s++)='\0';
521 while (isspace(*s)) 599 while (isspace((unsigned char)*s))
522 s++; 600 s++;
523 if (*s == '\0') 601 if (*s == '\0')
524 s=NULL; 602 s=NULL;
525 else 603 else
526 { 604 {
527 l=s; 605 l=s;
528 while ((*l != '\0') && !isspace(*l)) 606 while ((*l != '\0') && !isspace((unsigned char)*l))
529 l++; 607 l++;
530 if (*l != '\0') 608 if (*l != '\0')
531 { 609 {
532 *(l++)='\0'; 610 *(l++)='\0';
533 while (isspace(*l)) 611 while (isspace((unsigned char)*l))
534 l++; 612 l++;
535 if (*l == '\0') l=NULL; 613 if (*l == '\0') l=NULL;
536 } 614 }
@@ -544,13 +622,10 @@ BIO *in;
544 if (!OBJ_create(o,s,l)) return(num); 622 if (!OBJ_create(o,s,l)) return(num);
545 num++; 623 num++;
546 } 624 }
547 return(num); 625 /* return(num); */
548 } 626 }
549 627
550int OBJ_create(oid,sn,ln) 628int OBJ_create(char *oid, char *sn, char *ln)
551char *oid;
552char *sn;
553char *ln;
554 { 629 {
555 int ok=0; 630 int ok=0;
556 ASN1_OBJECT *op=NULL; 631 ASN1_OBJECT *op=NULL;