Skip to content

Commit 46cd6a7

Browse files
committed
Fix logical operator in public key type validation checks
Change && to || in 5 instances where public key type matching used AND instead of OR, causing WMEMCMP to be skipped when type sizes matched. Two key types with the same size but different content would incorrectly pass validation. Affected functions: DoUserAuthRequestRsaCert, DoUserAuthRequestEcc, and DoUserAuthRequestEccCert.
1 parent 4b46454 commit 46cd6a7

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/internal.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7210,8 +7210,9 @@ static int DoUserAuthRequestRsaCert(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
72107210
}
72117211

72127212
if (ret == WS_SUCCESS) {
7213-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7214-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7213+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7214+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7215+
publicKeyTypeSz) != 0) {
72157216

72167217
WLOG(WS_LOG_DEBUG,
72177218
"Signature's type does not match public key type");
@@ -7309,8 +7310,9 @@ static int DoUserAuthRequestEcc(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
73097310
if (ret == WS_SUCCESS) {
73107311
publicKeyType = pk->publicKey + i;
73117312
i += publicKeyTypeSz;
7312-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7313-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7313+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7314+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7315+
publicKeyTypeSz) != 0) {
73147316

73157317
WLOG(WS_LOG_DEBUG,
73167318
"Public Key's type does not match public key type");
@@ -7351,8 +7353,9 @@ static int DoUserAuthRequestEcc(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
73517353
publicKeyType = pk->signature + i;
73527354
i += publicKeyTypeSz;
73537355

7354-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7355-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7356+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7357+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7358+
publicKeyTypeSz) != 0) {
73567359

73577360
WLOG(WS_LOG_DEBUG,
73587361
"Signature's type does not match public key type");
@@ -7620,7 +7623,7 @@ static int DoUserAuthRequestEd25519(WOLFSSH* ssh,
76207623
publicKeyType = pk->publicKey + i;
76217624
i += publicKeyTypeSz;
76227625
if (publicKeyTypeSz != pk->publicKeyTypeSz
7623-
&& WMEMCMP(publicKeyType,
7626+
|| WMEMCMP(publicKeyType,
76247627
pk->publicKeyType, publicKeyTypeSz) != 0) {
76257628
WLOG(WS_LOG_DEBUG,
76267629
"Public Key's type does not match public key type");
@@ -7651,8 +7654,9 @@ static int DoUserAuthRequestEd25519(WOLFSSH* ssh,
76517654
publicKeyType = pk->signature + i;
76527655
i += publicKeyTypeSz;
76537656

7654-
if (publicKeyTypeSz != pk->publicKeyTypeSz &&
7655-
WMEMCMP(publicKeyType, pk->publicKeyType, publicKeyTypeSz) != 0) {
7657+
if (publicKeyTypeSz != pk->publicKeyTypeSz
7658+
|| WMEMCMP(publicKeyType, pk->publicKeyType,
7659+
publicKeyTypeSz) != 0) {
76567660

76577661
WLOG(WS_LOG_DEBUG,
76587662
"Signature's type does not match public key type");

0 commit comments

Comments
 (0)