diff options
Diffstat (limited to 'src/lib/libcrypto/objects/obj_dat.c')
| -rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 359 |
1 files changed, 224 insertions, 135 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 34866ebbd2..3ff64bb8d1 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 OPENSSL_NO_OBJECT | ||
| 67 | #include "obj_dat.h" | 68 | #include "obj_dat.h" |
| 68 | |||
| 69 | #ifndef NOPROTO | ||
| 70 | static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); | ||
| 71 | static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); | ||
| 72 | static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); | ||
| 73 | #else | 69 | #else |
| 74 | static int sn_cmp(); | 70 | /* You will have to load all the objects needed manually in the application */ |
| 75 | static int ln_cmp(); | 71 | #define NUM_NID 0 |
| 76 | static int obj_cmp(); | 72 | #define NUM_SN 0 |
| 73 | #define NUM_LN 0 | ||
| 74 | #define NUM_OBJ 0 | ||
| 75 | static unsigned char lvalues[1]; | ||
| 76 | static ASN1_OBJECT nid_objs[1]; | ||
| 77 | static ASN1_OBJECT *sn_objs[1]; | ||
| 78 | static ASN1_OBJECT *ln_objs[1]; | ||
| 79 | static ASN1_OBJECT *obj_objs[1]; | ||
| 77 | #endif | 80 | #endif |
| 78 | 81 | ||
| 82 | static int sn_cmp(const void *a, const void *b); | ||
| 83 | static int ln_cmp(const void *a, const void *b); | ||
| 84 | static int obj_cmp(const void *a, const void *b); | ||
| 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,23 +96,26 @@ typedef struct added_obj_st | |||
| 90 | static int new_nid=NUM_NID; | 96 | static int new_nid=NUM_NID; |
| 91 | static LHASH *added=NULL; | 97 | static LHASH *added=NULL; |
| 92 | 98 | ||
| 93 | static int sn_cmp(ap,bp) | 99 | static int sn_cmp(const void *a, const void *b) |
| 94 | ASN1_OBJECT **ap; | 100 | { |
| 95 | ASN1_OBJECT **bp; | 101 | const ASN1_OBJECT * const *ap = a, * const *bp = b; |
| 96 | { return(strcmp((*ap)->sn,(*bp)->sn)); } | 102 | return(strcmp((*ap)->sn,(*bp)->sn)); |
| 103 | } | ||
| 97 | 104 | ||
| 98 | static int ln_cmp(ap,bp) | 105 | static int ln_cmp(const void *a, const void *b) |
| 99 | ASN1_OBJECT **ap; | 106 | { |
| 100 | ASN1_OBJECT **bp; | 107 | const ASN1_OBJECT * const *ap = a, * const *bp = b; |
| 101 | { return(strcmp((*ap)->ln,(*bp)->ln)); } | 108 | return(strcmp((*ap)->ln,(*bp)->ln)); |
| 109 | } | ||
| 102 | 110 | ||
| 103 | static unsigned long add_hash(ca) | 111 | /* static unsigned long add_hash(ADDED_OBJ *ca) */ |
| 104 | ADDED_OBJ *ca; | 112 | static unsigned long add_hash(const void *ca_void) |
| 105 | { | 113 | { |
| 106 | ASN1_OBJECT *a; | 114 | const ASN1_OBJECT *a; |
| 107 | int i; | 115 | int i; |
| 108 | unsigned long ret=0; | 116 | unsigned long ret=0; |
| 109 | unsigned char *p; | 117 | unsigned char *p; |
| 118 | ADDED_OBJ *ca = (ADDED_OBJ *)ca_void; | ||
| 110 | 119 | ||
| 111 | a=ca->obj; | 120 | a=ca->obj; |
| 112 | switch (ca->type) | 121 | switch (ca->type) |
| @@ -127,18 +136,21 @@ ADDED_OBJ *ca; | |||
| 127 | ret=a->nid; | 136 | ret=a->nid; |
| 128 | break; | 137 | break; |
| 129 | default: | 138 | default: |
| 130 | abort(); | 139 | /* abort(); */ |
| 140 | return 0; | ||
| 131 | } | 141 | } |
| 132 | ret&=0x3fffffffL; | 142 | ret&=0x3fffffffL; |
| 133 | ret|=ca->type<<30L; | 143 | ret|=ca->type<<30L; |
| 134 | return(ret); | 144 | return(ret); |
| 135 | } | 145 | } |
| 136 | 146 | ||
| 137 | static int add_cmp(ca,cb) | 147 | /* static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) */ |
| 138 | ADDED_OBJ *ca,*cb; | 148 | static int add_cmp(const void *ca_void, const void *cb_void) |
| 139 | { | 149 | { |
| 140 | ASN1_OBJECT *a,*b; | 150 | ASN1_OBJECT *a,*b; |
| 141 | int i; | 151 | int i; |
| 152 | ADDED_OBJ *ca = (ADDED_OBJ *)ca_void; | ||
| 153 | ADDED_OBJ *cb = (ADDED_OBJ *)cb_void; | ||
| 142 | 154 | ||
| 143 | i=ca->type-cb->type; | 155 | i=ca->type-cb->type; |
| 144 | if (i) return(i); | 156 | if (i) return(i); |
| @@ -161,50 +173,52 @@ ADDED_OBJ *ca,*cb; | |||
| 161 | case ADDED_NID: | 173 | case ADDED_NID: |
| 162 | return(a->nid-b->nid); | 174 | return(a->nid-b->nid); |
| 163 | default: | 175 | default: |
| 164 | abort(); | 176 | /* abort(); */ |
| 177 | return 0; | ||
| 165 | } | 178 | } |
| 166 | } | 179 | } |
| 167 | 180 | ||
| 168 | static int init_added() | 181 | static int init_added(void) |
| 169 | { | 182 | { |
| 170 | if (added != NULL) return(1); | 183 | if (added != NULL) return(1); |
| 171 | added=lh_new(add_hash,add_cmp); | 184 | added=lh_new(add_hash,add_cmp); |
| 172 | return(added != NULL); | 185 | return(added != NULL); |
| 173 | } | 186 | } |
| 174 | 187 | ||
| 175 | static void cleanup1(a) | 188 | static void cleanup1(ADDED_OBJ *a) |
| 176 | ADDED_OBJ *a; | ||
| 177 | { | 189 | { |
| 178 | a->obj->nid=0; | 190 | a->obj->nid=0; |
| 179 | a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| | 191 | a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| |
| 180 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS; | 192 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| |
| 193 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 181 | } | 194 | } |
| 182 | 195 | ||
| 183 | static void cleanup2(a) | 196 | static void cleanup2(ADDED_OBJ *a) |
| 184 | ADDED_OBJ *a; | ||
| 185 | { a->obj->nid++; } | 197 | { a->obj->nid++; } |
| 186 | 198 | ||
| 187 | static void cleanup3(a) | 199 | static void cleanup3(ADDED_OBJ *a) |
| 188 | ADDED_OBJ *a; | ||
| 189 | { | 200 | { |
| 190 | if (--a->obj->nid == 0) | 201 | if (--a->obj->nid == 0) |
| 191 | ASN1_OBJECT_free(a->obj); | 202 | ASN1_OBJECT_free(a->obj); |
| 192 | Free(a); | 203 | OPENSSL_free(a); |
| 193 | } | 204 | } |
| 194 | 205 | ||
| 195 | void OBJ_cleanup() | 206 | static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *) |
| 207 | static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *) | ||
| 208 | static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *) | ||
| 209 | |||
| 210 | void OBJ_cleanup(void) | ||
| 196 | { | 211 | { |
| 197 | if (added == NULL) return; | 212 | if (added == NULL) return; |
| 198 | added->down_load=0; | 213 | added->down_load=0; |
| 199 | lh_doall(added,cleanup1); /* zero counters */ | 214 | lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */ |
| 200 | lh_doall(added,cleanup2); /* set counters */ | 215 | lh_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */ |
| 201 | lh_doall(added,cleanup3); /* free objects */ | 216 | lh_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */ |
| 202 | lh_free(added); | 217 | lh_free(added); |
| 203 | added=NULL; | 218 | added=NULL; |
| 204 | } | 219 | } |
| 205 | 220 | ||
| 206 | int OBJ_new_nid(num) | 221 | int OBJ_new_nid(int num) |
| 207 | int num; | ||
| 208 | { | 222 | { |
| 209 | int i; | 223 | int i; |
| 210 | 224 | ||
| @@ -213,27 +227,22 @@ int num; | |||
| 213 | return(i); | 227 | return(i); |
| 214 | } | 228 | } |
| 215 | 229 | ||
| 216 | int OBJ_add_object(obj) | 230 | int OBJ_add_object(const ASN1_OBJECT *obj) |
| 217 | ASN1_OBJECT *obj; | ||
| 218 | { | 231 | { |
| 219 | ASN1_OBJECT *o; | 232 | ASN1_OBJECT *o; |
| 220 | ADDED_OBJ *ao[4],*aop; | 233 | ADDED_OBJ *ao[4]={NULL,NULL,NULL,NULL},*aop; |
| 221 | int i; | 234 | int i; |
| 222 | 235 | ||
| 223 | if (added == NULL) | 236 | if (added == NULL) |
| 224 | if (!init_added()) return(0); | 237 | if (!init_added()) return(0); |
| 225 | if ((o=OBJ_dup(obj)) == NULL) goto err; | 238 | if ((o=OBJ_dup(obj)) == NULL) goto err; |
| 226 | ao[ADDED_DATA]=NULL; | 239 | if (!(ao[ADDED_NID]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err; |
| 227 | ao[ADDED_SNAME]=NULL; | ||
| 228 | ao[ADDED_LNAME]=NULL; | ||
| 229 | ao[ADDED_NID]=NULL; | ||
| 230 | ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | ||
| 231 | if ((o->length != 0) && (obj->data != NULL)) | 240 | if ((o->length != 0) && (obj->data != NULL)) |
| 232 | ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | 241 | ao[ADDED_DATA]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)); |
| 233 | if (o->sn != NULL) | 242 | if (o->sn != NULL) |
| 234 | ao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | 243 | ao[ADDED_SNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)); |
| 235 | if (o->ln != NULL) | 244 | if (o->ln != NULL) |
| 236 | ao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | 245 | ao[ADDED_LNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)); |
| 237 | 246 | ||
| 238 | for (i=ADDED_DATA; i<=ADDED_NID; i++) | 247 | for (i=ADDED_DATA; i<=ADDED_NID; i++) |
| 239 | { | 248 | { |
| @@ -241,23 +250,24 @@ ASN1_OBJECT *obj; | |||
| 241 | { | 250 | { |
| 242 | ao[i]->type=i; | 251 | ao[i]->type=i; |
| 243 | ao[i]->obj=o; | 252 | ao[i]->obj=o; |
| 244 | aop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]); | 253 | aop=(ADDED_OBJ *)lh_insert(added,ao[i]); |
| 245 | /* memory leak, buit should not normally matter */ | 254 | /* memory leak, buit should not normally matter */ |
| 246 | if (aop != NULL) | 255 | if (aop != NULL) |
| 247 | Free(aop); | 256 | OPENSSL_free(aop); |
| 248 | } | 257 | } |
| 249 | } | 258 | } |
| 250 | o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); | 259 | o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| |
| 260 | ASN1_OBJECT_FLAG_DYNAMIC_DATA); | ||
| 261 | |||
| 251 | return(o->nid); | 262 | return(o->nid); |
| 252 | err: | 263 | err: |
| 253 | for (i=ADDED_DATA; i<=ADDED_NID; i++) | 264 | for (i=ADDED_DATA; i<=ADDED_NID; i++) |
| 254 | if (ao[i] != NULL) Free(ao[i]); | 265 | if (ao[i] != NULL) OPENSSL_free(ao[i]); |
| 255 | if (o != NULL) Free(o); | 266 | if (o != NULL) OPENSSL_free(o); |
| 256 | return(NID_undef); | 267 | return(NID_undef); |
| 257 | } | 268 | } |
| 258 | 269 | ||
| 259 | ASN1_OBJECT *OBJ_nid2obj(n) | 270 | ASN1_OBJECT *OBJ_nid2obj(int n) |
| 260 | int n; | ||
| 261 | { | 271 | { |
| 262 | ADDED_OBJ ad,*adp; | 272 | ADDED_OBJ ad,*adp; |
| 263 | ASN1_OBJECT ob; | 273 | ASN1_OBJECT ob; |
| @@ -278,7 +288,7 @@ int n; | |||
| 278 | ad.type=ADDED_NID; | 288 | ad.type=ADDED_NID; |
| 279 | ad.obj= &ob; | 289 | ad.obj= &ob; |
| 280 | ob.nid=n; | 290 | ob.nid=n; |
| 281 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | 291 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
| 282 | if (adp != NULL) | 292 | if (adp != NULL) |
| 283 | return(adp->obj); | 293 | return(adp->obj); |
| 284 | else | 294 | else |
| @@ -289,8 +299,7 @@ int n; | |||
| 289 | } | 299 | } |
| 290 | } | 300 | } |
| 291 | 301 | ||
| 292 | char *OBJ_nid2sn(n) | 302 | const char *OBJ_nid2sn(int n) |
| 293 | int n; | ||
| 294 | { | 303 | { |
| 295 | ADDED_OBJ ad,*adp; | 304 | ADDED_OBJ ad,*adp; |
| 296 | ASN1_OBJECT ob; | 305 | ASN1_OBJECT ob; |
| @@ -311,7 +320,7 @@ int n; | |||
| 311 | ad.type=ADDED_NID; | 320 | ad.type=ADDED_NID; |
| 312 | ad.obj= &ob; | 321 | ad.obj= &ob; |
| 313 | ob.nid=n; | 322 | ob.nid=n; |
| 314 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | 323 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
| 315 | if (adp != NULL) | 324 | if (adp != NULL) |
| 316 | return(adp->obj->sn); | 325 | return(adp->obj->sn); |
| 317 | else | 326 | else |
| @@ -322,8 +331,7 @@ int n; | |||
| 322 | } | 331 | } |
| 323 | } | 332 | } |
| 324 | 333 | ||
| 325 | char *OBJ_nid2ln(n) | 334 | const char *OBJ_nid2ln(int n) |
| 326 | int n; | ||
| 327 | { | 335 | { |
| 328 | ADDED_OBJ ad,*adp; | 336 | ADDED_OBJ ad,*adp; |
| 329 | ASN1_OBJECT ob; | 337 | ASN1_OBJECT ob; |
| @@ -344,7 +352,7 @@ int n; | |||
| 344 | ad.type=ADDED_NID; | 352 | ad.type=ADDED_NID; |
| 345 | ad.obj= &ob; | 353 | ad.obj= &ob; |
| 346 | ob.nid=n; | 354 | ob.nid=n; |
| 347 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | 355 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
| 348 | if (adp != NULL) | 356 | if (adp != NULL) |
| 349 | return(adp->obj->ln); | 357 | return(adp->obj->ln); |
| 350 | else | 358 | else |
| @@ -355,8 +363,7 @@ int n; | |||
| 355 | } | 363 | } |
| 356 | } | 364 | } |
| 357 | 365 | ||
| 358 | int OBJ_obj2nid(a) | 366 | int OBJ_obj2nid(const ASN1_OBJECT *a) |
| 359 | ASN1_OBJECT *a; | ||
| 360 | { | 367 | { |
| 361 | ASN1_OBJECT **op; | 368 | ASN1_OBJECT **op; |
| 362 | ADDED_OBJ ad,*adp; | 369 | ADDED_OBJ ad,*adp; |
| @@ -369,56 +376,136 @@ ASN1_OBJECT *a; | |||
| 369 | if (added != NULL) | 376 | if (added != NULL) |
| 370 | { | 377 | { |
| 371 | ad.type=ADDED_DATA; | 378 | ad.type=ADDED_DATA; |
| 372 | ad.obj=a; | 379 | ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */ |
| 373 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | 380 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
| 374 | if (adp != NULL) return (adp->obj->nid); | 381 | if (adp != NULL) return (adp->obj->nid); |
| 375 | } | 382 | } |
| 376 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ, | 383 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ, |
| 377 | sizeof(ASN1_OBJECT *),(int (*)())obj_cmp); | 384 | sizeof(ASN1_OBJECT *),obj_cmp); |
| 378 | if (op == NULL) | 385 | if (op == NULL) |
| 379 | return(NID_undef); | 386 | return(NID_undef); |
| 380 | return((*op)->nid); | 387 | return((*op)->nid); |
| 381 | } | 388 | } |
| 382 | 389 | ||
| 383 | int OBJ_txt2nid(s) | 390 | /* Convert an object name into an ASN1_OBJECT |
| 384 | char *s; | 391 | * if "noname" is not set then search for short and long names first. |
| 392 | * This will convert the "dotted" form into an object: unlike OBJ_txt2nid | ||
| 393 | * it can be used with any objects, not just registered ones. | ||
| 394 | */ | ||
| 395 | |||
| 396 | ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) | ||
| 385 | { | 397 | { |
| 386 | int ret; | 398 | int nid = NID_undef; |
| 399 | ASN1_OBJECT *op=NULL; | ||
| 400 | unsigned char *buf,*p; | ||
| 401 | int i, j; | ||
| 387 | 402 | ||
| 388 | ret=OBJ_sn2nid(s); | 403 | if(!no_name) { |
| 389 | if (ret == NID_undef) | 404 | if( ((nid = OBJ_sn2nid(s)) != NID_undef) || |
| 390 | { | 405 | ((nid = OBJ_ln2nid(s)) != NID_undef) ) |
| 391 | ret=OBJ_ln2nid(s); | 406 | return OBJ_nid2obj(nid); |
| 392 | if (ret == NID_undef) | 407 | } |
| 393 | { | ||
| 394 | ASN1_OBJECT *op=NULL; | ||
| 395 | unsigned char *buf,*p; | ||
| 396 | int i; | ||
| 397 | 408 | ||
| 398 | i=a2d_ASN1_OBJECT(NULL,0,s,-1); | 409 | /* Work out size of content octets */ |
| 399 | if (i <= 0) | 410 | i=a2d_ASN1_OBJECT(NULL,0,s,-1); |
| 400 | { | 411 | if (i <= 0) { |
| 401 | /* clear the error */ | 412 | /* Clear the error */ |
| 402 | ERR_get_error(); | 413 | ERR_get_error(); |
| 403 | return(0); | 414 | return NULL; |
| 404 | } | 415 | } |
| 416 | /* Work out total size */ | ||
| 417 | j = ASN1_object_size(0,i,V_ASN1_OBJECT); | ||
| 418 | |||
| 419 | if((buf=(unsigned char *)OPENSSL_malloc(j)) == NULL) return NULL; | ||
| 420 | |||
| 421 | p = buf; | ||
| 422 | /* Write out tag+length */ | ||
| 423 | ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | ||
| 424 | /* Write out contents */ | ||
| 425 | a2d_ASN1_OBJECT(p,i,s,-1); | ||
| 426 | |||
| 427 | p=buf; | ||
| 428 | op=d2i_ASN1_OBJECT(NULL,&p,i); | ||
| 429 | OPENSSL_free(buf); | ||
| 430 | return op; | ||
| 431 | } | ||
| 432 | |||
| 433 | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | ||
| 434 | { | ||
| 435 | int i,idx=0,n=0,len,nid; | ||
| 436 | unsigned long l; | ||
| 437 | unsigned char *p; | ||
| 438 | const char *s; | ||
| 439 | char tbuf[32]; | ||
| 440 | |||
| 441 | if (buf_len <= 0) return(0); | ||
| 405 | 442 | ||
| 406 | if ((buf=(unsigned char *)Malloc(i)) == NULL) | 443 | if ((a == NULL) || (a->data == NULL)) { |
| 407 | return(NID_undef); | 444 | buf[0]='\0'; |
| 408 | a2d_ASN1_OBJECT(buf,i,s,-1); | 445 | return(0); |
| 409 | p=buf; | 446 | } |
| 410 | op=d2i_ASN1_OBJECT(NULL,&p,i); | 447 | |
| 411 | if (op == NULL) return(NID_undef); | 448 | if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) { |
| 412 | ret=OBJ_obj2nid(op); | 449 | len=a->length; |
| 413 | ASN1_OBJECT_free(op); | 450 | p=a->data; |
| 414 | Free(buf); | 451 | |
| 452 | idx=0; | ||
| 453 | l=0; | ||
| 454 | while (idx < a->length) { | ||
| 455 | l|=(p[idx]&0x7f); | ||
| 456 | if (!(p[idx] & 0x80)) break; | ||
| 457 | l<<=7L; | ||
| 458 | idx++; | ||
| 459 | } | ||
| 460 | idx++; | ||
| 461 | i=(int)(l/40); | ||
| 462 | if (i > 2) i=2; | ||
| 463 | l-=(long)(i*40); | ||
| 464 | |||
| 465 | sprintf(tbuf,"%d.%lu",i,l); | ||
| 466 | i=strlen(tbuf); | ||
| 467 | strncpy(buf,tbuf,buf_len); | ||
| 468 | buf_len-=i; | ||
| 469 | buf+=i; | ||
| 470 | n+=i; | ||
| 471 | |||
| 472 | l=0; | ||
| 473 | for (; idx<len; idx++) { | ||
| 474 | l|=p[idx]&0x7f; | ||
| 475 | if (!(p[idx] & 0x80)) { | ||
| 476 | sprintf(tbuf,".%lu",l); | ||
| 477 | i=strlen(tbuf); | ||
| 478 | if (buf_len > 0) | ||
| 479 | strncpy(buf,tbuf,buf_len); | ||
| 480 | buf_len-=i; | ||
| 481 | buf+=i; | ||
| 482 | n+=i; | ||
| 483 | l=0; | ||
| 415 | } | 484 | } |
| 485 | l<<=7L; | ||
| 416 | } | 486 | } |
| 417 | return(ret); | 487 | } else { |
| 488 | s=OBJ_nid2ln(nid); | ||
| 489 | if (s == NULL) | ||
| 490 | s=OBJ_nid2sn(nid); | ||
| 491 | strncpy(buf,s,buf_len); | ||
| 492 | n=strlen(s); | ||
| 418 | } | 493 | } |
| 494 | buf[buf_len-1]='\0'; | ||
| 495 | return(n); | ||
| 496 | } | ||
| 419 | 497 | ||
| 420 | int OBJ_ln2nid(s) | 498 | int OBJ_txt2nid(const char *s) |
| 421 | char *s; | 499 | { |
| 500 | ASN1_OBJECT *obj; | ||
| 501 | int nid; | ||
| 502 | obj = OBJ_txt2obj(s, 0); | ||
| 503 | nid = OBJ_obj2nid(obj); | ||
| 504 | ASN1_OBJECT_free(obj); | ||
| 505 | return nid; | ||
| 506 | } | ||
| 507 | |||
| 508 | int OBJ_ln2nid(const char *s) | ||
| 422 | { | 509 | { |
| 423 | ASN1_OBJECT o,*oo= &o,**op; | 510 | ASN1_OBJECT o,*oo= &o,**op; |
| 424 | ADDED_OBJ ad,*adp; | 511 | ADDED_OBJ ad,*adp; |
| @@ -428,17 +515,16 @@ char *s; | |||
| 428 | { | 515 | { |
| 429 | ad.type=ADDED_LNAME; | 516 | ad.type=ADDED_LNAME; |
| 430 | ad.obj= &o; | 517 | ad.obj= &o; |
| 431 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | 518 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
| 432 | if (adp != NULL) return (adp->obj->nid); | 519 | if (adp != NULL) return (adp->obj->nid); |
| 433 | } | 520 | } |
| 434 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN, | 521 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN, |
| 435 | sizeof(ASN1_OBJECT *),(int (*)())ln_cmp); | 522 | sizeof(ASN1_OBJECT *),ln_cmp); |
| 436 | if (op == NULL) return(NID_undef); | 523 | if (op == NULL) return(NID_undef); |
| 437 | return((*op)->nid); | 524 | return((*op)->nid); |
| 438 | } | 525 | } |
| 439 | 526 | ||
| 440 | int OBJ_sn2nid(s) | 527 | int OBJ_sn2nid(const char *s) |
| 441 | char *s; | ||
| 442 | { | 528 | { |
| 443 | ASN1_OBJECT o,*oo= &o,**op; | 529 | ASN1_OBJECT o,*oo= &o,**op; |
| 444 | ADDED_OBJ ad,*adp; | 530 | ADDED_OBJ ad,*adp; |
| @@ -448,37 +534,31 @@ char *s; | |||
| 448 | { | 534 | { |
| 449 | ad.type=ADDED_SNAME; | 535 | ad.type=ADDED_SNAME; |
| 450 | ad.obj= &o; | 536 | ad.obj= &o; |
| 451 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | 537 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
| 452 | if (adp != NULL) return (adp->obj->nid); | 538 | if (adp != NULL) return (adp->obj->nid); |
| 453 | } | 539 | } |
| 454 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN, | 540 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN, |
| 455 | sizeof(ASN1_OBJECT *),(int (*)())sn_cmp); | 541 | sizeof(ASN1_OBJECT *),sn_cmp); |
| 456 | if (op == NULL) return(NID_undef); | 542 | if (op == NULL) return(NID_undef); |
| 457 | return((*op)->nid); | 543 | return((*op)->nid); |
| 458 | } | 544 | } |
| 459 | 545 | ||
| 460 | static int obj_cmp(ap, bp) | 546 | static int obj_cmp(const void *ap, const void *bp) |
| 461 | ASN1_OBJECT **ap; | ||
| 462 | ASN1_OBJECT **bp; | ||
| 463 | { | 547 | { |
| 464 | int j; | 548 | int j; |
| 465 | ASN1_OBJECT *a= *ap; | 549 | ASN1_OBJECT *a= *(ASN1_OBJECT **)ap; |
| 466 | ASN1_OBJECT *b= *bp; | 550 | ASN1_OBJECT *b= *(ASN1_OBJECT **)bp; |
| 467 | 551 | ||
| 468 | j=(a->length - b->length); | 552 | j=(a->length - b->length); |
| 469 | if (j) return(j); | 553 | if (j) return(j); |
| 470 | return(memcmp(a->data,b->data,a->length)); | 554 | return(memcmp(a->data,b->data,a->length)); |
| 471 | } | 555 | } |
| 472 | 556 | ||
| 473 | char *OBJ_bsearch(key,base,num,size,cmp) | 557 | const char *OBJ_bsearch(const char *key, const char *base, int num, int size, |
| 474 | char *key; | 558 | int (*cmp)(const void *, const void *)) |
| 475 | char *base; | ||
| 476 | int num; | ||
| 477 | int size; | ||
| 478 | int (*cmp)(); | ||
| 479 | { | 559 | { |
| 480 | int l,h,i,c; | 560 | int l,h,i,c; |
| 481 | char *p; | 561 | const char *p; |
| 482 | 562 | ||
| 483 | if (num == 0) return(NULL); | 563 | if (num == 0) return(NULL); |
| 484 | l=0; | 564 | l=0; |
| @@ -495,14 +575,24 @@ int (*cmp)(); | |||
| 495 | else | 575 | else |
| 496 | return(p); | 576 | return(p); |
| 497 | } | 577 | } |
| 578 | #ifdef CHARSET_EBCDIC | ||
| 579 | /* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and | ||
| 580 | * I don't have perl (yet), we revert to a *LINEAR* search | ||
| 581 | * when the object wasn't found in the binary search. | ||
| 582 | */ | ||
| 583 | for (i=0; i<num; ++i) { | ||
| 584 | p= &(base[i*size]); | ||
| 585 | if ((*cmp)(key,p) == 0) | ||
| 586 | return p; | ||
| 587 | } | ||
| 588 | #endif | ||
| 498 | return(NULL); | 589 | return(NULL); |
| 499 | } | 590 | } |
| 500 | 591 | ||
| 501 | int OBJ_create_objects(in) | 592 | int OBJ_create_objects(BIO *in) |
| 502 | BIO *in; | ||
| 503 | { | 593 | { |
| 504 | MS_STATIC char buf[512]; | 594 | MS_STATIC char buf[512]; |
| 505 | int i,num= -1; | 595 | int i,num=0; |
| 506 | char *o,*s,*l=NULL; | 596 | char *o,*s,*l=NULL; |
| 507 | 597 | ||
| 508 | for (;;) | 598 | for (;;) |
| @@ -511,26 +601,26 @@ BIO *in; | |||
| 511 | i=BIO_gets(in,buf,512); | 601 | i=BIO_gets(in,buf,512); |
| 512 | if (i <= 0) return(num); | 602 | if (i <= 0) return(num); |
| 513 | buf[i-1]='\0'; | 603 | buf[i-1]='\0'; |
| 514 | if (!isalnum(buf[0])) return(num); | 604 | if (!isalnum((unsigned char)buf[0])) return(num); |
| 515 | o=s=buf; | 605 | o=s=buf; |
| 516 | while (isdigit(*s) || (*s == '.')) | 606 | while (isdigit((unsigned char)*s) || (*s == '.')) |
| 517 | s++; | 607 | s++; |
| 518 | if (*s != '\0') | 608 | if (*s != '\0') |
| 519 | { | 609 | { |
| 520 | *(s++)='\0'; | 610 | *(s++)='\0'; |
| 521 | while (isspace(*s)) | 611 | while (isspace((unsigned char)*s)) |
| 522 | s++; | 612 | s++; |
| 523 | if (*s == '\0') | 613 | if (*s == '\0') |
| 524 | s=NULL; | 614 | s=NULL; |
| 525 | else | 615 | else |
| 526 | { | 616 | { |
| 527 | l=s; | 617 | l=s; |
| 528 | while ((*l != '\0') && !isspace(*l)) | 618 | while ((*l != '\0') && !isspace((unsigned char)*l)) |
| 529 | l++; | 619 | l++; |
| 530 | if (*l != '\0') | 620 | if (*l != '\0') |
| 531 | { | 621 | { |
| 532 | *(l++)='\0'; | 622 | *(l++)='\0'; |
| 533 | while (isspace(*l)) | 623 | while (isspace((unsigned char)*l)) |
| 534 | l++; | 624 | l++; |
| 535 | if (*l == '\0') l=NULL; | 625 | if (*l == '\0') l=NULL; |
| 536 | } | 626 | } |
| @@ -544,13 +634,10 @@ BIO *in; | |||
| 544 | if (!OBJ_create(o,s,l)) return(num); | 634 | if (!OBJ_create(o,s,l)) return(num); |
| 545 | num++; | 635 | num++; |
| 546 | } | 636 | } |
| 547 | return(num); | 637 | /* return(num); */ |
| 548 | } | 638 | } |
| 549 | 639 | ||
| 550 | int OBJ_create(oid,sn,ln) | 640 | int OBJ_create(const char *oid, const char *sn, const char *ln) |
| 551 | char *oid; | ||
| 552 | char *sn; | ||
| 553 | char *ln; | ||
| 554 | { | 641 | { |
| 555 | int ok=0; | 642 | int ok=0; |
| 556 | ASN1_OBJECT *op=NULL; | 643 | ASN1_OBJECT *op=NULL; |
| @@ -560,19 +647,21 @@ char *ln; | |||
| 560 | i=a2d_ASN1_OBJECT(NULL,0,oid,-1); | 647 | i=a2d_ASN1_OBJECT(NULL,0,oid,-1); |
| 561 | if (i <= 0) return(0); | 648 | if (i <= 0) return(0); |
| 562 | 649 | ||
| 563 | if ((buf=(unsigned char *)Malloc(i)) == NULL) | 650 | if ((buf=(unsigned char *)OPENSSL_malloc(i)) == NULL) |
| 564 | { | 651 | { |
| 565 | OBJerr(OBJ_F_OBJ_CREATE,OBJ_R_MALLOC_FAILURE); | 652 | OBJerr(OBJ_F_OBJ_CREATE,OBJ_R_MALLOC_FAILURE); |
| 566 | return(0); | 653 | return(0); |
| 567 | } | 654 | } |
| 568 | i=a2d_ASN1_OBJECT(buf,i,oid,-1); | 655 | i=a2d_ASN1_OBJECT(buf,i,oid,-1); |
| 656 | if (i == 0) | ||
| 657 | goto err; | ||
| 569 | op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); | 658 | op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); |
| 570 | if (op == NULL) | 659 | if (op == NULL) |
| 571 | goto err; | 660 | goto err; |
| 572 | ok=OBJ_add_object(op); | 661 | ok=OBJ_add_object(op); |
| 573 | err: | 662 | err: |
| 574 | ASN1_OBJECT_free(op); | 663 | ASN1_OBJECT_free(op); |
| 575 | Free((char *)buf); | 664 | OPENSSL_free(buf); |
| 576 | return(ok); | 665 | return(ok); |
| 577 | } | 666 | } |
| 578 | 667 | ||
