/* Return BIO based on EncryptedContentInfo and key */
BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
- const CMS_CTX *cms_ctx)
+ const CMS_CTX *cms_ctx, int auth)
{
BIO *b;
EVP_CIPHER_CTX *ctx;
goto err;
}
if ((EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) {
+ if (!auth) {
+ ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_AEAD_IN_ENVELOPED_DATA);
+ goto err;
+ }
piv = aparams.iv;
if (ec->taglen > 0
&& EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
if (enc->encryptedContentInfo->cipher && enc->unprotectedAttrs)
enc->version = 2;
return ossl_cms_EncryptedContent_init_bio(enc->encryptedContentInfo,
- ossl_cms_get0_cmsctx(cms));
+ ossl_cms_get0_cmsctx(cms), 0);
}
{
CMS_EncryptedContentInfo *ec = cms->d.envelopedData->encryptedContentInfo;
BIO *contentBio = ossl_cms_EncryptedContent_init_bio(ec,
- ossl_cms_get0_cmsctx(cms));
+ ossl_cms_get0_cmsctx(cms),
+ 0);
EVP_CIPHER_CTX *ctx = NULL;
if (contentBio == NULL)
/* Get BIO first to set up key */
ec = env->encryptedContentInfo;
- ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms));
+ ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms), 0);
/* If error end of processing */
if (!ret)
ec->tag = aenv->mac->data;
ec->taglen = aenv->mac->length;
}
- ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms));
+ ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms), 1);
/* If error or no cipher end of processing */
if (ret == NULL || ec->cipher == NULL)
"certificate has no keyid"},
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_VERIFY_ERROR),
"certificate verify error"},
+ {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_AEAD_IN_ENVELOPED_DATA),
+ "cipher aead in enveloped data"},
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_AEAD_SET_TAG_ERROR),
"cipher aead set tag error"},
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_GET_TAG), "cipher get tag"},
int ossl_cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert);
BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
- const CMS_CTX *ctx);
+ const CMS_CTX *ctx, int auth);
BIO *ossl_cms_EncryptedData_init_bio(const CMS_ContentInfo *cms);
int ossl_cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
const EVP_CIPHER *cipher,
CMS_R_CERTIFICATE_ALREADY_PRESENT:175:certificate already present
CMS_R_CERTIFICATE_HAS_NO_KEYID:160:certificate has no keyid
CMS_R_CERTIFICATE_VERIFY_ERROR:100:certificate verify error
+CMS_R_CIPHER_AEAD_IN_ENVELOPED_DATA:200:cipher aead in enveloped data
CMS_R_CIPHER_AEAD_SET_TAG_ERROR:184:cipher aead set tag error
CMS_R_CIPHER_GET_TAG:185:cipher get tag
CMS_R_CIPHER_INITIALISATION_ERROR:101:cipher initialisation error
# define CMS_R_CERTIFICATE_ALREADY_PRESENT 175
# define CMS_R_CERTIFICATE_HAS_NO_KEYID 160
# define CMS_R_CERTIFICATE_VERIFY_ERROR 100
+# define CMS_R_CIPHER_AEAD_IN_ENVELOPED_DATA 200
# define CMS_R_CIPHER_AEAD_SET_TAG_ERROR 184
# define CMS_R_CIPHER_GET_TAG 185
# define CMS_R_CIPHER_INITIALISATION_ERROR 101
--- /dev/null
+-----BEGIN PKCS7-----
+MIAGCSqGSIb3DQEHA6CAMIACAQIxNqI0AgEEMAgEBkMwRkVFMDALBglghkgBZQME
+AQUEGPN0q9rM3neSiY7HIADpnqWym33mRZC4JDCABgkqhkiG9w0BBwEwHgYJYIZI
+AWUDBAEGMBEEDIExQGiHZFSYa0ZBqQIBEKCABGNap+JL1B21Mq7ojKPzVuxtRkg3
+LWt8khnK1EzfmV7e64l5KnTdjq9+gfbwOfbuhTavfBI7VK/ZtpH3HII4fCOe37kV
+mju8/YnYeRq2KcxESmJBySV/veMwxqmHGAw71JyHpg4AAAAAAAAAAAAA
+-----END PKCS7-----
CMS_TEXT)))
goto end;
- if (!TEST_ptr(contentbio =
- CMS_EnvelopedData_decrypt(content->d.envelopedData,
- NULL, privkey, cert, NULL,
- CMS_TEXT, NULL, NULL)))
+ if (!(EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)
+ && !TEST_ptr(contentbio =
+ CMS_EnvelopedData_decrypt(content->d.envelopedData,
+ NULL, privkey, cert, NULL,
+ CMS_TEXT, NULL, NULL)))
goto end;
/* Check we got the message we first started with */
$no_rc2 = 1 if disabled("legacy");
-plan tests => 32;
+plan tests => 33;
ok(run(test(["pkcs7_test"])), "test pkcs7");
])),
"issue#19643");
+# Check that users get error when using incorrect envelope type for AEAD algorithms
+ok(!run(app(['openssl', 'cms', '-decrypt',
+ '-inform', 'PEM', '-stream',
+ '-secretkey', '000102030405060708090A0B0C0D0E0F',
+ '-secretkeyid', 'C0FEE0',
+ '-in', srctop_file("test/cms-msg",
+ "enveloped-content-type-for-aes-gcm.pem")
+ ])),
+ "Error AES-GCM in enveloped content type");
+
# Check that kari encryption with originator does not segfault
with({ exit_checker => sub { return shift == 3; } },
sub {