flow.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __RELAY_H__
  2. #define __RELAY_H__
  3. #include <netinet/in.h>
  4. #include <openssl/bn.h>
  5. #include <openssl/ssl.h>
  6. #include "ptwist.h"
  7. #define MAX_FLOWS 10
  8. #define TLS_HELLO_REQ 0x00
  9. #define TLS_CLNT_HELLO 0x01
  10. #define TLS_SERV_HELLO 0x02
  11. #define TLS_NEW_SESS 0x04
  12. #define TLS_CERT 0x0b
  13. #define TLS_SRVR_KEYEX 0x0c
  14. #define TLS_CERT_REQ 0x0d
  15. #define TLS_SRVR_HELLO_DONE 0x0e
  16. #define TLS_CERT_VERIFY 0x0f
  17. #define TLS_CLNT_KEYEX 0x10
  18. #define TLS_FINISHED 0x14
  19. struct packet_st{
  20. uint32_t seq_num;
  21. uint16_t len;
  22. uint16_t data_len;
  23. uint8_t *data;
  24. struct packet_st *next;
  25. int incoming; //0 for outgoing, 1 for incoming
  26. };
  27. typedef struct packet_st packet;
  28. typedef struct flow_st {
  29. struct in_addr src_ip, dst_ip; /* Source (client) and Destination (server) addresses */
  30. uint16_t src_port, dst_port; /* Source and Destination ports */
  31. uint32_t seq_num; /* sequence number */
  32. byte key[16]; /* negotiated key */
  33. int state; /* TLS handshake state */
  34. int in_encrypted; /* indicates whether incoming flow is encrypted */
  35. int out_encrypted; /* indicates whether outgoing flow is encrypted */
  36. int application; /* indicates handshake is complete */
  37. packet *packet_chain; /* currently held data */
  38. uint8_t *censored_queue;
  39. DH *dh;
  40. uint8_t handshake_hash[EVP_MAX_MD_SIZE];
  41. EVP_MD_CTX *finish_md_ctx;
  42. EVP_CIPHER_CTX *read_ctx;
  43. EVP_CIPHER_CTX *write_ctx;
  44. uint8_t client_random[SSL3_RANDOM_SIZE];
  45. uint8_t server_random[SSL3_RANDOM_SIZE];
  46. uint8_t master_secret[SSL3_MASTER_SECRET_SIZE];
  47. uint8_t read_seq[8];
  48. uint8_t write_seq[8];
  49. } flow;
  50. typedef struct flow_table_st {
  51. flow *table;
  52. int len;
  53. int max_len;
  54. } flow_table;
  55. int init_flow_table (void);
  56. flow *add_flow(flow newFlow);
  57. int update_flow(flow *f);
  58. int remove_flow(int index);
  59. int check_flow(flow observed);
  60. flow *get_flow(int index);
  61. int add_packet(flow *f, uint8_t *data);
  62. #endif /* __RELAY_H__ */