Skip to content

Commit 89a7fc0

Browse files
Merge pull request #176 from LinuxJedi/wolfSSH-RFC-4256
Add wolfSSH documentation for Keyboard-Interactive
2 parents 23bfafc + 5cf4a79 commit 89a7fc0

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed

wolfSSH/src/chapter01.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The wolfSSH library is a lightweight SSHv2 server library written in ANSI C and
2929

3030
- Public key authentication options: RSA and ECDSA (with curves NISTP256, NISTP384, NISTP521)
3131

32-
- User authentication support (password and public key authentication)
32+
- User authentication support (password, keyboard-interactive and public key authentication)
3333

3434
- Simple API
3535

wolfSSH/src/chapter05.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following are values passed to the user authentication callback function in
4444

4545
```
4646
WOLFSSH_USERAUTH_PASSWORD
47+
WOLFSSH_USERAUTH_KEYBOARD
4748
WOLFSSH_USERAUTH_PUBLICKEY
4849
```
4950

@@ -72,6 +73,7 @@ WOLFSSH_USERAUTH_INVALID_USER
7273
WOLFSSH_USERAUTH_INVALID_PASSWORD
7374
WOLFSSH_USERAUTH_INVALID_PUBLICKEY
7475
WOLFSSH_USERAUTH_PARTIAL_SUCCESS
76+
WOLFSSH_USERAUTH_SUCCESS_ANOTHER
7577
```
7678

7779
## Callback Function Data Types
@@ -84,10 +86,11 @@ typedef struct WS_UserAuthData {
8486
byte* username ;
8587
word32 usernameSz ;
8688
byte* serviceName ;
87-
word32 serviceNameSz ; n
89+
word32 serviceNameSz ;
8890
union {
8991
WS_UserAuthData_Password password ;
9092
WS_UserAuthData_PublicKey publicKey ;
93+
WS_UserAuthData_Keyboard keyboard ;
9194
} sf;
9295
} WS_UserAuthData;
9396
```
@@ -110,6 +113,51 @@ typedef struct WS_UserAuthData_Password {
110113
} WS_UserAuthData_Password;
111114
```
112115

116+
### Keyboard-Interactive
117+
118+
The Keyboard-Interactive mode allows for an arbitrary number of prompts and
119+
responses from the server to the client. The structure that contains the
120+
information is as follows:
121+
122+
```c
123+
typedef struct WS_UserAuthData_Keyboard {
124+
word32 promptCount;
125+
word32 responseCount;
126+
word32 promptNameSz;
127+
word32 promptInstructionSz;
128+
word32 promptLanguageSz;
129+
byte* promptName;
130+
byte* promptInstruction;
131+
byte* promptLanguage;
132+
word32* promptLengths;
133+
word32* responseLengths;
134+
byte* promptEcho;
135+
byte** responses;
136+
byte** prompts;
137+
} WS_UserAuthData_Keyboard;
138+
```
139+
140+
On the client side, during authentication, the `promptName` and
141+
`promptInstruction` will indicate to the user information about the
142+
authentication. The `promptLanguage` field is a deprecated part of the API and
143+
is ignored.
144+
145+
The `promptCount` indicates how many prompts there are. `prompts` contains the
146+
array of prompts, `promptLengths` is an array containing the length of prompt
147+
in `prompts`. `promptEcho` in an array of booleans indicating whether or not
148+
each prompt response should be echoed to the user as they are typing.
149+
150+
Conversely there is `responseCount` to set the number of responses given.
151+
`responses` and `responseLengths` contain the response data for the prompts.
152+
153+
The server can set the prompts using the `wolfSSH_SetKeyboardAuthPrompts()`
154+
callback. The `WS_CallbackKeyboardAuthPrompts` callback should set the
155+
`promptCount`, `prompts`, `promptLengths` and `promptEcho`. The other `prompt*`
156+
items are optional.
157+
158+
The server should return `WOLFSSH_USERAUTH_SUCCESS_ANOTHER` from the
159+
`WS_CallbackUserAuth` callback to execute subsequent request / response rounds.
160+
113161
### Public Key
114162

115163
wolfSSH will support multiple public key algorithms. The publicKeyType member points to the algorithm name used.

wolfSSH/src/chapter06.md

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh );
2222
```
2323
This returns the pointer to the user authentication context data stored in the provided wolfSSH session. This is not to be confused with the wolfSSH’s context data used to create the session.
2424

25+
## Setting the Keyboard Authentication Prompts Callback Function
26+
```
27+
void wolfSSH_SetKeyboardAuthPrompts(WOLFSSH_CTX* ctx, WS_CallbackKeyboardAuthPrompts cb);
28+
```
29+
30+
The server needs to specify the prompts that are to be given to the client so
31+
that it can authenticate in Keyboard-Interactive mode. This callback allows the
32+
server to set the prompts ready to send to the client.
33+
34+
Without this set, Keyboard-Interactive mode will be disabled on the server, even
35+
if attempts are made to explicitly enable it.
36+
2537
## Example Echo Server User Authentication
2638

2739
The example echo server implements the authentication callback with sample users using passwords and public keys. The example callback, wsUserAuth, is set on the wolfSSH context:

wolfSSH/src/chapter13.md

+49
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,55 @@ authentication context.
841841
void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh )
842842
```
843843

844+
### wolfSSH_SetKeyboardAuthPrompts()
845+
846+
847+
**Synopsis**
848+
849+
**Description**
850+
851+
The wolfSSH_SetKeyboardAuthPrompts() function is used to setup the callback
852+
which will provide the server with the prompts to send to the client.
853+
854+
**Return Values**
855+
856+
None
857+
858+
**Parameters**
859+
860+
**ctx** - pointer to the wolfSSH context
861+
**cb** - callback function to provide the keyboard prompts
862+
863+
```
864+
#include <wolfssh/ssh.h>
865+
void wolfSSH_SetKeyboardAuthPrompts(WOLFSSH_CTX* ctx,
866+
WS_CallbackKeyboardAuthPrompts cb)
867+
```
868+
869+
### wolfSSH_SetKeyboardAuthCtx()
870+
871+
872+
**Synopsis**
873+
874+
**Description**
875+
876+
The wolfSSH_SetKeyboardAuthCtx() function is used to setup the user context
877+
for the wolfSSH_SetKeyboardAuthPrompts() function.
878+
879+
**Return Values**
880+
881+
None
882+
883+
**Parameters**
884+
885+
**ssh** - pointer to the WOLFSSH object
886+
**keyboardAuthCtx* - pointer to the user context data
887+
888+
```
889+
#include <wolfssh/ssh.h>
890+
void wolfSSH_SetKeyboardAuthCtx(WOLFSSH* ssh, void* keyboardAuthCtx)
891+
```
892+
844893
## Set Username
845894

846895

0 commit comments

Comments
 (0)