static void do_action()
{
	switch (action_id)
	{
		case 0:
		{
			int status;

			zrtp_log_set_log_engine((zrtp_log_engine*)print_log_ce); 
			status = zrtp_test_zrtp_init();
			if (0 != status) {
				return;
			}

			zrtp_test_crypto(zrtp_global);

			{
				zrtp_test_channel_id_t id;
				zrtp_test_channel_config_t sconfig;
				
				sconfig.is_autosecure = 0;
				sconfig.is_preshared  = 0;
				sconfig.streams_count = 1;
				
				status = zrtp_test_channel_create(&sconfig, &id);
				
				if (0 == status) {
					zrtp_test_channel_start(id);
				}
			}
			break;
		}
		case 1:
		{
			zrtp_thread_create(destroy_func, NULL);
			break;
		}
		case 2:
		{
			DeleteObject(font);
			if (log_file) fclose(log_file);
#ifdef WIN32_PLATFORM_WFSP
            DestroyWindow(g_hWnd);
#endif
#ifdef WIN32_PLATFORM_PSPC
			SendMessage(g_hWnd, WM_CLOSE, 0, 0);				
#endif // WIN32_PLATFORM_PSPC
			break;
		}
	}

	action_id++;
}
int main()
{
	int status;
	
	status = zrtp_test_zrtp_init();
	if (0 != status) {
		return status;
	}
#if (ZRTP_TEST_ENABLE_CRYPTO_SELFTESTS == 1)
	zrtp_test_crypto(zrtp_global);
#endif
	
	{
		zrtp_test_channel_id_t id;
		zrtp_test_channel_config_t sconfig;
		
		sconfig.is_autosecure = 0;
		sconfig.is_preshared  = 0;
		sconfig.streams_count = 1;
		
		status = zrtp_test_channel_create(&sconfig, &id);
		
		if (0 == status) {
			zrtp_test_channel_start(id);
		}
	}
	
	while (1) {
		zrtp_sleep(1000);
	}
	
	
	do_quit();
	
	return 0;
}
Example #3
0
static void enrollment_test() {
	zrtp_status_t s;

	zrtp_test_channel_info_t a2pbx_channel_info;
	zrtp_test_session_cfg_t session_config, session_config_enroll;
	zrtp_test_session_config_defaults(&session_config);
	zrtp_test_session_config_defaults(&session_config_enroll);

	session_config_enroll.is_enrollment = 1;

	/**************************************************************************
	 * Enroll Alice to PBX and check triggered events.
	 */
	prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL);

	/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
	s = zrtp_test_channel_start(g_alice2pbx_channel);
	assert_int_equal(zrtp_status_ok, s);

	int i = 30;
	for (; i>0; i--) {
		usleep(100*1000);
	}

	s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
	assert_int_equal(zrtp_status_ok, s);

	/* Both, Alice and PBX should switch secure */
	assert_true(a2pbx_channel_info.is_secure);

	/* Alice should receive Enrollment notification */
	zrtp_test_id_t alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
	assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT));

	/* PBX streams should receive incoming enrollment notification */
	zrtp_test_id_t pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
	assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_NEW_USER_ENROLLED));

	/* Confirm enrollment at the PBX side */
	s = zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(alice2pbx_stream));
	assert_int_equal(zrtp_status_ok, s);

	/* Clean-up */
	cleanup_alice_pbx_bob_setup();

	/**************************************************************************
	 * Try to make one more enrollment call. This time it should say "Already enrolled"
	 */
	prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL);

	/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
	s = zrtp_test_channel_start(g_alice2pbx_channel);
	assert_int_equal(zrtp_status_ok, s);

	i = 30;
	for (; i>0; i--) {
		usleep(100*1000);
	}

	s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
	assert_int_equal(zrtp_status_ok, s);

	assert_true(a2pbx_channel_info.is_secure);

	/* Alice should receive Enrollment notification */
	alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
	assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT));

	/* PBX streams should receive incoming enrollment notification */
	pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
	assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_USER_ALREADY_ENROLLED));

	// TODO: check if we have PBX secret cached
	// TODO: test zrtp_is_user_enrolled()
}