diff options
author | Paul Fariello <paul@fariello.eu> | 2019-02-26 19:03:08 +0140 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2019-04-10 16:03:50 +0200 |
commit | b1ae220aa47ff503fe368e4802061be159dfb42b (patch) | |
tree | 73876b55d33a41046b05e1f1baec6ce19e08ad6c | |
parent | f9216fddb106d46bac2d13d9dfe175b4a475a789 (diff) | |
download | profani-tty-b1ae220aa47ff503fe368e4802061be159dfb42b.tar.gz |
Create signal session
-rw-r--r-- | src/omemo/omemo.c | 19 | ||||
-rw-r--r-- | src/omemo/omemo.h | 2 | ||||
-rw-r--r-- | src/xmpp/omemo.c | 50 |
3 files changed, 65 insertions, 6 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 32fdce42..95de1aa2 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -249,15 +249,30 @@ omemo_set_device_list(const char *const jid, GList * device_list) } void -omemo_start_device_session(const char *const jid, uint32_t device_id, const unsigned char *const prekey, size_t prekey_len) +omemo_start_device_session(const char *const jid, uint32_t device_id, + uint32_t prekey_id, const unsigned char *const prekey_raw, size_t prekey_len, + uint32_t signed_prekey_id, const unsigned char *const signed_prekey_raw, + size_t signed_prekey_len, const unsigned char *const signature, + size_t signature_len, const unsigned char *const identity_key_raw, + size_t identity_key_len) { + session_pre_key_bundle *bundle; signal_protocol_address address = { jid, strlen(jid), device_id }; session_builder *builder; session_builder_create(&builder, omemo_ctx.store, &address, omemo_ctx.signal); - //session_builder_process_pre_key_bundle(builder, prekey); + + ec_public_key *prekey; + curve_decode_point(&prekey, prekey_raw, prekey_len, omemo_ctx.signal); + ec_public_key *signed_prekey; + curve_decode_point(&signed_prekey, signed_prekey_raw, signed_prekey_len, omemo_ctx.signal); + ec_public_key *identity_key; + curve_decode_point(&identity_key, identity_key_raw, identity_key_len, omemo_ctx.signal); + + session_pre_key_bundle_create(&bundle, 0, device_id, prekey_id, prekey, signed_prekey_id, signed_prekey, signature, signature_len, identity_key); + session_builder_process_pre_key_bundle(builder, bundle); } static void diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index 26bd6e65..bf42b3e3 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -15,6 +15,6 @@ void omemo_prekeys(GList **prekeys, GList **ids, GList **lengths); void omemo_set_device_list(const char *const jid, GList * device_list); void omemo_start_session(const char *const barejid); -void omemo_start_device_session(const char *const jid, uint32_t device_id, const unsigned char *const prekey, size_t prekey_len); +void omemo_start_device_session(const char *const jid, uint32_t device_id, uint32_t prekey_id, const unsigned char *const prekey, size_t prekey_len, uint32_t signed_prekey_id, const unsigned char *const signed_prekey, size_t signed_prekey_len, const unsigned char *const signature, size_t signature_len, const unsigned char *const identity_key, size_t identity_key_len); gboolean omemo_loaded(void); diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index f4641212..709b6ad8 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -134,16 +134,60 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *cons if (!prekey) { return 1; } - + const char *prekey_id_text = xmpp_stanza_get_attribute(prekey, "preKeyId"); + if (!prekey_id_text) { + return 1; + } + uint32_t prekey_id = strtoul(prekey_id_text, NULL, 10); xmpp_stanza_t *prekey_text = xmpp_stanza_get_children(prekey); if (!prekey_text) { return 1; } - size_t prekey_len; unsigned char *prekey_raw = g_base64_decode(xmpp_stanza_get_text(prekey_text), &prekey_len); - omemo_start_device_session(from, device_id, prekey_raw, prekey_len); + xmpp_stanza_t *signed_prekey = xmpp_stanza_get_child_by_name(bundle, "signedPreKeyPublic"); + if (!signed_prekey) { + return 1; + } + const char *signed_prekey_id_text = xmpp_stanza_get_attribute(signed_prekey, "signedPreKeyId"); + if (!signed_prekey_id_text) { + return 1; + } + uint32_t signed_prekey_id = strtoul(signed_prekey_id_text, NULL, 10); + xmpp_stanza_t *signed_prekey_text = xmpp_stanza_get_children(signed_prekey); + if (!signed_prekey_text) { + return 1; + } + size_t signed_prekey_len; + unsigned char *signed_prekey_raw = g_base64_decode(xmpp_stanza_get_text(signed_prekey_text), &signed_prekey_len); + + xmpp_stanza_t *signed_prekey_signature = xmpp_stanza_get_child_by_name(bundle, "signedPreKeySignature"); + if (!signed_prekey_signature) { + return 1; + } + xmpp_stanza_t *signed_prekey_signature_text = xmpp_stanza_get_children(signed_prekey_signature); + if (!signed_prekey_signature_text) { + return 1; + } + size_t signed_prekey_signature_len; + unsigned char *signed_prekey_signature_raw = g_base64_decode(xmpp_stanza_get_text(signed_prekey_signature_text), &signed_prekey_signature_len); + + xmpp_stanza_t *identity_key = xmpp_stanza_get_child_by_name(bundle, "identityKey"); + if (!identity_key) { + return 1; + } + xmpp_stanza_t *identity_key_text = xmpp_stanza_get_children(identity_key); + if (!identity_key_text) { + return 1; + } + size_t identity_key_len; + unsigned char *identity_key_raw = g_base64_decode(xmpp_stanza_get_text(identity_key_text), &identity_key_len); + + omemo_start_device_session(from, device_id, prekey_id, prekey_raw, + prekey_len, signed_prekey_id, signed_prekey_raw, signed_prekey_len, + signed_prekey_signature_raw, signed_prekey_signature_len, + identity_key_raw, identity_key_len); return 1; } |