Skip to content

Commit

Permalink
Service State
Browse files Browse the repository at this point in the history
1. Add a new state variable to the WOLFSSH object for the current
   service that it is working under. (none, ssh-userauth, or
   ssh-connection.)
2. Start processing service requests more rigorously.
  • Loading branch information
ejohnstown committed May 16, 2024
1 parent 5ef2bc5 commit e0e447e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
ssh->kSz = (word32)sizeof(ssh->k);
ssh->handshake = handshake;
ssh->connectChannelId = WOLFSSH_SESSION_SHELL;
ssh->service = ID_NONE;
ssh->algoListKex = ctx->algoListKex;
ssh->algoListKey = ctx->algoListKey;
ssh->algoListCipher = ctx->algoListCipher;
Expand Down Expand Up @@ -5879,37 +5880,26 @@ static int DoDisconnect(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
}


static int DoServiceRequest(WOLFSSH* ssh,
byte* buf, word32 len, word32* idx)
static int DoServiceRequest(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
{
word32 begin = *idx;
const char *name = NULL;
word32 nameSz;
char serviceName[WOLFSSH_MAX_NAMESZ];

WOLFSSH_UNUSED(len);
int ret;

ato32(buf + begin, &nameSz);
begin += LENGTH_SZ;
ret = GetStringRef(&nameSz, (const byte **)&name, buf, len, idx);
if (ret == WS_SUCCESS) {
byte serviceId;

if (begin + nameSz > len || nameSz >= WOLFSSH_MAX_NAMESZ) {
return WS_BUFFER_E;
serviceId = NameToId(name, nameSz);
WLOG(WS_LOG_DEBUG, "Requesting service: %s", IdToName(serviceId));
ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE;
}

WMEMCPY(serviceName, buf + begin, nameSz);
begin += nameSz;
serviceName[nameSz] = 0;

*idx = begin;

WLOG(WS_LOG_DEBUG, "Requesting service: %s", serviceName);
ssh->clientState = CLIENT_USERAUTH_REQUEST_DONE;

return WS_SUCCESS;
return ret;
}


static int DoServiceAccept(WOLFSSH* ssh,
byte* buf, word32 len, word32* idx)
static int DoServiceAccept(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
{
word32 begin = *idx;
word32 nameSz;
Expand Down
1 change: 1 addition & 0 deletions wolfssh/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ struct WOLFSSH {
const char* algoListCipher;
const char* algoListMac;
const char* algoListKeyAccepted;
byte service;
byte acceptState;
byte connectState;
byte clientState;
Expand Down

0 comments on commit e0e447e

Please sign in to comment.