Example #1
0
RSA *d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length)
	{
	int i=ASN1_R_PARSING;
	ASN1_INTEGER *bs=NULL;
	M_ASN1_D2I_vars(a,RSA *,RSA_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn;

	M_ASN1_INTEGER_free(bs);
	bs=NULL;

	M_ASN1_D2I_Finish_2(a);

err_bn:
	i=ERR_R_BN_LIB;
err:
	ASN1err(ASN1_F_D2I_RSAPUBLICKEY,i);
	if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret);
	if (bs != NULL) M_ASN1_INTEGER_free(bs);
	return(NULL);
	}
PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length)
{
	M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR);
	M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR);
	M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM);
}
Example #3
0
X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length)
{
    M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);

    M_ASN1_D2I_Init();
    M_ASN1_D2I_start_sequence();
    M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
    M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING);
    M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG);
}
Example #4
0
PKCS12_MAC_DATA *d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **a, unsigned char **pp,
	     long length)
{
	M_ASN1_D2I_vars(a,PKCS12_MAC_DATA *,PKCS12_MAC_DATA_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->dinfo, d2i_X509_SIG);
	M_ASN1_D2I_get(ret->salt, d2i_ASN1_OCTET_STRING);
	M_ASN1_D2I_get_opt(ret->iter, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
	M_ASN1_D2I_Finish(a, PKCS12_MAC_DATA_free, ASN1_F_D2I_PKCS12_MAC_DATA);
}
Example #5
0
X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
	{
	M_ASN1_D2I_vars(a,X509 *,X509_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
	M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
	M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
	M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
	}
Example #6
0
X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, unsigned char **pp,
                                     long length)
{
    M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new);

    M_ASN1_D2I_Init();
    M_ASN1_D2I_start_sequence();
    M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
    M_ASN1_D2I_get(ret->value,d2i_ASN1_PRINTABLE);
    ret->set=0;
    M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY);
}
PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp,
	     long length)
{
	M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE);
	M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
	M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
	M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE);
	M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM);
}
Example #8
0
AC_ATTRIBUTE *d2i_AC_ATTRIBUTE(AC_ATTRIBUTE **a, VOMS_MAYBECONST unsigned char **pp, long length)
{
  M_ASN1_D2I_vars(a, AC_ATTRIBUTE *, AC_ATTRIBUTE_new);

  M_ASN1_D2I_Init();
  M_ASN1_D2I_start_sequence();
  M_ASN1_D2I_get(ret->name,      d2i_ASN1_OCTET_STRING);
  M_ASN1_D2I_get(ret->value,     d2i_ASN1_OCTET_STRING);
  M_ASN1_D2I_get(ret->qualifier, d2i_ASN1_OCTET_STRING);

  M_ASN1_D2I_Finish(a, AC_ATTRIBUTE_free, AC_F_D2I_AC_ATTRIBUTE);
}
Example #9
0
PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a, unsigned char **pp,
                                 long length)
{
    M_ASN1_D2I_vars(a,PKCS7_ENCRYPT *,PKCS7_ENCRYPT_new);

    M_ASN1_D2I_Init();
    M_ASN1_D2I_start_sequence();
    M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
    M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT);

    M_ASN1_D2I_Finish(a,PKCS7_ENCRYPT_free,ASN1_F_D2I_PKCS7_ENCRYPT);
}
Example #10
0
pkcs7_issuer_and_subject *
d2i_pkcs7_issuer_and_subject(pkcs7_issuer_and_subject **a,
		unsigned char **pp, long length) {

	M_ASN1_D2I_vars(a, pkcs7_issuer_and_subject *,
		pkcs7_issuer_and_subject_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
	M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
	M_ASN1_D2I_Finish(a,pkcs7_issuer_and_subject_free, 99);
}
Example #11
0
static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, unsigned char **pp,
	     long length)
	{
	M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
	M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
	M_ASN1_D2I_get(ret->private_key,d2i_ASN1_OCTET_STRING);
	M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY);
	}
Example #12
0
PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
	     unsigned char **pp, long length)
{
	M_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
	M_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR);
	M_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE);
	M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,
					d2i_X509_ATTRIBUTE,
					X509_ATTRIBUTE_free, 0);
	M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
}
Example #13
0
X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, unsigned char **pp,
	     long length)
	{
	M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
	M_ASN1_D2I_get(ret->public_key,d2i_ASN1_BIT_STRING);
	if (ret->pkey != NULL)
		{
		EVP_PKEY_free(ret->pkey);
		ret->pkey=NULL;
		}
	M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY);
	}
Example #14
0
X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length)
	{
	M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->algorithm,d2i_ASN1_OBJECT);
	if (!M_ASN1_D2I_end_sequence())
		{ M_ASN1_D2I_get(ret->parameter,d2i_ASN1_TYPE); }
	else
		{
		ASN1_TYPE_free(ret->parameter);
		ret->parameter=NULL;
		}
	M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR);
	}
Example #15
0
/**
 * @ingroup proxypolicy
 *
 * Converts the PROXYPOLICY from its DER encoded form
 * to an internal PROXYPOLICY structure
 *
 * @param a the PROXYPOLICY struct to set
 * @param pp the DER encoding to get the PROXYPOLICY from
 * @param length the length of the DER encoding
 * 
 * @return the resulting PROXYPOLICY in its internal structure
 * form - this variable has been allocated using _new routines, 
 * so it needs to be freed once its no longer used
 */
PROXYPOLICY * d2i_PROXYPOLICY(
    PROXYPOLICY **                      a,
    unsigned char **                    pp,
    long                                length)
{
    M_ASN1_D2I_vars(a, PROXYPOLICY *, PROXYPOLICY_new);
    
    M_ASN1_D2I_Init();
    M_ASN1_D2I_start_sequence();
    M_ASN1_D2I_get(ret->policy_language, d2i_ASN1_OBJECT);

    /* need to try getting the policy using
     *     a) a call expecting no tags
     *     b) a call expecting tags
     * one of which should succeed
     */
    
    M_ASN1_D2I_get_opt(ret->policy,
                       d2i_ASN1_OCTET_STRING,
                       V_ASN1_OCTET_STRING);
    
    M_ASN1_D2I_get_IMP_opt(ret->policy,
                           d2i_ASN1_OCTET_STRING,
                           0,
                           V_ASN1_OCTET_STRING);

    M_ASN1_D2I_Finish(a, 
                      PROXYPOLICY_free, 
                      ASN1_F_D2I_PROXYPOLICY);
}
Example #16
0
RSA *d2i_RSA_NET(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey)
	{
	RSA *ret=NULL;
	ASN1_OCTET_STRING *os=NULL;
	ASN1_CTX c;

	c.pp=pp;
	c.error=ASN1_R_DECODING_ERROR;

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
	if ((os->length != 11) || (strncmp("private-key",
		(char *)os->data,os->length) != 0))
		{
		ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
		M_ASN1_BIT_STRING_free(os);
		goto err;
		}
	M_ASN1_BIT_STRING_free(os);
	c.q=c.p;
	if ((ret=d2i_RSA_NET_2(a,&c.p,c.slen,cb, sgckey)) == NULL) goto err;
	/* Note: some versions of IIS key files use length values that are
	 * too small for the surrounding SEQUENCEs. This following line
	 * effectively disable length checking.
	 */
	c.slen = 0;

	M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
	}
Example #17
0
AC_ATT_HOLDER *d2i_AC_ATT_HOLDER(AC_ATT_HOLDER **a, VOMS_MAYBECONST unsigned char **pp, long length)
{
  M_ASN1_D2I_vars(a, AC_ATT_HOLDER *, AC_ATT_HOLDER_new);

  M_ASN1_D2I_Init();
  M_ASN1_D2I_start_sequence();
  M_ASN1_D2I_get(ret->grantor, d2i_GENERAL_NAMES);
  M_ASN1_D2I_get_seq(ret->attributes, d2i_AC_ATTRIBUTE, AC_ATTRIBUTE_free);
  M_ASN1_D2I_Finish(a, AC_ATT_HOLDER_free, ASN1_F_D2I_AC_ATT_HOLDER);
}
ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, unsigned char **pp,
	     long length)
	{
	M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);

	M_ASN1_D2I_Init();
        M_ASN1_D2I_start_sequence();
        M_ASN1_D2I_get(ret->header,d2i_ASN1_OCTET_STRING);
	if (ret->meth != NULL)
		{
		M_ASN1_D2I_get(ret->data,ret->meth->d2i);
		}
	else
		{
		if (a != NULL) (*a)=ret;
		return(ret);
		}
        M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
	}
Example #19
0
PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
	     unsigned char **pp, long length)
	{
	M_ASN1_D2I_vars(a,PKCS7_SIGNER_INFO *,PKCS7_SIGNER_INFO_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
	M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL);
	M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR);
	M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->auth_attr,
					d2i_X509_ATTRIBUTE,X509_ATTRIBUTE_free,
					0);
	M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR);
	M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING);
	M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->unauth_attr,
					d2i_X509_ATTRIBUTE,
					X509_ATTRIBUTE_free,1);

	M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free,
		ASN1_F_D2I_PKCS7_SIGNER_INFO);
	}
Example #20
0
NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
	     unsigned char **pp, long length)
{
	M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
					NETSCAPE_CERT_SEQUENCE_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
	M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
					V_ASN1_SEQUENCE);
	M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
			  ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
}
Example #21
0
RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length)
	{
	int i=ASN1_R_PARSING;
	ASN1_INTEGER *bs=NULL;
	M_ASN1_D2I_vars(a,RSA *,RSA_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if (bs->length == 0)
		ret->version=0;
	else	ret->version=bs->data[0];
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->d=BN_bin2bn(bs->data,bs->length,ret->d)) == NULL) goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->dmp1=BN_bin2bn(bs->data,bs->length,ret->dmp1)) == NULL)
		goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->dmq1=BN_bin2bn(bs->data,bs->length,ret->dmq1)) == NULL)
		goto err_bn;
	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
	if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL)
		goto err_bn;

	M_ASN1_INTEGER_free(bs);

	M_ASN1_D2I_Finish_2(a);
err_bn:
	i=ERR_R_BN_LIB;
err:
	ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i);
	if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret);
	if (bs != NULL) M_ASN1_INTEGER_free(bs);

	return(NULL);
	}
X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, unsigned char **pp,
                                   long length)
{
    M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new);

    M_ASN1_D2I_Init();
    M_ASN1_D2I_start_sequence();
    M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);

    if ((c.slen != 0) &&
            (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET)))
    {
        ret->set=1;
        M_ASN1_D2I_get_set_type(ASN1_TYPE,ret->value.set,d2i_ASN1_TYPE,
                                ASN1_TYPE_free);
    }
    else
    {
        ret->set=0;
        M_ASN1_D2I_get(ret->value.single,d2i_ASN1_TYPE);
    }

    M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE);
}
Example #23
0
X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, unsigned char **pp,
	     long length)
	{
	int i;
	M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new);

	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);

	ret->netscape_hack=0;
	if ((c.slen != 0) &&
		(M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN)))
		{
		c.q=c.p;
		if (d2i_ASN1_BOOLEAN(&i,&c.p,c.slen) < 0) goto err;
		ret->critical=i;
		c.slen-=(c.p-c.q);
		if (ret->critical == 0) ret->netscape_hack=1;
		}
	M_ASN1_D2I_get(ret->value,d2i_ASN1_OCTET_STRING);

	M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION);
	}
PKCS12_SAFEBAG *d2i_PKCS12_SAFEBAG(PKCS12_SAFEBAG **a, unsigned char **pp,
	     long length)
{
	int bagnid;
	M_ASN1_D2I_vars(a,PKCS12_SAFEBAG *,PKCS12_SAFEBAG_new);
	M_ASN1_D2I_Init();
	M_ASN1_D2I_start_sequence();
	M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
	bagnid = OBJ_obj2nid (ret->type);

	switch (bagnid) {

		case NID_keyBag:
			M_ASN1_D2I_get_EXP_opt (ret->value.keybag,
						 d2i_PKCS8_PRIV_KEY_INFO, 0);
		break;

		case NID_pkcs8ShroudedKeyBag:
			M_ASN1_D2I_get_EXP_opt (ret->value.shkeybag,
						 	d2i_X509_SIG, 0);
		break;

		case NID_safeContentsBag:
			M_ASN1_D2I_get_EXP_set_opt_type
			  (PKCS12_SAFEBAG, ret->value.safes,
			   d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free, 0,
			   V_ASN1_SEQUENCE);
		break;

		case NID_certBag:
		case NID_crlBag:
		case NID_secretBag:
			M_ASN1_D2I_get_EXP_opt (ret->value.bag,
							 d2i_PKCS12_BAGS, 0);
		break;

		default:
			M_ASN1_D2I_get_EXP_opt (ret->value.other,
							 d2i_ASN1_TYPE, 0);
		break;
	}
	M_ASN1_D2I_get_set_opt_type(X509_ATTRIBUTE,ret->attrib,
				    d2i_X509_ATTRIBUTE,X509_ATTRIBUTE_free);
	M_ASN1_D2I_Finish(a, PKCS12_SAFEBAG_free, ASN1_F_D2I_PKCS12_SAFEBAG);
}
Example #25
0
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
}
Example #26
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
}
Example #27
0
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);
	}