check_tagged.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /** check_tagged.c
  2. *
  3. * Test the tag-check functionality of Slitheen
  4. */
  5. #include <check.h>
  6. #include <stdlib.h>
  7. #include "../flow.h"
  8. #include "../crypto.h"
  9. #include "../cryptothread.h"
  10. #include "../packet.h"
  11. #include "../util.h"
  12. START_TEST(test_recognize_notag){
  13. struct packet_info *info;
  14. uint8_t *data;
  15. FILE *fp;
  16. uint64_t fsize;
  17. //populate packet_info with a tagged ClientHello message
  18. fp = fopen("data/packet_untagged.dat", "rb");
  19. if (fp == NULL) {
  20. perror("fopen");
  21. ck_abort();
  22. }
  23. fseek(fp, 0, SEEK_END);
  24. fsize = ftell(fp);
  25. fseek(fp, 0, SEEK_SET);
  26. data = smalloc(fsize);
  27. int32_t result = fread(data, fsize, 1, fp);
  28. fclose(fp);
  29. info = smalloc(sizeof(struct packet_info));
  30. extract_packet_headers(data, info);
  31. ck_assert_int_eq(check_handshake(info), 0);
  32. }
  33. END_TEST
  34. START_TEST(test_recognize_tag){
  35. struct packet_info *info;
  36. uint8_t *data;
  37. FILE *fp;
  38. uint64_t fsize;
  39. //populate packet_info with a tagged ClientHello message
  40. fp = fopen("data/packet_tagged.dat", "rb");
  41. if (fp == NULL) {
  42. perror("fopen");
  43. ck_abort();
  44. }
  45. fseek(fp, 0, SEEK_END);
  46. fsize = ftell(fp);
  47. fseek(fp, 0, SEEK_SET);
  48. data = smalloc(fsize);
  49. int32_t result = fread(data, fsize, 1, fp);
  50. fclose(fp);
  51. info = smalloc(sizeof(struct packet_info));
  52. extract_packet_headers(data, info);
  53. ck_assert_int_eq(check_handshake(info), 1);
  54. }
  55. END_TEST
  56. Suite *tag_suite(void) {
  57. Suite *s;
  58. TCase *tc_core;
  59. s = suite_create("Tag");
  60. tc_core = tcase_create("Core");
  61. tcase_add_test(tc_core, test_recognize_tag);
  62. tcase_add_test(tc_core, test_recognize_notag);
  63. suite_add_tcase(s, tc_core);
  64. return s;
  65. }
  66. int main(void){
  67. int number_failed;
  68. Suite *s;
  69. SRunner *sr;
  70. //initialize Slitheen structures
  71. if(init_tables()){
  72. exit(1);
  73. }
  74. if(init_session_cache()){
  75. exit(1);
  76. }
  77. init_crypto_locks();
  78. s = tag_suite();
  79. sr = srunner_create(s);
  80. srunner_set_fork_status(sr, CK_NOFORK);
  81. srunner_run_all(sr, CK_NORMAL);
  82. number_failed = srunner_ntests_failed(sr);
  83. srunner_free(sr);
  84. crypto_locks_cleanup();
  85. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  86. }