-
-static STACK *load_extensions(sec)
-char *sec;
- {
- STACK *ext;
- STACK *ret=NULL;
- CONF_VALUE *cv;
- ASN1_OCTET_STRING *str=NULL;
- ASN1_STRING *tmp=NULL;
- X509_EXTENSION *x;
- BIO *mem=NULL;
- BUF_MEM *buf=NULL;
- int i,nid,len;
- unsigned char *ptr;
- int pack_type;
- int data_type;
-
- if ((ext=CONF_get_section(conf,sec)) == NULL)
- {
- BIO_printf(bio_err,"unable to find extension section called '%s'\n",sec);
- return(NULL);
- }
-
- if ((ret=sk_new_null()) == NULL) return(NULL);
-
- for (i=0; i<sk_num(ext); i++)
- {
- cv=(CONF_VALUE *)sk_value(ext,i); /* get the object id */
- if ((nid=OBJ_txt2nid(cv->name)) == NID_undef)
- {
- BIO_printf(bio_err,"%s:unknown object type in section, '%s'\n",sec,cv->name);
- goto err;
- }
-
- pack_type=X509v3_pack_type_by_NID(nid);
- data_type=X509v3_data_type_by_NID(nid);
-
- /* pack up the input bytes */
- ptr=(unsigned char *)cv->value;
- len=strlen((char *)ptr);
- if ((len > 2) && (cv->value[0] == '0') &&
- (cv->value[1] == 'x'))
- {
- if (data_type == V_ASN1_UNDEF)
- {
- BIO_printf(bio_err,"data type for extension %s is unknown\n",cv->name);
- goto err;
- }
- if (mem == NULL)
- if ((mem=BIO_new(BIO_s_mem())) == NULL)
- goto err;
- if (((buf=BUF_MEM_new()) == NULL) ||
- !BUF_MEM_grow(buf,128))
- goto err;
- if ((tmp=ASN1_STRING_new()) == NULL) goto err;
-
- BIO_reset(mem);
- BIO_write(mem,(char *)&(ptr[2]),len-2);
- if (!a2i_ASN1_STRING(mem,tmp,buf->data,buf->max))
- goto err;
- len=tmp->length;
- ptr=tmp->data;
- }
-
- switch (pack_type)
- {
- case X509_EXT_PACK_STRING:
- if ((str=X509v3_pack_string(&str,
- data_type,ptr,len)) == NULL)
- goto err;
- break;
- case X509_EXT_PACK_UNKNOWN:
- default:
- BIO_printf(bio_err,"Don't know how to pack extension %s\n",cv->name);
- goto err;
- /* break; */
- }
-
- if ((x=X509_EXTENSION_create_by_NID(NULL,nid,0,str)) == NULL)
- goto err;
- sk_push(ret,(char *)x);
- }
-
- if (0)
- {
-err:
- if (ret != NULL) sk_pop_free(ret,X509_EXTENSION_free);
- ret=NULL;
- }
- if (str != NULL) ASN1_OCTET_STRING_free(str);
- if (tmp != NULL) ASN1_STRING_free(tmp);
- if (buf != NULL) BUF_MEM_free(buf);
- if (mem != NULL) BIO_free(mem);
- return(ret);
- }
-