mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
679fa90dfe
sshbpp.h now defines a classoid that encapsulates both directions of an SSH binary packet protocol - that is, a system for reading a bufchain of incoming data and turning it into a stream of PktIn, and another system for taking a PktOut and turning it into data on an outgoing bufchain. The state structure in each of those files contains everything that used to be in the 'rdpkt2_state' structure and its friends, and also quite a lot of bits and pieces like cipher and MAC states that used to live in the main Ssh structure. One minor effect of this layer separation is that I've had to extend the packet dispatch table by one, because the BPP layer can no longer directly trigger sending of SSH_MSG_UNIMPLEMENTED for a message too short to have a type byte. Instead, I extend the PktIn type field to use an out-of-range value to encode that, and the easiest way to make that trigger an UNIMPLEMENTED message is to have the dispatch table contain an entry for it. (That's a system that may come in useful again - I was also wondering about inventing a fake type code to indicate network EOF, so that that could be propagated through the layers and be handled by whichever one currently knew best how to respond.) I've also moved the packet-censoring code into its own pair of files, partly because I was going to want to do that anyway sooner or later, and mostly because it's called from the BPP code, and the SSH-2 version in particular has to be called from both the main SSH-2 BPP and the bare unencrypted protocol used for connection sharing. While I was at it, I took the opportunity to merge the outgoing and incoming censor functions, so that the parts that were common between them (e.g. CHANNEL_DATA messages look the same in both directions) didn't need to be repeated.
55 lines
1.8 KiB
C
55 lines
1.8 KiB
C
/*
|
|
* Abstraction of the binary packet protocols used in SSH.
|
|
*/
|
|
|
|
#ifndef PUTTY_SSHBPP_H
|
|
#define PUTTY_SSHBPP_H
|
|
|
|
typedef struct BinaryPacketProtocol BinaryPacketProtocol;
|
|
|
|
struct BinaryPacketProtocolVtable {
|
|
void (*free)(BinaryPacketProtocol *);
|
|
void (*handle_input)(BinaryPacketProtocol *);
|
|
PktOut *(*new_pktout)(int type);
|
|
void (*format_packet)(BinaryPacketProtocol *, PktOut *);
|
|
};
|
|
|
|
struct BinaryPacketProtocol {
|
|
const struct BinaryPacketProtocolVtable *vt;
|
|
bufchain *in_raw, *out_raw;
|
|
PacketQueue *in_pq;
|
|
PacketLogSettings *pls;
|
|
void *logctx;
|
|
|
|
int seen_disconnect;
|
|
char *error;
|
|
};
|
|
|
|
#define ssh_bpp_free(bpp) ((bpp)->vt->free(bpp))
|
|
#define ssh_bpp_handle_input(bpp) ((bpp)->vt->handle_input(bpp))
|
|
#define ssh_bpp_new_pktout(bpp, type) ((bpp)->vt->new_pktout(type))
|
|
#define ssh_bpp_format_packet(bpp, pkt) ((bpp)->vt->format_packet(bpp, pkt))
|
|
|
|
BinaryPacketProtocol *ssh1_bpp_new(void);
|
|
void ssh1_bpp_new_cipher(BinaryPacketProtocol *bpp,
|
|
const struct ssh_cipher *cipher,
|
|
const void *session_key);
|
|
void ssh1_bpp_start_compression(BinaryPacketProtocol *bpp);
|
|
|
|
BinaryPacketProtocol *ssh2_bpp_new(void);
|
|
void ssh2_bpp_new_outgoing_crypto(
|
|
BinaryPacketProtocol *bpp,
|
|
const struct ssh2_cipher *cipher, const void *ckey, const void *iv,
|
|
const struct ssh_mac *mac, int etm_mode, const void *mac_key,
|
|
const struct ssh_compress *compression);
|
|
void ssh2_bpp_new_incoming_crypto(
|
|
BinaryPacketProtocol *bpp,
|
|
const struct ssh2_cipher *cipher, const void *ckey, const void *iv,
|
|
const struct ssh_mac *mac, int etm_mode, const void *mac_key,
|
|
const struct ssh_compress *compression);
|
|
int ssh2_bpp_temporarily_disable_compression(BinaryPacketProtocol *bpp);
|
|
|
|
BinaryPacketProtocol *ssh2_bare_bpp_new(void);
|
|
|
|
#endif /* PUTTY_SSHBPP_H */
|