CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, const unsigned char *key, size_t keylen, unsigned int flags) { CMS_ContentInfo *cms; if (!cipher) { CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER); return NULL; } cms = CMS_ContentInfo_new(); if (!cms) return NULL; if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) return NULL; if(!(flags & CMS_DETACHED)) CMS_set_detached(cms, 0); if ((flags & (CMS_STREAM|CMS_PARTIAL)) || CMS_final(cms, in, NULL, flags)) return cms; CMS_ContentInfo_free(cms); return NULL; }
CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) { CMS_ContentInfo *cms; CMS_DigestedData *dd; cms = CMS_ContentInfo_new(); if (!cms) return NULL; dd = M_ASN1_new_of(CMS_DigestedData); if (!dd) goto err; cms->contentType = OBJ_nid2obj(NID_pkcs7_digest); cms->d.digestedData = dd; dd->version = 0; dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); cms_DigestAlgorithm_set(dd->digestAlgorithm, md); return cms; err: if (cms) CMS_ContentInfo_free(cms); return NULL; }
static int openssl_cms_create(lua_State*L) { CMS_ContentInfo *cms = NULL; if (lua_gettop(L) == 1) { cms = CMS_ContentInfo_new(); } else { BIO* in = load_bio_object(L, 1); if (lua_isuserdata(L, 2)) { const EVP_MD* md = get_digest(L, 2); int flags = luaL_optint(L, 3, 0); cms = CMS_digest_create(in, md, flags); } else { int flags = luaL_optint(L, 2, 0); cms = CMS_data_create(in, flags); } } PUSH_OBJECT(cms, "openssl.cms"); return 1; }
static VALUE ossl_cms_s_read_cms(VALUE klass, VALUE arg) { BIO *in; CMS_ContentInfo *cms, *out; VALUE ret; arg = ossl_to_der_if_possible(arg); in = ossl_obj2bio(arg); out = CMS_ContentInfo_new(); cms = PEM_read_bio_CMS(in, &out, NULL, NULL); if (!cms) { OSSL_BIO_reset(in); cms = d2i_CMS_bio(in, &out); if (!cms) { BIO_free(in); CMS_ContentInfo_free(out); ossl_raise(rb_eArgError, "Could not parse the CMS"); } } WrapCMS(cCMS, ret, cms); BIO_free(in); ossl_cms_set_data(ret, Qnil); ossl_cms_set_err_string(ret, Qnil); return ret; }
CMS_ContentInfo *cms_Data_create(void) { CMS_ContentInfo *cms; cms = CMS_ContentInfo_new(); if (cms) { cms->contentType = OBJ_nid2obj(NID_pkcs7_data); /* Never detached */ CMS_set_detached(cms, 0); } return cms; }
static VALUE ossl_cms_alloc(VALUE klass) { CMS_ContentInfo *cms; VALUE obj; if (!(cms = CMS_ContentInfo_new())) { ossl_raise(eCMSError, NULL); } WrapCMS(klass, obj, cms); return obj; }
CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher) { CMS_ContentInfo *cms; CMS_EnvelopedData *env; cms = CMS_ContentInfo_new(); if (!cms) goto merr; env = cms_enveloped_data_init(cms); if (!env) goto merr; if (!cms_EncryptedContent_init(env->encryptedContentInfo, cipher, NULL, 0)) goto merr; return cms; merr: CMS_ContentInfo_free(cms); CMSerr(CMS_F_CMS_ENVELOPEDDATA_CREATE, ERR_R_MALLOC_FAILURE); return NULL; }
CMS_ContentInfo *cms_CompressedData_create(int comp_nid) { CMS_ContentInfo *cms; CMS_CompressedData *cd; /* Will need something cleverer if there is ever more than one * compression algorithm or parameters have some meaning... */ if (comp_nid != NID_zlib_compression) { CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); return NULL; } cms = CMS_ContentInfo_new(); if (!cms) return NULL; cd = M_ASN1_new_of(CMS_CompressedData); if (!cd) goto err; cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData); cms->d.compressedData = cd; cd->version = 0; X509_ALGOR_set0(cd->compressionAlgorithm, OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL); cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); return cms; err: if (cms) CMS_ContentInfo_free(cms); return NULL; }