sshbpp.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Abstraction of the binary packet protocols used in SSH.
  3. */
  4. #ifndef PUTTY_SSHBPP_H
  5. #define PUTTY_SSHBPP_H
  6. typedef struct BinaryPacketProtocol BinaryPacketProtocol;
  7. struct BinaryPacketProtocolVtable {
  8. void (*free)(BinaryPacketProtocol *);
  9. void (*handle_input)(BinaryPacketProtocol *);
  10. PktOut *(*new_pktout)(int type);
  11. void (*format_packet)(BinaryPacketProtocol *, PktOut *);
  12. };
  13. struct BinaryPacketProtocol {
  14. const struct BinaryPacketProtocolVtable *vt;
  15. bufchain *in_raw, *out_raw;
  16. PktInQueue *in_pq;
  17. PacketLogSettings *pls;
  18. LogContext *logctx;
  19. int seen_disconnect;
  20. char *error;
  21. };
  22. #define ssh_bpp_free(bpp) ((bpp)->vt->free(bpp))
  23. #define ssh_bpp_handle_input(bpp) ((bpp)->vt->handle_input(bpp))
  24. #define ssh_bpp_new_pktout(bpp, type) ((bpp)->vt->new_pktout(type))
  25. #define ssh_bpp_format_packet(bpp, pkt) ((bpp)->vt->format_packet(bpp, pkt))
  26. BinaryPacketProtocol *ssh1_bpp_new(void);
  27. void ssh1_bpp_new_cipher(BinaryPacketProtocol *bpp,
  28. const struct ssh1_cipheralg *cipher,
  29. const void *session_key);
  30. void ssh1_bpp_start_compression(BinaryPacketProtocol *bpp);
  31. BinaryPacketProtocol *ssh2_bpp_new(void);
  32. void ssh2_bpp_new_outgoing_crypto(
  33. BinaryPacketProtocol *bpp,
  34. const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
  35. const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
  36. const struct ssh_compression_alg *compression);
  37. void ssh2_bpp_new_incoming_crypto(
  38. BinaryPacketProtocol *bpp,
  39. const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
  40. const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
  41. const struct ssh_compression_alg *compression);
  42. BinaryPacketProtocol *ssh2_bare_bpp_new(void);
  43. /*
  44. * The initial code to handle the SSH version exchange is also
  45. * structured as an implementation of BinaryPacketProtocol, because
  46. * that makes it easy to switch from that to the next BPP once it
  47. * tells us which one we're using.
  48. */
  49. struct ssh_version_receiver {
  50. void (*got_ssh_version)(struct ssh_version_receiver *rcv,
  51. int major_version);
  52. };
  53. BinaryPacketProtocol *ssh_verstring_new(
  54. Conf *conf, Frontend *frontend, int bare_connection_mode,
  55. const char *protoversion, struct ssh_version_receiver *rcv);
  56. const char *ssh_verstring_get_remote(BinaryPacketProtocol *);
  57. const char *ssh_verstring_get_local(BinaryPacketProtocol *);
  58. int ssh_verstring_get_bugs(BinaryPacketProtocol *);
  59. #endif /* PUTTY_SSHBPP_H */