2020-03-06 19:11:10 +01:00
|
|
|
/* $OpenBSD: packet.h,v 1.92 2020/03/06 18:11:10 markus Exp $ */
|
2002-03-05 02:53:02 +01:00
|
|
|
|
1999-10-27 05:42:43 +02:00
|
|
|
/*
|
1999-11-24 14:26:21 +01:00
|
|
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
|
|
|
* All rights reserved
|
|
|
|
* Interface for the packet protocol functions.
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
2000-09-16 04:29:08 +02:00
|
|
|
* As far as I am concerned, the code I have written for this software
|
|
|
|
* can be used freely for any purpose. Any derived versions of this
|
|
|
|
* software must be clearly marked as such, and if the derived work is
|
|
|
|
* incompatible with the protocol description in the RFC file, it must be
|
|
|
|
* called by a name other than "ssh" or "Secure Shell".
|
1999-11-24 14:26:21 +01:00
|
|
|
*/
|
|
|
|
|
1999-10-27 05:42:43 +02:00
|
|
|
#ifndef PACKET_H
|
|
|
|
#define PACKET_H
|
|
|
|
|
2006-03-15 01:11:28 +01:00
|
|
|
#include <termios.h>
|
|
|
|
|
2015-01-19 20:52:16 +01:00
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
# include <openssl/bn.h>
|
|
|
|
# ifdef OPENSSL_HAS_ECC
|
|
|
|
# include <openssl/ec.h>
|
2015-01-30 13:10:17 +01:00
|
|
|
# else /* OPENSSL_HAS_ECC */
|
|
|
|
# define EC_KEY void
|
|
|
|
# define EC_GROUP void
|
|
|
|
# define EC_POINT void
|
|
|
|
# endif /* OPENSSL_HAS_ECC */
|
|
|
|
#else /* WITH_OPENSSL */
|
|
|
|
# define BIGNUM void
|
|
|
|
# define EC_KEY void
|
|
|
|
# define EC_GROUP void
|
|
|
|
# define EC_POINT void
|
|
|
|
#endif /* WITH_OPENSSL */
|
|
|
|
|
2015-02-24 07:06:56 +01:00
|
|
|
#include <signal.h>
|
2015-02-23 23:02:54 +01:00
|
|
|
#include "openbsd-compat/sys-queue.h"
|
2015-01-19 20:52:16 +01:00
|
|
|
|
|
|
|
struct kex;
|
|
|
|
struct sshkey;
|
|
|
|
struct sshbuf;
|
|
|
|
struct session_state; /* private session data */
|
|
|
|
|
2015-01-19 21:07:45 +01:00
|
|
|
#include "dispatch.h" /* typedef, DISPATCH_MAX */
|
|
|
|
|
2015-01-19 21:30:23 +01:00
|
|
|
struct key_entry {
|
|
|
|
TAILQ_ENTRY(key_entry) next;
|
|
|
|
struct sshkey *key;
|
|
|
|
};
|
|
|
|
|
2015-01-19 20:52:16 +01:00
|
|
|
struct ssh {
|
|
|
|
/* Session state */
|
|
|
|
struct session_state *state;
|
|
|
|
|
|
|
|
/* Key exchange */
|
|
|
|
struct kex *kex;
|
|
|
|
|
2016-03-07 20:02:43 +01:00
|
|
|
/* cached local and remote ip addresses and ports */
|
2015-01-19 20:52:16 +01:00
|
|
|
char *remote_ipaddr;
|
|
|
|
int remote_port;
|
2016-03-07 20:02:43 +01:00
|
|
|
char *local_ipaddr;
|
|
|
|
int local_port;
|
2017-10-25 02:17:08 +02:00
|
|
|
char *rdomain_in;
|
2015-01-19 20:52:16 +01:00
|
|
|
|
2017-02-04 00:03:33 +01:00
|
|
|
/* Optional preamble for log messages (e.g. username) */
|
|
|
|
char *log_preamble;
|
|
|
|
|
2015-01-19 21:07:45 +01:00
|
|
|
/* Dispatcher table */
|
|
|
|
dispatch_fn *dispatch[DISPATCH_MAX];
|
|
|
|
/* number of packets to ignore in the dispatcher */
|
|
|
|
int dispatch_skip_packets;
|
|
|
|
|
2015-01-19 20:52:16 +01:00
|
|
|
/* datafellows */
|
|
|
|
int compat;
|
2015-01-19 21:30:23 +01:00
|
|
|
|
|
|
|
/* Lists for private and public keys */
|
|
|
|
TAILQ_HEAD(, key_entry) private_keys;
|
|
|
|
TAILQ_HEAD(, key_entry) public_keys;
|
|
|
|
|
2017-05-30 16:18:15 +02:00
|
|
|
/* Client/Server authentication context */
|
|
|
|
void *authctxt;
|
|
|
|
|
2017-09-12 08:32:07 +02:00
|
|
|
/* Channels context */
|
|
|
|
struct ssh_channels *chanctxt;
|
|
|
|
|
2015-01-19 21:30:23 +01:00
|
|
|
/* APP data */
|
|
|
|
void *app_data;
|
2015-01-19 20:52:16 +01:00
|
|
|
};
|
|
|
|
|
2016-10-11 23:47:45 +02:00
|
|
|
typedef int (ssh_packet_hook_fn)(struct ssh *, struct sshbuf *,
|
|
|
|
u_char *, void *);
|
|
|
|
|
2015-01-19 20:52:16 +01:00
|
|
|
struct ssh *ssh_alloc_session_state(void);
|
|
|
|
struct ssh *ssh_packet_set_connection(struct ssh *, int, int);
|
|
|
|
void ssh_packet_set_timeout(struct ssh *, int, int);
|
|
|
|
int ssh_packet_stop_discard(struct ssh *);
|
|
|
|
int ssh_packet_connection_af(struct ssh *);
|
|
|
|
void ssh_packet_set_nonblocking(struct ssh *);
|
|
|
|
int ssh_packet_get_connection_in(struct ssh *);
|
|
|
|
int ssh_packet_get_connection_out(struct ssh *);
|
|
|
|
void ssh_packet_close(struct ssh *);
|
2016-10-11 23:47:45 +02:00
|
|
|
void ssh_packet_set_input_hook(struct ssh *, ssh_packet_hook_fn *, void *);
|
2017-05-31 10:09:45 +02:00
|
|
|
void ssh_packet_clear_keys(struct ssh *);
|
|
|
|
void ssh_clear_newkeys(struct ssh *, int);
|
2016-10-11 23:47:45 +02:00
|
|
|
|
2016-02-08 11:57:07 +01:00
|
|
|
int ssh_packet_is_rekeying(struct ssh *);
|
2015-01-19 20:52:16 +01:00
|
|
|
void ssh_packet_set_protocol_flags(struct ssh *, u_int);
|
|
|
|
u_int ssh_packet_get_protocol_flags(struct ssh *);
|
|
|
|
void ssh_packet_set_tos(struct ssh *, int);
|
|
|
|
void ssh_packet_set_interactive(struct ssh *, int, int, int);
|
|
|
|
int ssh_packet_is_interactive(struct ssh *);
|
|
|
|
void ssh_packet_set_server(struct ssh *);
|
|
|
|
void ssh_packet_set_authenticated(struct ssh *);
|
2016-09-30 11:19:13 +02:00
|
|
|
void ssh_packet_set_mux(struct ssh *);
|
|
|
|
int ssh_packet_get_mux(struct ssh *);
|
2017-02-04 00:03:33 +01:00
|
|
|
int ssh_packet_set_log_preamble(struct ssh *, const char *, ...)
|
|
|
|
__attribute__((format(printf, 2, 3)));
|
2016-09-30 11:19:13 +02:00
|
|
|
|
|
|
|
int ssh_packet_log_type(u_char);
|
2015-01-19 20:52:16 +01:00
|
|
|
|
|
|
|
int ssh_packet_send2_wrapped(struct ssh *);
|
|
|
|
int ssh_packet_send2(struct ssh *);
|
|
|
|
|
|
|
|
int ssh_packet_read(struct ssh *);
|
2015-01-30 02:13:33 +01:00
|
|
|
int ssh_packet_read_expect(struct ssh *, u_int type);
|
2015-01-19 20:52:16 +01:00
|
|
|
int ssh_packet_read_poll(struct ssh *);
|
|
|
|
int ssh_packet_read_poll2(struct ssh *, u_char *, u_int32_t *seqnr_p);
|
2015-01-28 22:15:47 +01:00
|
|
|
int ssh_packet_process_incoming(struct ssh *, const char *buf, u_int len);
|
2015-01-19 20:52:16 +01:00
|
|
|
int ssh_packet_read_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p);
|
|
|
|
int ssh_packet_read_poll_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p);
|
|
|
|
|
|
|
|
const void *ssh_packet_get_string_ptr(struct ssh *, u_int *length_ptr);
|
|
|
|
void ssh_packet_disconnect(struct ssh *, const char *fmt, ...)
|
|
|
|
__attribute__((format(printf, 2, 3)))
|
|
|
|
__attribute__((noreturn));
|
|
|
|
void ssh_packet_send_debug(struct ssh *, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
|
|
|
|
|
|
|
int ssh_set_newkeys(struct ssh *, int mode);
|
|
|
|
void ssh_packet_get_bytes(struct ssh *, u_int64_t *, u_int64_t *);
|
|
|
|
|
2015-01-30 02:13:33 +01:00
|
|
|
int ssh_packet_write_poll(struct ssh *);
|
|
|
|
int ssh_packet_write_wait(struct ssh *);
|
2015-01-19 20:52:16 +01:00
|
|
|
int ssh_packet_have_data_to_write(struct ssh *);
|
|
|
|
int ssh_packet_not_very_much_data_to_write(struct ssh *);
|
|
|
|
|
|
|
|
int ssh_packet_connection_is_on_socket(struct ssh *);
|
|
|
|
int ssh_packet_remaining(struct ssh *);
|
1999-10-27 05:42:43 +02:00
|
|
|
|
2018-07-09 23:20:26 +02:00
|
|
|
void ssh_tty_make_modes(struct ssh *, int, struct termios *);
|
|
|
|
void ssh_tty_parse_modes(struct ssh *, int);
|
1999-10-27 05:42:43 +02:00
|
|
|
|
2015-01-19 20:52:16 +01:00
|
|
|
void ssh_packet_set_alive_timeouts(struct ssh *, int);
|
|
|
|
int ssh_packet_inc_alive_timeouts(struct ssh *);
|
|
|
|
int ssh_packet_set_maxsize(struct ssh *, u_int);
|
|
|
|
u_int ssh_packet_get_maxsize(struct ssh *);
|
|
|
|
|
|
|
|
int ssh_packet_get_state(struct ssh *, struct sshbuf *);
|
|
|
|
int ssh_packet_set_state(struct ssh *, struct sshbuf *);
|
|
|
|
|
|
|
|
const char *ssh_remote_ipaddr(struct ssh *);
|
2015-12-11 04:24:25 +01:00
|
|
|
int ssh_remote_port(struct ssh *);
|
2016-03-07 20:02:43 +01:00
|
|
|
const char *ssh_local_ipaddr(struct ssh *);
|
|
|
|
int ssh_local_port(struct ssh *);
|
2017-10-25 02:17:08 +02:00
|
|
|
const char *ssh_packet_rdomain_in(struct ssh *);
|
2015-01-19 20:52:16 +01:00
|
|
|
|
2017-02-03 03:56:00 +01:00
|
|
|
void ssh_packet_set_rekey_limits(struct ssh *, u_int64_t, u_int32_t);
|
2015-01-19 20:52:16 +01:00
|
|
|
time_t ssh_packet_get_rekey_timeout(struct ssh *);
|
|
|
|
|
|
|
|
void *ssh_packet_get_input(struct ssh *);
|
|
|
|
void *ssh_packet_get_output(struct ssh *);
|
|
|
|
|
|
|
|
/* new API */
|
|
|
|
int sshpkt_start(struct ssh *ssh, u_char type);
|
|
|
|
int sshpkt_send(struct ssh *ssh);
|
2015-01-30 02:13:33 +01:00
|
|
|
int sshpkt_disconnect(struct ssh *, const char *fmt, ...)
|
|
|
|
__attribute__((format(printf, 2, 3)));
|
2015-01-19 20:52:16 +01:00
|
|
|
int sshpkt_add_padding(struct ssh *, u_char);
|
2019-01-19 22:33:13 +01:00
|
|
|
void sshpkt_fatal(struct ssh *ssh, int r, const char *fmt, ...)
|
2020-03-06 19:11:10 +01:00
|
|
|
__attribute__((format(printf, 3, 4)))
|
|
|
|
__attribute__((noreturn));
|
2017-09-12 08:32:07 +02:00
|
|
|
int sshpkt_msg_ignore(struct ssh *, u_int);
|
2015-01-19 20:52:16 +01:00
|
|
|
|
|
|
|
int sshpkt_put(struct ssh *ssh, const void *v, size_t len);
|
|
|
|
int sshpkt_putb(struct ssh *ssh, const struct sshbuf *b);
|
|
|
|
int sshpkt_put_u8(struct ssh *ssh, u_char val);
|
|
|
|
int sshpkt_put_u32(struct ssh *ssh, u_int32_t val);
|
|
|
|
int sshpkt_put_u64(struct ssh *ssh, u_int64_t val);
|
|
|
|
int sshpkt_put_string(struct ssh *ssh, const void *v, size_t len);
|
|
|
|
int sshpkt_put_cstring(struct ssh *ssh, const void *v);
|
|
|
|
int sshpkt_put_stringb(struct ssh *ssh, const struct sshbuf *v);
|
|
|
|
int sshpkt_put_ec(struct ssh *ssh, const EC_POINT *v, const EC_GROUP *g);
|
|
|
|
int sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v);
|
|
|
|
|
|
|
|
int sshpkt_get(struct ssh *ssh, void *valp, size_t len);
|
|
|
|
int sshpkt_get_u8(struct ssh *ssh, u_char *valp);
|
|
|
|
int sshpkt_get_u32(struct ssh *ssh, u_int32_t *valp);
|
|
|
|
int sshpkt_get_u64(struct ssh *ssh, u_int64_t *valp);
|
|
|
|
int sshpkt_get_string(struct ssh *ssh, u_char **valp, size_t *lenp);
|
|
|
|
int sshpkt_get_string_direct(struct ssh *ssh, const u_char **valp, size_t *lenp);
|
2017-09-12 08:32:07 +02:00
|
|
|
int sshpkt_peek_string_direct(struct ssh *ssh, const u_char **valp, size_t *lenp);
|
2015-01-19 20:52:16 +01:00
|
|
|
int sshpkt_get_cstring(struct ssh *ssh, char **valp, size_t *lenp);
|
2019-01-21 11:35:09 +01:00
|
|
|
int sshpkt_getb_froms(struct ssh *ssh, struct sshbuf **valp);
|
2015-01-19 20:52:16 +01:00
|
|
|
int sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g);
|
2019-01-21 10:54:11 +01:00
|
|
|
int sshpkt_get_bignum2(struct ssh *ssh, BIGNUM **valp);
|
2015-01-19 20:52:16 +01:00
|
|
|
int sshpkt_get_end(struct ssh *ssh);
|
2017-12-10 06:55:29 +01:00
|
|
|
void sshpkt_fmt_connection_id(struct ssh *ssh, char *s, size_t l);
|
2015-01-19 20:52:16 +01:00
|
|
|
const u_char *sshpkt_ptr(struct ssh *, size_t *lenp);
|
|
|
|
|
2015-01-30 13:10:17 +01:00
|
|
|
#if !defined(WITH_OPENSSL)
|
|
|
|
# undef BIGNUM
|
|
|
|
# undef EC_KEY
|
|
|
|
# undef EC_GROUP
|
|
|
|
# undef EC_POINT
|
|
|
|
#elif !defined(OPENSSL_HAS_ECC)
|
|
|
|
# undef EC_KEY
|
|
|
|
# undef EC_GROUP
|
|
|
|
# undef EC_POINT
|
|
|
|
#endif
|
|
|
|
|
1999-11-24 14:26:21 +01:00
|
|
|
#endif /* PACKET_H */
|