flow.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
  20. (((unsigned int)(c[1])) )),c+=2)
  21. struct packet_st{
  22. uint32_t seq_num;
  23. uint16_t len;
  24. uint16_t data_len;
  25. uint8_t *data;
  26. struct packet_st *next;
  27. int incoming; //0 for outgoing, 1 for incoming
  28. };
  29. typedef struct packet_st packet;
  30. typedef struct flow_st {
  31. struct in_addr src_ip, dst_ip; /* Source (client) and Destination (server) addresses */
  32. uint16_t src_port, dst_port; /* Source and Destination ports */
  33. uint32_t seq_num; /* sequence number */
  34. byte key[16]; /* negotiated key */
  35. int state; /* TLS handshake state */
  36. int in_encrypted; /* indicates whether incoming flow is encrypted */
  37. int out_encrypted; /* indicates whether outgoing flow is encrypted */
  38. packet *packet_chain; /* currently held data */
  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. } flow;
  48. typedef struct flow_table_st {
  49. flow *table;
  50. int len;
  51. int max_len;
  52. } flow_table;
  53. int init_flow_table (void);
  54. flow *add_flow(flow newFlow);
  55. int update_flow(flow *f);
  56. int remove_flow(int index);
  57. int check_flow(flow observed);
  58. flow *get_flow(int index);
  59. int add_packet(flow *f, uint8_t *data);
  60. int extract_parameters(flow *f, uint8_t *hs);
  61. int decrypt_fin(flow *f, uint8_t *hs, int32_t len, int32_t incoming);
  62. void extract_server_random(flow *f, uint8_t *hs);
  63. int compute_master_secret(flow *f);
  64. #endif /* __RELAY_H__ */