example set key algos

pull/662/head
JacobBarthelmeh 2024-03-04 01:52:17 -07:00
parent a9973e0136
commit e617e20e7a
2 changed files with 80 additions and 2 deletions

View File

@ -117,6 +117,8 @@ static void ShowUsage(void)
printf(" -A <filename> filename for DER CA certificate to verify host\n"); printf(" -A <filename> filename for DER CA certificate to verify host\n");
printf(" -X Ignore IP checks on peer vs peer certificate\n"); printf(" -X Ignore IP checks on peer vs peer certificate\n");
#endif #endif
printf(" -E List all possible algos\n");
printf(" -k set the list of key algos to use\n");
} }
@ -624,7 +626,9 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
const char* password = NULL; const char* password = NULL;
const char* cmd = NULL; const char* cmd = NULL;
const char* privKeyName = NULL; const char* privKeyName = NULL;
const char* keyList = NULL;
byte imExit = 0; byte imExit = 0;
byte listAlgos = 0;
byte nonBlock = 0; byte nonBlock = 0;
byte keepOpen = 0; byte keepOpen = 0;
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
@ -641,7 +645,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
(void)keepOpen; (void)keepOpen;
while ((ch = mygetopt(argc, argv, "?ac:h:i:j:p:tu:xzNP:RJ:A:Xe")) != -1) { while ((ch = mygetopt(argc, argv, "?ac:h:i:j:p:tu:xzNP:RJ:A:XeEk:")) != -1) {
switch (ch) { switch (ch) {
case 'h': case 'h':
host = myoptarg; host = myoptarg;
@ -701,6 +705,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
#endif #endif
#endif #endif
case 'E':
listAlgos = 1;
break;
case 'x': case 'x':
/* exit after successful connection without read/write */ /* exit after successful connection without read/write */
imExit = 1; imExit = 1;
@ -710,6 +718,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
nonBlock = 1; nonBlock = 1;
break; break;
case 'k':
keyList = myoptarg;
break;
#if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS) #if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS)
case 'c': case 'c':
cmd = myoptarg; cmd = myoptarg;
@ -779,6 +791,12 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
if (ctx == NULL) if (ctx == NULL)
err_sys("Couldn't create wolfSSH client context."); err_sys("Couldn't create wolfSSH client context.");
if (keyList) {
if (wolfSSH_CTX_SetAlgoListKey(ctx, NULL) != WS_SUCCESS) {
err_sys("Error setting key list.\n");
}
}
if (((func_args*)args)->user_auth == NULL) if (((func_args*)args)->user_auth == NULL)
wolfSSH_SetUserAuth(ctx, ClientUserAuth); wolfSSH_SetUserAuth(ctx, ClientUserAuth);
else else
@ -825,6 +843,54 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
if (ret != WS_SUCCESS) if (ret != WS_SUCCESS)
err_sys("Couldn't set the username."); err_sys("Couldn't set the username.");
if (listAlgos) {
word32 idx = 0;
const char* current = NULL;
printf("KEX:\n");
do {
current = wolfSSH_QueryKex(&idx);
if (current) {
printf("\t%d: %s\n", idx, current);
}
} while (current != NULL);
printf("Set KEX: %s\n\n", wolfSSH_GetAlgoListKex(ssh));
idx = 0;
printf("Key:\n");
do {
current = wolfSSH_QueryKey(&idx);
if (current) {
printf("\t%d: %s\n", idx, current);
}
} while (current != NULL);
printf("Set Key: %s\n\n", wolfSSH_GetAlgoListKey(ssh));
idx = 0;
printf("Cipher:\n");
do {
current = wolfSSH_QueryCipher(&idx);
if (current) {
printf("\t%d: %s\n", idx, current);
}
} while (current != NULL);
printf("Set Cipher: %s\n\n", wolfSSH_GetAlgoListCipher(ssh));
idx = 0;
printf("Mac:\n");
do {
current = wolfSSH_QueryMac(&idx);
if (current) {
printf("\t%d: %s\n", idx, current);
}
} while (current != NULL);
printf("Set Mac: %s\n", wolfSSH_GetAlgoListMac(ssh));
wolfSSH_free(ssh);
wolfSSH_CTX_free(ctx);
return 0;
}
build_addr(&clientAddr, host, port); build_addr(&clientAddr, host, port);
tcp_socket(&sockFd); tcp_socket(&sockFd);
ret = connect(sockFd, (const struct sockaddr *)&clientAddr, clientAddrSz); ret = connect(sockFd, (const struct sockaddr *)&clientAddr, clientAddrSz);

View File

@ -2156,6 +2156,7 @@ static void ShowUsage(void)
#ifdef WOLFSSH_CERTS #ifdef WOLFSSH_CERTS
printf(" -a <file> load in a root CA certificate file\n"); printf(" -a <file> load in a root CA certificate file\n");
#endif #endif
printf(" -k set the list of key algos to use\n");
} }
@ -2194,6 +2195,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
WS_SOCKET_T listenFd = WOLFSSH_SOCKET_INVALID; WS_SOCKET_T listenFd = WOLFSSH_SOCKET_INVALID;
word32 defaultHighwater = EXAMPLE_HIGHWATER_MARK; word32 defaultHighwater = EXAMPLE_HIGHWATER_MARK;
word32 threadCount = 0; word32 threadCount = 0;
const char* keyList = NULL;
int multipleConnections = 1; int multipleConnections = 1;
int userEcc = 0; int userEcc = 0;
int peerEcc = 0; int peerEcc = 0;
@ -2215,7 +2217,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
serverArgs->return_code = EXIT_SUCCESS; serverArgs->return_code = EXIT_SUCCESS;
if (argc > 0) { if (argc > 0) {
const char* optlist = "?1a:d:efEp:R:Ni:j:I:J:K:P:"; const char* optlist = "?1a:d:efEp:R:Ni:j:I:J:K:P:k:";
myoptind = 0; myoptind = 0;
while ((ch = mygetopt(argc, argv, optlist)) != -1) { while ((ch = mygetopt(argc, argv, optlist)) != -1) {
switch (ch) { switch (ch) {
@ -2237,6 +2239,10 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
userEcc = 1; userEcc = 1;
break; break;
case 'k' :
keyList = myoptarg;
break;
case 'E': case 'E':
peerEcc = 1; peerEcc = 1;
break; break;
@ -2332,6 +2338,12 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
ES_ERROR("Couldn't allocate SSH CTX data.\n"); ES_ERROR("Couldn't allocate SSH CTX data.\n");
} }
if (keyList) {
if (wolfSSH_CTX_SetAlgoListKey(ctx, keyList) != WS_SUCCESS) {
ES_ERROR("Error setting key list.\n");
}
}
WMEMSET(&pwMapList, 0, sizeof(pwMapList)); WMEMSET(&pwMapList, 0, sizeof(pwMapList));
if (serverArgs->user_auth == NULL) if (serverArgs->user_auth == NULL)
wolfSSH_SetUserAuth(ctx, wsUserAuth); wolfSSH_SetUserAuth(ctx, wsUserAuth);