-
Notifications
You must be signed in to change notification settings - Fork 105
Add service-name check and regress test #953
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8345,7 +8345,8 @@ static int DoUserAuthRequest(WOLFSSH* ssh, | |
| { | ||
| word32 begin; | ||
| int ret = WS_SUCCESS; | ||
| byte authNameId; | ||
| byte authNameId = ID_UNKNOWN; | ||
| int serviceValid = 1; | ||
| WS_UserAuthData authData; | ||
|
|
||
| WLOG(WS_LOG_DEBUG, "Entering DoUserAuthRequest()"); | ||
|
|
@@ -8356,37 +8357,32 @@ static int DoUserAuthRequest(WOLFSSH* ssh, | |
| if (ret == WS_SUCCESS) { | ||
| begin = *idx; | ||
| WMEMSET(&authData, 0, sizeof(authData)); | ||
| ret = GetSize(&authData.usernameSz, buf, len, &begin); | ||
| } | ||
|
|
||
| if (ret == WS_SUCCESS) { | ||
| authData.username = buf + begin; | ||
| begin += authData.usernameSz; | ||
|
|
||
| ret = GetUint32(&authData.serviceNameSz, buf, len, &begin); | ||
| ret = GetStringRef(&authData.usernameSz, &authData.username, | ||
| buf, len, &begin); | ||
| } | ||
|
|
||
| if (ret == WS_SUCCESS) { | ||
| ret = wolfSSH_SetUsernameRaw(ssh, authData.username, authData.usernameSz); | ||
| ret = GetStringRef(&authData.serviceNameSz, &authData.serviceName, | ||
| buf, len, &begin); | ||
| } | ||
|
|
||
| if (ret == WS_SUCCESS) { | ||
| if (authData.serviceNameSz > len - begin) { | ||
| ret = WS_BUFFER_E; | ||
| if (NameToId((const char*)authData.serviceName, authData.serviceNameSz) | ||
|
aidangarske marked this conversation as resolved.
|
||
| != ID_SERVICE_CONNECTION) { | ||
| WLOG(WS_LOG_DEBUG, "DUAR: Invalid service name"); | ||
|
yosuke-wolfssl marked this conversation as resolved.
|
||
| serviceValid = 0; | ||
| ret = SendUserAuthFailure(ssh, 0); | ||
|
aidangarske marked this conversation as resolved.
yosuke-wolfssl marked this conversation as resolved.
|
||
| /* Consume all remaining data */ | ||
| *idx = len; | ||
|
yosuke-wolfssl marked this conversation as resolved.
|
||
| } | ||
| else { | ||
| ret = GetStringRef(&authData.authNameSz, &authData.authName, | ||
| buf, len, &begin); | ||
| } | ||
| } | ||
|
yosuke-wolfssl marked this conversation as resolved.
|
||
|
|
||
| if (ret == WS_SUCCESS) { | ||
| authData.serviceName = buf + begin; | ||
| begin += authData.serviceNameSz; | ||
|
|
||
| ret = GetSize(&authData.authNameSz, buf, len, &begin); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function GetStringRef() was added for cases like this. It does all the appropriate length checking and it updates the idx. I just never got around to replacing all GetSize() and adjusting the idx myself with this function. GetStringRef will give you a pointer into buf that points at the string, and it gives you the length. You don't need to free it, and the pointer is to const. |
||
| } | ||
|
|
||
| if (ret == WS_SUCCESS) { | ||
| authData.authName = buf + begin; | ||
| begin += authData.authNameSz; | ||
| authNameId = NameToId((char*)authData.authName, authData.authNameSz); | ||
| if (ret == WS_SUCCESS && serviceValid) { | ||
| authNameId = NameToId((const char*)authData.authName, authData.authNameSz); | ||
| ssh->authId = authNameId; | ||
|
|
||
| if (authNameId == ID_USERAUTH_PASSWORD) | ||
|
|
@@ -8409,11 +8405,14 @@ static int DoUserAuthRequest(WOLFSSH* ssh, | |
| #endif | ||
| else { | ||
|
yosuke-wolfssl marked this conversation as resolved.
|
||
| WLOG(WS_LOG_DEBUG, | ||
| "invalid userauth type: %s", IdToName(authNameId)); | ||
| "DUAR: invalid userauth type: %s", IdToName(authNameId)); | ||
| ret = SendUserAuthFailure(ssh, 0); | ||
| /* Consume all remaining data */ | ||
| begin = len; | ||
| } | ||
|
|
||
| if (ret == WS_SUCCESS) { | ||
| /* Set the username for valid service only */ | ||
| ret = wolfSSH_SetUsernameRaw(ssh, | ||
| authData.username, authData.usernameSz); | ||
| } | ||
|
|
@@ -17976,6 +17975,12 @@ int wolfSSH_TestChannelPutData(WOLFSSH_CHANNEL* channel, byte* data, | |
| return ChannelPutData(channel, data, dataSz); | ||
| } | ||
|
|
||
| int wolfSSH_TestDoUserAuthRequest(WOLFSSH* ssh, byte* buf, word32 len, | ||
| word32* idx) | ||
| { | ||
| return DoUserAuthRequest(ssh, buf, len, idx); | ||
| } | ||
|
|
||
| #ifndef WOLFSSH_NO_DH_GEX_SHA256 | ||
|
|
||
| int wolfSSH_TestDoKexDhGexRequest(WOLFSSH* ssh, byte* buf, word32 len, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.