1323124Sdes/* $OpenBSD: packet.h,v 1.71 2016/03/07 19:02:43 djm Exp $ */ 292559Sdes 357429Smarkm/* 457429Smarkm * Author: Tatu Ylonen <ylo@cs.hut.fi> 557429Smarkm * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 657429Smarkm * All rights reserved 757429Smarkm * Interface for the packet protocol functions. 860576Skris * 965674Skris * As far as I am concerned, the code I have written for this software 1065674Skris * can be used freely for any purpose. Any derived versions of this 1165674Skris * software must be clearly marked as such, and if the derived work is 1265674Skris * incompatible with the protocol description in the RFC file, it must be 1365674Skris * called by a name other than "ssh" or "Secure Shell". 1457429Smarkm */ 1557429Smarkm 1657429Smarkm#ifndef PACKET_H 1757429Smarkm#define PACKET_H 1857429Smarkm 19162856Sdes#include <termios.h> 20162856Sdes 21295367Sdes#ifdef WITH_OPENSSL 22295367Sdes# include <openssl/bn.h> 23295367Sdes# ifdef OPENSSL_HAS_ECC 24295367Sdes# include <openssl/ec.h> 25295367Sdes# else /* OPENSSL_HAS_ECC */ 26295367Sdes# define EC_KEY void 27295367Sdes# define EC_GROUP void 28295367Sdes# define EC_POINT void 29295367Sdes# endif /* OPENSSL_HAS_ECC */ 30295367Sdes#else /* WITH_OPENSSL */ 31295367Sdes# define BIGNUM void 32295367Sdes# define EC_KEY void 33295367Sdes# define EC_GROUP void 34295367Sdes# define EC_POINT void 35295367Sdes#endif /* WITH_OPENSSL */ 3657429Smarkm 37295367Sdes#include <signal.h> 38295367Sdes#include "openbsd-compat/sys-queue.h" 3957429Smarkm 40295367Sdesstruct kex; 41295367Sdesstruct sshkey; 42295367Sdesstruct sshbuf; 43295367Sdesstruct session_state; /* private session data */ 4457429Smarkm 45295367Sdes#include "dispatch.h" /* typedef, DISPATCH_MAX */ 4657429Smarkm 47295367Sdesstruct key_entry { 48295367Sdes TAILQ_ENTRY(key_entry) next; 49295367Sdes struct sshkey *key; 50295367Sdes}; 5157429Smarkm 52295367Sdesstruct ssh { 53295367Sdes /* Session state */ 54295367Sdes struct session_state *state; 5598684Sdes 56295367Sdes /* Key exchange */ 57295367Sdes struct kex *kex; 5857429Smarkm 59323124Sdes /* cached local and remote ip addresses and ports */ 60295367Sdes char *remote_ipaddr; 61295367Sdes int remote_port; 62323124Sdes char *local_ipaddr; 63323124Sdes int local_port; 6457429Smarkm 65295367Sdes /* Dispatcher table */ 66295367Sdes dispatch_fn *dispatch[DISPATCH_MAX]; 67295367Sdes /* number of packets to ignore in the dispatcher */ 68295367Sdes int dispatch_skip_packets; 69295367Sdes 70295367Sdes /* datafellows */ 71295367Sdes int compat; 72295367Sdes 73295367Sdes /* Lists for private and public keys */ 74295367Sdes TAILQ_HEAD(, key_entry) private_keys; 75295367Sdes TAILQ_HEAD(, key_entry) public_keys; 76295367Sdes 77295367Sdes /* APP data */ 78295367Sdes void *app_data; 79295367Sdes}; 80295367Sdes 81295367Sdesstruct ssh *ssh_alloc_session_state(void); 82295367Sdesstruct ssh *ssh_packet_set_connection(struct ssh *, int, int); 83295367Sdesvoid ssh_packet_set_timeout(struct ssh *, int, int); 84295367Sdesint ssh_packet_stop_discard(struct ssh *); 85295367Sdesint ssh_packet_connection_af(struct ssh *); 86295367Sdesvoid ssh_packet_set_nonblocking(struct ssh *); 87295367Sdesint ssh_packet_get_connection_in(struct ssh *); 88295367Sdesint ssh_packet_get_connection_out(struct ssh *); 89295367Sdesvoid ssh_packet_close(struct ssh *); 90295367Sdesvoid ssh_packet_set_encryption_key(struct ssh *, const u_char *, u_int, int); 91296781Sdesint ssh_packet_is_rekeying(struct ssh *); 92295367Sdesvoid ssh_packet_set_protocol_flags(struct ssh *, u_int); 93295367Sdesu_int ssh_packet_get_protocol_flags(struct ssh *); 94295367Sdesint ssh_packet_start_compression(struct ssh *, int); 95295367Sdesvoid ssh_packet_set_tos(struct ssh *, int); 96295367Sdesvoid ssh_packet_set_interactive(struct ssh *, int, int, int); 97295367Sdesint ssh_packet_is_interactive(struct ssh *); 98295367Sdesvoid ssh_packet_set_server(struct ssh *); 99295367Sdesvoid ssh_packet_set_authenticated(struct ssh *); 100295367Sdes 101295367Sdesint ssh_packet_send1(struct ssh *); 102295367Sdesint ssh_packet_send2_wrapped(struct ssh *); 103295367Sdesint ssh_packet_send2(struct ssh *); 104295367Sdes 105295367Sdesint ssh_packet_read(struct ssh *); 106295367Sdesint ssh_packet_read_expect(struct ssh *, u_int type); 107295367Sdesint ssh_packet_read_poll(struct ssh *); 108295367Sdesint ssh_packet_read_poll1(struct ssh *, u_char *); 109295367Sdesint ssh_packet_read_poll2(struct ssh *, u_char *, u_int32_t *seqnr_p); 110295367Sdesint ssh_packet_process_incoming(struct ssh *, const char *buf, u_int len); 111295367Sdesint ssh_packet_read_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p); 112295367Sdesint ssh_packet_read_poll_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p); 113295367Sdes 114295367Sdesconst void *ssh_packet_get_string_ptr(struct ssh *, u_int *length_ptr); 115295367Sdesvoid ssh_packet_disconnect(struct ssh *, const char *fmt, ...) 116295367Sdes __attribute__((format(printf, 2, 3))) 117295367Sdes __attribute__((noreturn)); 118295367Sdesvoid ssh_packet_send_debug(struct ssh *, const char *fmt, ...) __attribute__((format(printf, 2, 3))); 119295367Sdes 120295367Sdesint ssh_set_newkeys(struct ssh *, int mode); 121295367Sdesvoid ssh_packet_get_bytes(struct ssh *, u_int64_t *, u_int64_t *); 122295367Sdes 123295367Sdestypedef void *(ssh_packet_comp_alloc_func)(void *, u_int, u_int); 124295367Sdestypedef void (ssh_packet_comp_free_func)(void *, void *); 125295367Sdesvoid ssh_packet_set_compress_hooks(struct ssh *, void *, 126295367Sdes ssh_packet_comp_alloc_func *, ssh_packet_comp_free_func *); 127295367Sdes 128295367Sdesint ssh_packet_write_poll(struct ssh *); 129295367Sdesint ssh_packet_write_wait(struct ssh *); 130295367Sdesint ssh_packet_have_data_to_write(struct ssh *); 131295367Sdesint ssh_packet_not_very_much_data_to_write(struct ssh *); 132295367Sdes 133295367Sdesint ssh_packet_connection_is_on_socket(struct ssh *); 134295367Sdesint ssh_packet_remaining(struct ssh *); 135295367Sdesvoid ssh_packet_send_ignore(struct ssh *, int); 136295367Sdes 13792559Sdesvoid tty_make_modes(int, struct termios *); 13892559Sdesvoid tty_parse_modes(int, int *); 13957429Smarkm 140295367Sdesvoid ssh_packet_set_alive_timeouts(struct ssh *, int); 141295367Sdesint ssh_packet_inc_alive_timeouts(struct ssh *); 142295367Sdesint ssh_packet_set_maxsize(struct ssh *, u_int); 143295367Sdesu_int ssh_packet_get_maxsize(struct ssh *); 14457429Smarkm 145295367Sdesint ssh_packet_get_state(struct ssh *, struct sshbuf *); 146295367Sdesint ssh_packet_set_state(struct ssh *, struct sshbuf *); 14760576Skris 148295367Sdesconst char *ssh_remote_ipaddr(struct ssh *); 149296781Sdesint ssh_remote_port(struct ssh *); 150323124Sdesconst char *ssh_local_ipaddr(struct ssh *); 151323124Sdesint ssh_local_port(struct ssh *); 152124211Sdes 153296781Sdesvoid ssh_packet_set_rekey_limits(struct ssh *, u_int64_t, time_t); 154295367Sdestime_t ssh_packet_get_rekey_timeout(struct ssh *); 155197679Sdes 156295367Sdesvoid *ssh_packet_get_input(struct ssh *); 157295367Sdesvoid *ssh_packet_get_output(struct ssh *); 158295367Sdes 159295367Sdes/* new API */ 160295367Sdesint sshpkt_start(struct ssh *ssh, u_char type); 161295367Sdesint sshpkt_send(struct ssh *ssh); 162295367Sdesint sshpkt_disconnect(struct ssh *, const char *fmt, ...) 163295367Sdes __attribute__((format(printf, 2, 3))); 164295367Sdesint sshpkt_add_padding(struct ssh *, u_char); 165295367Sdesvoid sshpkt_fatal(struct ssh *ssh, const char *tag, int r); 166295367Sdes 167295367Sdesint sshpkt_put(struct ssh *ssh, const void *v, size_t len); 168295367Sdesint sshpkt_putb(struct ssh *ssh, const struct sshbuf *b); 169295367Sdesint sshpkt_put_u8(struct ssh *ssh, u_char val); 170295367Sdesint sshpkt_put_u32(struct ssh *ssh, u_int32_t val); 171295367Sdesint sshpkt_put_u64(struct ssh *ssh, u_int64_t val); 172295367Sdesint sshpkt_put_string(struct ssh *ssh, const void *v, size_t len); 173295367Sdesint sshpkt_put_cstring(struct ssh *ssh, const void *v); 174295367Sdesint sshpkt_put_stringb(struct ssh *ssh, const struct sshbuf *v); 175295367Sdesint sshpkt_put_ec(struct ssh *ssh, const EC_POINT *v, const EC_GROUP *g); 176295367Sdesint sshpkt_put_bignum1(struct ssh *ssh, const BIGNUM *v); 177295367Sdesint sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v); 178295367Sdes 179295367Sdesint sshpkt_get(struct ssh *ssh, void *valp, size_t len); 180295367Sdesint sshpkt_get_u8(struct ssh *ssh, u_char *valp); 181295367Sdesint sshpkt_get_u32(struct ssh *ssh, u_int32_t *valp); 182295367Sdesint sshpkt_get_u64(struct ssh *ssh, u_int64_t *valp); 183295367Sdesint sshpkt_get_string(struct ssh *ssh, u_char **valp, size_t *lenp); 184295367Sdesint sshpkt_get_string_direct(struct ssh *ssh, const u_char **valp, size_t *lenp); 185295367Sdesint sshpkt_get_cstring(struct ssh *ssh, char **valp, size_t *lenp); 186295367Sdesint sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g); 187295367Sdesint sshpkt_get_bignum1(struct ssh *ssh, BIGNUM *v); 188295367Sdesint sshpkt_get_bignum2(struct ssh *ssh, BIGNUM *v); 189295367Sdesint sshpkt_get_end(struct ssh *ssh); 190295367Sdesconst u_char *sshpkt_ptr(struct ssh *, size_t *lenp); 191295367Sdes 192295367Sdes/* OLD API */ 193295367Sdesextern struct ssh *active_state; 194295367Sdes#include "opacket.h" 195295367Sdes 196295367Sdes#if !defined(WITH_OPENSSL) 197295367Sdes# undef BIGNUM 198295367Sdes# undef EC_KEY 199295367Sdes# undef EC_GROUP 200295367Sdes# undef EC_POINT 201295367Sdes#elif !defined(OPENSSL_HAS_ECC) 202295367Sdes# undef EC_KEY 203295367Sdes# undef EC_GROUP 204295367Sdes# undef EC_POINT 205295367Sdes#endif 206295367Sdes 20757429Smarkm#endif /* PACKET_H */ 208