Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example set key algos #662

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ static void ShowUsage(void)
printf(" -A <filename> filename for DER CA certificate to verify host\n");
printf(" -X Ignore IP checks on peer vs peer certificate\n");
#endif
printf(" -E List all possible algos\n");
printf(" -k set the list of key algos to use\n");
}


Expand Down Expand Up @@ -624,7 +626,9 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
const char* password = NULL;
const char* cmd = NULL;
const char* privKeyName = NULL;
const char* keyList = NULL;
byte imExit = 0;
byte listAlgos = 0;
byte nonBlock = 0;
byte keepOpen = 0;
#ifdef USE_WINDOWS_API
Expand All @@ -641,7 +645,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)

(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) {
case 'h':
host = myoptarg;
Expand Down Expand Up @@ -701,6 +705,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
#endif
#endif

case 'E':
listAlgos = 1;
break;

case 'x':
/* exit after successful connection without read/write */
imExit = 1;
Expand All @@ -710,6 +718,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
nonBlock = 1;
break;

case 'k':
keyList = myoptarg;
break;

#if !defined(SINGLE_THREADED) && !defined(WOLFSSL_NUCLEUS)
case 'c':
cmd = myoptarg;
Expand Down Expand Up @@ -779,6 +791,12 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
if (ctx == NULL)
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)
wolfSSH_SetUserAuth(ctx, ClientUserAuth);
else
Expand Down Expand Up @@ -825,6 +843,54 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
if (ret != WS_SUCCESS)
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);
WOLFSSL_RETURN_FROM_THREAD(0);
}

build_addr(&clientAddr, host, port);
tcp_socket(&sockFd);
ret = connect(sockFd, (const struct sockaddr *)&clientAddr, clientAddrSz);
Expand Down
14 changes: 13 additions & 1 deletion examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ static void ShowUsage(void)
#ifdef WOLFSSH_CERTS
printf(" -a <file> load in a root CA certificate file\n");
#endif
printf(" -k set the list of key algos to use\n");
}


Expand Down Expand Up @@ -2194,6 +2195,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
WS_SOCKET_T listenFd = WOLFSSH_SOCKET_INVALID;
word32 defaultHighwater = EXAMPLE_HIGHWATER_MARK;
word32 threadCount = 0;
const char* keyList = NULL;
int multipleConnections = 1;
int userEcc = 0;
int peerEcc = 0;
Expand All @@ -2215,7 +2217,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
serverArgs->return_code = EXIT_SUCCESS;

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;
while ((ch = mygetopt(argc, argv, optlist)) != -1) {
switch (ch) {
Expand All @@ -2237,6 +2239,10 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
userEcc = 1;
break;

case 'k' :
keyList = myoptarg;
break;

case 'E':
peerEcc = 1;
break;
Expand Down Expand Up @@ -2332,6 +2338,12 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
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));
if (serverArgs->user_auth == NULL)
wolfSSH_SetUserAuth(ctx, wsUserAuth);
Expand Down
Loading