コード例 #1
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);
	}
コード例 #2
0
void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
{
    if (a == NULL) return;
    ASN1_OBJECT_free(a->object);
    M_ASN1_BIT_STRING_free(a->value);
    OPENSSL_free(a);
}
コード例 #3
0
ファイル: a_bitstr.c プロジェクト: gdzhu/opensgx
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
                                     const unsigned char **pp, long len)
{
    ASN1_BIT_STRING *ret = NULL;
    const unsigned char *p;
    unsigned char *s;
    int i;

    if (len < 1) {
        i = ASN1_R_STRING_TOO_SHORT;
        goto err;
    }

    if ((a == NULL) || ((*a) == NULL)) {
        if ((ret = M_ASN1_BIT_STRING_new()) == NULL)
            return (NULL);
    } else
        ret = (*a);

    p = *pp;
    i = *(p++);
    if (i > 7) {
        i = ASN1_R_INVALID_BIT_STRING_BITS_LEFT;
        goto err;
    }
    /*
     * We do this to preserve the settings.  If we modify the settings, via
     * the _set_bit function, we will recalculate on output
     */
    ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
    ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */

    if (len-- > 1) {            /* using one because of the bits left byte */
        s = (unsigned char *)OPENSSL_malloc((int)len);
        if (s == NULL) {
            i = ERR_R_MALLOC_FAILURE;
            goto err;
        }
        sgx_memcpy(s, p, (int)len);
        s[len - 1] &= (0xff << i);
        p += len;
    } else
        s = NULL;

    ret->length = (int)len;
    if (ret->data != NULL)
        OPENSSL_free(ret->data);
    ret->data = s;
    ret->type = V_ASN1_BIT_STRING;
    if (a != NULL)
        (*a) = ret;
    *pp = p;
    return (ret);
 err:
    ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i);
    if ((ret != NULL) && ((a == NULL) || (*a != ret)))
        M_ASN1_BIT_STRING_free(ret);
    return (NULL);
}
コード例 #4
0
void X509_PUBKEY_free(X509_PUBKEY *a)
	{
	if (a == NULL) return;
	X509_ALGOR_free(a->algor);
	M_ASN1_BIT_STRING_free(a->public_key);
	if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
	OPENSSL_free(a);
	}
コード例 #5
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);
	}