mirror of https://github.com/wolfSSL/wolfssh.git
1. Commented out some of the distracting debugging output.
2. Accepts the none client authentication. 3. Starts to parse the channel open message. 4. Starting to handle channels.pull/1/head
parent
38e51c45c8
commit
0455fe43dd
174
src/internal.c
174
src/internal.c
|
@ -166,7 +166,10 @@ static const NameIdPair NameIdMap[] = {
|
||||||
{ ID_DH_GROUP14_SHA1, "diffie-hellman-group14-sha1" },
|
{ ID_DH_GROUP14_SHA1, "diffie-hellman-group14-sha1" },
|
||||||
|
|
||||||
/* Public Key IDs */
|
/* Public Key IDs */
|
||||||
{ ID_SSH_RSA, "ssh-rsa" }
|
{ ID_SSH_RSA, "ssh-rsa" },
|
||||||
|
|
||||||
|
/* UserAuth IDs */
|
||||||
|
{ ID_USERAUTH_PASSWORD, "password" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,14 +233,16 @@ int BufferInit(Buffer* buffer, uint32_t size, void* heap)
|
||||||
|
|
||||||
int GrowBuffer(Buffer* buf, uint32_t sz, uint32_t usedSz)
|
int GrowBuffer(Buffer* buf, uint32_t sz, uint32_t usedSz)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
WLOG(WS_LOG_DEBUG, "GB: buf = %p", buf);
|
WLOG(WS_LOG_DEBUG, "GB: buf = %p", buf);
|
||||||
WLOG(WS_LOG_DEBUG, "GB: sz = %d", sz);
|
WLOG(WS_LOG_DEBUG, "GB: sz = %d", sz);
|
||||||
WLOG(WS_LOG_DEBUG, "GB: usedSz = %d", usedSz);
|
WLOG(WS_LOG_DEBUG, "GB: usedSz = %d", usedSz);
|
||||||
|
#endif
|
||||||
/* New buffer will end up being sz+usedSz long
|
/* New buffer will end up being sz+usedSz long
|
||||||
* empty space at the head of the buffer will be compressed */
|
* empty space at the head of the buffer will be compressed */
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
uint32_t newSz = sz + usedSz;
|
uint32_t newSz = sz + usedSz;
|
||||||
WLOG(WS_LOG_DEBUG, "GB: newSz = %d", newSz);
|
/*WLOG(WS_LOG_DEBUG, "GB: newSz = %d", newSz);*/
|
||||||
|
|
||||||
if (newSz > buf->bufferSz) {
|
if (newSz > buf->bufferSz) {
|
||||||
uint8_t* newBuffer = (uint8_t*)WMALLOC(newSz,
|
uint8_t* newBuffer = (uint8_t*)WMALLOC(newSz,
|
||||||
|
@ -246,7 +251,7 @@ int GrowBuffer(Buffer* buf, uint32_t sz, uint32_t usedSz)
|
||||||
if (newBuffer == NULL)
|
if (newBuffer == NULL)
|
||||||
return WS_MEMORY_E;
|
return WS_MEMORY_E;
|
||||||
|
|
||||||
WLOG(WS_LOG_DEBUG, "GB: resizing buffer");
|
/*WLOG(WS_LOG_DEBUG, "GB: resizing buffer");*/
|
||||||
if (buf->length > 0)
|
if (buf->length > 0)
|
||||||
WMEMCPY(newBuffer, buf->buffer + buf->idx, buf->length);
|
WMEMCPY(newBuffer, buf->buffer + buf->idx, buf->length);
|
||||||
|
|
||||||
|
@ -268,25 +273,33 @@ int GrowBuffer(Buffer* buf, uint32_t sz, uint32_t usedSz)
|
||||||
|
|
||||||
void ShrinkBuffer(Buffer* buf, int forcedFree)
|
void ShrinkBuffer(Buffer* buf, int forcedFree)
|
||||||
{
|
{
|
||||||
|
WLOG(WS_LOG_DEBUG, "Entering %s", __func__);
|
||||||
|
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
uint32_t usedSz = buf->length - buf->idx;
|
uint32_t usedSz = buf->length - buf->idx;
|
||||||
|
|
||||||
if (!forcedFree && usedSz > STATIC_BUFFER_LEN)
|
WLOG(WS_LOG_DEBUG, "SB: usedSz = %u, forcedFree = %u", usedSz, forcedFree);
|
||||||
|
if (!forcedFree && usedSz > STATIC_BUFFER_LEN) {
|
||||||
|
WLOG(WS_LOG_DEBUG, "SB: shifting down");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WLOG(WS_LOG_DEBUG, "Shrinking buffer");
|
if (!forcedFree && usedSz) {
|
||||||
|
WLOG(WS_LOG_DEBUG, "SB: shifting down");
|
||||||
if (!forcedFree && usedSz)
|
|
||||||
WMEMCPY(buf->staticBuffer, buf->buffer + buf->idx, usedSz);
|
WMEMCPY(buf->staticBuffer, buf->buffer + buf->idx, usedSz);
|
||||||
|
}
|
||||||
|
|
||||||
if (buf->dynamicFlag)
|
if (buf->dynamicFlag) {
|
||||||
|
WLOG(WS_LOG_DEBUG, "SB: releasing dynamic buffer");
|
||||||
WFREE(buf->buffer, buf->heap, DYNTYPE_BUFFER);
|
WFREE(buf->buffer, buf->heap, DYNTYPE_BUFFER);
|
||||||
|
}
|
||||||
buf->dynamicFlag = 0;
|
buf->dynamicFlag = 0;
|
||||||
buf->buffer = buf->staticBuffer;
|
buf->buffer = buf->staticBuffer;
|
||||||
buf->bufferSz = STATIC_BUFFER_LEN;
|
buf->bufferSz = STATIC_BUFFER_LEN;
|
||||||
buf->length = forcedFree ? 0 : usedSz;
|
buf->length = forcedFree ? 0 : usedSz;
|
||||||
buf->idx = 0;
|
buf->idx = 0;
|
||||||
}
|
}
|
||||||
|
WLOG(WS_LOG_DEBUG, "Leaving %s", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -409,6 +422,7 @@ static int SendBuffered(WOLFSSH* ssh)
|
||||||
|
|
||||||
ssh->outputBuffer.idx = 0;
|
ssh->outputBuffer.idx = 0;
|
||||||
|
|
||||||
|
WLOG(WS_LOG_DEBUG, "SB: Shrinking output buffer");
|
||||||
ShrinkBuffer(&ssh->outputBuffer, 0);
|
ShrinkBuffer(&ssh->outputBuffer, 0);
|
||||||
|
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
|
@ -436,12 +450,12 @@ static int GetInputData(WOLFSSH* ssh, uint32_t size)
|
||||||
usedLength = ssh->inputBuffer.length - ssh->inputBuffer.idx;
|
usedLength = ssh->inputBuffer.length - ssh->inputBuffer.idx;
|
||||||
maxLength = ssh->inputBuffer.bufferSz - usedLength;
|
maxLength = ssh->inputBuffer.bufferSz - usedLength;
|
||||||
inSz = (int)(size - usedLength); /* from last partial read */
|
inSz = (int)(size - usedLength); /* from last partial read */
|
||||||
|
#if 0
|
||||||
WLOG(WS_LOG_DEBUG, "GID: size = %u", size);
|
WLOG(WS_LOG_DEBUG, "GID: size = %u", size);
|
||||||
WLOG(WS_LOG_DEBUG, "GID: usedLength = %d", usedLength);
|
WLOG(WS_LOG_DEBUG, "GID: usedLength = %d", usedLength);
|
||||||
WLOG(WS_LOG_DEBUG, "GID: maxLength = %d", maxLength);
|
WLOG(WS_LOG_DEBUG, "GID: maxLength = %d", maxLength);
|
||||||
WLOG(WS_LOG_DEBUG, "GID: inSz = %d", inSz);
|
WLOG(WS_LOG_DEBUG, "GID: inSz = %d", inSz);
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* usedLength - how much untouched data is in the buffer
|
* usedLength - how much untouched data is in the buffer
|
||||||
* maxLength - how much empty space is in the buffer
|
* maxLength - how much empty space is in the buffer
|
||||||
|
@ -539,7 +553,7 @@ static int DoNameList(uint8_t* idList, uint32_t* idListSz,
|
||||||
{
|
{
|
||||||
const char* displayName = IdToName(id);
|
const char* displayName = IdToName(id);
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
WLOG(WS_LOG_DEBUG, "DNL: name ID = %s", displayName);
|
/*WLOG(WS_LOG_DEBUG, "DNL: name ID = %s", displayName);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (id != ID_UNKNOWN)
|
if (id != ID_UNKNOWN)
|
||||||
|
@ -580,7 +594,9 @@ static uint8_t MatchIdLists(const uint8_t* left, uint32_t leftSz,
|
||||||
for (i = 0; i < leftSz; i++) {
|
for (i = 0; i < leftSz; i++) {
|
||||||
for (j = 0; j < rightSz; j++) {
|
for (j = 0; j < rightSz; j++) {
|
||||||
if (left[i] == right[j]) {
|
if (left[i] == right[j]) {
|
||||||
|
#if 0
|
||||||
WLOG(WS_LOG_DEBUG, "MID: matched %s", IdToName(left[i]));
|
WLOG(WS_LOG_DEBUG, "MID: matched %s", IdToName(left[i]));
|
||||||
|
#endif
|
||||||
return left[i];
|
return left[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1134,10 +1150,10 @@ static int DoDisconnect(WOLFSSH* ssh, uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static const char serviceNameUserAuth[] = "ssh-userauth";
|
static const char serviceNameUserAuth[] = "ssh-userauth";
|
||||||
/*static const char serviceNameConnection[] = "ssh-connection";*/
|
static const char serviceNameConnection[] = "ssh-connection";
|
||||||
|
#endif
|
||||||
|
|
||||||
static int DoServiceRequest(WOLFSSH* ssh,
|
static int DoServiceRequest(WOLFSSH* ssh,
|
||||||
uint8_t* buf, uint32_t len, uint32_t* idx)
|
uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||||
|
@ -1145,8 +1161,8 @@ static int DoServiceRequest(WOLFSSH* ssh,
|
||||||
uint32_t begin = *idx;
|
uint32_t begin = *idx;
|
||||||
uint32_t nameSz;
|
uint32_t nameSz;
|
||||||
char serviceName[32];
|
char serviceName[32];
|
||||||
|
|
||||||
(void)ssh;
|
(void)ssh;
|
||||||
(void)buf;
|
|
||||||
(void)len;
|
(void)len;
|
||||||
|
|
||||||
ato32(buf + begin, &nameSz);
|
ato32(buf + begin, &nameSz);
|
||||||
|
@ -1154,11 +1170,87 @@ static int DoServiceRequest(WOLFSSH* ssh,
|
||||||
|
|
||||||
XMEMCPY(serviceName, buf + begin, nameSz);
|
XMEMCPY(serviceName, buf + begin, nameSz);
|
||||||
begin += nameSz;
|
begin += nameSz;
|
||||||
|
|
||||||
serviceName[nameSz] = 0;
|
serviceName[nameSz] = 0;
|
||||||
|
|
||||||
WLOG(WS_LOG_DEBUG, "Requesting service: %s\n", serviceName);
|
WLOG(WS_LOG_DEBUG, "Requesting service: %s", serviceName);
|
||||||
SendServiceAccept(ssh, serviceNameUserAuth);
|
|
||||||
|
SendServiceAccept(ssh, serviceName);
|
||||||
|
|
||||||
|
*idx = begin;
|
||||||
|
|
||||||
|
return WS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int DoUserAuthRequest(WOLFSSH* ssh,
|
||||||
|
uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||||
|
{
|
||||||
|
uint32_t begin = *idx;
|
||||||
|
uint32_t valueSz;
|
||||||
|
char value[32];
|
||||||
|
|
||||||
|
(void)ssh;
|
||||||
|
(void)len;
|
||||||
|
|
||||||
|
ato32(buf + begin, &valueSz);
|
||||||
|
begin += LENGTH_SZ;
|
||||||
|
|
||||||
|
XMEMCPY(value, buf + begin, valueSz);
|
||||||
|
begin += valueSz;
|
||||||
|
value[valueSz] = 0;
|
||||||
|
|
||||||
|
ato32(buf + begin, &valueSz);
|
||||||
|
begin += LENGTH_SZ;
|
||||||
|
|
||||||
|
XMEMCPY(value, buf + begin, valueSz);
|
||||||
|
begin += valueSz;
|
||||||
|
value[valueSz] = 0;
|
||||||
|
|
||||||
|
ato32(buf + begin, &valueSz);
|
||||||
|
begin += LENGTH_SZ;
|
||||||
|
|
||||||
|
XMEMCPY(value, buf + begin, valueSz);
|
||||||
|
begin += valueSz;
|
||||||
|
value[valueSz] = 0;
|
||||||
|
|
||||||
|
*idx = begin;
|
||||||
|
|
||||||
|
SendUserAuthSuccess(ssh);
|
||||||
|
|
||||||
|
return WS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int DoChannelOpen(WOLFSSH* ssh,
|
||||||
|
uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||||
|
{
|
||||||
|
uint32_t begin = *idx;
|
||||||
|
uint32_t value;
|
||||||
|
uint32_t typeSz;
|
||||||
|
char type[32];
|
||||||
|
|
||||||
|
(void)ssh;
|
||||||
|
(void)len;
|
||||||
|
|
||||||
|
ato32(buf + begin, &typeSz);
|
||||||
|
begin += LENGTH_SZ;
|
||||||
|
|
||||||
|
XMEMCPY(type, buf + begin, typeSz);
|
||||||
|
begin += typeSz;
|
||||||
|
type[typeSz] = 0;
|
||||||
|
WLOG(WS_LOG_DEBUG, "%s: type = %s", __func__, type);
|
||||||
|
|
||||||
|
ato32(buf + begin, &value);
|
||||||
|
begin += UINT32_SZ;
|
||||||
|
WLOG(WS_LOG_DEBUG, "%s: channel = %u", __func__, value);
|
||||||
|
|
||||||
|
ato32(buf + begin, &value);
|
||||||
|
begin += UINT32_SZ;
|
||||||
|
WLOG(WS_LOG_DEBUG, "%s: initialWindowSz = %u", __func__, value);
|
||||||
|
|
||||||
|
ato32(buf + begin, &value);
|
||||||
|
begin += UINT32_SZ;
|
||||||
|
WLOG(WS_LOG_DEBUG, "%s: maxPacketSz = %u", __func__, value);
|
||||||
|
|
||||||
*idx = begin;
|
*idx = begin;
|
||||||
|
|
||||||
|
@ -1235,6 +1327,13 @@ static int DoPacket(WOLFSSH* ssh)
|
||||||
|
|
||||||
case MSGID_USERAUTH_REQUEST:
|
case MSGID_USERAUTH_REQUEST:
|
||||||
WLOG(WS_LOG_DEBUG, "Decoding MSGID_USERAUTH_REQUEST");
|
WLOG(WS_LOG_DEBUG, "Decoding MSGID_USERAUTH_REQUEST");
|
||||||
|
DoUserAuthRequest(ssh, buf, payloadSz, &idx);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSGID_CHANNEL_OPEN:
|
||||||
|
WLOG(WS_LOG_DEBUG, "Decoding MSGID_CHANNEL_OPEN");
|
||||||
|
DoChannelOpen(ssh, buf, payloadSz, &idx);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
WLOG(WS_LOG_DEBUG, "Unimplemented message ID (%d)", msg);
|
WLOG(WS_LOG_DEBUG, "Unimplemented message ID (%d)", msg);
|
||||||
|
@ -1472,6 +1571,8 @@ int ProcessReply(WOLFSSH* ssh)
|
||||||
WLOG(WS_LOG_DEBUG, "Bad process input state, program error");
|
WLOG(WS_LOG_DEBUG, "Bad process input state, program error");
|
||||||
return WS_INPUT_CASE_E;
|
return WS_INPUT_CASE_E;
|
||||||
}
|
}
|
||||||
|
WLOG(WS_LOG_DEBUG, "PR4: Shrinking input buffer");
|
||||||
|
ShrinkBuffer(&ssh->inputBuffer, 1);
|
||||||
ssh->processReplyState = PROCESS_INIT;
|
ssh->processReplyState = PROCESS_INIT;
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -2086,12 +2187,47 @@ int SendServiceAccept(WOLFSSH* ssh, const char* name)
|
||||||
ssh->outputBuffer.length = idx;
|
ssh->outputBuffer.length = idx;
|
||||||
|
|
||||||
BundlePacket(ssh);
|
BundlePacket(ssh);
|
||||||
/*SendBuffered(ssh);*/
|
|
||||||
SendUserAuthBanner(ssh);
|
SendUserAuthBanner(ssh);
|
||||||
|
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static const char cannedAuths[] = "password";
|
||||||
|
static const uint32_t cannedAuthsSz = sizeof(cannedAuths) - 1;
|
||||||
|
|
||||||
|
|
||||||
|
int SendUserAuthFailure(WOLFSSH* ssh, uint8_t partialSuccess)
|
||||||
|
{
|
||||||
|
(void)ssh;
|
||||||
|
(void)partialSuccess;
|
||||||
|
return WS_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int SendUserAuthSuccess(WOLFSSH* ssh)
|
||||||
|
{
|
||||||
|
uint8_t* output;
|
||||||
|
uint32_t idx;
|
||||||
|
|
||||||
|
if (ssh == NULL)
|
||||||
|
return WS_BAD_ARGUMENT;
|
||||||
|
|
||||||
|
PreparePacket(ssh, MSG_ID_SZ);
|
||||||
|
|
||||||
|
output = ssh->outputBuffer.buffer;
|
||||||
|
idx = ssh->outputBuffer.length;
|
||||||
|
|
||||||
|
output[idx++] = MSGID_USERAUTH_SUCCESS;
|
||||||
|
|
||||||
|
ssh->outputBuffer.length = idx;
|
||||||
|
|
||||||
|
BundlePacket(ssh);
|
||||||
|
SendBuffered(ssh);
|
||||||
|
|
||||||
|
return WS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char cannedBanner[] =
|
static const char cannedBanner[] =
|
||||||
"CANNED BANNER\r\n"
|
"CANNED BANNER\r\n"
|
||||||
|
|
|
@ -78,6 +78,9 @@ enum {
|
||||||
/* Public Key IDs */
|
/* Public Key IDs */
|
||||||
ID_SSH_RSA,
|
ID_SSH_RSA,
|
||||||
|
|
||||||
|
/* UserAuth IDs */
|
||||||
|
ID_USERAUTH_PASSWORD,
|
||||||
|
|
||||||
ID_UNKNOWN
|
ID_UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -157,6 +160,15 @@ typedef struct HandshakeInfo {
|
||||||
} HandshakeInfo;
|
} HandshakeInfo;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct Channel {
|
||||||
|
uint32_t windowSz;
|
||||||
|
uint32_t maxPacketSz;
|
||||||
|
uint8_t channelType;
|
||||||
|
uint32_t sender; /* Note for John: client's channel number for session */
|
||||||
|
uint32_t recipient; /* server's channel number for session */
|
||||||
|
} Channel;
|
||||||
|
|
||||||
|
|
||||||
/* our wolfSSH session */
|
/* our wolfSSH session */
|
||||||
struct WOLFSSH {
|
struct WOLFSSH {
|
||||||
WOLFSSH_CTX* ctx; /* owner context */
|
WOLFSSH_CTX* ctx; /* owner context */
|
||||||
|
@ -239,6 +251,8 @@ WOLFSSH_LOCAL int SendDisconnect(WOLFSSH*, uint32_t);
|
||||||
WOLFSSH_LOCAL int SendIgnore(WOLFSSH*, const unsigned char*, uint32_t);
|
WOLFSSH_LOCAL int SendIgnore(WOLFSSH*, const unsigned char*, uint32_t);
|
||||||
WOLFSSH_LOCAL int SendDebug(WOLFSSH*, byte, const char*);
|
WOLFSSH_LOCAL int SendDebug(WOLFSSH*, byte, const char*);
|
||||||
WOLFSSH_LOCAL int SendServiceAccept(WOLFSSH*, const char*);
|
WOLFSSH_LOCAL int SendServiceAccept(WOLFSSH*, const char*);
|
||||||
|
WOLFSSH_LOCAL int SendUserAuthSuccess(WOLFSSH*);
|
||||||
|
WOLFSSH_LOCAL int SendUserAuthFailure(WOLFSSH*, uint8_t);
|
||||||
WOLFSSH_LOCAL int SendUserAuthBanner(WOLFSSH*);
|
WOLFSSH_LOCAL int SendUserAuthBanner(WOLFSSH*);
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,7 +305,9 @@ enum WS_MessageIds {
|
||||||
MSGID_USERAUTH_REQUEST = 50,
|
MSGID_USERAUTH_REQUEST = 50,
|
||||||
MSGID_USERAUTH_FAILURE = 51,
|
MSGID_USERAUTH_FAILURE = 51,
|
||||||
MSGID_USERAUTH_SUCCESS = 52,
|
MSGID_USERAUTH_SUCCESS = 52,
|
||||||
MSGID_USERAUTH_BANNER = 53
|
MSGID_USERAUTH_BANNER = 53,
|
||||||
|
|
||||||
|
MSGID_CHANNEL_OPEN = 90
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue