aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-01-06 17:40:39 +0000
committerRichard van der Hoff <richard@matrix.org>2017-01-09 17:45:46 +0000
commita2f0c93a93f6914291954b08a7518b4f17561c11 (patch)
treefc75bc7e84808868bc4b9eb3844115bab277ada2 /src
parent5fbeb3e29b6440a799d9320e871a1d4d509130b8 (diff)
Implement importing group session data
olm_import_inbound_group_session, which reads the format written by olm_export_inbound_group_session to initialise a group session.
Diffstat (limited to 'src')
-rw-r--r--src/inbound_group_session.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/inbound_group_session.c b/src/inbound_group_session.c
index 122c26c..be0984c 100644
--- a/src/inbound_group_session.c
+++ b/src/inbound_group_session.c
@@ -79,15 +79,17 @@ size_t olm_clear_inbound_group_session(
(1 + 4 + MEGOLM_RATCHET_LENGTH + ED25519_PUBLIC_KEY_LENGTH\
+ ED25519_SIGNATURE_LENGTH)
-/** init the session keys from the un-base64-ed session keys */
static size_t _init_group_session_keys(
OlmInboundGroupSession *session,
- const uint8_t *key_buf
+ const uint8_t *key_buf,
+ int export_format
) {
+ const uint8_t expected_version =
+ (export_format ? SESSION_EXPORT_VERSION : SESSION_KEY_VERSION);
const uint8_t *ptr = key_buf;
size_t version = *ptr++;
- if (version != SESSION_KEY_VERSION) {
+ if (version != expected_version) {
session->last_error = OLM_BAD_SESSION_KEY;
return (size_t)-1;
}
@@ -107,7 +109,7 @@ static size_t _init_group_session_keys(
);
ptr += ED25519_PUBLIC_KEY_LENGTH;
- if (!_olm_crypto_ed25519_verify(
+ if (!export_format && !_olm_crypto_ed25519_verify(
&session->signing_key, key_buf, ptr - key_buf, ptr
)) {
session->last_error = OLM_BAD_SIGNATURE;
@@ -135,11 +137,35 @@ size_t olm_init_inbound_group_session(
}
_olm_decode_base64(session_key, session_key_length, key_buf);
- result = _init_group_session_keys(session, key_buf);
+ result = _init_group_session_keys(session, key_buf, 0);
_olm_unset(key_buf, SESSION_KEY_RAW_LENGTH);
return result;
}
+size_t olm_import_inbound_group_session(
+ OlmInboundGroupSession *session,
+ const uint8_t * session_key, size_t session_key_length
+) {
+ uint8_t key_buf[SESSION_EXPORT_RAW_LENGTH];
+ size_t raw_length = _olm_decode_base64_length(session_key_length);
+ size_t result;
+
+ if (raw_length == (size_t)-1) {
+ session->last_error = OLM_INVALID_BASE64;
+ return (size_t)-1;
+ }
+
+ if (raw_length != SESSION_EXPORT_RAW_LENGTH) {
+ session->last_error = OLM_BAD_SESSION_KEY;
+ return (size_t)-1;
+ }
+
+ _olm_decode_base64(session_key, session_key_length, key_buf);
+ result = _init_group_session_keys(session, key_buf, 1);
+ _olm_unset(key_buf, SESSION_EXPORT_RAW_LENGTH);
+ return result;
+}
+
static size_t raw_pickle_length(
const OlmInboundGroupSession *session
) {