flow.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "slitheen.h"
  8. #define MAX_FLOWS 10
  9. #define TLS_HELLO_REQ 0x00
  10. #define TLS_CLNT_HELLO 0x01
  11. #define TLS_SERV_HELLO 0x02
  12. #define TLS_NEW_SESS 0x04
  13. #define TLS_CERT 0x0b
  14. #define TLS_SRVR_KEYEX 0x0c
  15. #define TLS_CERT_REQ 0x0d
  16. #define TLS_SRVR_HELLO_DONE 0x0e
  17. #define TLS_CERT_VERIFY 0x0f
  18. #define TLS_CLNT_KEYEX 0x10
  19. #define TLS_FINISHED 0x14
  20. struct packet_st{
  21. uint32_t seq_num;
  22. uint16_t len;
  23. uint16_t data_len;
  24. uint8_t *data;
  25. struct packet_st *next;
  26. int incoming; //0 for outgoing, 1 for incoming
  27. };
  28. typedef struct queue_block_st{
  29. int32_t len;
  30. int32_t offset;
  31. uint8_t *data;
  32. struct queue_block_st *next;
  33. } queue_block;
  34. typedef struct packet_st packet;
  35. typedef struct flow_st {
  36. struct in_addr src_ip, dst_ip; /* Source (client) and Destination (server) addresses */
  37. uint16_t src_port, dst_port; /* Source and Destination ports */
  38. uint32_t seq_num; /* sequence number */
  39. byte key[16]; /* negotiated key */
  40. int state; /* TLS handshake state */
  41. int in_encrypted; /* indicates whether incoming flow is encrypted */
  42. int out_encrypted; /* indicates whether outgoing flow is encrypted */
  43. int application; /* indicates handshake is complete */
  44. packet *packet_chain; /* currently held data */
  45. queue_block *censored_queue;
  46. DH *dh;
  47. uint8_t handshake_hash[EVP_MAX_MD_SIZE];
  48. EVP_MD_CTX *finish_md_ctx;
  49. EVP_CIPHER_CTX *clnt_read_ctx;
  50. EVP_CIPHER_CTX *clnt_write_ctx;
  51. EVP_CIPHER_CTX *srvr_read_ctx;
  52. EVP_CIPHER_CTX *srvr_write_ctx;
  53. EVP_MD_CTX *read_mac_ctx;
  54. EVP_MD_CTX *write_mac_ctx;
  55. uint8_t client_random[SSL3_RANDOM_SIZE];
  56. uint8_t server_random[SSL3_RANDOM_SIZE];
  57. uint8_t master_secret[SSL3_MASTER_SECRET_SIZE];
  58. uint8_t read_seq[8];
  59. uint8_t write_seq[8];
  60. uint8_t *outbox;
  61. int32_t outbox_len;
  62. } flow;
  63. typedef struct flow_table_st {
  64. flow *table;
  65. int len;
  66. int max_len;
  67. } flow_table;
  68. int init_flow_table (void);
  69. flow *add_flow(flow newFlow);
  70. int update_flow(flow *f);
  71. int remove_flow(int index);
  72. int check_flow(flow observed);
  73. flow *get_flow(int index);
  74. int add_packet(flow *f, struct packet_info *info);
  75. #endif /* __RELAY_H__ */