PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
	{
	PKCS7_RECIP_INFO *ri;

	if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
	if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
	if (!PKCS7_add_recipient_info(p7,ri)) goto err;
	return(ri);
err:
	return(NULL);
	}
static VALUE
ossl_pkcs7ri_new(PKCS7_RECIP_INFO *p7ri)
{
    PKCS7_RECIP_INFO *pkcs7;
    VALUE obj;

    pkcs7 = p7ri ? PKCS7_RECIP_INFO_dup(p7ri) : PKCS7_RECIP_INFO_new();
    if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
    WrapPKCS7ri(cPKCS7Recipient, obj, pkcs7);

    return obj;
}
/*
 * RECIPIENT INFO
 */
static VALUE
ossl_pkcs7ri_alloc(VALUE klass)
{
    PKCS7_RECIP_INFO *p7ri;
    VALUE obj;

    if (!(p7ri = PKCS7_RECIP_INFO_new())) {
	ossl_raise(ePKCS7Error, NULL);
    }
    WrapPKCS7ri(klass, obj, p7ri);

    return obj;
}
Пример #4
0
static VALUE
ossl_pkcs7ri_new(PKCS7_RECIP_INFO *p7ri)
{
    PKCS7_RECIP_INFO *pkcs7;
    VALUE obj;

    obj = NewPKCS7ri(cPKCS7Recipient);
    pkcs7 = p7ri ? ossl_PKCS7_RECIP_INFO_dup(p7ri) : PKCS7_RECIP_INFO_new();
    if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
    SetPKCS7ri(obj, pkcs7);

    return obj;
}
Пример #5
0
void openssl_pkcs7_enveloped()
{
	int len;
	FILE *fp;
	PKCS7 *p7;
	PKCS7_RECIP_INFO *inf;
	unsigned char *der, *p;
	const unsigned char edata[COMM_LEN] = "info....";
	const unsigned char ekeys[COMM_LEN] = "key info....";

	p7 = PKCS7_new();
	PKCS7_set_type(p7, NID_pkcs7_enveloped);
	ASN1_INTEGER_set(p7->d.enveloped->version, 3);

	inf = PKCS7_RECIP_INFO_new();
	ASN1_INTEGER_set(inf->version, 4);
	ASN1_INTEGER_set(inf->issuer_and_serial->serial, 888888);
	inf->key_enc_algor->algorithm = OBJ_nid2obj(NID_des_ede3_cbc);
	ASN1_OCTET_STRING_set(inf->enc_key, ekeys, 12);
	sk_PKCS7_RECIP_INFO_push(p7->d.enveloped->recipientinfo, inf);

	p7->d.enveloped->enc_data->algorithm->algorithm =
		OBJ_nid2obj(NID_des_ede3_cbc);
	p7->d.enveloped->enc_data->enc_data = ASN1_OCTET_STRING_new();
	ASN1_OCTET_STRING_set(p7->d.enveloped->enc_data->enc_data, edata, 8);

	len = i2d_PKCS7(p7, NULL);
	der = (unsigned char *)malloc(len);
	p = der;
	len = i2d_PKCS7(p7, &p);
	fp = fopen("/tmp/test.cer", "wb");
	fwrite(der, 1, len, fp);
	fclose(fp);

	free(der);
	PKCS7_free(p7);

	p7 = PKCS7_new();
	PKCS7_set_type(p7, NID_pkcs7_signedAndEnveloped);
	len = i2d_PKCS7(p7, NULL);
	der = (unsigned char *)malloc(len);
	p = der;
	len = i2d_PKCS7(p7, &p);
	fp = fopen("/tmp/testEnv.cer", "wb");
	fwrite(der, 1, len, fp);
	fclose(fp);

	PKCS7_free(p7);
	free(der);
}