Commits (5)
......@@ -37,14 +37,14 @@ PKGCFG_L=$(GLIB_LDFLAGS) \
$(LIBGCRYPT_LDFLAGS)
HEADERS=-I$(AX_DIR)/src
CFLAGS += $(HEADERS) $(PKGCFG_C) -std=c11 -Wall -Wextra -Wpedantic \
CFLAGS += $(HEADERS) $(PKGCFG_C) -std=c11 -g -Wall -Wextra -Wpedantic \
-Wstrict-overflow -fno-strict-aliasing -funsigned-char \
-fno-builtin-memset
CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE
TESTFLAGS=$(HEADERS) $(PKGCFG_C) -g -O0 --coverage
PICFLAGS=-fPIC $(CFLAGS)
LDFLAGS += -pthread -ldl $(PKGCFG_L) $(AX_PATH) -lm
LDFLAGS_T= -lcmocka $(LFLAGS)
LDFLAGS_T= -lcmocka $(LDFLAGS)
all: $(BDIR)/libaxc.a
......@@ -81,24 +81,20 @@ $(AX_PATH):
$(MAKE)
.PHONY: test
test: $(AX_PATH) test_store.o test_client.o
test: $(AX_PATH) test_store test_client
.PHONY: test_store.o
test_store.o: $(SDIR)/axc_store.c $(SDIR)/axc_crypto.c $(TDIR)/test_store.c
$(CC) $(TESTFLAGS) -o $(TDIR)/$@ $(TDIR)/test_store.c $(SDIR)/axc_crypto.c $(LDFLAGS_T)
-$(TDIR)/$@
.PHONY: test_store
test_store: $(SDIR)/axc_store.c $(SDIR)/axc_crypto.c $(TDIR)/test_store.c
$(CC) $(TESTFLAGS) -o $(TDIR)/$@.o $(TDIR)/test_store.c $(SDIR)/axc_crypto.c $(LDFLAGS_T)
-$(TDIR)/$@.o
mv *.g* $(TDIR)
test_store: test_store.o
.PHONY: test_client.o
test_client.o: $(SDIR)/axc.c $(SDIR)/axc_crypto.c $(SDIR)/axc_store.c $(TDIR)/test_client.c
$(CC) $(TESTFLAGS) -g $(HEADERS) -o $(TDIR)/$@ $(SDIR)/axc_crypto.c $(TDIR)/test_client.c $(LDFLAGS_T)
-$(TDIR)/$@
.PHONY: test_client
test_client: $(SDIR)/axc.c $(SDIR)/axc_crypto.c $(SDIR)/axc_store.c $(TDIR)/test_client.c
$(CC) $(TESTFLAGS) -g $(HEADERS) -o $(TDIR)/$@.o $(SDIR)/axc_crypto.c $(TDIR)/test_client.c $(LDFLAGS_T)
-$(TDIR)/$@.o
mv *.g* $(TDIR)
test_client: test_client.o
.PHONY: coverage
coverage: test
gcovr -r . --html --html-details -o $@.html
......@@ -108,8 +104,11 @@ coverage: test
.PHONY: clean
clean:
rm -rf client $(BDIR) $(CDIR) $(AX_DIR)/build
rm -f $(TDIR)/*.o
rm -f $(TDIR)/*.gcno $(TDIR)/*.gcda $(TDIR)/*.sqlite
.PHONY: clean-all
clean-all: clean
rm -rf client $(BDIR) $(CDIR) $(AX_DIR)/build
# axc 0.3.0
# axc 0.3.1
Client lib for [libsignal-c](https://github.com/WhisperSystems/libsignal-protocol-c), implementing the needed database and crypto interfaces using SQLite and gcrypt.
Initially, the library's name was _libaxolotl_, hence the name.
......
......@@ -929,6 +929,9 @@ int axc_session_exists_initiated(const axc_address * addr_p, axc_context * ctx_p
session_record * session_record_p = (void *) 0;
session_state * session_state_p = (void *) 0;
//TODO: if there was no response yet, even though it is an established session it keeps sending prekeymsgs
// maybe that is "uninitiated" too?
if(!signal_protocol_session_contains_session(ctx_p->axolotl_store_context_p, addr_p)) {
return 0;
}
......
......@@ -12,11 +12,11 @@ char * test_fn = "test/test.sqlite";
char * a_fn = "test/a.sqlite";
char * b_fn = "test/b.sqlite";
axolotl_address addr_alice_42 = {.name = "alice", .name_len = 5, .device_id = 42};
axolotl_address addr_alice_21 = {.name = "alice", .name_len = 5, .device_id = 21};
axolotl_address addr_alice = {.name = "alice", .name_len = 5, .device_id = 0};
signal_protocol_address addr_alice_42 = {.name = "alice", .name_len = 5, .device_id = 42};
signal_protocol_address addr_alice_21 = {.name = "alice", .name_len = 5, .device_id = 21};
signal_protocol_address addr_alice = {.name = "alice", .name_len = 5, .device_id = 0};
axolotl_address addr_bob_12 = {.name = "bob", .name_len = 3, .device_id = 12};
signal_protocol_address addr_bob_12 = {.name = "bob", .name_len = 3, .device_id = 12};
axc_address addr_bob = {.name = "bob", .name_len = 3, .device_id = 0};
axc_context * ctx_global_p;
......@@ -117,6 +117,12 @@ int client_setup_sessions(void ** state) {
axc_buf * pt_buf_p;
assert_int_equal(axc_pre_key_message_process(ct_buf_p, &addr_alice, ctx_b_p, &pt_buf_p), 0);
axc_buf_free(ct_buf_p);
axc_buf_free(pt_buf_p);
assert_int_equal(axc_message_encrypt_and_serialize(msg_buf_p, &addr_alice, ctx_b_p, &ct_buf_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_buf_p, &addr_bob, ctx_a_p, &pt_buf_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob, ctx_a_p), 1);
assert_int_equal(axc_session_exists_initiated(&addr_alice, ctx_b_p), 1);
......@@ -268,134 +274,9 @@ void test_install_should_reset_if_needed(void **state) {
assert_int_not_equal(reg_id_1, reg_id_2);
}
void test_handshake_alloc(void **state) {
(void) state;
session_builder * s_p = (session_builder *) 0xB16B00B5;
axc_buf * msg_p = (axc_buf *) 0xBADF3315;
axc_handshake * h_p = axc_handshake_alloc(s_p, msg_p);
assert_ptr_not_equal(h_p, (void *) 0);
assert_ptr_equal(h_p->session_builder_p, s_p);
assert_ptr_equal(h_p->handshake_msg_p, msg_p);
}
void test_handshake_initiate_no_nullpointers(void **state) {
(void) state;
assert_int_not_equal(axc_handshake_initiate((void *) 0, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_initiate(&addr_bob_12, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_initiate(&addr_bob_12, ctx_global_p, (void *) 0), 0);
}
void test_handshake_initiate(void **state) {
(void) state;
assert_int_equal(axc_install(ctx_global_p), 0);
axc_handshake * handshake_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_global_p, &handshake_p), 0);
assert_ptr_not_equal(handshake_p, (void *) 0);
assert_ptr_not_equal(handshake_p->session_builder_p, (void *) 0);
assert_ptr_not_equal(handshake_p->handshake_msg_p, (void *) 0);
key_exchange_message * k_xchg_p = (void *) 0;
assert_int_equal(key_exchange_message_deserialize(&k_xchg_p, axc_buf_get_data(handshake_p->handshake_msg_p), axc_buf_get_len(handshake_p->handshake_msg_p), ctx_global_p->axolotl_global_context_p), 0);
assert_int_not_equal(key_exchange_message_is_initiate(k_xchg_p), 0);
axc_handshake_destroy(handshake_p);
AXOLOTL_UNREF(k_xchg_p);
}
void test_handshake_accept_no_nullpointers(void **state) {
(void) state;
assert_int_equal(axc_install(ctx_global_p), 0);
axc_handshake * handshake_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_global_p, &handshake_p), 0);
assert_int_not_equal(axc_handshake_accept((void *) 0, (void *) 0, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_accept(handshake_p->handshake_msg_p, (void *) 0, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_accept(handshake_p->handshake_msg_p, &addr_bob_12, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_accept(handshake_p->handshake_msg_p, &addr_bob_12, ctx_global_p, (void *) 0), 0);
axc_handshake_destroy(handshake_p);
}
void test_handshake_accept(void **state) {
(void) state;
assert_int_equal(axc_install(ctx_global_p), 0);
axc_handshake * handshake_recv_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_global_p, &handshake_recv_p), 0);
axc_handshake * handshake_send_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_recv_p->handshake_msg_p, &addr_bob_12, ctx_global_p, &handshake_send_p), 0);
key_exchange_message * xchg_msg_p = (void*) 0;
assert_int_equal(key_exchange_message_deserialize(&xchg_msg_p, axc_buf_get_data(handshake_send_p->handshake_msg_p), axc_buf_get_len(handshake_send_p->handshake_msg_p), ctx_global_p->axolotl_global_context_p), 0);
assert_int_not_equal(key_exchange_message_is_response_for_simultaneous_initiate(xchg_msg_p), 0);
assert_int_not_equal(axc_handshake_accept(handshake_send_p->handshake_msg_p, &addr_bob_12, ctx_global_p, &handshake_recv_p), 0);
AXOLOTL_UNREF(xchg_msg_p);
axc_handshake_destroy(handshake_send_p);
axc_handshake_destroy(handshake_recv_p);
}
void test_handshake_acknowledge_no_nullpointers(void **state) {
(void) state;
assert_int_equal(axc_install(ctx_global_p), 0);
axc_handshake * handshake_send_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_global_p, &handshake_send_p), 0);
axc_handshake * handshake_recv_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_send_p->handshake_msg_p, &addr_bob_12, ctx_global_p, &handshake_recv_p), 0);
assert_int_not_equal(axc_handshake_acknowledge((void *) 0, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_acknowledge(handshake_recv_p->handshake_msg_p, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_handshake_acknowledge(handshake_recv_p->handshake_msg_p, handshake_send_p, (void *) 0), 0);
axc_handshake_destroy(handshake_send_p);
axc_handshake_destroy(handshake_recv_p);
}
void test_handshake_acknowledge(void **state) {
(void) state;
axc_handshake * handshake_init_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_a_p, &handshake_init_p), 0);
axc_handshake * handshake_accept_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_init_p->handshake_msg_p, &addr_alice_21, ctx_b_p, &handshake_accept_p), 0);
assert_int_equal(axc_handshake_acknowledge(handshake_accept_p->handshake_msg_p, handshake_init_p, ctx_a_p), 0);
assert_int_not_equal(axc_handshake_acknowledge(handshake_init_p->handshake_msg_p, handshake_init_p, ctx_a_p), 0);
assert_int_not_equal(axc_handshake_acknowledge(handshake_init_p->handshake_msg_p, handshake_init_p, ctx_b_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob_12, ctx_a_p), 1);
assert_int_equal(axc_session_exists_initiated(&addr_alice_21, ctx_b_p), 1);
axc_handshake_destroy(handshake_accept_p);
axc_handshake_destroy(handshake_init_p);
}
void test_message_encrypt_decrypt(void **state) {
(void) state;
axc_handshake * handshake_init_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_a_p, &handshake_init_p), 0);
axc_handshake * handshake_accept_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_init_p->handshake_msg_p, &addr_alice_21, ctx_b_p, &handshake_accept_p), 0);
assert_int_equal(axc_handshake_acknowledge(handshake_accept_p->handshake_msg_p, handshake_init_p, ctx_a_p), 0);
axc_buf * msg_a1_p = axc_buf_create((uint8_t *) "hallo", 6);
axc_buf * msg_a2_p = axc_buf_create((uint8_t *) "sup", 4);
axc_buf * msg_b1_p = axc_buf_create((uint8_t *) "0123456789abcdef", 16);
......@@ -408,29 +289,29 @@ void test_message_encrypt_decrypt(void **state) {
axc_buf * ct_a1_p = (void *) 0;
axc_buf * ct_a2_p = (void *) 0;
assert_int_equal(axc_message_encrypt_and_serialize(msg_a1_p, &addr_bob_12, ctx_a_p, &ct_a1_p), 0);
assert_int_equal(axc_message_encrypt_and_serialize(msg_a2_p, &addr_bob_12, ctx_a_p, &ct_a2_p), 0);
assert_int_equal(axc_message_encrypt_and_serialize(msg_a1_p, &addr_bob, ctx_a_p, &ct_a1_p), 0);
assert_int_equal(axc_message_encrypt_and_serialize(msg_a2_p, &addr_bob, ctx_a_p, &ct_a2_p), 0);
axc_buf * pt_a1_p = (void *) 0;
axc_buf * pt_a2_p = (void *) 0;
assert_int_not_equal(axc_message_decrypt_from_serialized((void *) 0, (void *) 0, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_message_decrypt_from_serialized(ct_a1_p, (void *) 0, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_message_decrypt_from_serialized(ct_a1_p, &addr_alice_21, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_message_decrypt_from_serialized(ct_a1_p, &addr_alice_21, ctx_b_p, (void *) 0), 0);
assert_int_not_equal(axc_message_decrypt_from_serialized(ct_a1_p, &addr_alice, (void *) 0, (void *) 0), 0);
assert_int_not_equal(axc_message_decrypt_from_serialized(ct_a1_p, &addr_alice, ctx_b_p, (void *) 0), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_a1_p, &addr_alice_21, ctx_b_p, &pt_a1_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_a2_p, &addr_alice_21, ctx_b_p, &pt_a2_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_a1_p, &addr_alice, ctx_b_p, &pt_a1_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_a2_p, &addr_alice, ctx_b_p, &pt_a2_p), 0);
axc_buf * ct_b1_p = (void *) 0;
axc_buf * ct_b2_p = (void *) 0;
assert_int_equal(axc_message_encrypt_and_serialize(msg_b1_p, &addr_alice_21, ctx_b_p, &ct_b1_p), 0);
assert_int_equal(axc_message_encrypt_and_serialize(msg_b2_p, &addr_alice_21, ctx_b_p, &ct_b2_p), 0);
assert_int_equal(axc_message_encrypt_and_serialize(msg_b1_p, &addr_alice, ctx_b_p, &ct_b1_p), 0);
assert_int_equal(axc_message_encrypt_and_serialize(msg_b2_p, &addr_alice, ctx_b_p, &ct_b2_p), 0);
axc_buf * pt_b1_p = (void *) 0;
axc_buf * pt_b2_p = (void *) 0;
assert_int_equal(axc_message_decrypt_from_serialized(ct_b2_p, &addr_bob_12, ctx_a_p, &pt_b2_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_b1_p, &addr_bob_12, ctx_a_p, &pt_b1_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_b2_p, &addr_bob, ctx_a_p, &pt_b2_p), 0);
assert_int_equal(axc_message_decrypt_from_serialized(ct_b1_p, &addr_bob, ctx_a_p, &pt_b1_p), 0);
assert_int_equal(axc_buf_get_len(msg_a1_p), axc_buf_get_len(pt_a1_p));
assert_memory_equal(axc_buf_get_data(msg_a1_p), axc_buf_get_data(pt_a1_p), axc_buf_get_len(pt_a1_p));
......@@ -444,9 +325,6 @@ void test_message_encrypt_decrypt(void **state) {
assert_int_equal(axc_buf_get_len(msg_b2_p), axc_buf_get_len(pt_b2_p));
assert_memory_equal(axc_buf_get_data(msg_b2_p), axc_buf_get_data(pt_b2_p), axc_buf_get_len(pt_b2_p));
axc_handshake_destroy(handshake_accept_p);
axc_handshake_destroy(handshake_init_p);
axc_buf_free(msg_a1_p);
axc_buf_free(msg_a2_p);
axc_buf_free(msg_b1_p);
......@@ -463,46 +341,46 @@ void test_message_encrypt_decrypt(void **state) {
axc_buf_free(pt_b2_p);
}
void test_session_exists_initiated(void **state) {
void test_session_exists_any(void ** state) {
(void) state;
assert_int_equal(axc_session_exists_initiated(&addr_bob_12, ctx_a_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_alice_21, ctx_b_p), 0);
axc_handshake * handshake_init_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_a_p, &handshake_init_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob_12, ctx_a_p), 0);
axc_handshake * handshake_accept_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_init_p->handshake_msg_p, &addr_alice_21, ctx_b_p, &handshake_accept_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob, ctx_a_p), 0);
assert_int_equal(axc_session_exists_any(addr_bob.name, ctx_a_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_alice_21, ctx_b_p), 1);
assert_int_equal(axc_session_exists_initiated(&addr_alice, ctx_b_p), 0);
assert_int_equal(axc_session_exists_any(addr_alice.name, ctx_b_p), 0);
assert_int_equal(axc_handshake_acknowledge(handshake_accept_p->handshake_msg_p, handshake_init_p, ctx_a_p), 0);
axc_bundle * bundle_bob_p;
assert_int_equal(axc_bundle_collect(AXC_PRE_KEYS_AMOUNT, ctx_b_p, &bundle_bob_p), 0);
addr_bob.device_id = bundle_bob_p->registration_id;
assert_int_equal(axc_session_exists_initiated(&addr_bob_12, ctx_a_p), 1);
assert_int_equal(axc_session_from_bundle(axc_buf_list_item_get_id(bundle_bob_p->pre_keys_head_p),
axc_buf_list_item_get_buf(bundle_bob_p->pre_keys_head_p),
bundle_bob_p->signed_pre_key_id,
bundle_bob_p->signed_pre_key_public_serialized_p,
bundle_bob_p->signed_pre_key_signature_p,
bundle_bob_p->identity_key_public_serialized_p,
&addr_bob,
ctx_a_p),
0);
axc_handshake_destroy(handshake_accept_p);
axc_handshake_destroy(handshake_init_p);
}
axc_buf * msg_buf_p = axc_buf_create("hello", strlen("hello") + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);
void test_session_exists_any(void ** state) {
(void) state;
axc_buf * ct_buf_p;
assert_int_equal(axc_message_encrypt_and_serialize(msg_buf_p, &addr_bob, ctx_a_p, &ct_buf_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob_12, ctx_a_p), 0);
assert_int_equal(axc_session_exists_any(addr_bob_12.name, ctx_a_p), 0);
uint32_t alice_id;
assert_int_equal(axc_get_device_id(ctx_a_p, &alice_id), 0);
assert_int_equal(axc_session_exists_initiated(&addr_alice_21, ctx_b_p), 0);
assert_int_equal(axc_session_exists_any(addr_alice_21.name, ctx_b_p), 0);
addr_alice.device_id = alice_id;
axc_handshake * handshake_init_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_a_p, &handshake_init_p), 0);
axc_handshake * handshake_accept_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_init_p->handshake_msg_p, &addr_alice_21, ctx_b_p, &handshake_accept_p), 0);
axc_buf * pt_buf_p;
assert_int_equal(axc_pre_key_message_process(ct_buf_p, &addr_alice, ctx_b_p, &pt_buf_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_alice_21, ctx_b_p), 1);
assert_int_equal(axc_session_exists_any(addr_alice_21.name, ctx_b_p), 1);
assert_int_equal(axc_session_exists_initiated(&addr_alice, ctx_b_p), 1);
assert_int_equal(axc_session_exists_initiated(&addr_alice_42, ctx_b_p), 0);
assert_int_equal(axc_session_exists_any(addr_alice.name, ctx_b_p), 1);
}
......@@ -515,7 +393,7 @@ void test_session_from_bundle_and_handle_prekey_message(void **state) {
uint32_t pre_key_id_bob = 10;
session_pre_key * pre_key_bob_p = (void *) 0;
assert_int_equal(axolotl_pre_key_load_key(ctx_b_p->axolotl_store_context_p, &pre_key_bob_p, pre_key_id_bob), 0);
assert_int_equal(signal_protocol_pre_key_load_key(ctx_b_p->axolotl_store_context_p, &pre_key_bob_p, pre_key_id_bob), 0);
ec_key_pair * pre_key_pair_p = session_pre_key_get_key_pair(pre_key_bob_p);
ec_public_key * pre_key_public_p = ec_key_pair_get_public(pre_key_pair_p);
axc_buf * pre_key_public_data_p = (void *) 0;
......@@ -523,7 +401,7 @@ void test_session_from_bundle_and_handle_prekey_message(void **state) {
uint32_t signed_pre_key_id_bob = 0;
session_signed_pre_key * signed_pre_key_bob_p = (void *) 0;
assert_int_equal(axolotl_signed_pre_key_load_key(ctx_b_p->axolotl_store_context_p, &signed_pre_key_bob_p, signed_pre_key_id_bob), 0);
assert_int_equal(signal_protocol_signed_pre_key_load_key(ctx_b_p->axolotl_store_context_p, &signed_pre_key_bob_p, signed_pre_key_id_bob), 0);
ec_key_pair * signed_pre_key_pair_p = session_signed_pre_key_get_key_pair(signed_pre_key_bob_p);
ec_public_key * signed_pre_key_public_p = ec_key_pair_get_public(signed_pre_key_pair_p);
axc_buf * signed_pre_key_public_data_p = (void *) 0;
......@@ -679,7 +557,7 @@ void test_key_load_public_own(void ** state) {
assert_int_equal(axc_key_load_public_own(ctx_global_p, &key_buf_p), 0);
ratchet_identity_key_pair * kp_p;
assert_int_equal(axolotl_identity_get_key_pair(ctx_global_p->axolotl_store_context_p, &kp_p), 0);
assert_int_equal(signal_protocol_identity_get_key_pair(ctx_global_p->axolotl_store_context_p, &kp_p), 0);
axc_buf * db_key_buf_p;
assert_int_equal(ec_public_key_serialize(&db_key_buf_p, ratchet_identity_key_pair_get_public(kp_p)), 0);
......@@ -699,7 +577,7 @@ void test_key_load_public_addr(void ** state) {
assert_int_equal(axc_key_load_public_addr(addr_bob.name, addr_bob.device_id, ctx_a_p, &key_buf_p), 1);
session_record * sr_p;
assert_int_equal(axolotl_session_load_session(ctx_a_p->axolotl_store_context_p, &sr_p, &addr_bob), 0);
assert_int_equal(signal_protocol_session_load_session(ctx_a_p->axolotl_store_context_p, &sr_p, &addr_bob), 0);
assert_int_equal(session_record_is_fresh(sr_p), 0);
axc_buf * db_key_buf_p;
......@@ -708,7 +586,7 @@ void test_key_load_public_addr(void ** state) {
axc_buf_free(key_buf_p);
axc_buf_free(db_key_buf_p);
AXOLOTL_UNREF(sr_p);
SIGNAL_UNREF(sr_p);
}
......@@ -724,17 +602,8 @@ int main(void) {
cmocka_unit_test_setup_teardown(test_install_should_not_do_anything_if_already_initialiased, client_setup, client_teardown),
cmocka_unit_test_setup_teardown(test_install_should_reset_if_needed, client_setup, client_teardown),
cmocka_unit_test(test_handshake_alloc),
cmocka_unit_test_setup_teardown(test_handshake_initiate_no_nullpointers, client_setup, client_teardown),
cmocka_unit_test_setup_teardown(test_handshake_initiate, client_setup, client_teardown),
cmocka_unit_test_setup_teardown(test_handshake_accept, client_setup, client_teardown),
cmocka_unit_test_setup_teardown(test_handshake_accept_no_nullpointers, client_setup, client_teardown),
cmocka_unit_test_setup_teardown(test_handshake_acknowledge_no_nullpointers, client_setup, client_teardown),
cmocka_unit_test_setup_teardown(test_handshake_acknowledge, client_setup_two_dbs, client_teardown_two_dbs),
cmocka_unit_test_setup_teardown(test_message_encrypt_decrypt, client_setup_two_dbs, client_teardown_two_dbs),
cmocka_unit_test_setup_teardown(test_message_encrypt_decrypt, client_setup_sessions, client_teardown_two_dbs),
cmocka_unit_test_setup_teardown(test_session_exists_initiated, client_setup_two_dbs, client_teardown_two_dbs),
cmocka_unit_test_setup_teardown(test_session_exists_any, client_setup_two_dbs, client_teardown_two_dbs),
cmocka_unit_test_setup_teardown(test_session_exists_prekeys, client_setup_two_dbs, client_teardown_two_dbs),
......
......@@ -17,10 +17,10 @@ sqlite3_stmt * pstmt_p;
char * db_filename = "test/test.sqlite";
axc_context * ctx_global_p;
axolotl_address addr_alice_42 = {.name = "alice", .name_len = 5, .device_id = 42};
axolotl_address addr_alice_21 = {.name = "alice", .name_len = 5, .device_id = 21};
signal_protocol_address addr_alice_42 = {.name = "alice", .name_len = 5, .device_id = 42};
signal_protocol_address addr_alice_21 = {.name = "alice", .name_len = 5, .device_id = 21};
axolotl_address addr_bob_12 = {.name = "bob", .name_len = 3, .device_id = 12};
signal_protocol_address addr_bob_12 = {.name = "bob", .name_len = 3, .device_id = 12};
uint8_t bytes_1[] = {0xB1, 0x6B, 0x00, 0xB5};
size_t bytes_1_len = sizeof(bytes_1);
......@@ -341,16 +341,16 @@ void test_db_session_load_should_find_session(void **state) {
assert_int_equal(axc_db_session_store(&addr_alice_42, bytes_1, bytes_1_len, ctx_global_p), 0);
axolotl_buffer * buf = (void *) 0;
signal_buffer * buf = (void *) 0;
assert_int_equal(axc_db_session_load(&buf, &addr_alice_42, ctx_global_p), 1);
assert_memory_equal(axolotl_buffer_data(buf), bytes_1, bytes_1_len);
assert_int_equal(axolotl_buffer_len(buf), bytes_1_len);
assert_memory_equal(signal_buffer_data(buf), bytes_1, bytes_1_len);
assert_int_equal(signal_buffer_len(buf), bytes_1_len);
}
void test_db_session_load_should_not_find_session(void **state) {
(void) state;
axolotl_buffer * buf = (void *) 0;
signal_buffer * buf = (void *) 0;
assert_int_equal(axc_db_session_load(&buf, &addr_alice_42, ctx_global_p), 0);
}
......@@ -360,14 +360,14 @@ void test_db_session_get_sub_device_sessions_should_find_and_return_correct_numb
assert_int_equal(axc_db_session_store(&addr_alice_42, bytes_1, bytes_1_len, ctx_global_p), 0);
assert_int_equal(axc_db_session_store(&addr_alice_21, bytes_2, bytes_2_len, ctx_global_p), 0);
axolotl_int_list * list_a = (void *) 0;
signal_int_list * list_a = (void *) 0;
assert_int_equal(axc_db_session_get_sub_device_sessions(&list_a, addr_alice_42.name, addr_alice_42.name_len, ctx_global_p), 2);
axolotl_int_list * list_b = (void *) 0;
signal_int_list * list_b = (void *) 0;
assert_int_equal(axc_db_session_get_sub_device_sessions(&list_b, addr_bob_12.name, addr_bob_12.name_len, ctx_global_p), 0);
assert_int_equal(axolotl_int_list_size(list_a), 2);
assert_int_equal(axolotl_int_list_size(list_b), 0);
assert_int_equal(signal_int_list_size(list_a), 2);
assert_int_equal(signal_int_list_size(list_b), 0);
}
void test_db_session_contains_should_return_correct_values(void ** state) {
......@@ -379,6 +379,9 @@ void test_db_session_contains_should_return_correct_values(void ** state) {
axc_context * ctx_a_p = (void *) 0;
axc_context * ctx_b_p = (void *) 0;
signal_protocol_address addr_alice = {.name = "alice", .name_len = 5, .device_id = 0};
axc_address addr_bob = {.name = "bob", .name_len = 3, .device_id = 0};
assert_int_equal(axc_context_create(&ctx_a_p), 0);
assert_int_equal(axc_context_create(&ctx_b_p), 0);
......@@ -391,21 +394,43 @@ void test_db_session_contains_should_return_correct_values(void ** state) {
assert_int_equal(axc_install(ctx_a_p), 0);
assert_int_equal(axc_install(ctx_b_p), 0);
assert_int_equal(axc_db_session_contains(&addr_alice_21, ctx_b_p), 0);
assert_int_equal(axc_db_session_contains(&addr_bob_12, ctx_a_p), 0);
assert_int_equal(axc_db_session_contains(&addr_alice, ctx_b_p), 0);
assert_int_equal(axc_db_session_contains(&addr_bob, ctx_a_p), 0);
axc_bundle * bundle_bob_p;
assert_int_equal(axc_bundle_collect(AXC_PRE_KEYS_AMOUNT, ctx_b_p, &bundle_bob_p), 0);
addr_bob.device_id = bundle_bob_p->registration_id;
assert_int_equal(axc_session_from_bundle(axc_buf_list_item_get_id(bundle_bob_p->pre_keys_head_p),
axc_buf_list_item_get_buf(bundle_bob_p->pre_keys_head_p),
bundle_bob_p->signed_pre_key_id,
bundle_bob_p->signed_pre_key_public_serialized_p,
bundle_bob_p->signed_pre_key_signature_p,
bundle_bob_p->identity_key_public_serialized_p,
&addr_bob,
ctx_a_p),
0);
axc_handshake * handshake_init_p = (void *) 0;
assert_int_equal(axc_handshake_initiate(&addr_bob_12, ctx_a_p, &handshake_init_p), 0);
axc_buf * msg_buf_p = axc_buf_create("hello", strlen("hello") + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);
assert_int_equal(axc_db_session_contains(&addr_bob_12, ctx_a_p), 1);
axc_buf * ct_buf_p;
assert_int_equal(axc_message_encrypt_and_serialize(msg_buf_p, &addr_bob, ctx_a_p, &ct_buf_p), 0);
axc_handshake * handshake_accept_p = (void *) 0;
assert_int_equal(axc_handshake_accept(handshake_init_p->handshake_msg_p, &addr_alice_21, ctx_b_p, &handshake_accept_p), 0);
uint32_t alice_id;
assert_int_equal(axc_get_device_id(ctx_a_p, &alice_id), 0);
assert_int_equal(axc_db_session_contains(&addr_alice_21, ctx_b_p), 1);
addr_alice.device_id = alice_id;
assert_int_equal(axc_handshake_acknowledge(handshake_accept_p->handshake_msg_p, handshake_init_p, ctx_a_p), 0);
assert_int_equal(axc_db_session_contains(&addr_bob_12, ctx_a_p), 1);
axc_buf * pt_buf_p;
assert_int_equal(axc_pre_key_message_process(ct_buf_p, &addr_alice, ctx_b_p, &pt_buf_p), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob, ctx_a_p), 1);
assert_int_equal(axc_session_exists_initiated(&addr_alice, ctx_b_p), 1);
axc_buf_free(msg_buf_p);
axc_buf_free(ct_buf_p);
axc_buf_free(pt_buf_p);
axc_cleanup(ctx_a_p);
axc_cleanup(ctx_b_p);
......@@ -425,7 +450,7 @@ void test_db_session_delete_should_return_correct_values(void **state) {
void test_db_session_delete_all_should_return_correct_values(void **state) {
(void) state;
axolotl_int_list * sessions = (void *) 0;
signal_int_list * sessions = (void *) 0;
assert_int_equal(axc_db_session_store(&addr_alice_42, bytes_1, bytes_1_len, ctx_global_p), 0);
assert_int_equal(axc_db_session_store(&addr_alice_21, bytes_2, bytes_2_len, ctx_global_p), 0);
......@@ -455,11 +480,11 @@ void test_db_pre_key_load_should_return_correct_values_and_key(void **state) {
assert_int_equal(axc_db_pre_key_store(id, bytes_1, bytes_1_len, ctx_global_p), 0);
axolotl_buffer * buf = (void *) 0;
assert_int_equal(axc_db_pre_key_load(&buf, id, ctx_global_p), AX_SUCCESS);
assert_memory_equal(axolotl_buffer_data(buf), bytes_1, bytes_1_len);
signal_buffer * buf = (void *) 0;
assert_int_equal(axc_db_pre_key_load(&buf, id, ctx_global_p), SG_SUCCESS);
assert_memory_equal(signal_buffer_data(buf), bytes_1, bytes_1_len);
assert_int_equal(axc_db_pre_key_load(&buf, id + 1, ctx_global_p), AX_ERR_INVALID_KEY_ID);
assert_int_equal(axc_db_pre_key_load(&buf, id + 1, ctx_global_p), SG_ERR_INVALID_KEY_ID);
}
void test_db_pre_key_contains_should_return_correct_values(void **state) {
......@@ -491,9 +516,9 @@ void test_db_pre_key_store_list(void **state) {
assert_int_equal(axc_init(ctx_p), 0);
axolotl_key_helper_pre_key_list_node * pre_keys_head_p = (void *) 0;
signal_protocol_key_helper_pre_key_list_node * pre_keys_head_p = (void *) 0;
// for some reason, key IDs is not inclusive and starts at +1!
assert_int_equal(axolotl_key_helper_generate_pre_keys(&pre_keys_head_p, 0, pre_key_num, ctx_p->axolotl_global_context_p), 0);
assert_int_equal(signal_protocol_key_helper_generate_pre_keys(&pre_keys_head_p, 0, pre_key_num, ctx_p->axolotl_global_context_p), 0);
assert_int_equal(axc_db_pre_key_store_list(pre_keys_head_p, ctx_p), 0);
assert_int_not_equal(sprintf(stmt, "SELECT count(*) FROM pre_key_store;"), 0);
......@@ -502,10 +527,10 @@ void test_db_pre_key_store_list(void **state) {
assert_int_equal(sqlite3_column_int(pstmt_p, 0), pre_key_num);
assert_int_equal(sqlite3_finalize(pstmt_p), SQLITE_OK);
session_pre_key * pre_key_p = axolotl_key_helper_key_list_element(pre_keys_head_p);
session_pre_key * pre_key_p = signal_protocol_key_helper_key_list_element(pre_keys_head_p);
assert_ptr_not_equal(pre_key_p, (void *) 0);
axolotl_buffer * key_buf_p = (void *) 0;
signal_buffer * key_buf_p = (void *) 0;
assert_int_equal(session_pre_key_serialize(&key_buf_p, pre_key_p), 0);
......@@ -513,8 +538,8 @@ void test_db_pre_key_store_list(void **state) {
assert_int_equal(sqlite3_prepare_v2(db_p, stmt, -1, &pstmt_p, (void *) 0), SQLITE_OK);
assert_int_equal(sqlite3_step(pstmt_p), SQLITE_ROW);
assert_int_equal(sqlite3_column_int(pstmt_p, 0), session_pre_key_get_id(pre_key_p));
assert_memory_equal(sqlite3_column_blob(pstmt_p, 1), axolotl_buffer_data(key_buf_p), axolotl_buffer_len(key_buf_p));
assert_int_equal(sqlite3_column_int(pstmt_p, 2), axolotl_buffer_len(key_buf_p));
assert_memory_equal(sqlite3_column_blob(pstmt_p, 1), signal_buffer_data(key_buf_p), signal_buffer_len(key_buf_p));
assert_int_equal(sqlite3_column_int(pstmt_p, 2), signal_buffer_len(key_buf_p));
}
void test_db_pre_key_get_list(void ** state) {
......@@ -535,7 +560,7 @@ void test_db_pre_key_get_list(void ** state) {
count++;
buf_p = axc_buf_list_item_get_buf(curr);
assert_int_equal(curve_decode_point(&pre_key_public_p, axc_buf_get_data(buf_p), axc_buf_get_len(buf_p), ctx_global_p->axolotl_global_context_p), 0);
AXOLOTL_UNREF(pre_key_public_p);
SIGNAL_UNREF(pre_key_public_p);
curr = curr->next_p;
}
......@@ -577,11 +602,11 @@ void test_db_signed_pre_key_load_should_return_correct_values_and_key(void **sta
assert_int_equal(axc_db_signed_pre_key_store(id, bytes_1, bytes_1_len, ctx_global_p), 0);
axolotl_buffer * buf = (void *) 0;
assert_int_equal(axc_db_signed_pre_key_load(&buf, id, ctx_global_p), AX_SUCCESS);
assert_memory_equal(axolotl_buffer_data(buf), bytes_1, bytes_1_len);
signal_buffer * buf = (void *) 0;
assert_int_equal(axc_db_signed_pre_key_load(&buf, id, ctx_global_p), SG_SUCCESS);
assert_memory_equal(signal_buffer_data(buf), bytes_1, bytes_1_len);
assert_int_equal(axc_db_signed_pre_key_load(&buf, id + 1, ctx_global_p), AX_ERR_INVALID_KEY_ID);
assert_int_equal(axc_db_signed_pre_key_load(&buf, id + 1, ctx_global_p), SG_ERR_INVALID_KEY_ID);
}
void test_db_signed_pre_key_contains_should_return_correct_values(void **state) {
......@@ -610,34 +635,34 @@ void test_db_identity_set_and_get_key_pair(void **state) {
assert_int_equal(axc_init(ctx_p), 0);
ratchet_identity_key_pair * identity_key_pair_p = (void *) 0;
assert_int_equal(axolotl_key_helper_generate_identity_key_pair(&identity_key_pair_p, ctx_p->axolotl_global_context_p), 0);
assert_int_equal(signal_protocol_key_helper_generate_identity_key_pair(&identity_key_pair_p, ctx_p->axolotl_global_context_p), 0);
assert_int_equal(axc_db_identity_set_key_pair(identity_key_pair_p, ctx_p), 0);
axolotl_buffer * pubkey_saved_p = (void *) 0;
axolotl_buffer * privkey_saved_p = (void *) 0;
signal_buffer * pubkey_saved_p = (void *) 0;
signal_buffer * privkey_saved_p = (void *) 0;
assert_int_equal(axc_db_identity_get_key_pair(&pubkey_saved_p, &privkey_saved_p, ctx_p), 0);
axolotl_buffer * pubkey_orig_p = (void *) 0;
axolotl_buffer * privkey_orig_p = (void *) 0;
signal_buffer * pubkey_orig_p = (void *) 0;
signal_buffer * privkey_orig_p = (void *) 0;
assert_int_equal(ec_public_key_serialize(&pubkey_orig_p,
ratchet_identity_key_pair_get_public(identity_key_pair_p)), 0);
assert_memory_equal(axolotl_buffer_data(pubkey_orig_p), axolotl_buffer_data(pubkey_saved_p), axolotl_buffer_len(pubkey_saved_p));
assert_memory_equal(signal_buffer_data(pubkey_orig_p), signal_buffer_data(pubkey_saved_p), signal_buffer_len(pubkey_saved_p));
assert_int_equal(ec_private_key_serialize(&privkey_orig_p,
ratchet_identity_key_pair_get_private(identity_key_pair_p)), 0);
assert_memory_equal(axolotl_buffer_data(privkey_orig_p), axolotl_buffer_data(privkey_saved_p), axolotl_buffer_len(privkey_saved_p));
assert_memory_equal(signal_buffer_data(privkey_orig_p), signal_buffer_data(privkey_saved_p), signal_buffer_len(privkey_saved_p));
axolotl_buffer_free(pubkey_orig_p);
axolotl_buffer_free(pubkey_saved_p);
axolotl_buffer_free(privkey_orig_p);
axolotl_buffer_free(privkey_saved_p);
signal_buffer_free(pubkey_orig_p);
signal_buffer_free(pubkey_saved_p);
signal_buffer_free(privkey_orig_p);
signal_buffer_free(privkey_saved_p);
}
void test_db_identity_get_key_pair_keys_not_found(void ** state) {
(void) state;
assert_int_equal(axc_db_identity_get_key_pair((void * ) 0, (void *) 0, ctx_global_p), AX_ERR_INVALID_KEY_ID);
assert_int_equal(axc_db_identity_get_key_pair((void * ) 0, (void *) 0, ctx_global_p), SG_ERR_INVALID_KEY_ID);
axc_context * ctx_p = (void *) 0;
assert_int_equal(axc_context_create(&ctx_p), 0);
......@@ -650,7 +675,7 @@ void test_db_identity_get_key_pair_keys_not_found(void ** state) {
assert_int_equal(db_conn_open(&db_p, &pstmt_p, stmt, ctx_p), 0);
assert_int_equal(sqlite3_step(pstmt_p), SQLITE_DONE);
assert_int_equal(axc_db_identity_get_key_pair((void *) 0, (void *) 0, ctx_p), AX_ERR_INVALID_KEY_ID);
assert_int_equal(axc_db_identity_get_key_pair((void *) 0, (void *) 0, ctx_p), SG_ERR_INVALID_KEY_ID);
}
void test_db_identity_set_local_registration_id(void ** state) {
......@@ -676,7 +701,7 @@ void test_db_identity_get_local_registration_id(void **state) {
void test_db_identity_save(void **state) {
(void) state;
assert_int_equal(axc_db_identity_save(addr_alice_21.name, 0, bytes_1, bytes_1_len, ctx_global_p), 0);
assert_int_equal(axc_db_identity_save(&addr_alice_21, bytes_1, bytes_1_len, ctx_global_p), 0);
const char * stmt = "SELECT * FROM identity_key_store WHERE name='alice';";
......@@ -689,7 +714,7 @@ void test_db_identity_save(void **state) {
assert_int_equal(sqlite3_step(pstmt_p), SQLITE_DONE);
assert_int_equal(axc_db_identity_save(addr_alice_21.name, 0, (void *) 0, 0, ctx_global_p), 0);
assert_int_equal(axc_db_identity_save(&addr_alice_21, (void *) 0, 0, ctx_global_p), 0);
assert_int_equal(sqlite3_reset(pstmt_p), SQLITE_OK);
assert_int_equal(sqlite3_step(pstmt_p), SQLITE_DONE);
......