Run through more code in PKCS#8 and SPKI parsers

Bug: 438886851
Change-Id: I10f2575889135b94b5a5104a44568e3ac39b442c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81369
Commit-Queue: Lily Chen <chlily@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
This commit is contained in:
David Benjamin
2025-08-15 13:23:44 -04:00
committed by Boringssl LUCI CQ
parent 4d0dfef2f0
commit e3727310c6
2 changed files with 27 additions and 24 deletions
+15 -12
View File
@@ -13,6 +13,7 @@
// limitations under the License.
#include <openssl/crypto.h>
#include <openssl/bio.h>
#include <openssl/bytestring.h>
#include <openssl/err.h>
#include <openssl/evp.h>
@@ -25,21 +26,23 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
CBS cbs;
CBS_init(&cbs, buf, len);
EVP_PKEY *pkey = EVP_parse_private_key(&cbs);
if (pkey == NULL) {
bssl::UniquePtr<EVP_PKEY> pkey(EVP_parse_private_key(&cbs));
if (pkey == nullptr) {
ERR_clear_error();
return 0;
}
uint8_t *der;
size_t der_len;
CBB cbb;
if (CBB_init(&cbb, 0) &&
EVP_marshal_private_key(&cbb, pkey) &&
CBB_finish(&cbb, &der, &der_len)) {
OPENSSL_free(der);
}
CBB_cleanup(&cbb);
EVP_PKEY_free(pkey);
// Every parsed private key should be serializable.
bssl::ScopedCBB cbb;
BSSL_CHECK(CBB_init(cbb.get(), 0));
BSSL_CHECK(EVP_marshal_public_key(cbb.get(), pkey.get()));
BSSL_CHECK(EVP_marshal_private_key(cbb.get(), pkey.get()));
bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
EVP_PKEY_print_params(bio.get(), pkey.get(), 0, nullptr);
EVP_PKEY_print_public(bio.get(), pkey.get(), 0, nullptr);
EVP_PKEY_print_private(bio.get(), pkey.get(), 0, nullptr);
ERR_clear_error();
return 0;
}
+12 -12
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <openssl/bio.h>
#include <openssl/bytestring.h>
#include <openssl/err.h>
#include <openssl/evp.h>
@@ -20,22 +21,21 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
CBS cbs;
CBS_init(&cbs, buf, len);
EVP_PKEY *pkey = EVP_parse_public_key(&cbs);
if (pkey == NULL) {
bssl::UniquePtr<EVP_PKEY> pkey(EVP_parse_public_key(&cbs));
if (pkey == nullptr) {
ERR_clear_error();
return 0;
}
uint8_t *der;
size_t der_len;
CBB cbb;
if (CBB_init(&cbb, 0) &&
EVP_marshal_public_key(&cbb, pkey) &&
CBB_finish(&cbb, &der, &der_len)) {
OPENSSL_free(der);
}
CBB_cleanup(&cbb);
EVP_PKEY_free(pkey);
// Every parsed public key should be serializable.
bssl::ScopedCBB cbb;
BSSL_CHECK(CBB_init(cbb.get(), 0));
BSSL_CHECK(EVP_marshal_public_key(cbb.get(), pkey.get()));
bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
EVP_PKEY_print_params(bio.get(), pkey.get(), 0, nullptr);
EVP_PKEY_print_public(bio.get(), pkey.get(), 0, nullptr);
ERR_clear_error();
return 0;
}