From 29ce7166155b54e0d0f908ee93c4f795489d8add Mon Sep 17 00:00:00 2001 From: Kareem Date: Tue, 1 Apr 2025 14:07:31 -0700 Subject: [PATCH] Add test case for parsing PKCS8 key with existing header. --- tests/api.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/api.c b/tests/api.c index 0a0913586..e103f386e 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33039,6 +33039,21 @@ static int test_wolfSSL_PKCS8_d2i(void) evpPkey = NULL; BIO_free(bio); bio = NULL; + + /* https://github.com/wolfSSL/wolfssl/issues/8610 */ + bytes = (int)XSTRLEN((void*)pkcs8_buffer); + ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes)); + ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes); + ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0); + + ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, + (void*)"yassl123")); + ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, evpPkey, NULL, + NULL, 0, NULL, NULL), bytes); + EVP_PKEY_free(evpPkey); + evpPkey = NULL; + BIO_free(bio); + bio = NULL; #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */ EVP_PKEY_free(pkey); pkey = NULL;