@@ -12757,7 +12757,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1275712757 {
1275812758 int r = 0;
1275912759 SrpSide srp_side = SRP_CLIENT_SIDE;
12760- byte salt[SRP_SALT_SIZE];
1276112760
1276212761 WOLFSSL_ENTER("wolfSSL_CTX_set_srp_username");
1276312762 if (ctx == NULL || ctx->srp == NULL || username==NULL)
@@ -12786,37 +12785,11 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1278612785 }
1278712786
1278812787 /* if wolfSSL_CTX_set_srp_password has already been called, */
12789- /* execute wc_SrpSetPassword here */
12788+ /* use saved password here */
1279012789 if (ctx->srp_password != NULL) {
12791- WC_RNG rng;
12792- if (wc_InitRng(&rng) < 0){
12793- WOLFSSL_MSG("wc_InitRng failed");
12794- return WOLFSSL_FAILURE;
12795- }
12796- XMEMSET(salt, 0, sizeof(salt)/sizeof(salt[0]));
12797- r = wc_RNG_GenerateBlock(&rng, salt, sizeof(salt)/sizeof(salt[0]));
12798- wc_FreeRng(&rng);
12799- if (r < 0) {
12800- WOLFSSL_MSG("wc_RNG_GenerateBlock failed");
12790+ if (ctx->srp->user == NULL)
1280112791 return WOLFSSL_FAILURE;
12802- }
12803-
12804- if (wc_SrpSetParams(ctx->srp, srp_N, sizeof(srp_N)/sizeof(srp_N[0]),
12805- srp_g, sizeof(srp_g)/sizeof(srp_g[0]),
12806- salt, sizeof(salt)/sizeof(salt[0])) < 0) {
12807- WOLFSSL_MSG("wc_SrpSetParam failed");
12808- return WOLFSSL_FAILURE;
12809- }
12810- r = wc_SrpSetPassword(ctx->srp,
12811- (const byte*)ctx->srp_password,
12812- (word32)XSTRLEN((char *)ctx->srp_password));
12813- if (r < 0) {
12814- WOLFSSL_MSG("fail to set srp password.");
12815- return WOLFSSL_FAILURE;
12816- }
12817-
12818- XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
12819- ctx->srp_password = NULL;
12792+ return wolfSSL_CTX_set_srp_password(ctx, (char*)ctx->srp_password);
1282012793 }
1282112794
1282212795 return WOLFSSL_SUCCESS;
0 commit comments