Skip to content

Commit

Permalink
wolfSSH Client
Browse files Browse the repository at this point in the history
1. In the windowMonitor(), move the check for quit outside the
   conditional build so it works for both macOS and Linux.
2. Removed a dead store in readPeer(). If the socket wants read, that's
   fine. Don't need to override it.
3. When allocating memory for the hostname, don't forget the nul.
4. When parsing the command line and storing a copy of it to send to the
   peer, stash it in the config.
5. When allocating memory for the username, add 1 for the nul outside
   the strlen().
6. When canceling a thread, be sure to join it afterwards.
7. Added a read me document for wolfSSH client. Just a quick note. To be
   replaced later with something more formal.
  • Loading branch information
ejohnstown committed Sep 22, 2023
1 parent 79d29f3 commit a4af966
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
13 changes: 13 additions & 0 deletions apps/wolfssh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
WOLFSSH CLIENT
==============

The wolfSSH client will connect to a server and try to open a terminal. It'll
default the username to your current username, and it will try to use your
ecdsa private key to authenticate. The key file path is hard coded to
`$HOME/.ssh/id_ecdsa`. It is currently far enough along I can use it. The
private keys are the ones produced by the OpenSSL command line tool, not the
ssh-keygen tool.

Phase 2 is going to bring reading the config files `/etc/ssh/ssh_config` and
`$HOME/.ssh/config`. It will handle OpenSSH style modern keys. It will also
have support for SSH-AGENT and forwarding.
2 changes: 2 additions & 0 deletions apps/wolfssh/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ apps_wolfssh_wolfssh_LDADD = src/libwolfssh.la
apps_wolfssh_wolfssh_DEPENDENCIES = src/libwolfssh.la

endif BUILD_SSHCLIENT

EXTRA_DIST+= apps/wolfssh/README.md
16 changes: 9 additions & 7 deletions apps/wolfssh/wolfssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ static THREAD_RET windowMonitor(void* in)
do {
#if (defined(__OSX__) || defined(__APPLE__))
dispatch_semaphore_wait(windowSem, DISPATCH_TIME_FOREVER);
if (args->quit) {
break;
}
#else
sem_wait(&windowSem);
#endif
if (args->quit) {
break;
}
ret = sendCurrentWindowSize(args);
(void)ret;
} while (1);
Expand Down Expand Up @@ -375,7 +375,7 @@ static THREAD_RET readPeer(void* in)
if (ret == WS_FATAL_ERROR) {
ret = wolfSSH_get_error(args->ssh);
if (ret == WS_WANT_READ) {
ret = WS_SUCCESS;
continue;
}
#ifdef WOLFSSH_AGENT
else if (ret == WS_CHAN_RXD) {
Expand Down Expand Up @@ -605,7 +605,7 @@ static int config_init_default(struct config* config)
if (env != NULL) {
char* user;

sz = strlen(env + 1);
sz = strlen(env) + 1;
user = (char*)malloc(sz);
if (user != NULL) {
strcpy(user, env);
Expand Down Expand Up @@ -726,7 +726,7 @@ static int config_parse_command_line(struct config* config,
if (found != NULL) {
*found = '\0';
sz = strlen(cursor);
config->hostname = (char*)malloc(sz);
config->hostname = (char*)malloc(sz + 1);
strcpy(config->hostname, cursor);
cursor = found + 1;
if (*cursor != 0) {
Expand All @@ -736,7 +736,7 @@ static int config_parse_command_line(struct config* config,
}
else {
sz = strlen(cursor);
config->hostname = (char*)malloc(sz);
config->hostname = (char*)malloc(sz + 1);
strcpy(config->hostname, cursor);
}

Expand All @@ -758,6 +758,7 @@ static int config_parse_command_line(struct config* config,
}

command = (char*)malloc(commandSz);
config->command = command;
cursor = command;

for (i = myoptind; i < argc; i++) {
Expand Down Expand Up @@ -998,6 +999,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
#endif
pthread_join(thread[0], NULL);
pthread_cancel(thread[1]);
pthread_join(thread[1], NULL);
#if (defined(__OSX__) || defined(__APPLE__))
dispatch_release(windowSem);
#else
Expand Down

0 comments on commit a4af966

Please sign in to comment.