diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_object.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_object.c | 195 |
1 files changed, 63 insertions, 132 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 5a7eeef8d8..71ce7c3896 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
| @@ -58,25 +58,19 @@ | |||
| 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 "asn1.h" | 62 | #include <openssl/asn1.h> |
| 63 | #include "objects.h" | 63 | #include <openssl/objects.h> |
| 64 | 64 | ||
| 65 | /* ASN1err(ASN1_F_ASN1_OBJECT_NEW,ASN1_R_EXPECTING_AN_OBJECT); | 65 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) |
| 66 | * ASN1err(ASN1_F_D2I_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); | ||
| 67 | * ASN1err(ASN1_F_I2T_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); | ||
| 68 | */ | ||
| 69 | |||
| 70 | int i2d_ASN1_OBJECT(a, pp) | ||
| 71 | ASN1_OBJECT *a; | ||
| 72 | unsigned char **pp; | ||
| 73 | { | 66 | { |
| 74 | unsigned char *p; | 67 | unsigned char *p; |
| 68 | int objsize; | ||
| 75 | 69 | ||
| 76 | if ((a == NULL) || (a->data == NULL)) return(0); | 70 | if ((a == NULL) || (a->data == NULL)) return(0); |
| 77 | 71 | ||
| 78 | if (pp == NULL) | 72 | objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); |
| 79 | return(ASN1_object_size(0,a->length,V_ASN1_OBJECT)); | 73 | if (pp == NULL) return objsize; |
| 80 | 74 | ||
| 81 | p= *pp; | 75 | p= *pp; |
| 82 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | 76 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); |
| @@ -84,17 +78,14 @@ unsigned char **pp; | |||
| 84 | p+=a->length; | 78 | p+=a->length; |
| 85 | 79 | ||
| 86 | *pp=p; | 80 | *pp=p; |
| 87 | return(a->length); | 81 | return(objsize); |
| 88 | } | 82 | } |
| 89 | 83 | ||
| 90 | int a2d_ASN1_OBJECT(out,olen,buf,num) | 84 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) |
| 91 | unsigned char *out; | ||
| 92 | int olen; | ||
| 93 | char *buf; | ||
| 94 | int num; | ||
| 95 | { | 85 | { |
| 96 | int i,first,len=0,c; | 86 | int i,first,len=0,c; |
| 97 | char tmp[24],*p; | 87 | char tmp[24]; |
| 88 | const char *p; | ||
| 98 | unsigned long l; | 89 | unsigned long l; |
| 99 | 90 | ||
| 100 | if (num == 0) | 91 | if (num == 0) |
| @@ -180,85 +171,12 @@ err: | |||
| 180 | return(0); | 171 | return(0); |
| 181 | } | 172 | } |
| 182 | 173 | ||
| 183 | int i2t_ASN1_OBJECT(buf,buf_len,a) | 174 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) |
| 184 | char *buf; | 175 | { |
| 185 | int buf_len; | 176 | return OBJ_obj2txt(buf, buf_len, a, 0); |
| 186 | ASN1_OBJECT *a; | 177 | } |
| 187 | { | ||
| 188 | int i,idx=0,n=0,len,nid; | ||
| 189 | unsigned long l; | ||
| 190 | unsigned char *p; | ||
| 191 | char *s; | ||
| 192 | char tbuf[32]; | ||
| 193 | |||
| 194 | if (buf_len <= 0) return(0); | ||
| 195 | |||
| 196 | if ((a == NULL) || (a->data == NULL)) | ||
| 197 | { | ||
| 198 | buf[0]='\0'; | ||
| 199 | return(0); | ||
| 200 | } | ||
| 201 | |||
| 202 | nid=OBJ_obj2nid(a); | ||
| 203 | if (nid == NID_undef) | ||
| 204 | { | ||
| 205 | len=a->length; | ||
| 206 | p=a->data; | ||
| 207 | 178 | ||
| 208 | idx=0; | 179 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) |
| 209 | l=0; | ||
| 210 | while (idx < a->length) | ||
| 211 | { | ||
| 212 | l|=(p[idx]&0x7f); | ||
| 213 | if (!(p[idx] & 0x80)) break; | ||
| 214 | l<<=7L; | ||
| 215 | idx++; | ||
| 216 | } | ||
| 217 | idx++; | ||
| 218 | i=(int)(l/40); | ||
| 219 | if (i > 2) i=2; | ||
| 220 | l-=(long)(i*40); | ||
| 221 | |||
| 222 | sprintf(tbuf,"%d.%ld",i,l); | ||
| 223 | i=strlen(tbuf); | ||
| 224 | strncpy(buf,tbuf,buf_len); | ||
| 225 | buf_len-=i; | ||
| 226 | buf+=i; | ||
| 227 | n+=i; | ||
| 228 | |||
| 229 | l=0; | ||
| 230 | for (; idx<len; idx++) | ||
| 231 | { | ||
| 232 | l|=p[idx]&0x7f; | ||
| 233 | if (!(p[idx] & 0x80)) | ||
| 234 | { | ||
| 235 | sprintf(tbuf,".%ld",l); | ||
| 236 | i=strlen(tbuf); | ||
| 237 | if (buf_len > 0) | ||
| 238 | strncpy(buf,tbuf,buf_len); | ||
| 239 | buf_len-=i; | ||
| 240 | buf+=i; | ||
| 241 | n+=i; | ||
| 242 | l=0; | ||
| 243 | } | ||
| 244 | l<<=7L; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | else | ||
| 248 | { | ||
| 249 | s=(char *)OBJ_nid2ln(nid); | ||
| 250 | if (s == NULL) | ||
| 251 | s=(char *)OBJ_nid2sn(nid); | ||
| 252 | strncpy(buf,s,buf_len); | ||
| 253 | n=strlen(s); | ||
| 254 | } | ||
| 255 | buf[buf_len-1]='\0'; | ||
| 256 | return(n); | ||
| 257 | } | ||
| 258 | |||
| 259 | int i2a_ASN1_OBJECT(bp,a) | ||
| 260 | BIO *bp; | ||
| 261 | ASN1_OBJECT *a; | ||
| 262 | { | 180 | { |
| 263 | char buf[80]; | 181 | char buf[80]; |
| 264 | int i; | 182 | int i; |
| @@ -271,28 +189,15 @@ ASN1_OBJECT *a; | |||
| 271 | return(i); | 189 | return(i); |
| 272 | } | 190 | } |
| 273 | 191 | ||
| 274 | ASN1_OBJECT *d2i_ASN1_OBJECT(a, pp, length) | 192 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, |
| 275 | ASN1_OBJECT **a; | 193 | long length) |
| 276 | unsigned char **pp; | 194 | { |
| 277 | long length; | ||
| 278 | { | ||
| 279 | ASN1_OBJECT *ret=NULL; | ||
| 280 | unsigned char *p; | 195 | unsigned char *p; |
| 281 | long len; | 196 | long len; |
| 282 | int tag,xclass; | 197 | int tag,xclass; |
| 283 | int inf,i; | 198 | int inf,i; |
| 284 | 199 | ASN1_OBJECT *ret = NULL; | |
| 285 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
| 286 | * for ->sn or ->ln */ | ||
| 287 | if ((a == NULL) || ((*a) == NULL) || | ||
| 288 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 289 | { | ||
| 290 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
| 291 | } | ||
| 292 | else ret=(*a); | ||
| 293 | |||
| 294 | p= *pp; | 200 | p= *pp; |
| 295 | |||
| 296 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 201 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); |
| 297 | if (inf & 0x80) | 202 | if (inf & 0x80) |
| 298 | { | 203 | { |
| @@ -305,10 +210,36 @@ long length; | |||
| 305 | i=ASN1_R_EXPECTING_AN_OBJECT; | 210 | i=ASN1_R_EXPECTING_AN_OBJECT; |
| 306 | goto err; | 211 | goto err; |
| 307 | } | 212 | } |
| 213 | ret = c2i_ASN1_OBJECT(a, &p, len); | ||
| 214 | if(ret) *pp = p; | ||
| 215 | return ret; | ||
| 216 | err: | ||
| 217 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | ||
| 218 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 219 | ASN1_OBJECT_free(ret); | ||
| 220 | return(NULL); | ||
| 221 | } | ||
| 222 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | ||
| 223 | long len) | ||
| 224 | { | ||
| 225 | ASN1_OBJECT *ret=NULL; | ||
| 226 | unsigned char *p; | ||
| 227 | int i; | ||
| 228 | |||
| 229 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
| 230 | * for ->sn or ->ln */ | ||
| 231 | if ((a == NULL) || ((*a) == NULL) || | ||
| 232 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 233 | { | ||
| 234 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
| 235 | } | ||
| 236 | else ret=(*a); | ||
| 237 | |||
| 238 | p= *pp; | ||
| 308 | if ((ret->data == NULL) || (ret->length < len)) | 239 | if ((ret->data == NULL) || (ret->length < len)) |
| 309 | { | 240 | { |
| 310 | if (ret->data != NULL) Free((char *)ret->data); | 241 | if (ret->data != NULL) OPENSSL_free(ret->data); |
| 311 | ret->data=(unsigned char *)Malloc((int)len); | 242 | ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1); |
| 312 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 243 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
| 313 | if (ret->data == NULL) | 244 | if (ret->data == NULL) |
| 314 | { i=ERR_R_MALLOC_FAILURE; goto err; } | 245 | { i=ERR_R_MALLOC_FAILURE; goto err; } |
| @@ -330,11 +261,11 @@ err: | |||
| 330 | return(NULL); | 261 | return(NULL); |
| 331 | } | 262 | } |
| 332 | 263 | ||
| 333 | ASN1_OBJECT *ASN1_OBJECT_new() | 264 | ASN1_OBJECT *ASN1_OBJECT_new(void) |
| 334 | { | 265 | { |
| 335 | ASN1_OBJECT *ret; | 266 | ASN1_OBJECT *ret; |
| 336 | 267 | ||
| 337 | ret=(ASN1_OBJECT *)Malloc(sizeof(ASN1_OBJECT)); | 268 | ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT)); |
| 338 | if (ret == NULL) | 269 | if (ret == NULL) |
| 339 | { | 270 | { |
| 340 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | 271 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); |
| @@ -349,31 +280,29 @@ ASN1_OBJECT *ASN1_OBJECT_new() | |||
| 349 | return(ret); | 280 | return(ret); |
| 350 | } | 281 | } |
| 351 | 282 | ||
| 352 | void ASN1_OBJECT_free(a) | 283 | void ASN1_OBJECT_free(ASN1_OBJECT *a) |
| 353 | ASN1_OBJECT *a; | ||
| 354 | { | 284 | { |
| 355 | if (a == NULL) return; | 285 | if (a == NULL) return; |
| 356 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | 286 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) |
| 357 | { | 287 | { |
| 358 | if (a->sn != NULL) Free(a->sn); | 288 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ |
| 359 | if (a->ln != NULL) Free(a->ln); | 289 | if (a->sn != NULL) OPENSSL_free((void *)a->sn); |
| 290 | if (a->ln != NULL) OPENSSL_free((void *)a->ln); | ||
| 291 | #endif | ||
| 360 | a->sn=a->ln=NULL; | 292 | a->sn=a->ln=NULL; |
| 361 | } | 293 | } |
| 362 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | 294 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) |
| 363 | { | 295 | { |
| 364 | if (a->data != NULL) Free(a->data); | 296 | if (a->data != NULL) OPENSSL_free(a->data); |
| 365 | a->data=NULL; | 297 | a->data=NULL; |
| 366 | a->length=0; | 298 | a->length=0; |
| 367 | } | 299 | } |
| 368 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | 300 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) |
| 369 | Free((char *)a); | 301 | OPENSSL_free(a); |
| 370 | } | 302 | } |
| 371 | 303 | ||
| 372 | ASN1_OBJECT *ASN1_OBJECT_create(nid,data,len,sn,ln) | 304 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, |
| 373 | int nid; | 305 | const char *sn, const char *ln) |
| 374 | unsigned char *data; | ||
| 375 | int len; | ||
| 376 | char *sn,*ln; | ||
| 377 | { | 306 | { |
| 378 | ASN1_OBJECT o; | 307 | ASN1_OBJECT o; |
| 379 | 308 | ||
| @@ -382,8 +311,10 @@ char *sn,*ln; | |||
| 382 | o.data=data; | 311 | o.data=data; |
| 383 | o.nid=nid; | 312 | o.nid=nid; |
| 384 | o.length=len; | 313 | o.length=len; |
| 385 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC| | 314 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| |
| 386 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 315 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
| 387 | return(OBJ_dup(&o)); | 316 | return(OBJ_dup(&o)); |
| 388 | } | 317 | } |
| 389 | 318 | ||
| 319 | IMPLEMENT_STACK_OF(ASN1_OBJECT) | ||
| 320 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) | ||
