@@ -1696,6 +1696,68 @@ static int test_dual_alg_ecdsa_mldsa(void)
16961696 return EXPECT_RESULT();
16971697}
16981698
1699+ /* Test wolfSSL_use_AltPrivateKey_Id.
1700+ * Verify that a valid key ID can be set successfully. Guards against an
1701+ * inverted AllocDer return check (== 0 vs != 0) that would treat successful
1702+ * allocation as failure. */
1703+ static int test_wolfSSL_use_AltPrivateKey_Id(void)
1704+ {
1705+ EXPECT_DECLS;
1706+ #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_TLS) && \
1707+ !defined(NO_WOLFSSL_CLIENT)
1708+ WOLFSSL_CTX* ctx = NULL;
1709+ WOLFSSL* ssl = NULL;
1710+ const unsigned char id[] = { 0x01, 0x02, 0x03, 0x04 };
1711+
1712+ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
1713+ ExpectNotNull(ssl = wolfSSL_new(ctx));
1714+
1715+ /* Negative tests. */
1716+ ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(NULL, id, sizeof(id),
1717+ INVALID_DEVID), 0);
1718+ ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(ssl, NULL, sizeof(id),
1719+ INVALID_DEVID), 0);
1720+
1721+ /* Positive test - valid ID should succeed. */
1722+ ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(ssl, id, sizeof(id),
1723+ INVALID_DEVID), 1);
1724+
1725+ wolfSSL_free(ssl);
1726+ wolfSSL_CTX_free(ctx);
1727+ #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_TLS && !NO_WOLFSSL_CLIENT */
1728+ return EXPECT_RESULT();
1729+ }
1730+
1731+ /* Test wolfSSL_use_AltPrivateKey_Label.
1732+ * Verify that a valid key label can be set successfully. Guards against an
1733+ * inverted AllocDer return check (== 0 vs != 0) that would treat successful
1734+ * allocation as failure. */
1735+ static int test_wolfSSL_use_AltPrivateKey_Label(void)
1736+ {
1737+ EXPECT_DECLS;
1738+ #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_TLS) && \
1739+ !defined(NO_WOLFSSL_CLIENT)
1740+ WOLFSSL_CTX* ctx = NULL;
1741+ WOLFSSL* ssl = NULL;
1742+
1743+ ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
1744+ ExpectNotNull(ssl = wolfSSL_new(ctx));
1745+
1746+ /* Negative tests. */
1747+ ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(NULL, "label", INVALID_DEVID),
1748+ 0);
1749+ ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, NULL, INVALID_DEVID), 0);
1750+
1751+ /* Positive test - valid label should succeed. */
1752+ ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, "test_label",
1753+ INVALID_DEVID), 1);
1754+
1755+ wolfSSL_free(ssl);
1756+ wolfSSL_CTX_free(ctx);
1757+ #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_TLS && !NO_WOLFSSL_CLIENT */
1758+ return EXPECT_RESULT();
1759+ }
1760+
16991761
17001762/*----------------------------------------------------------------------------*
17011763 | Context
@@ -3505,6 +3567,11 @@ static int test_wolfSSL_CTX_add1_chain_cert(void)
35053567 }
35063568
35073569 ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
3570+ /* add1 must increment ref count (was 1, now 2). Verifies the
3571+ * up_ref return value is assigned, not just compared. */
3572+ if (EXPECT_SUCCESS() && x509 != NULL) {
3573+ ExpectIntEQ(wolfSSL_RefCur(x509->ref), 2);
3574+ }
35083575 X509_free(x509);
35093576 x509 = NULL;
35103577 }
@@ -3524,6 +3591,10 @@ static int test_wolfSSL_CTX_add1_chain_cert(void)
35243591 }
35253592
35263593 ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
3594+ /* add1 must increment ref count (was 1, now 2) */
3595+ if (EXPECT_SUCCESS() && x509 != NULL) {
3596+ ExpectIntEQ(wolfSSL_RefCur(x509->ref), 2);
3597+ }
35273598 X509_free(x509);
35283599 x509 = NULL;
35293600 }
@@ -13248,6 +13319,64 @@ static int test_wolfSSL_tmp_dh(void)
1324813319 return EXPECT_RESULT();
1324913320}
1325013321
13322+ /* Tests SSL_CTX_set_tmp_dh with single-operand failure (p set, g missing)
13323+ * and wolfSSL_CTX_SetTmpDH_buffer with WOLFSSL_FILETYPE_ASN1 DER input. */
13324+ static int test_wolfSSL_tmp_dh_regression(void)
13325+ {
13326+ EXPECT_DECLS;
13327+ #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && !defined(NO_CERTS) && \
13328+ !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_TLS) && \
13329+ !defined(NO_WOLFSSL_SERVER)
13330+ SSL_CTX* ctx = NULL;
13331+
13332+ ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
13333+ ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
13334+ WOLFSSL_FILETYPE_PEM));
13335+ ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
13336+ WOLFSSL_FILETYPE_PEM));
13337+
13338+ #if defined(OPENSSL_ALL) || \
13339+ (defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L)
13340+ {
13341+ /* Test single-operand failure: DH with p but no g. */
13342+ DH* dh = NULL;
13343+ WOLFSSL_BIGNUM* p_bn = NULL;
13344+
13345+ ExpectNotNull(dh = wolfSSL_DH_new());
13346+ ExpectNotNull(p_bn = wolfSSL_BN_new());
13347+ ExpectIntEQ(wolfSSL_BN_set_word(p_bn, 0xFFFF), 1);
13348+ if (dh != NULL && p_bn != NULL) {
13349+ if (wolfSSL_DH_set0_pqg(dh, p_bn, NULL, NULL) == 1) {
13350+ p_bn = NULL; /* ownership transferred on success */
13351+ }
13352+ }
13353+ ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_FATAL_ERROR);
13354+ DH_free(dh);
13355+ wolfSSL_BN_free(p_bn);
13356+ }
13357+ #endif
13358+
13359+ /* Test ASN1/DER path through wolfSSL_CTX_SetTmpDH_buffer. */
13360+ {
13361+ byte derBuf[4096];
13362+ XFILE f = XBADFILE;
13363+ int derSz = 0;
13364+
13365+ ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
13366+ if (f != XBADFILE) {
13367+ derSz = (int)XFREAD(derBuf, 1, sizeof(derBuf), f);
13368+ XFCLOSE(f);
13369+ }
13370+ ExpectIntGT(derSz, 0);
13371+ ExpectIntEQ(wolfSSL_CTX_SetTmpDH_buffer(ctx, derBuf, (long)derSz,
13372+ WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
13373+ }
13374+
13375+ SSL_CTX_free(ctx);
13376+ #endif
13377+ return EXPECT_RESULT();
13378+ }
13379+
1325113380static int test_wolfSSL_ctrl(void)
1325213381{
1325313382 EXPECT_DECLS;
@@ -35313,6 +35442,9 @@ TEST_CASE testCases[] = {
3531335442
3531435443 TEST_DECL(test_dual_alg_ecdsa_mldsa),
3531535444
35445+ TEST_DECL(test_wolfSSL_use_AltPrivateKey_Id),
35446+ TEST_DECL(test_wolfSSL_use_AltPrivateKey_Label),
35447+
3531635448 /*********************************
3531735449 * OpenSSL compatibility API tests
3531835450 *********************************/
@@ -35584,6 +35716,7 @@ TEST_CASE testCases[] = {
3558435716 TEST_TLS13_DECLS,
3558535717
3558635718 TEST_DECL(test_wolfSSL_tmp_dh),
35719+ TEST_DECL(test_wolfSSL_tmp_dh_regression),
3558735720 TEST_DECL(test_wolfSSL_ctrl),
3558835721
3558935722 TEST_DECL(test_wolfSSL_get0_param),
0 commit comments