diff options
Diffstat (limited to 'src/lib/libcrypto/x509/x509_att.c')
| -rw-r--r-- | src/lib/libcrypto/x509/x509_att.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c index 0bae3d32a1..511b49d589 100644 --- a/src/lib/libcrypto/x509/x509_att.c +++ b/src/lib/libcrypto/x509/x509_att.c | |||
| @@ -67,8 +67,7 @@ | |||
| 67 | 67 | ||
| 68 | int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) | 68 | int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) |
| 69 | { | 69 | { |
| 70 | if (!x) return 0; | 70 | return sk_X509_ATTRIBUTE_num(x); |
| 71 | return(sk_X509_ATTRIBUTE_num(x)); | ||
| 72 | } | 71 | } |
| 73 | 72 | ||
| 74 | int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, | 73 | int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, |
| @@ -125,7 +124,13 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, | |||
| 125 | X509_ATTRIBUTE *new_attr=NULL; | 124 | X509_ATTRIBUTE *new_attr=NULL; |
| 126 | STACK_OF(X509_ATTRIBUTE) *sk=NULL; | 125 | STACK_OF(X509_ATTRIBUTE) *sk=NULL; |
| 127 | 126 | ||
| 128 | if ((x != NULL) && (*x == NULL)) | 127 | if (x == NULL) |
| 128 | { | ||
| 129 | X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_PASSED_NULL_PARAMETER); | ||
| 130 | goto err2; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (*x == NULL) | ||
| 129 | { | 134 | { |
| 130 | if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL) | 135 | if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL) |
| 131 | goto err; | 136 | goto err; |
| @@ -137,11 +142,11 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, | |||
| 137 | goto err2; | 142 | goto err2; |
| 138 | if (!sk_X509_ATTRIBUTE_push(sk,new_attr)) | 143 | if (!sk_X509_ATTRIBUTE_push(sk,new_attr)) |
| 139 | goto err; | 144 | goto err; |
| 140 | if ((x != NULL) && (*x == NULL)) | 145 | if (*x == NULL) |
| 141 | *x=sk; | 146 | *x=sk; |
| 142 | return(sk); | 147 | return(sk); |
| 143 | err: | 148 | err: |
| 144 | X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE); | 149 | X509err(X509_F_X509AT_ADD1_ATTR,ERR_R_MALLOC_FAILURE); |
| 145 | err2: | 150 | err2: |
| 146 | if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr); | 151 | if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr); |
| 147 | if (sk != NULL) sk_X509_ATTRIBUTE_free(sk); | 152 | if (sk != NULL) sk_X509_ATTRIBUTE_free(sk); |
| @@ -187,6 +192,22 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, | |||
| 187 | return ret; | 192 | return ret; |
| 188 | } | 193 | } |
| 189 | 194 | ||
| 195 | void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, | ||
| 196 | ASN1_OBJECT *obj, int lastpos, int type) | ||
| 197 | { | ||
| 198 | int i; | ||
| 199 | X509_ATTRIBUTE *at; | ||
| 200 | i = X509at_get_attr_by_OBJ(x, obj, lastpos); | ||
| 201 | if (i == -1) | ||
| 202 | return NULL; | ||
| 203 | if ((lastpos <= -2) && (X509at_get_attr_by_OBJ(x, obj, i) != -1)) | ||
| 204 | return NULL; | ||
| 205 | at = X509at_get_attr(x, i); | ||
| 206 | if (lastpos <= -3 && (X509_ATTRIBUTE_count(at) != 1)) | ||
| 207 | return NULL; | ||
| 208 | return X509_ATTRIBUTE_get0_data(at, 0, type, NULL); | ||
| 209 | } | ||
| 210 | |||
| 190 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, | 211 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, |
| 191 | int atrtype, const void *data, int len) | 212 | int atrtype, const void *data, int len) |
| 192 | { | 213 | { |
| @@ -264,8 +285,8 @@ int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj) | |||
| 264 | int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len) | 285 | int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len) |
| 265 | { | 286 | { |
| 266 | ASN1_TYPE *ttmp; | 287 | ASN1_TYPE *ttmp; |
| 267 | ASN1_STRING *stmp; | 288 | ASN1_STRING *stmp = NULL; |
| 268 | int atype; | 289 | int atype = 0; |
| 269 | if (!attr) return 0; | 290 | if (!attr) return 0; |
| 270 | if(attrtype & MBSTRING_FLAG) { | 291 | if(attrtype & MBSTRING_FLAG) { |
| 271 | stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, | 292 | stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, |
| @@ -275,16 +296,22 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *dat | |||
| 275 | return 0; | 296 | return 0; |
| 276 | } | 297 | } |
| 277 | atype = stmp->type; | 298 | atype = stmp->type; |
| 278 | } else { | 299 | } else if (len != -1){ |
| 279 | if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err; | 300 | if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err; |
| 280 | if(!ASN1_STRING_set(stmp, data, len)) goto err; | 301 | if(!ASN1_STRING_set(stmp, data, len)) goto err; |
| 281 | atype = attrtype; | 302 | atype = attrtype; |
| 282 | } | 303 | } |
| 283 | if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; | 304 | if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; |
| 284 | if(!(ttmp = ASN1_TYPE_new())) goto err; | 305 | if(!(ttmp = ASN1_TYPE_new())) goto err; |
| 306 | if (len == -1) | ||
| 307 | { | ||
| 308 | if (!ASN1_TYPE_set1(ttmp, attrtype, data)) | ||
| 309 | goto err; | ||
| 310 | } | ||
| 311 | else | ||
| 312 | ASN1_TYPE_set(ttmp, atype, stmp); | ||
| 285 | if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err; | 313 | if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err; |
| 286 | attr->single = 0; | 314 | attr->single = 0; |
| 287 | ASN1_TYPE_set(ttmp, atype, stmp); | ||
| 288 | return 1; | 315 | return 1; |
| 289 | err: | 316 | err: |
| 290 | X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE); | 317 | X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE); |
