libssh: /build/libssh/src/libssh-0.8.6/include/libssh/session.h Source File

libssh 0.8.6 The SSH library

session.h
1 /*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef SESSION_H_
22 #define SESSION_H_
23 #include "libssh/priv.h"
24 #include "libssh/kex.h"
25 #include "libssh/packet.h"
26 #include "libssh/pcap.h"
27 #include "libssh/auth.h"
28 #include "libssh/channels.h"
29 #include "libssh/poll.h"
30
31 /* These are the different states a SSH session can be into its life */
32 enum ssh_session_state_e {
33 SSH_SESSION_STATE_NONE=0,
34 SSH_SESSION_STATE_CONNECTING,
35 SSH_SESSION_STATE_SOCKET_CONNECTED,
36 SSH_SESSION_STATE_BANNER_RECEIVED,
37 SSH_SESSION_STATE_INITIAL_KEX,
38 SSH_SESSION_STATE_KEXINIT_RECEIVED,
39 SSH_SESSION_STATE_DH,
40 SSH_SESSION_STATE_AUTHENTICATING,
41 SSH_SESSION_STATE_AUTHENTICATED,
42 SSH_SESSION_STATE_ERROR,
43 SSH_SESSION_STATE_DISCONNECTED
44 };
45
46 enum ssh_dh_state_e {
47 DH_STATE_INIT=0,
48 DH_STATE_INIT_SENT,
49 DH_STATE_NEWKEYS_SENT,
50 DH_STATE_FINISHED
51 };
52
53 enum ssh_pending_call_e {
54 SSH_PENDING_CALL_NONE = 0,
55 SSH_PENDING_CALL_CONNECT,
56 SSH_PENDING_CALL_AUTH_NONE,
57 SSH_PENDING_CALL_AUTH_PASSWORD,
58 SSH_PENDING_CALL_AUTH_OFFER_PUBKEY,
59 SSH_PENDING_CALL_AUTH_PUBKEY,
60 SSH_PENDING_CALL_AUTH_AGENT,
61 SSH_PENDING_CALL_AUTH_KBDINT_INIT,
62 SSH_PENDING_CALL_AUTH_KBDINT_SEND,
63 SSH_PENDING_CALL_AUTH_GSSAPI_MIC
64 };
65
66 /* libssh calls may block an undefined amount of time */
67 #define SSH_SESSION_FLAG_BLOCKING 1
68
69 /* Client successfully authenticated */
70 #define SSH_SESSION_FLAG_AUTHENTICATED 2
71
72 /* codes to use with ssh_handle_packets*() */
73 /* Infinite timeout */
74 #define SSH_TIMEOUT_INFINITE -1
75 /* Use the timeout defined by user if any. Mostly used with new connections */
76 #define SSH_TIMEOUT_USER -2
77 /* Use the default timeout, depending on ssh_is_blocking() */
78 #define SSH_TIMEOUT_DEFAULT -3
79 /* Don't block at all */
80 #define SSH_TIMEOUT_NONBLOCKING 0
81
82 /* options flags */
83 /* Authentication with *** allowed */
84 #define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
85 #define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
86 #define SSH_OPT_FLAG_KBDINT_AUTH 0x4
87 #define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
88
89 /* extensions flags */
90 /* server-sig-algs extension */
91 #define SSH_EXT_SIG_RSA_SHA256 0x01
92 #define SSH_EXT_SIG_RSA_SHA512 0x02
93 #define SSH_EXT_ALL SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512
94
95 /* members that are common to ssh_session and ssh_bind */
96 struct ssh_common_struct {
97 struct error_struct error;
98 ssh_callbacks callbacks; /* Callbacks to user functions */
99 int log_verbosity; /* verbosity of the log functions */
100 };
101
102 struct ssh_session_struct {
103 struct ssh_common_struct common;
104 struct ssh_socket_struct *socket;
105 char *serverbanner;
106 char *clientbanner;
107 int protoversion;
108 int server;
109 int client;
110 int openssh;
111 uint32_t send_seq;
112 uint32_t recv_seq;
113
114 int connected;
115 /* !=0 when the user got a session handle */
116 int alive;
117 /* two previous are deprecated */
118 /* int auth_service_asked; */
119
120 /* session flags (SSH_SESSION_FLAG_*) */
121 int flags;
122
123 /* Extensions negotiated using RFC 8308 */
124 uint32_t extensions;
125
126 ssh_string banner; /* that's the issue banner from
127 the server */
128 char *discon_msg; /* disconnect message from
129 the remote host */
130 ssh_buffer in_buffer;
131 PACKET in_packet;
132 ssh_buffer out_buffer;
133
134 /* the states are used by the nonblocking stuff to remember */
135 /* where it was before being interrupted */
136 enum ssh_pending_call_e pending_call_state;
137 enum ssh_session_state_e session_state;
138 int packet_state;
139 enum ssh_dh_state_e dh_handshake_state;
140 enum ssh_channel_request_state_e global_req_state;
141 struct ssh_agent_state_struct *agent_state;
142
143 struct {
144 struct ssh_auth_auto_state_struct *auto_state;
145 enum ssh_auth_service_state_e service_state;
146 enum ssh_auth_state_e state;
147 uint32_t supported_methods;
148 uint32_t current_method;
149 } auth;
150
151 /*
152 * RFC 4253, 7.1: if the first_kex_packet_follows flag was set in
153 * the received SSH_MSG_KEXINIT, but the guess was wrong, this
154 * field will be set such that the following guessed packet will
155 * be ignored. Once that packet has been received and ignored,
156 * this field is cleared.
157 */
158 int first_kex_follows_guess_wrong;
159
160 ssh_buffer in_hashbuf;
161 ssh_buffer out_hashbuf;
162 struct ssh_crypto_struct *current_crypto;
163 struct ssh_crypto_struct *next_crypto; /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
164
165 struct ssh_list *channels; /* linked list of channels */
166 int maxchannel;
167 ssh_agent agent; /* ssh agent */
168
169 /* keyb interactive data */
170 struct ssh_kbdint_struct *kbdint;
171 struct ssh_gssapi_struct *gssapi;
172
173 /* server host keys */
174 struct {
175 ssh_key rsa_key;
176 ssh_key dsa_key;
177 ssh_key ecdsa_key;
178 ssh_key ed25519_key;
179 /* The type of host key wanted by client */
180 enum ssh_keytypes_e hostkey;
181 } srv;
182
183 /* auths accepted by server */
184 struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
185 int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg, void *userdata);
186 void *ssh_message_callback_data;
187 ssh_server_callbacks server_callbacks;
188 void (*ssh_connection_callback)( struct ssh_session_struct *session);
189 struct ssh_packet_callbacks_struct default_packet_callbacks;
190 struct ssh_list *packet_callbacks;
191 struct ssh_socket_callbacks_struct socket_callbacks;
192 ssh_poll_ctx default_poll_ctx;
193 /* options */
194 #ifdef WITH_PCAP
195 ssh_pcap_context pcap_ctx; /* pcap debugging context */
196 #endif
197 struct {
198 struct ssh_list *identity;
199 char *username;
200 char *host;
201 char *bindaddr; /* bind the client to an ip addr */
202 char *sshdir;
203 char *knownhosts;
204 char *global_knownhosts;
205 char *wanted_methods[10];
206 char *pubkey_accepted_types;
207 char *ProxyCommand;
208 char *custombanner;
209 unsigned long timeout; /* seconds */
210 unsigned long timeout_usec;
211 unsigned int port;
212 socket_t fd;
213 int StrictHostKeyChecking;
214 char compressionlevel;
215 char *gss_server_identity;
216 char *gss_client_identity;
217 int gss_delegate_creds;
218 int flags;
219 int nodelay;
220 } opts;
221 /* counters */
222 ssh_counter socket_counter;
223 ssh_counter raw_counter;
224 };
225
231 typedef int (*ssh_termination_function)(void *user);
232 int ssh_handle_packets(ssh_session session, int timeout);
233 int ssh_handle_packets_termination(ssh_session session, int timeout,
234 ssh_termination_function fct, void *user);
235 void ssh_socket_exception_callback(int code, int errno_code, void *user);
236
237 #endif /* SESSION_H_ */
ssh_key_struct
Definition: pki.h:42
ssh_socket_callbacks_struct
Definition: callbacks.h:378
ssh_kbdint_struct
Definition: auth.h:37
ssh_crypto_struct
Definition: crypto.h:84
ssh_agent_struct
Definition: agent.h:73
ssh_callbacks_struct
Definition: callbacks.h:142
ssh_message_struct
Definition: messages.h:84
ssh_poll_ctx_struct
Definition: poll.c:76
ssh_packet_callbacks_struct
Definition: callbacks.h:530
ssh_session_struct
Definition: session.h:102
ssh_gssapi_struct
Definition: gssapi.c:48
packet_struct
Definition: packet.h:29
ssh_auth_auto_state_struct
Definition: auth.c:980
ssh_list
Definition: misc.h:38
ssh_server_callbacks_struct
Definition: callbacks.h:304
ssh_string_struct
Definition: string.h:29
ssh_agent_state_struct
Definition: auth.c:842
error_struct
Definition: priv.h:227
ssh_socket_struct
Definition: socket.c:76
ssh_common_struct
Definition: session.h:96
ssh_buffer_struct
Definition: buffer.c:47
ssh_counter_struct
Definition: libssh.h:108