|
52 | 52 | #include "transport.h"
|
53 | 53 | #include "session.h"
|
54 | 54 | #include "userauth.h"
|
| 55 | +#include "userauth_kbd_packet.h" |
55 | 56 |
|
56 | 57 | /* libssh2_userauth_list
|
57 | 58 | *
|
@@ -1878,13 +1879,13 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
|
1878 | 1879 | ((*response_callback)))
|
1879 | 1880 | {
|
1880 | 1881 | unsigned char *s;
|
| 1882 | + |
1881 | 1883 | int rc;
|
1882 | 1884 |
|
1883 | 1885 | static const unsigned char reply_codes[4] = {
|
1884 | 1886 | SSH_MSG_USERAUTH_SUCCESS,
|
1885 | 1887 | SSH_MSG_USERAUTH_FAILURE, SSH_MSG_USERAUTH_INFO_REQUEST, 0
|
1886 | 1888 | };
|
1887 |
| - unsigned int language_tag_len; |
1888 | 1889 | unsigned int i;
|
1889 | 1890 |
|
1890 | 1891 | if(session->userauth_kybd_state == libssh2_NB_state_idle) {
|
@@ -2007,215 +2008,14 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
|
2007 | 2008 | }
|
2008 | 2009 |
|
2009 | 2010 | /* server requested PAM-like conversation */
|
2010 |
| - s = session->userauth_kybd_data + 1; |
2011 |
| - |
2012 |
| - if(session->userauth_kybd_data_len >= 5) { |
2013 |
| - /* string name (ISO-10646 UTF-8) */ |
2014 |
| - session->userauth_kybd_auth_name_len = _libssh2_ntohu32(s); |
2015 |
| - if(session->userauth_kybd_auth_name_len > |
2016 |
| - session->userauth_kybd_data_len - 5) |
2017 |
| - return _libssh2_error(session, |
2018 |
| - LIBSSH2_ERROR_OUT_OF_BOUNDARY, |
2019 |
| - "Bad keyboard auth name"); |
2020 |
| - s += 4; |
2021 |
| - } |
2022 |
| - else { |
2023 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2024 |
| - "userauth keyboard data buffer too small" |
2025 |
| - "to get length"); |
2026 |
| - goto cleanup; |
2027 |
| - } |
2028 |
| - |
2029 |
| - if(session->userauth_kybd_auth_name_len) { |
2030 |
| - session->userauth_kybd_auth_name = |
2031 |
| - LIBSSH2_ALLOC(session, |
2032 |
| - session->userauth_kybd_auth_name_len); |
2033 |
| - if(!session->userauth_kybd_auth_name) { |
2034 |
| - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, |
2035 |
| - "Unable to allocate memory for " |
2036 |
| - "keyboard-interactive 'name' " |
2037 |
| - "request field"); |
2038 |
| - goto cleanup; |
2039 |
| - } |
2040 |
| - if(s + session->userauth_kybd_auth_name_len <= |
2041 |
| - session->userauth_kybd_data + |
2042 |
| - session->userauth_kybd_data_len) { |
2043 |
| - memcpy(session->userauth_kybd_auth_name, s, |
2044 |
| - session->userauth_kybd_auth_name_len); |
2045 |
| - s += session->userauth_kybd_auth_name_len; |
2046 |
| - } |
2047 |
| - else { |
2048 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2049 |
| - "userauth keyboard data buffer too small" |
2050 |
| - "for auth name"); |
2051 |
| - goto cleanup; |
2052 |
| - } |
2053 |
| - } |
2054 |
| - |
2055 |
| - if(s + 4 <= session->userauth_kybd_data + |
2056 |
| - session->userauth_kybd_data_len) { |
2057 |
| - /* string instruction (ISO-10646 UTF-8) */ |
2058 |
| - session->userauth_kybd_auth_instruction_len = |
2059 |
| - _libssh2_ntohu32(s); |
2060 |
| - s += 4; |
2061 |
| - } |
2062 |
| - else { |
2063 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2064 |
| - "userauth keyboard data buffer too small" |
2065 |
| - "for auth instruction length"); |
| 2011 | + if(userauth_keyboard_interactive_decode_info_request(session) |
| 2012 | + < 0) { |
2066 | 2013 | goto cleanup;
|
2067 | 2014 | }
|
2068 | 2015 |
|
2069 |
| - if(session->userauth_kybd_auth_instruction_len) { |
2070 |
| - session->userauth_kybd_auth_instruction = |
2071 |
| - LIBSSH2_ALLOC(session, |
2072 |
| - session->userauth_kybd_auth_instruction_len); |
2073 |
| - if(!session->userauth_kybd_auth_instruction) { |
2074 |
| - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, |
2075 |
| - "Unable to allocate memory for " |
2076 |
| - "keyboard-interactive 'instruction' " |
2077 |
| - "request field"); |
2078 |
| - goto cleanup; |
2079 |
| - } |
2080 |
| - if(s + session->userauth_kybd_auth_instruction_len <= |
2081 |
| - session->userauth_kybd_data + |
2082 |
| - session->userauth_kybd_data_len) { |
2083 |
| - memcpy(session->userauth_kybd_auth_instruction, s, |
2084 |
| - session->userauth_kybd_auth_instruction_len); |
2085 |
| - s += session->userauth_kybd_auth_instruction_len; |
2086 |
| - } |
2087 |
| - else { |
2088 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2089 |
| - "userauth keyboard data buffer too small" |
2090 |
| - "for auth instruction"); |
2091 |
| - goto cleanup; |
2092 |
| - } |
2093 |
| - } |
2094 |
| - |
2095 |
| - if(s + 4 <= session->userauth_kybd_data + |
2096 |
| - session->userauth_kybd_data_len) { |
2097 |
| - /* string language tag (as defined in [RFC-3066]) */ |
2098 |
| - language_tag_len = _libssh2_ntohu32(s); |
2099 |
| - s += 4; |
2100 |
| - } |
2101 |
| - else { |
2102 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2103 |
| - "userauth keyboard data buffer too small" |
2104 |
| - "for auth language tag length"); |
2105 |
| - goto cleanup; |
2106 |
| - } |
2107 |
| - |
2108 |
| - if(s + language_tag_len <= session->userauth_kybd_data + |
2109 |
| - session->userauth_kybd_data_len) { |
2110 |
| - /* ignoring this field as deprecated */ |
2111 |
| - s += language_tag_len; |
2112 |
| - } |
2113 |
| - else { |
2114 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2115 |
| - "userauth keyboard data buffer too small" |
2116 |
| - "for auth language tag"); |
2117 |
| - goto cleanup; |
2118 |
| - } |
2119 |
| - |
2120 |
| - if(s + 4 <= session->userauth_kybd_data + |
2121 |
| - session->userauth_kybd_data_len) { |
2122 |
| - /* int num-prompts */ |
2123 |
| - session->userauth_kybd_num_prompts = _libssh2_ntohu32(s); |
2124 |
| - s += 4; |
2125 |
| - } |
2126 |
| - else { |
2127 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2128 |
| - "userauth keyboard data buffer too small" |
2129 |
| - "for auth num keyboard prompts"); |
2130 |
| - goto cleanup; |
2131 |
| - } |
2132 |
| - |
2133 |
| - if(session->userauth_kybd_num_prompts > 100) { |
2134 |
| - _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, |
2135 |
| - "Too many replies for " |
2136 |
| - "keyboard-interactive prompts"); |
2137 |
| - goto cleanup; |
2138 |
| - } |
2139 |
| - |
2140 |
| - if(session->userauth_kybd_num_prompts) { |
2141 |
| - session->userauth_kybd_prompts = |
2142 |
| - LIBSSH2_CALLOC(session, |
2143 |
| - sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * |
2144 |
| - session->userauth_kybd_num_prompts); |
2145 |
| - if(!session->userauth_kybd_prompts) { |
2146 |
| - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, |
2147 |
| - "Unable to allocate memory for " |
2148 |
| - "keyboard-interactive prompts array"); |
2149 |
| - goto cleanup; |
2150 |
| - } |
2151 |
| - |
2152 |
| - session->userauth_kybd_responses = |
2153 |
| - LIBSSH2_CALLOC(session, |
2154 |
| - sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * |
2155 |
| - session->userauth_kybd_num_prompts); |
2156 |
| - if(!session->userauth_kybd_responses) { |
2157 |
| - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, |
2158 |
| - "Unable to allocate memory for " |
2159 |
| - "keyboard-interactive responses array"); |
2160 |
| - goto cleanup; |
2161 |
| - } |
2162 |
| - |
2163 |
| - for(i = 0; i < session->userauth_kybd_num_prompts; i++) { |
2164 |
| - if(s + 4 <= session->userauth_kybd_data + |
2165 |
| - session->userauth_kybd_data_len) { |
2166 |
| - /* string prompt[1] (ISO-10646 UTF-8) */ |
2167 |
| - session->userauth_kybd_prompts[i].length = |
2168 |
| - _libssh2_ntohu32(s); |
2169 |
| - s += 4; |
2170 |
| - } |
2171 |
| - else { |
2172 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2173 |
| - "userauth keyboard data buffer too " |
2174 |
| - "small for auth keyboard " |
2175 |
| - "prompt length"); |
2176 |
| - goto cleanup; |
2177 |
| - } |
2178 |
| - |
2179 |
| - session->userauth_kybd_prompts[i].text = |
2180 |
| - LIBSSH2_CALLOC(session, |
2181 |
| - session->userauth_kybd_prompts[i]. |
2182 |
| - length); |
2183 |
| - if(!session->userauth_kybd_prompts[i].text) { |
2184 |
| - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, |
2185 |
| - "Unable to allocate memory for " |
2186 |
| - "keyboard-interactive prompt message"); |
2187 |
| - goto cleanup; |
2188 |
| - } |
2189 |
| - |
2190 |
| - if(s + session->userauth_kybd_prompts[i].length <= |
2191 |
| - session->userauth_kybd_data + |
2192 |
| - session->userauth_kybd_data_len) { |
2193 |
| - memcpy(session->userauth_kybd_prompts[i].text, s, |
2194 |
| - session->userauth_kybd_prompts[i].length); |
2195 |
| - s += session->userauth_kybd_prompts[i].length; |
2196 |
| - } |
2197 |
| - else { |
2198 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2199 |
| - "userauth keyboard data buffer too " |
2200 |
| - "small for auth keyboard prompt"); |
2201 |
| - goto cleanup; |
2202 |
| - } |
2203 |
| - if(s < session->userauth_kybd_data + |
2204 |
| - session->userauth_kybd_data_len) { |
2205 |
| - /* boolean echo[1] */ |
2206 |
| - session->userauth_kybd_prompts[i].echo = *s++; |
2207 |
| - } |
2208 |
| - else { |
2209 |
| - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
2210 |
| - "userauth keyboard data buffer too " |
2211 |
| - "small for auth keyboard prompt echo"); |
2212 |
| - goto cleanup; |
2213 |
| - } |
2214 |
| - } |
2215 |
| - } |
2216 |
| - |
2217 |
| - response_callback(session->userauth_kybd_auth_name, |
| 2016 | + response_callback((const char *)session->userauth_kybd_auth_name, |
2218 | 2017 | session->userauth_kybd_auth_name_len,
|
| 2018 | + (const char *) |
2219 | 2019 | session->userauth_kybd_auth_instruction,
|
2220 | 2020 | session->userauth_kybd_auth_instruction_len,
|
2221 | 2021 | session->userauth_kybd_num_prompts,
|
|
0 commit comments