Skip to content

Commit 6325742

Browse files
authored
Merge pull request #896 from yosuke-wolfssl/fix_Fenrir858-859
Fix fenrir858-859
2 parents 5be43b6 + 7bb982a commit 6325742

1 file changed

Lines changed: 43 additions & 26 deletions

File tree

src/internal.c

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5014,8 +5014,13 @@ static int ParseEd25519PubKey(WOLFSSH *ssh,
50145014
if (ret == WS_SUCCESS) {
50155015
ret = wc_ed25519_import_public(encA, encASz,
50165016
&sigKeyBlock_ptr->sk.ed25519.key);
5017-
if (ret != 0)
5017+
if (ret != 0) {
50185018
ret = WS_ED25519_E;
5019+
}
5020+
}
5021+
5022+
if (ret == 0) {
5023+
sigKeyBlock_ptr->keyAllocated = 1;
50195024
}
50205025
return ret;
50215026
}
@@ -5328,6 +5333,11 @@ static void FreePubKey(struct wolfSSH_sigKeyBlock *p)
53285333
wc_ecc_free(&p->sk.ecc.key);
53295334
#endif
53305335
}
5336+
else if (p->useEd25519) {
5337+
#ifndef WOLFSSH_NO_ED25519
5338+
wc_ed25519_free(&p->sk.ed25519.key);
5339+
#endif
5340+
}
53315341
p->keyAllocated = 0;
53325342
}
53335343
}
@@ -14090,10 +14100,12 @@ static int BuildUserAuthRequestRsa(WOLFSSH* ssh,
1409014100
if (ret == WS_SUCCESS) {
1409114101
WMEMSET(digest, 0, sizeof(digest));
1409214102
ret = wc_HashInit(&hash, hashId);
14093-
if (ret == WS_SUCCESS)
14103+
if (ret == WS_SUCCESS) {
1409414104
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14095-
if (ret == WS_SUCCESS)
14096-
ret = wc_HashFinal(&hash, hashId, digest);
14105+
if (ret == WS_SUCCESS)
14106+
ret = wc_HashFinal(&hash, hashId, digest);
14107+
wc_HashFree(&hash, hashId);
14108+
}
1409714109
}
1409814110

1409914111
if (ret == WS_SUCCESS) {
@@ -14324,11 +14336,12 @@ static int BuildUserAuthRequestRsaCert(WOLFSSH* ssh,
1432414336

1432514337
WMEMSET(digest, 0, sizeof(digest));
1432614338
ret = wc_HashInit(&hash, hashId);
14327-
if (ret == WS_SUCCESS)
14339+
if (ret == WS_SUCCESS) {
1432814340
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14329-
if (ret == WS_SUCCESS)
14330-
ret = wc_HashFinal(&hash, hashId, digest);
14331-
14341+
if (ret == WS_SUCCESS)
14342+
ret = wc_HashFinal(&hash, hashId, digest);
14343+
wc_HashFree(&hash, hashId);
14344+
}
1433214345
if (ret == WS_SUCCESS) {
1433314346
c32toa(keySig->sigSz + 7 + LENGTH_SZ * 2, output + begin);
1433414347
begin += LENGTH_SZ;
@@ -14547,16 +14560,18 @@ static int BuildUserAuthRequestEcc(WOLFSSH* ssh,
1454714560
if (ret == WS_SUCCESS) {
1454814561
WLOG(WS_LOG_INFO, "Signing hash with ECDSA.");
1454914562
ret = wc_HashInit(&hash, hashId);
14550-
if (ret == WS_SUCCESS)
14563+
if (ret == WS_SUCCESS) {
1455114564
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14552-
if (ret == WS_SUCCESS)
14553-
ret = wc_HashFinal(&hash, hashId, digest);
14554-
if (ret == WS_SUCCESS)
14555-
ret = wc_ecc_sign_hash(digest, digestSz, sig_ptr, &sigSz,
14556-
ssh->rng, &keySig->ks.ecc.key);
14557-
if (ret != WS_SUCCESS) {
14558-
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Sign");
14559-
ret = WS_ECC_E;
14565+
if (ret == WS_SUCCESS)
14566+
ret = wc_HashFinal(&hash, hashId, digest);
14567+
if (ret == WS_SUCCESS)
14568+
ret = wc_ecc_sign_hash(digest, digestSz, sig_ptr, &sigSz,
14569+
ssh->rng, &keySig->ks.ecc.key);
14570+
if (ret != WS_SUCCESS) {
14571+
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Sign");
14572+
ret = WS_ECC_E;
14573+
}
14574+
wc_HashFree(&hash, hashId);
1456014575
}
1456114576
}
1456214577

@@ -14787,16 +14802,18 @@ static int BuildUserAuthRequestEccCert(WOLFSSH* ssh,
1478714802
if (ret == WS_SUCCESS) {
1478814803
WLOG(WS_LOG_INFO, "Signing hash with ECDSA cert.");
1478914804
ret = wc_HashInit(&hash, hashId);
14790-
if (ret == WS_SUCCESS)
14805+
if (ret == WS_SUCCESS) {
1479114806
ret = HashUpdate(&hash, hashId, checkData, checkDataSz);
14792-
if (ret == WS_SUCCESS)
14793-
ret = wc_HashFinal(&hash, hashId, digest);
14794-
if (ret == WS_SUCCESS)
14795-
ret = wc_ecc_sign_hash(digest, digestSz, sig, &sigSz,
14796-
ssh->rng, &keySig->ks.ecc.key);
14797-
if (ret != WS_SUCCESS) {
14798-
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Cert Sign");
14799-
ret = WS_ECC_E;
14807+
if (ret == WS_SUCCESS)
14808+
ret = wc_HashFinal(&hash, hashId, digest);
14809+
if (ret == WS_SUCCESS)
14810+
ret = wc_ecc_sign_hash(digest, digestSz, sig, &sigSz,
14811+
ssh->rng, &keySig->ks.ecc.key);
14812+
if (ret != WS_SUCCESS) {
14813+
WLOG(WS_LOG_DEBUG, "SUAR: Bad ECC Cert Sign");
14814+
ret = WS_ECC_E;
14815+
}
14816+
wc_HashFree(&hash, hashId);
1480014817
}
1480114818
}
1480214819

0 commit comments

Comments
 (0)