add sanity checks and adjust parameter name

pull/694/head
JacobBarthelmeh 2024-05-17 14:57:49 -06:00
parent ebfd175bf1
commit fa8a8182a8
3 changed files with 21 additions and 22 deletions

View File

@ -3650,7 +3650,7 @@ INLINE enum wc_HashType HashForId(byte id)
#if !defined(WOLFSSH_NO_ECDSA) || !defined(WOLFSSH_NO_ECDH) #if !defined(WOLFSSH_NO_ECDSA) || !defined(WOLFSSH_NO_ECDH)
INLINE int wcPrimeForId(byte id) int wcPrimeForId(byte id)
{ {
switch (id) { switch (id) {
#ifndef WOLFSSH_NO_ECDH_NISTP256_KYBER_LEVEL1_SHA256 #ifndef WOLFSSH_NO_ECDH_NISTP256_KYBER_LEVEL1_SHA256

View File

@ -2939,41 +2939,40 @@ static const char* MacNameForId(byte macid, byte cipherid)
return ""; return "";
} }
size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, size_t strsz) size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, size_t strSz)
{ {
int ret = 0; int ret = 0;
if (!ssh)
return 0;
static const char standard_dh_format[] = static const char standard_dh_format[] =
"%d-bit Diffie-Hellman with standard group %d"; "%d-bit Diffie-Hellman with standard group %d";
if (!ssh || str == NULL || strSz <= 0)
return 0;
switch (id) { switch (id) {
case WOLFSSH_TEXT_KEX_HASH: case WOLFSSH_TEXT_KEX_HASH:
ret = WSNPRINTF(str, strsz, "%s", HashNameForId(ssh->kexId)); ret = WSNPRINTF(str, strSz, "%s", HashNameForId(ssh->kexId));
break; break;
case WOLFSSH_TEXT_KEX_CURVE: case WOLFSSH_TEXT_KEX_CURVE:
ret = WSNPRINTF(str, strsz, "%s", CurveNameForId(ssh->kexId)); ret = WSNPRINTF(str, strSz, "%s", CurveNameForId(ssh->kexId));
break; break;
case WOLFSSH_TEXT_CRYPTO_IN_CIPHER: case WOLFSSH_TEXT_CRYPTO_IN_CIPHER:
ret = WSNPRINTF(str, strsz, "%s", ret = WSNPRINTF(str, strSz, "%s",
CipherNameForId(ssh->peerEncryptId)); CipherNameForId(ssh->peerEncryptId));
break; break;
case WOLFSSH_TEXT_CRYPTO_OUT_CIPHER: case WOLFSSH_TEXT_CRYPTO_OUT_CIPHER:
ret = WSNPRINTF(str, strsz, "%s", CipherNameForId(ssh->encryptId)); ret = WSNPRINTF(str, strSz, "%s", CipherNameForId(ssh->encryptId));
break; break;
case WOLFSSH_TEXT_CRYPTO_IN_MAC: case WOLFSSH_TEXT_CRYPTO_IN_MAC:
ret = WSNPRINTF(str, strsz, "%s", MacNameForId(ssh->peerMacId, ret = WSNPRINTF(str, strSz, "%s", MacNameForId(ssh->peerMacId,
ssh->peerEncryptId)); ssh->peerEncryptId));
break; break;
case WOLFSSH_TEXT_CRYPTO_OUT_MAC: case WOLFSSH_TEXT_CRYPTO_OUT_MAC:
ret = WSNPRINTF(str, strsz, "%s", MacNameForId(ssh->macId, ret = WSNPRINTF(str, strSz, "%s", MacNameForId(ssh->macId,
ssh->encryptId)); ssh->encryptId));
break; break;
@ -2987,38 +2986,38 @@ size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, size_t strsz)
#ifndef WOLFSSH_NO_CURVE25519_SHA256 #ifndef WOLFSSH_NO_CURVE25519_SHA256
case ID_CURVE25519_SHA256: case ID_CURVE25519_SHA256:
#endif #endif
ret = WSNPRINTF(str, strsz, "%s", "ECDH"); ret = WSNPRINTF(str, strSz, "%s", "ECDH");
break; break;
#ifndef WOLFSSH_NO_ECDH_NISTP256_KYBER_LEVEL1_SHA256 #ifndef WOLFSSH_NO_ECDH_NISTP256_KYBER_LEVEL1_SHA256
case ID_ECDH_NISTP256_KYBER_LEVEL1_SHA256: case ID_ECDH_NISTP256_KYBER_LEVEL1_SHA256:
ret = WSNPRINTF(str, strsz, "%s", "Kyber1"); ret = WSNPRINTF(str, strSz, "%s", "Kyber1");
break; break;
#endif #endif
case ID_DH_GROUP1_SHA1: case ID_DH_GROUP1_SHA1:
ret = WSNPRINTF(str, strsz, standard_dh_format, ret = WSNPRINTF(str, strSz, standard_dh_format,
ssh->primeGroupSz*8, 1); ssh->primeGroupSz*8, 1);
break; break;
case ID_DH_GROUP14_SHA1: case ID_DH_GROUP14_SHA1:
case ID_DH_GROUP14_SHA256: case ID_DH_GROUP14_SHA256:
ret = WSNPRINTF(str, strsz, standard_dh_format, ret = WSNPRINTF(str, strSz, standard_dh_format,
ssh->primeGroupSz*8, 14); ssh->primeGroupSz*8, 14);
break; break;
case ID_DH_GEX_SHA256: case ID_DH_GEX_SHA256:
ret = WSNPRINTF(str, strsz, ret = WSNPRINTF(str, strSz,
"%d-bit Diffie-Hellman with server-supplied group", "%d-bit Diffie-Hellman with server-supplied group",
ssh->primeGroupSz*8); ssh->primeGroupSz*8);
break; break;
case ID_EXTINFO_S: case ID_EXTINFO_S:
ret = WSNPRINTF(str, strsz, "Server extensions KEX"); ret = WSNPRINTF(str, strSz, "Server extensions KEX");
break; break;
case ID_EXTINFO_C: case ID_EXTINFO_C:
ret = WSNPRINTF(str, strsz, "Client extensions KEX"); ret = WSNPRINTF(str, strSz, "Client extensions KEX");
break; break;
} }

View File

@ -137,7 +137,7 @@ typedef enum WS_Text {
/* /*
* Outputs the c-string representation of the data entry identified by the id to * Outputs the c-string representation of the data entry identified by the id to
* the character string str, writing no more than strsz bytes, including the * the character string str, writing no more than strSz bytes, including the
* terminating null byte ('\0'). * terminating null byte ('\0').
* *
* Returns the number of characters written (excluding the null byte used to end * Returns the number of characters written (excluding the null byte used to end
@ -146,11 +146,11 @@ typedef enum WS_Text {
* would have been written to the final string if enough space had been * would have been written to the final string if enough space had been
* available. * available.
* *
* Thus, a return value of strsz or more means that the output was truncated. * Thus, a return value of strSz or more means that the output was truncated.
*/ */
WOLFSSH_API size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, WOLFSSH_API size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str,
size_t strsz); size_t strSz);
typedef void (*WS_CallbackKeyingCompletion)(void *); typedef void (*WS_CallbackKeyingCompletion)(void *);
WOLFSSH_API void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX*, WOLFSSH_API void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX*,