From cadea76e43859e09932d4c63dbaea09dff356fa5 Mon Sep 17 00:00:00 2001 From: effbiae Date: Sun, 12 Oct 2025 12:28:07 +1100 Subject: [PATCH] refactor wolfSSL_CTX_set_srp_username --- src/ssl.c | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 9241ae5c1..4b7db033c 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -12757,7 +12757,6 @@ cleanup: { int r = 0; SrpSide srp_side = SRP_CLIENT_SIDE; - byte salt[SRP_SALT_SIZE]; WOLFSSL_ENTER("wolfSSL_CTX_set_srp_username"); if (ctx == NULL || ctx->srp == NULL || username==NULL) @@ -12786,37 +12785,11 @@ cleanup: } /* if wolfSSL_CTX_set_srp_password has already been called, */ - /* execute wc_SrpSetPassword here */ + /* use saved password here */ if (ctx->srp_password != NULL) { - WC_RNG rng; - if (wc_InitRng(&rng) < 0){ - WOLFSSL_MSG("wc_InitRng failed"); + if (ctx->srp->user == NULL) return WOLFSSL_FAILURE; - } - XMEMSET(salt, 0, sizeof(salt)/sizeof(salt[0])); - r = wc_RNG_GenerateBlock(&rng, salt, sizeof(salt)/sizeof(salt[0])); - wc_FreeRng(&rng); - if (r < 0) { - WOLFSSL_MSG("wc_RNG_GenerateBlock failed"); - return WOLFSSL_FAILURE; - } - - if (wc_SrpSetParams(ctx->srp, srp_N, sizeof(srp_N)/sizeof(srp_N[0]), - srp_g, sizeof(srp_g)/sizeof(srp_g[0]), - salt, sizeof(salt)/sizeof(salt[0])) < 0) { - WOLFSSL_MSG("wc_SrpSetParam failed"); - return WOLFSSL_FAILURE; - } - r = wc_SrpSetPassword(ctx->srp, - (const byte*)ctx->srp_password, - (word32)XSTRLEN((char *)ctx->srp_password)); - if (r < 0) { - WOLFSSL_MSG("fail to set srp password."); - return WOLFSSL_FAILURE; - } - - XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP); - ctx->srp_password = NULL; + return wolfSSL_CTX_set_srp_password(ctx, (char*)ctx->srp_password); } return WOLFSSL_SUCCESS;