Skip to content

Commit f53191b

Browse files
authored
Merge pull request wolfSSL#9416 from julek-wolfssl/priv-key-blinding
Fix errors when blinding private keys
2 parents e78752f + 32911dc commit f53191b

File tree

3 files changed

+53
-35
lines changed

3 files changed

+53
-35
lines changed

.github/workflows/os-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
'--enable-dtls --enable-dtls13 --enable-ocspstapling --enable-ocspstapling2
6565
--enable-cert-setup-cb --enable-sessioncerts',
6666
'--disable-sni --disable-ecc --disable-tls13 --disable-secure-renegotiation-info',
67+
'CPPFLAGS=-DWOLFSSL_BLIND_PRIVATE_KEY',
6768
]
6869
name: make check
6970
if: github.repository_owner == 'wolfssl'

src/ssl_load.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,26 +1354,31 @@ static int ProcessBufferPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
13541354
#endif /* WOLFSSL_ENCRYPTED_KEYS && !NO_PWDBASED */
13551355

13561356
#ifdef WOLFSSL_BLIND_PRIVATE_KEY
1357+
{
1358+
int blindRet = 0;
13571359
#ifdef WOLFSSL_DUAL_ALG_CERTS
1358-
if (type == ALT_PRIVATEKEY_TYPE) {
1360+
if (type == ALT_PRIVATEKEY_TYPE) {
1361+
if (ssl != NULL) {
1362+
blindRet = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.altKey,
1363+
&ssl->buffers.altKeyMask);
1364+
}
1365+
else {
1366+
blindRet = wolfssl_priv_der_blind(NULL, ctx->altPrivateKey,
1367+
&ctx->altPrivateKeyMask);
1368+
}
1369+
}
1370+
else
1371+
#endif
13591372
if (ssl != NULL) {
1360-
ret = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.altKey,
1361-
&ssl->buffers.altKeyMask);
1373+
blindRet = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.key,
1374+
&ssl->buffers.keyMask);
13621375
}
13631376
else {
1364-
ret = wolfssl_priv_der_blind(NULL, ctx->altPrivateKey,
1365-
&ctx->altPrivateKeyMask);
1377+
blindRet = wolfssl_priv_der_blind(NULL, ctx->privateKey,
1378+
&ctx->privateKeyMask);
13661379
}
1367-
}
1368-
else
1369-
#endif
1370-
if (ssl != NULL) {
1371-
ret = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.key,
1372-
&ssl->buffers.keyMask);
1373-
}
1374-
else {
1375-
ret = wolfssl_priv_der_blind(NULL, ctx->privateKey,
1376-
&ctx->privateKeyMask);
1380+
if (ret == 0 && blindRet != 0)
1381+
ret = blindRet;
13771382
}
13781383
#endif
13791384

tests/api.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50626,6 +50626,8 @@ static int test_wolfSSL_inject(void)
5062650626
struct test_memio_ctx test_ctx;
5062750627
WOLFSSL_ALERT_HISTORY h;
5062850628
int rounds;
50629+
int hs_c = 0;
50630+
int hs_s = 0;
5062950631

5063050632
printf("Testing %s\n", params[i].tls_version);
5063150633

@@ -50635,31 +50637,41 @@ static int test_wolfSSL_inject(void)
5063550637
params[i].client_meth, params[i].server_meth), 0);
5063650638

5063750639
for (rounds = 0; rounds < 10 && EXPECT_SUCCESS(); rounds++) {
50638-
wolfSSL_SetLoggingPrefix("client");
50639-
if (wolfSSL_negotiate(ssl_c) != 1) {
50640-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
50641-
WOLFSSL_ERROR_WANT_READ);
50642-
}
50643-
wolfSSL_SetLoggingPrefix("server");
50644-
if (test_ctx.s_len > 0) {
50645-
ExpectIntEQ(wolfSSL_inject(ssl_s, test_ctx.s_buff,
50646-
test_ctx.s_len), 1);
50647-
test_memio_clear_buffer(&test_ctx, 0);
50640+
if (!hs_c) {
50641+
wolfSSL_SetLoggingPrefix("client");
50642+
if (wolfSSL_negotiate(ssl_c) != 1) {
50643+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
50644+
WOLFSSL_ERROR_WANT_READ);
50645+
}
50646+
else
50647+
hs_c = 1;
5064850648
}
50649-
if (wolfSSL_negotiate(ssl_s) != 1) {
50650-
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
50651-
WOLFSSL_ERROR_WANT_READ);
50649+
if (!hs_s) {
50650+
wolfSSL_SetLoggingPrefix("server");
50651+
if (test_ctx.s_len > 0) {
50652+
ExpectIntEQ(wolfSSL_inject(ssl_s, test_ctx.s_buff,
50653+
test_ctx.s_len), 1);
50654+
test_memio_clear_buffer(&test_ctx, 0);
50655+
}
50656+
if (wolfSSL_negotiate(ssl_s) != 1) {
50657+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
50658+
WOLFSSL_ERROR_WANT_READ);
50659+
}
50660+
else
50661+
hs_s = 1;
5065250662
}
50653-
wolfSSL_SetLoggingPrefix("client");
50654-
if (test_ctx.c_len > 0) {
50655-
ExpectIntEQ(wolfSSL_inject(ssl_c, test_ctx.c_buff,
50656-
test_ctx.c_len), 1);
50657-
test_memio_clear_buffer(&test_ctx, 1);
50663+
if (!hs_c) {
50664+
wolfSSL_SetLoggingPrefix("client");
50665+
if (test_ctx.c_len > 0) {
50666+
ExpectIntEQ(wolfSSL_inject(ssl_c, test_ctx.c_buff,
50667+
test_ctx.c_len), 1);
50668+
test_memio_clear_buffer(&test_ctx, 1);
50669+
}
5065850670
}
5065950671
wolfSSL_SetLoggingPrefix(NULL);
5066050672
}
50661-
ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
50662-
ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
50673+
ExpectIntEQ(hs_c, 1);
50674+
ExpectIntEQ(hs_s, 1);
5066350675

5066450676
wolfSSL_free(ssl_c);
5066550677
wolfSSL_free(ssl_s);

0 commit comments

Comments
 (0)