diff --git a/src/client.c b/src/client.c index 6c4870b8..754fa2bb 100644 --- a/src/client.c +++ b/src/client.c @@ -123,7 +123,6 @@ API void otrng_client_free(otrng_client_s *client) { otrng_client_profile_free(client->exp_client_profile); otrng_prekey_profile_free(client->prekey_profile); otrng_prekey_profile_free(client->exp_prekey_profile); - otrng_shared_prekey_pair_free(client->shared_prekey_pair); otrng_list_free(client->conversations, conversation_free); otrng_prekey_client_free(client->prekey_client); @@ -869,39 +868,6 @@ API otrng_result otrng_client_add_exp_client_profile( return OTRNG_SUCCESS; } -INTERNAL otrng_result otrng_client_add_shared_prekey_v4( - otrng_client_s *client, const uint8_t sym[ED448_PRIVATE_BYTES]) { - assert(client); - - if (client->shared_prekey_pair) { - return OTRNG_ERROR; - } - - /* @secret_information: the shared keypair lives for as long the client - decides */ - client->shared_prekey_pair = otrng_shared_prekey_pair_new(); - if (!client->shared_prekey_pair) { - return OTRNG_ERROR; - } - - otrng_shared_prekey_pair_generate(client->shared_prekey_pair, sym); - return OTRNG_SUCCESS; -} - -static const otrng_shared_prekey_pair_s * -get_shared_prekey_pair(otrng_client_s *client) { - assert(client); - - if (client->shared_prekey_pair) { - return client->shared_prekey_pair; - } - - client->global_state->callbacks->create_shared_prekey(client, - client->client_id); - - return client->shared_prekey_pair; -} - API otrng_prekey_profile_s * otrng_client_get_prekey_profile(otrng_client_s *client) { assert(client); @@ -920,17 +886,13 @@ API otrng_prekey_profile_s * otrng_client_build_default_prekey_profile(otrng_client_s *client) { assert(client); - /* @secret: the shared prekey should be deleted once the prekey profile - * expires */ return otrng_prekey_profile_build(otrng_client_get_instance_tag(client), - otrng_client_get_keypair_v4(client), - get_shared_prekey_pair(client)); + otrng_client_get_keypair_v4(client)); } API otrng_result otrng_client_add_prekey_profile( otrng_client_s *client, const otrng_prekey_profile_s *profile) { assert(client); - if (client->prekey_profile) { return OTRNG_ERROR; } diff --git a/src/client.h b/src/client.h index b233db05..81eba67f 100644 --- a/src/client.h +++ b/src/client.h @@ -68,9 +68,6 @@ typedef struct otrng_client_s { otrng_prekey_profile_s *exp_prekey_profile; list_element_s *our_prekeys; /* otrng_stored_prekeys_s */ - /* @secret: this should be deleted once the prekey profile expires */ - otrng_shared_prekey_pair_s *shared_prekey_pair; - unsigned int max_stored_msg_keys; unsigned int max_published_prekey_msg; unsigned int minimum_stored_prekey_msg; @@ -217,9 +214,6 @@ otrng_client_get_exp_client_profile(otrng_client_s *client); API otrng_result otrng_client_add_exp_client_profile( otrng_client_s *client, const otrng_client_profile_s *exp_profile); -INTERNAL otrng_result otrng_client_add_shared_prekey_v4( - otrng_client_s *client, const uint8_t sym[ED448_PRIVATE_BYTES]); - API otrng_prekey_profile_s * otrng_client_get_prekey_profile(otrng_client_s *client); diff --git a/src/client_callbacks.c b/src/client_callbacks.c index 567f1aa6..cb5fa5a1 100644 --- a/src/client_callbacks.c +++ b/src/client_callbacks.c @@ -31,7 +31,6 @@ otrng_client_callbacks_ensure_needed_exist(const otrng_client_callbacks_s *cb) { cb->write_expired_client_profile != NULL && cb->create_prekey_profile != NULL && cb->write_expired_prekey_profile != NULL && - cb->create_shared_prekey != NULL && cb->get_shared_session_state != NULL && cb->load_privkey_v4 != NULL && cb->load_client_profile != NULL && cb->load_prekey_profile != NULL && cb->store_client_profile != NULL && cb->store_prekey_profile != NULL); diff --git a/src/client_callbacks.h b/src/client_callbacks.h index f2aaf5d0..3b5ff508 100644 --- a/src/client_callbacks.h +++ b/src/client_callbacks.h @@ -83,10 +83,6 @@ typedef struct otrng_client_callbacks_s { struct otrng_client_s *client, const struct otrng_client_id_s client_opdata); - /* REQUIRED */ - void (*create_shared_prekey)(struct otrng_client_s *client, - const struct otrng_client_id_s client_opdata); - /* OPTIONAL */ void (*gone_secure)(const struct otrng_s *); diff --git a/src/messaging.c b/src/messaging.c index fc9d88e7..b827629a 100644 --- a/src/messaging.c +++ b/src/messaging.c @@ -176,26 +176,6 @@ API otrng_result otrng_global_state_generate_forging_key( return r; } -API otrng_result otrng_global_state_generate_shared_prekey( - otrng_global_state_s *gs, const otrng_client_id_s client_id) { - otrng_result r; - uint8_t *sym = otrng_secure_alloc(ED448_PRIVATE_BYTES); - otrng_client_s *client; - - gcry_randomize(sym, ED448_PRIVATE_BYTES, GCRY_VERY_STRONG_RANDOM); - - client = get_client(gs, client_id); - if (!client) { - return OTRNG_ERROR; - } - - r = otrng_client_add_shared_prekey_v4(client, sym); - - otrng_secure_wipe(sym, ED448_PRIVATE_BYTES); - free(sym); - return r; -} - API otrng_result otrng_global_state_generate_client_profile( otrng_global_state_s *gs, const otrng_client_id_s client_id) { otrng_client_profile_s *profile; @@ -276,25 +256,6 @@ API otrng_result otrng_global_state_forging_key_write_to( return OTRNG_SUCCESS; } -tstatic void add_shared_prekey_to(list_element_s *node, void *context) { - otrng_client_s *client = node->data; - // TODO: check the return value - if (!otrng_client_shared_prekey_write_to(client, context)) { - return; - } -} - -API otrng_result otrng_global_state_shared_prekey_write_to( - const otrng_global_state_s *gs, FILE *shared_prekey_f) { - if (!shared_prekey_f) { - return OTRNG_ERROR; - } - - otrng_list_foreach(gs->clients, add_shared_prekey_to, shared_prekey_f); - - return OTRNG_SUCCESS; -} - tstatic void add_client_profile_to(list_element_s *node, void *context) { otrng_client_client_profile_write_to(node->data, context); } @@ -409,32 +370,6 @@ API otrng_result otrng_global_state_forging_key_read_from( return OTRNG_SUCCESS; } -API otrng_result otrng_global_state_shared_prekey_read_from( - otrng_global_state_s *gs, FILE *shared_prekeyf, - otrng_client_id_s (*read_client_id_for_key)(FILE *filep)) { - if (!shared_prekeyf) { - return OTRNG_ERROR; - } - - // Scan the whole file for a private key for this client - while (!feof(shared_prekeyf)) { - otrng_client_s *client; - const otrng_client_id_s client_id = read_client_id_for_key(shared_prekeyf); - if (!client_id.protocol || !client_id.account) { - continue; - } - - client = get_client(gs, client_id); - if (otrng_client_shared_prekey_read_from(client, shared_prekeyf) != - OTRNG_SUCCESS) { - return OTRNG_ERROR; /* We decide to abort, since this means the file is - malformed */ - } - } - - return OTRNG_SUCCESS; -} - API otrng_result otrng_global_state_client_profile_read_from( otrng_global_state_s *gs, FILE *profile_filep, otrng_client_id_s (*read_client_id_for_key)(FILE *filep)) { diff --git a/src/messaging.h b/src/messaging.h index 6d20ed2c..123e481e 100644 --- a/src/messaging.h +++ b/src/messaging.h @@ -72,9 +72,6 @@ API otrng_result otrng_global_state_generate_private_key( API otrng_result otrng_global_state_generate_forging_key( otrng_global_state_s *gs, const otrng_client_id_s client_id); -API otrng_result otrng_global_state_generate_shared_prekey( - otrng_global_state_s *gs, const otrng_client_id_s client_id); - API otrng_result otrng_global_state_generate_client_profile( otrng_global_state_s *gs, const otrng_client_id_s client_id); @@ -87,9 +84,6 @@ API otrng_result otrng_global_state_private_key_v4_write_to( API otrng_result otrng_global_state_forging_key_write_to( const otrng_global_state_s *gs, FILE *f); -API otrng_result otrng_global_state_shared_prekey_write_to( - const otrng_global_state_s *gs, FILE *shared_prekey_f); - API otrng_result otrng_global_state_client_profile_write_to( const otrng_global_state_s *gs, FILE *privf); @@ -113,10 +107,6 @@ API otrng_result otrng_global_state_forging_key_read_from( otrng_global_state_s *gs, FILE *f, otrng_client_id_s (*read_client_id_for_key)(FILE *f)); -API otrng_result otrng_global_state_shared_prekey_read_from( - otrng_global_state_s *gs, FILE *shared_prekeyf, - otrng_client_id_s (*read_client_id_for_key)(FILE *filep)); - API otrng_result otrng_global_state_client_profile_read_from( otrng_global_state_s *gs, FILE *profile_filep, otrng_client_id_s (*read_client_id_for_key)(FILE *filep)); diff --git a/src/otrng.c b/src/otrng.c index 990cc7ee..e5fa7392 100644 --- a/src/otrng.c +++ b/src/otrng.c @@ -141,7 +141,7 @@ tstatic void allowed_versions(string_p destination, const otrng_s *otr) { tstatic const otrng_shared_prekey_pair_s * our_shared_prekey(const otrng_s *otr) { - return otr->client->shared_prekey_pair; + return otr->client->prekey_profile->keys; } INTERNAL otrng_s *otrng_new(otrng_client_s *client, otrng_policy_s policy) { diff --git a/src/persistence.c b/src/persistence.c index 043c719c..93fe1ab6 100644 --- a/src/persistence.c +++ b/src/persistence.c @@ -265,99 +265,6 @@ INTERNAL otrng_result otrng_client_forging_key_read_from(otrng_client_s *client, return otrng_client_add_forging_key(client, key); } -INTERNAL otrng_result otrng_client_shared_prekey_write_to( - const otrng_client_s *client, FILE *shared_prekey_f) { - char *storage_id; - int err; - char *buff = NULL; - size_t s = 0; - - if (!shared_prekey_f) { - return OTRNG_ERROR; - } - - if (!client->shared_prekey_pair) { - return OTRNG_ERROR; - } - - storage_id = otrng_client_get_storage_id(client); - if (!storage_id) { - return OTRNG_ERROR; - } - - err = fputs(storage_id, shared_prekey_f); - free(storage_id); - - if (EOF == err) { - return OTRNG_ERROR; - } - - if (EOF == fputs("\n", shared_prekey_f)) { - return OTRNG_ERROR; - } - - if (!otrng_symmetric_key_serialize(&buff, &s, - client->shared_prekey_pair->sym)) { - return OTRNG_ERROR; - } - - err = fwrite(buff, s, 1, shared_prekey_f); - free(buff); - - if (err != 1) { - return OTRNG_ERROR; - } - - if (EOF == fputs("\n", shared_prekey_f)) { - return OTRNG_ERROR; - } - - return OTRNG_SUCCESS; -} - -INTERNAL otrng_result otrng_client_shared_prekey_read_from( - otrng_client_s *client, FILE *shared_prekeyf) { - char *line = NULL; - int len = 0; - otrng_shared_prekey_pair_s *shared_prekey_pair; - - if (!shared_prekeyf) { - return OTRNG_ERROR; - } - - if (feof(shared_prekeyf)) { - return OTRNG_ERROR; - } - - /* Free current keypair if any */ - otrng_shared_prekey_pair_free(client->shared_prekey_pair); - client->shared_prekey_pair = NULL; - - shared_prekey_pair = otrng_shared_prekey_pair_new(); - if (!shared_prekey_pair) { - return OTRNG_ERROR; - } - - len = get_limited_line(&line, shared_prekeyf); - if (len < 0) { - return OTRNG_ERROR; - } - - /* line has the /n */ - if (!otrng_symmetric_shared_prekey_deserialize(shared_prekey_pair, line, - len)) { - free(line); - otrng_shared_prekey_pair_free(client->shared_prekey_pair); - return OTRNG_ERROR; - } - - free(line); - - client->shared_prekey_pair = shared_prekey_pair; - - return OTRNG_SUCCESS; -} - INTERNAL otrng_result otrng_client_instance_tag_write_to(otrng_client_s *client, FILE *instagf) { // TODO: We could use a "get storage key" callback and use it as diff --git a/src/persistence.h b/src/persistence.h index 1e0be65b..a89c0266 100644 --- a/src/persistence.h +++ b/src/persistence.h @@ -35,12 +35,6 @@ otrng_client_private_key_v4_write_to(const otrng_client_s *client, FILE *privf); INTERNAL otrng_result otrng_client_forging_key_write_to(const otrng_client_s *client, FILE *f); -INTERNAL otrng_result otrng_client_shared_prekey_write_to( - const otrng_client_s *client, FILE *shared_prekey_f); - -INTERNAL otrng_result otrng_client_shared_prekey_read_from( - otrng_client_s *client, FILE *shared_prekeyf); - INTERNAL otrng_result otrng_client_instance_tag_read_from(otrng_client_s *client, FILE *instag); diff --git a/src/prekey_profile.c b/src/prekey_profile.c index 2cc1fbb8..9376af31 100644 --- a/src/prekey_profile.c +++ b/src/prekey_profile.c @@ -31,6 +31,7 @@ INTERNAL void otrng_prekey_profile_destroy(otrng_prekey_profile_s *destination) { + otrng_shared_prekey_pair_free(destination->keys); otrng_ec_point_destroy(destination->shared_prekey); memset(destination->signature, 0, ED448_SIGNATURE_BYTES); } @@ -56,6 +57,11 @@ INTERNAL void otrng_prekey_profile_copy(otrng_prekey_profile_s *destination, destination->expires = source->expires; otrng_ec_point_copy(destination->shared_prekey, source->shared_prekey); + if (destination->keys != NULL) { + otrng_shared_prekey_pair_free(destination->keys); + } + destination->keys = otrng_secure_alloc(sizeof(otrng_shared_prekey_pair_s)); + memcpy(destination->keys, source->keys, sizeof(otrng_shared_prekey_pair_s)); memcpy(destination->signature, source->signature, ED448_SIGNATURE_BYTES); destination->should_publish = source->should_publish; @@ -136,22 +142,43 @@ INTERNAL otrng_result otrng_prekey_profile_deserialize( INTERNAL otrng_result otrng_prekey_profile_deserialize_with_metadata( otrng_prekey_profile_s *target, const uint8_t *buffer, size_t buflen, size_t *nread) { - size_t nread1, nread2; + size_t read = 0; + size_t w = 0; otrng_result result = - otrng_prekey_profile_deserialize(target, buffer, buflen, &nread1); + otrng_prekey_profile_deserialize(target, buffer, buflen, &read); + if (otrng_failed(result)) { + return result; + } + + w += read; + + result = otrng_deserialize_uint8(&target->should_publish, buffer + w, + buflen - w, &read); + if (otrng_failed(result)) { return result; } - result = otrng_deserialize_uint8(&target->should_publish, buffer + nread1, - buflen - nread1, &nread2); + w += read; + + target->keys = otrng_secure_alloc(sizeof(otrng_shared_prekey_pair_s)); + result = otrng_deserialize_bytes_array(target->keys->sym, ED448_PRIVATE_BYTES, + buffer + w, buflen - w); + if (otrng_failed(result)) { + return OTRNG_ERROR; + } + + otrng_shared_prekey_pair_generate(target->keys, target->keys->sym); + otrng_ec_point_copy(target->shared_prekey, target->keys->pub); + + w += ED448_PRIVATE_BYTES; if (otrng_failed(result)) { return result; } if (nread) { - *nread = nread1 + nread2; + *nread = w; } return OTRNG_SUCCESS; @@ -220,7 +247,8 @@ INTERNAL otrng_result otrng_prekey_profile_serialize( INTERNAL otrng_result otrng_prekey_profile_serialize_with_metadata( uint8_t **destination, size_t *nbytes, otrng_prekey_profile_s *profile) { - size_t size = PREKEY_PROFILE_BODY_BYTES + ED448_SIGNATURE_BYTES + 1; + size_t size = PREKEY_PROFILE_BODY_BYTES + ED448_SIGNATURE_BYTES + 1 + + ED448_PRIVATE_BYTES; uint8_t *buff = otrng_xmalloc_z(size); size_t written; @@ -241,6 +269,9 @@ INTERNAL otrng_result otrng_prekey_profile_serialize_with_metadata( written += otrng_serialize_uint8(buff + written, profile->should_publish); + written += otrng_serialize_bytes_array(buff + written, profile->keys->sym, + ED448_PRIVATE_BYTES); + *destination = buff; if (nbytes) { *nbytes = written; @@ -267,24 +298,27 @@ INTERNAL otrng_result prekey_profile_sign( INTERNAL otrng_prekey_profile_s * otrng_prekey_profile_build(uint32_t instance_tag, - const otrng_keypair_s *longterm_pair, - const otrng_shared_prekey_pair_s *prekey_pair) { + const otrng_keypair_s *longterm_pair) { otrng_prekey_profile_s *prekey_profile; time_t expires = time(NULL); - if (!prekey_pair || !longterm_pair || - !otrng_instance_tag_valid(instance_tag)) { + if (!longterm_pair || !otrng_instance_tag_valid(instance_tag)) { return NULL; } prekey_profile = otrng_xmalloc_z(sizeof(otrng_prekey_profile_s)); + prekey_profile->keys = otrng_shared_prekey_pair_new(); + gcry_randomize(prekey_profile->keys->sym, ED448_PRIVATE_BYTES, + GCRY_VERY_STRONG_RANDOM); + otrng_shared_prekey_pair_generate(prekey_profile->keys, + prekey_profile->keys->sym); + otrng_ec_point_copy(prekey_profile->shared_prekey, prekey_profile->keys->pub); + prekey_profile->instance_tag = instance_tag; #define PREKEY_PROFILE_EXPIRATION_SECONDS 1 * 30 * 24 * 60 * 60; /* 1 month */ prekey_profile->expires = expires + PREKEY_PROFILE_EXPIRATION_SECONDS; - otrng_ec_point_copy(prekey_profile->shared_prekey, - prekey_pair->pub); /* Key "D" */ if (!prekey_profile_sign(prekey_profile, longterm_pair)) { otrng_prekey_profile_free(prekey_profile); diff --git a/src/prekey_profile.h b/src/prekey_profile.h index 773105ee..345ffbaa 100644 --- a/src/prekey_profile.h +++ b/src/prekey_profile.h @@ -31,6 +31,8 @@ typedef struct prekey_profile_s { ec_point_t shared_prekey; /* Key "D" */ eddsa_signature_t signature; + otrng_shared_prekey_pair_s *keys; + otrng_bool should_publish; otrng_bool is_publishing; } otrng_prekey_profile_s; @@ -44,8 +46,7 @@ INTERNAL void otrng_prekey_profile_copy(otrng_prekey_profile_s *destination, INTERNAL otrng_prekey_profile_s * otrng_prekey_profile_build(uint32_t instance_tag, - const otrng_keypair_s *longterm_pair, - const otrng_shared_prekey_pair_s *prekey_pair); + const otrng_keypair_s *longterm_pair); INTERNAL otrng_bool otrng_prekey_profile_expired(time_t expires); diff --git a/src/protocol.c b/src/protocol.c index 27be549b..f1cbfb5f 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -50,10 +50,6 @@ INTERNAL void maybe_create_keys(otrng_client_s *client) { cb->create_forging_key(client_id); } - if (!client->shared_prekey_pair) { - cb->create_shared_prekey(client, client_id); - } - instance_tag = otrng_client_get_instance_tag(client); if (!instance_tag) { otrng_client_callbacks_create_instag(cb, client_id); @@ -81,6 +77,7 @@ INTERNAL const otrng_client_profile_s *get_my_exp_client_profile(otrng_s *otr) { INTERNAL const otrng_prekey_profile_s *get_my_prekey_profile(otrng_s *otr) { otrng_client_s *client = otr->client; + maybe_create_keys(client); return otrng_client_get_prekey_profile(client); } diff --git a/src/test/test_fixtures.c b/src/test/test_fixtures.c index 3523ab63..1784f67c 100644 --- a/src/test/test_fixtures.c +++ b/src/test/test_fixtures.c @@ -112,7 +112,6 @@ otrng_client_callbacks_s test_callbacks[1] = {{ .create_forging_key = &create_forging_key_cb_empty, .write_expired_client_profile = &write_expired_client_profile_cb_empty, .write_expired_prekey_profile = &write_expired_prekey_profile_cb_empty, - .create_shared_prekey = &create_shared_prekey_cb_empty, .load_privkey_v4 = &load_privkey_v4_cb_empty, .load_client_profile = &load_client_profile_cb_empty, .load_prekey_profile = &load_prekey_profile_cb_empty, @@ -142,7 +141,6 @@ void otrng_fixture_set_up(otrng_fixture_s *otrng_fixture, gconstpointer data) { otrng_public_key_t *fk = create_forging_key_from(sym2); otrng_client_add_forging_key(otrng_fixture->client, *fk); free(fk); - otrng_client_add_shared_prekey_v4(otrng_fixture->client, sym); otrng_policy_s policy = {.allows = OTRNG_ALLOW_V4}; otrng_fixture->otr = otrng_new(otrng_fixture->client, policy); @@ -351,13 +349,11 @@ void set_up_client(otrng_client_s *client, const char *account_name, int byte) { uint8_t long_term_priv[ED448_PRIVATE_BYTES] = {byte + 0xA}; uint8_t forging_sym[ED448_PRIVATE_BYTES] = {byte + 0xD}; - uint8_t shared_prekey_priv[ED448_PRIVATE_BYTES] = {byte + 0xF}; otrng_client_add_private_key_v4(client, long_term_priv); otrng_public_key_t *fk = create_forging_key_from(forging_sym); otrng_client_add_forging_key(client, *fk); free(fk); - otrng_client_add_shared_prekey_v4(client, shared_prekey_priv); otrng_client_add_instance_tag(client, 0x100 + byte); client->client_profile = otrng_client_build_default_client_profile(client); @@ -420,13 +416,6 @@ void write_expired_prekey_profile_cb_empty( (void)client_opdata; } -void create_shared_prekey_cb_empty( - struct otrng_client_s *client, - const struct otrng_client_id_s client_opdata) { - (void)client; - (void)client_opdata; -} - otrng_shared_session_state_s get_shared_session_state_cb_empty(const struct otrng_s *conv) { otrng_shared_session_state_s result; diff --git a/src/test/units/test_messaging.c b/src/test/units/test_messaging.c index 81f1cc37..da38f2b1 100644 --- a/src/test/units/test_messaging.c +++ b/src/test/units/test_messaging.c @@ -66,7 +66,6 @@ static otrng_client_callbacks_s empty_callbacks[1] = {{ .create_forging_key = &create_forging_key_cb_empty, .write_expired_client_profile = &write_expired_client_profile_cb_empty, .write_expired_prekey_profile = &write_expired_prekey_profile_cb_empty, - .create_shared_prekey = &create_shared_prekey_cb_empty, .load_privkey_v4 = &load_privkey_v4_cb_empty, .load_client_profile = &load_client_profile_cb_empty, .load_prekey_profile = &load_prekey_profile_cb_empty, @@ -119,55 +118,6 @@ static void test_global_state_key_management(void) { otrng_global_state_free(state); } -static void test_global_state_shared_prekey_management(void) { - const uint8_t alice_sym[ED448_PRIVATE_BYTES] = {1}; - const uint8_t bob_sym[ED448_PRIVATE_BYTES] = {2}; - - otrng_global_state_s *state = - otrng_global_state_new(empty_callbacks, otrng_false); - otrng_global_state_add_private_key_v4( - state, create_client_id("otr", alice_account), alice_sym); - otrng_global_state_add_private_key_v4( - state, create_client_id("otr", bob_account), bob_sym); - - otrng_assert(otrng_global_state_get_private_key_v4( - state, create_client_id("otr", alice_account))); - otrng_assert(otrng_global_state_get_private_key_v4( - state, create_client_id("otr", bob_account))); - otrng_assert(!otrng_global_state_get_private_key_v4( - state, create_client_id("otr", charlie_account))); - - /* Generate file */ - FILE *keys = tmpfile(); - - fputs("charlie@xmpp\n" - "mgRi+jOWSHludTU/v0QE/" - "6W88WmxUmKMh1QpRbrEw4LESkL0mnOgZBbqpInVFJGy3v2aKbBFj4c0\n", - keys); - rewind(keys); - - otrng_result result = otrng_global_state_shared_prekey_read_from( - state, keys, read_client_id_for_privf); - otrng_assert_is_success(result); - fclose(keys); - - otrng_client_s *client = - get_client(state, create_client_id("otr", charlie_account)); - - char *buffer = NULL; - size_t s = 0; - otrng_symmetric_key_serialize(&buffer, &s, client->shared_prekey_pair->sym); - - const char *expected = - "mgRi+jOWSHludTU/v0QE/" - "6W88WmxUmKMh1QpRbrEw4LESkL0mnOgZBbqpInVFJGy3v2aKbBFj4c0"; - - otrng_assert_cmpmem(expected, buffer, s); - - free(buffer); - otrng_global_state_free(state); -} - static void test_global_state_client_profile_management(void) { const uint8_t alice_sym[ED448_PRIVATE_BYTES] = {1}; const uint8_t bob_sym[ED448_PRIVATE_BYTES] = {2}; @@ -281,7 +231,9 @@ static void test_global_state_prekey_profile_management(void) { "s1vlz8xF+vPV82xSwmEA65IyR3ZaR6NzZNNAznBrXXb7YjvMuYtTtKnp+" "LZfUSYFcjoZACAqnA8V5fDvuuCFFMINr6rKZihf4wTVOKO+hO+" "rMWi7dsYeLu3eee7fZ9LsHUuriHxadL6mW0J6QAPeo2n75TnDUt1aVpjCK0Mrut0hTstbD" - "oyyEVaVNh2Rx87o30YStXn92fDNCBsGHU+F2xv/ZQ2OQAA\n", + "oyyEVaVNh2Rx87o30YStXn92fDNCBsGHU+F2xv/ZQ2OQAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n", prekey_profile); rewind(prekey_profile); @@ -299,12 +251,13 @@ static void test_global_state_prekey_profile_management(void) { size_t s = 0; otrng_prekey_profile_serialize(&buffer, &s, client->prekey_profile); char *encoded = otrng_base64_encode(buffer, s); + const char *expected = - "26FP8QAAAABbxy5lABFQAQ3a/" - "s1vlz8xF+vPV82xSwmEA65IyR3ZaR6NzZNNAznBrXXb7YjvMuYtTtKnp+" - "LZfUSYFcjoZACAqnA8V5fDvuuCFFMINr6rKZihf4wTVOKO+hO+" - "rMWi7dsYeLu3eee7fZ9LsHUuriHxadL6mW0J6QAPeo2n75TnDUt1aVpjCK0Mrut0hTstbDoy" - "yEVaVNh2Rx87o30YStXn92fDNCBsGHU+F2xv/ZQ2OQAA"; + "26FP8QAAAABbxy5lABFbOv4Dh" + "4pJsoIy1PGkQq694Qn4B6zvff2af2W5Yv5S1lRzEsrOz/BDN1CPnSUpqP" + "FmkWmyHDLEgACAqnA8V5fDvuuCFFMINr6rKZihf4wTVOKO+hO+" + "rMWi7dsYeLu3eee7fZ9LsHUuriHxadL6mW0J6QAPeo2n75TnDUt1aVpjCK0Mrut0hTstbD" + "oyyEVaVNh2Rx87o30YStXn92fDNCBsGHU+F2xv/ZQ2OQA="; otrng_assert_cmpmem(expected, encoded, s); @@ -418,8 +371,6 @@ static void test_instance_tag_api(void) { void units_messaging_add_tests() { g_test_add_func("/global_state/key_management", test_global_state_key_management); - g_test_add_func("/global_state/shared_prekey_management", - test_global_state_shared_prekey_management); g_test_add_func("/global_state/client_profile", test_global_state_client_profile_management); g_test_add_func("/global_state/prekey_profile", diff --git a/src/test/units/test_otrng.c b/src/test/units/test_otrng.c index 04ddb020..c0091ad3 100644 --- a/src/test/units/test_otrng.c +++ b/src/test/units/test_otrng.c @@ -238,7 +238,6 @@ static void test_otrng_destroy() { static void test_otrng_build_prekey_ensemble() { uint8_t long_term_priv[ED448_PRIVATE_BYTES] = {0xA}; - uint8_t shared_prekey_priv[ED448_PRIVATE_BYTES] = {0XF}; uint8_t forging_priv[ED448_PRIVATE_BYTES] = { 2}; // non-random forging key on purpose otrng_keypair_s *kforging = otrng_keypair_new(); @@ -251,8 +250,6 @@ static void test_otrng_build_prekey_ensemble() { otrng_client_add_private_key_v4(client, long_term_priv)); otrng_assert_is_success(otrng_client_add_forging_key(client, kforging->pub)); otrng_keypair_free(kforging); - otrng_assert_is_success( - otrng_client_add_shared_prekey_v4(client, shared_prekey_priv)); otrng_assert_is_success(otrng_client_add_instance_tag(client, 0x100A0F)); otrng_keypair_s *keypair = otrng_client_get_keypair_v4(client); diff --git a/src/test/units/test_prekey_profile.c b/src/test/units/test_prekey_profile.c index 759b3161..7ee129bb 100644 --- a/src/test/units/test_prekey_profile.c +++ b/src/test/units/test_prekey_profile.c @@ -34,8 +34,8 @@ static void test_prekey_profile_validates() { otrng_shared_prekey_pair_s *shared_prekey = otrng_shared_prekey_pair_new(); otrng_shared_prekey_pair_generate(shared_prekey, sym_shared); - otrng_prekey_profile_s *profile = otrng_prekey_profile_build( - OTRNG_MIN_VALID_INSTAG + 0x01, long_term, shared_prekey); + otrng_prekey_profile_s *profile = + otrng_prekey_profile_build(OTRNG_MIN_VALID_INSTAG + 0x01, long_term); otrng_assert(otrng_prekey_profile_valid(profile, profile->instance_tag, long_term->pub)); @@ -71,7 +71,7 @@ static void test_prekey_profile_serialize() { otrng_shared_prekey_pair_generate(shared_prekey, sym); otrng_prekey_profile_s *profile = - otrng_prekey_profile_build(instance_tag, &keypair, shared_prekey); + otrng_prekey_profile_build(instance_tag, &keypair); otrng_assert(profile != NULL); @@ -118,7 +118,7 @@ static void test_prekey_profile_deserialize() { otrng_shared_prekey_pair_generate(shared_prekey, sym); otrng_prekey_profile_s *profile = - otrng_prekey_profile_build(instance_tag, &keypair, shared_prekey); + otrng_prekey_profile_build(instance_tag, &keypair); otrng_assert(profile != NULL);