40
#include "libssh2_priv.h"
41
#include "userauth_kbd_packet.h"
43
int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *session)
45
unsigned char *language_tag;
46
size_t language_tag_len;
48
unsigned char packet_type;
51
struct string_buf decoded;
53
decoded.data = session->userauth_kybd_data;
54
decoded.dataptr = session->userauth_kybd_data;
55
decoded.len = session->userauth_kybd_data_len;
57
if(session->userauth_kybd_data_len < 17) {
58
_libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
59
"userauth keyboard data buffer too small "
65
_libssh2_get_byte(&decoded, &packet_type);
68
if(_libssh2_copy_string(session, &decoded,
69
&session->userauth_kybd_auth_name,
70
&session->userauth_kybd_auth_name_len) == -1) {
71
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
73
"keyboard-interactive 'name' "
79
if(_libssh2_copy_string(session, &decoded,
80
&session->userauth_kybd_auth_instruction,
81
&session->userauth_kybd_auth_instruction_len)
83
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
85
"keyboard-interactive 'instruction' "
91
if(_libssh2_get_string(&decoded, &language_tag,
92
&language_tag_len) == -1) {
93
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
95
"keyboard-interactive 'language tag' "
101
if(_libssh2_get_u32(&decoded, &tmp_u32) == -1 ||
102
(session->userauth_kybd_num_prompts = tmp_u32) != tmp_u32) {
103
_libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
105
"keyboard-interactive number of keyboard prompts");
109
if(session->userauth_kybd_num_prompts > 100) {
110
_libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY,
111
"Too many replies for "
112
"keyboard-interactive prompts");
116
if(session->userauth_kybd_num_prompts == 0) {
120
session->userauth_kybd_prompts =
121
LIBSSH2_CALLOC(session,
122
sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) *
123
session->userauth_kybd_num_prompts);
124
if(!session->userauth_kybd_prompts) {
125
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
126
"Unable to allocate memory for "
127
"keyboard-interactive prompts array");
131
session->userauth_kybd_responses =
132
LIBSSH2_CALLOC(session,
133
sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) *
134
session->userauth_kybd_num_prompts);
135
if(!session->userauth_kybd_responses) {
136
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
137
"Unable to allocate memory for "
138
"keyboard-interactive responses array");
142
for(i = 0; i < session->userauth_kybd_num_prompts; i++) {
144
if(_libssh2_copy_string(session, &decoded,
145
&session->userauth_kybd_prompts[i].text,
146
&session->userauth_kybd_prompts[i].length)
148
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
150
"keyboard-interactive prompt message");
155
if(_libssh2_get_boolean(&decoded,
156
&session->userauth_kybd_prompts[i].echo)
158
_libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
160
"user auth keyboard prompt echo");