2
0

go_secure_test.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. #include "engine_helpers.c"
  10. static void setup() {
  11. zrtp_status_t s;
  12. zrtp_test_endpoint_cfg_t endpoint_cfg;
  13. zrtp_test_endpoint_config_defaults(&endpoint_cfg);
  14. s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice);
  15. assert_int_equal(zrtp_status_ok, s);
  16. assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice);
  17. s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob);
  18. assert_int_equal(zrtp_status_ok, s);
  19. assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob);
  20. }
  21. static void teardown() {
  22. zrtp_test_endpoint_destroy(g_alice);
  23. zrtp_test_endpoint_destroy(g_bob);
  24. }
  25. static void go_secure_test() {
  26. /*
  27. * Create two test sessions, one for Alice and one for Bob and link them
  28. * into test secure channel
  29. */
  30. prepare_alice_bob();
  31. start_alice_bob_and_wait4secure();
  32. release_alice_bob();
  33. }
  34. static void go_secure_flags_test() {
  35. zrtp_status_t s;
  36. zrtp_test_session_info_t alice_ses_info;
  37. prepare_alice_bob();
  38. start_alice_bob_and_wait4secure();
  39. /* All flags should be clear */
  40. s = zrtp_test_session_get(g_alice_sid, &alice_ses_info);
  41. assert_int_equal(zrtp_status_ok, s);
  42. assert_int_equal(0, alice_ses_info.zrtp.matches_flags);
  43. assert_int_equal(0, alice_ses_info.zrtp.cached_flags);
  44. assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags);
  45. /*
  46. * Now let's make one more call, RS1 should match and cached
  47. */
  48. release_alice_bob();
  49. prepare_alice_bob();
  50. start_alice_bob_and_wait4secure();
  51. s = zrtp_test_session_get(g_alice_sid, &alice_ses_info);
  52. assert_int_equal(zrtp_status_ok, s);
  53. assert_int_equal((int)ZRTP_BIT_RS1, alice_ses_info.zrtp.matches_flags);
  54. assert_int_equal((int)ZRTP_BIT_RS1, alice_ses_info.zrtp.cached_flags);
  55. assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags);
  56. /*
  57. * And one more time.. both RS1 and RS2 should be cached and should match.
  58. */
  59. release_alice_bob();
  60. prepare_alice_bob();
  61. start_alice_bob_and_wait4secure();
  62. s = zrtp_test_session_get(g_alice_sid, &alice_ses_info);
  63. assert_int_equal(zrtp_status_ok, s);
  64. assert_int_equal((int)(ZRTP_BIT_RS1 | ZRTP_BIT_RS2) , alice_ses_info.zrtp.matches_flags);
  65. assert_int_equal((int)(ZRTP_BIT_RS1 | ZRTP_BIT_RS2), alice_ses_info.zrtp.cached_flags);
  66. assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags);
  67. }
  68. int main(void) {
  69. const UnitTest tests[] = {
  70. unit_test_setup_teardown(go_secure_test, setup, teardown),
  71. unit_test_setup_teardown(go_secure_flags_test, setup, teardown),
  72. };
  73. return run_tests(tests);
  74. }