mirror of https://github.com/wolfSSL/wolfssh.git
1. Adding parsing of publickey authentication data.
2. Changed logging of authentication requests. 3. Reply to "none" authentication types with a failure that has the supported auth type list. 4. Fixed bug where passing payload to the DoUserAuthRequest wasn't getting the correct payload length. 5. Reordered a couple utility functions.pull/4/head
parent
8e3e5a1bf5
commit
911ac8c433
151
src/internal.c
151
src/internal.c
|
|
@ -163,6 +163,7 @@ static const NameIdPair NameIdMap[] = {
|
|||
|
||||
/* UserAuth IDs */
|
||||
{ ID_USERAUTH_PASSWORD, "password" },
|
||||
{ ID_USERAUTH_PUBLICKEY, "publickey" },
|
||||
|
||||
/* Channel Type IDs */
|
||||
{ ID_CHANTYPE_SESSION, "session" }
|
||||
|
|
@ -1275,11 +1276,13 @@ static int DoDisconnect(WOLFSSH* ssh, uint8_t* buf, uint32_t len, uint32_t* idx)
|
|||
return WS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
static const char serviceNameUserAuth[] = "ssh-userauth";
|
||||
static const char serviceNameConnection[] = "ssh-connection";
|
||||
#endif
|
||||
|
||||
|
||||
static int DoServiceRequest(WOLFSSH* ssh,
|
||||
uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||
{
|
||||
|
|
@ -1305,45 +1308,6 @@ static int DoServiceRequest(WOLFSSH* ssh,
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
ssh->clientState = CLIENT_USERAUTH_DONE;
|
||||
|
||||
return WS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int GetBoolean(uint8_t* v, uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||
{
|
||||
int result = WS_BUFFER_E;
|
||||
|
|
@ -1366,6 +1330,7 @@ static int GetUint32(uint32_t* v, uint8_t* buf, uint32_t len, uint32_t* idx)
|
|||
*idx += UINT32_SZ;
|
||||
result = WS_SUCCESS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -1391,6 +1356,73 @@ static int GetString(char* s, uint32_t* sSz,
|
|||
}
|
||||
|
||||
|
||||
static int DoUserAuthRequest(WOLFSSH* ssh,
|
||||
uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||
{
|
||||
uint32_t begin = *idx;
|
||||
int ret;
|
||||
uint32_t valueSz;
|
||||
char value[32];
|
||||
uint8_t authNameId;
|
||||
|
||||
(void)ssh;
|
||||
(void)len;
|
||||
|
||||
DumpOctetString(buf, len);
|
||||
ato32(buf + begin, &valueSz);
|
||||
begin += LENGTH_SZ;
|
||||
|
||||
XMEMCPY(value, buf + begin, valueSz);
|
||||
begin += valueSz;
|
||||
value[valueSz] = 0;
|
||||
WLOG(WS_LOG_DEBUG, "DUAR: userName = %s", value);
|
||||
|
||||
ato32(buf + begin, &valueSz);
|
||||
begin += LENGTH_SZ;
|
||||
|
||||
XMEMCPY(value, buf + begin, valueSz);
|
||||
begin += valueSz;
|
||||
value[valueSz] = 0;
|
||||
WLOG(WS_LOG_DEBUG, "DUAR: serviceName = %s", value);
|
||||
|
||||
ato32(buf + begin, &valueSz);
|
||||
begin += LENGTH_SZ;
|
||||
|
||||
XMEMCPY(value, buf + begin, valueSz);
|
||||
begin += valueSz;
|
||||
value[valueSz] = 0;
|
||||
WLOG(WS_LOG_DEBUG, "DUAR: authName = %s", value);
|
||||
authNameId = NameToId(value, valueSz);
|
||||
|
||||
if (authNameId == ID_USERAUTH_PASSWORD) {
|
||||
uint8_t pwChanged;
|
||||
ret = GetBoolean(&pwChanged, buf, len, &begin);
|
||||
WLOG(WS_LOG_DEBUG, "DUAR: pwChanged = %s",
|
||||
(pwChanged ? "TRUE" : "FALSE"));
|
||||
if (!pwChanged) {
|
||||
ret = GetString(value, &valueSz, buf, len, &begin);
|
||||
if (ret == WS_SUCCESS)
|
||||
WLOG(WS_LOG_DEBUG, "DUAR: password = %s", value);
|
||||
else
|
||||
WLOG(WS_LOG_DEBUG, "DUAR: password = error? %d", ret);
|
||||
}
|
||||
else {
|
||||
/* Skip the password change. Maybe error out since we aren't
|
||||
* supporting password changes at this time. */
|
||||
}
|
||||
}
|
||||
else if (authNameId == ID_USERAUTH_PUBLICKEY) {
|
||||
} else
|
||||
SendUserAuthFailure(ssh, 0);
|
||||
|
||||
*idx = begin;
|
||||
|
||||
ssh->clientState = CLIENT_USERAUTH_DONE;
|
||||
|
||||
return WS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int DoChannelOpen(WOLFSSH* ssh,
|
||||
uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||
{
|
||||
|
|
@ -1670,7 +1702,8 @@ static int DoPacket(WOLFSSH* ssh)
|
|||
|
||||
case MSGID_USERAUTH_REQUEST:
|
||||
WLOG(WS_LOG_DEBUG, "Decoding MSGID_USERAUTH_REQUEST");
|
||||
DoUserAuthRequest(ssh, buf, payloadSz, &idx);
|
||||
DoUserAuthRequest(ssh, buf + idx, payloadSz, &payloadIdx);
|
||||
idx += payloadIdx;
|
||||
break;
|
||||
|
||||
case MSGID_CHANNEL_OPEN:
|
||||
|
|
@ -2623,18 +2656,48 @@ int SendServiceAccept(WOLFSSH* ssh)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static const char cannedAuths[] = "password";
|
||||
static const uint32_t cannedAuthsSz = sizeof(cannedAuths) - 1;
|
||||
|
||||
|
||||
int SendUserAuthFailure(WOLFSSH* ssh, uint8_t partialSuccess)
|
||||
{
|
||||
(void)ssh;
|
||||
uint8_t* output;
|
||||
uint32_t idx;
|
||||
int ret;
|
||||
|
||||
(void)partialSuccess;
|
||||
return WS_SUCCESS;
|
||||
|
||||
WLOG(WS_LOG_DEBUG, "Entering SendUserAuthFailure()");
|
||||
|
||||
if (ssh == NULL)
|
||||
return WS_BAD_ARGUMENT;
|
||||
|
||||
ret = PreparePacket(ssh,
|
||||
MSG_ID_SZ + LENGTH_SZ + cannedAuthsSz + BOOLEAN_SZ);
|
||||
if (ret != WS_SUCCESS)
|
||||
return ret;
|
||||
|
||||
output = ssh->outputBuffer.buffer;
|
||||
idx = ssh->outputBuffer.length;
|
||||
|
||||
output[idx++] = MSGID_USERAUTH_FAILURE;
|
||||
c32toa(cannedAuthsSz, output + idx);
|
||||
idx += LENGTH_SZ;
|
||||
WMEMCPY(output + idx, cannedAuths, cannedAuthsSz);
|
||||
idx += cannedAuthsSz;
|
||||
output[idx++] = 0;
|
||||
|
||||
ssh->outputBuffer.length = idx;
|
||||
|
||||
ret = BundlePacket(ssh);
|
||||
if (ret == WS_SUCCESS)
|
||||
ret = SendBuffered(ssh);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int SendUserAuthSuccess(WOLFSSH* ssh)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -228,6 +228,9 @@ static void SshResourceFree(WOLFSSH* ssh, void* heap)
|
|||
/* FreeRng(ssh->rng); */
|
||||
WFREE(ssh->rng, heap, DYNTYPE_RNG);
|
||||
}
|
||||
if (ssh->userName) {
|
||||
WFREE(ssh->userName, heap, DYNTYPE_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ enum {
|
|||
|
||||
/* UserAuth IDs */
|
||||
ID_USERAUTH_PASSWORD,
|
||||
ID_USERAUTH_PUBLICKEY,
|
||||
|
||||
/* Channel Type IDs */
|
||||
ID_CHANTYPE_SESSION,
|
||||
|
|
@ -246,6 +247,9 @@ struct WOLFSSH {
|
|||
uint8_t macKeyServerSz;
|
||||
|
||||
HandshakeInfo* handshake;
|
||||
|
||||
uint8_t* userName;
|
||||
uint32_t userNameSz;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue