From 9a1682eb6351753ac323c8a94e56eb9805c08d79 Mon Sep 17 00:00:00 2001 From: samuel40791765 Date: Wed, 18 Dec 2024 00:56:08 +0000 Subject: [PATCH] Add PKCS7_print_ctx as a no-op --- crypto/pkcs7/pkcs7_asn1.c | 10 ++++++++++ crypto/pkcs7/pkcs7_test.cc | 11 +++++++++++ include/openssl/pkcs7.h | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/crypto/pkcs7/pkcs7_asn1.c b/crypto/pkcs7/pkcs7_asn1.c index d1bc0c0f74e..4fb6881a673 100644 --- a/crypto/pkcs7/pkcs7_asn1.c +++ b/crypto/pkcs7/pkcs7_asn1.c @@ -186,3 +186,13 @@ ASN1_SEQUENCE(PKCS7_ENVELOPE) = { PKCS7_ENC_CONTENT)} ASN1_SEQUENCE_END(PKCS7_ENVELOPE) IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE) + +int PKCS7_print_ctx(BIO *bio, PKCS7 *pkcs7, int indent, const ASN1_PCTX *pctx) { + GUARD_PTR(bio); + GUARD_PTR(pkcs7); + + if (BIO_printf(bio, "PKCS7 printing is not supported") <= 0) { + return 0; + } + return 1; +} diff --git a/crypto/pkcs7/pkcs7_test.cc b/crypto/pkcs7/pkcs7_test.cc index b24a59230b1..b901f8e7dbf 100644 --- a/crypto/pkcs7/pkcs7_test.cc +++ b/crypto/pkcs7/pkcs7_test.cc @@ -2032,3 +2032,14 @@ TEST(PKCS7Test, TestSigned) { EXPECT_FALSE(PKCS7_verify(p7.get(), certs.get(), store.get(), bio_in.get(), bio_out.get(), /*flags*/ 0)); } + +TEST(PKCS7Test, PKCS7PrintNoop) { + bssl::UniquePtr bio(BIO_new(BIO_s_mem())); + bssl::UniquePtr p7(PKCS7_new()); + ASSERT_TRUE(PKCS7_print_ctx(bio.get(), p7.get(), 0, nullptr)); + + const uint8_t *contents; + size_t len; + ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len)); + EXPECT_EQ(Bytes(contents, len), Bytes("PKCS7 printing is not supported")); +} diff --git a/include/openssl/pkcs7.h b/include/openssl/pkcs7.h index b53ebe68e20..bb930566e94 100644 --- a/include/openssl/pkcs7.h +++ b/include/openssl/pkcs7.h @@ -523,6 +523,11 @@ OPENSSL_EXPORT OPENSSL_DEPRECATED PKCS7 *SMIME_read_PKCS7(BIO *in, BIO **bcont); OPENSSL_EXPORT OPENSSL_DEPRECATED int SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags); +// PKCS7_print_ctx prints "PKCS7 printing is not supported" and returns 1. +OPENSSL_EXPORT OPENSSL_DEPRECATED int PKCS7_print_ctx(BIO *bio, PKCS7 *pkcs7, + int indent, + const ASN1_PCTX *pctx); + #if defined(__cplusplus) } // extern C