/* For this case, I will malloc the return strings */ static int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2) { ASN1_TYPE *so; #if 0 if (signed_seq2string_nid == -1) signed_seq2string_nid= OBJ_create("1.9.9999","OID_example","Our example OID"); /* To retrieve */ so=PKCS7_get_signed_attribute(si,signed_seq2string_nid); if (so && (so->type == V_ASN1_SEQUENCE)) { ASN1_CTX c; ASN1_STRING *s; long length; ASN1_OCTET_STRING *os1,*os2; s=so->value.sequence; c.p=ASN1_STRING_data(s); c.max=c.p+ASN1_STRING_length(s); if (!asn1_GetSequence(&c,&length)) GOTO_ERR("") err; /* Length is the length of the seqence */ c.q=c.p; if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) GOTO_ERR(""); c.slen-=(c.p-c.q); c.q=c.p; if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) GOTO_ERR(""); c.slen-=(c.p-c.q); if (!asn1_Finish(&c)) GOTO_ERR("") err; *str1=Malloc(os1->length+1); *str2=Malloc(os2->length+1); memcpy(*str1,os1->data,os1->length); memcpy(*str2,os2->data,os2->length); (*str1)[os1->length]='\0'; (*str2)[os2->length]='\0'; ASN1_OCTET_STRING_free(os1); ASN1_OCTET_STRING_free(os2); return(1); } #endif err: return(0); }
DLA3_QUERYURL *d2i_DLA3_QUERYURL(DLA3_QUERYURL **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,DLA3_QUERYURL *,DLA3_QUERYURL_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get (ret->queryUrl, d2i_ASN1_OCTET_STRING); #if 0 M_ASN1_D2I_Finish(a, DLA3_QUERYURL_free, ASN1_F_D2I_DLA3_QUERYURL); #else if (!asn1_Finish(&c)) goto err; *pp = c.p; if (a != NULL) (*a)=ret; return(ret); err: if ((ret != NULL) && ((a == NULL) || (*a != ret))) DLA3_QUERYURL_free(ret); return(NULL); #endif }
KCA_VERSION *d2i_KCA_VERSION(KCA_VERSION **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,KCA_VERSION *,KCA_VERSION_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get (ret->Version, d2i_ASN1_OCTET_STRING); #if 0 M_ASN1_D2I_Finish(a, KCA_VERSION_free, ASN1_F_D2I_KCA_VERSION); #else if (!asn1_Finish(&c)) goto err; *pp = c.p; if (a != NULL) (*a)=ret; return(ret); err: if ((ret != NULL) && ((a == NULL) || (*a != ret))) KCA_VERSION_free(ret); return(NULL); #endif }
RSA *d2i_RSA_NET_2(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey) { NETSCAPE_PKEY *pkey=NULL; RSA *ret=NULL; int i,j; unsigned char buf[256],*zz; unsigned char key[EVP_MAX_KEY_LENGTH]; EVP_CIPHER_CTX ctx; X509_ALGOR *alg=NULL; ASN1_OCTET_STRING *os=NULL; ASN1_CTX c; c.error=ERR_R_NESTED_ASN1_ERROR; c.pp=pp; M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(alg,d2i_X509_ALGOR); if (OBJ_obj2nid(alg->algorithm) != NID_rc4) { ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); goto err; } M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING); if (cb == NULL) cb=EVP_read_pw_string; i=cb(buf,256,"Enter Private Key password:"******"SGCKEYSALT", 10); i = 26; } EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); memset(buf,0,256); EVP_CIPHER_CTX_init(&ctx); EVP_DecryptInit(&ctx,EVP_rc4(),key,NULL); EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length); EVP_DecryptFinal(&ctx,&(os->data[i]),&j); EVP_CIPHER_CTX_cleanup(&ctx); os->length=i+j; zz=os->data; if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) { ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); goto err; } zz=pkey->private_key->data; if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) { ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); goto err; } if (!asn1_Finish(&c)) goto err; *pp=c.p; err: if (pkey != NULL) NETSCAPE_PKEY_free(pkey); if (os != NULL) M_ASN1_BIT_STRING_free(os); if (alg != NULL) X509_ALGOR_free(alg); return(ret); }