From 89d9b972a6d629648d18f4227a08596c65c3894d Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 16 Jul 2015 10:45:10 +0100 Subject: Add versions of olm_session_create_inbound and olm_session_matches_inbound which take the curve25519 identity key of the remote device we think the message is from as an additional argument --- src/olm.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'src/olm.cpp') diff --git a/src/olm.cpp b/src/olm.cpp index b121ec7..17461fe 100644 --- a/src/olm.cpp +++ b/src/olm.cpp @@ -518,7 +518,36 @@ size_t olm_create_inbound_session( return std::size_t(-1); } return from_c(session)->new_inbound_session( - *from_c(account), from_c(one_time_key_message), raw_length + *from_c(account), nullptr, from_c(one_time_key_message), raw_length + ); +} + + +size_t olm_create_inbound_session_from( + OlmSession * session, + OlmAccount * account, + void const * their_identity_key, size_t their_identity_key_length, + void * one_time_key_message, size_t message_length +) { + if (olm::decode_base64_length(their_identity_key_length) != 32) { + from_c(session)->last_error = olm::ErrorCode::INVALID_BASE64; + return std::size_t(-1); + } + olm::Curve25519PublicKey identity_key; + olm::decode_base64( + from_c(their_identity_key), their_identity_key_length, + identity_key.public_key + ); + + std::size_t raw_length = b64_input( + from_c(one_time_key_message), message_length, from_c(session)->last_error + ); + if (raw_length == std::size_t(-1)) { + return std::size_t(-1); + } + return from_c(session)->new_inbound_session( + *from_c(account), &identity_key, + from_c(one_time_key_message), raw_length ); } @@ -534,7 +563,35 @@ size_t olm_matches_inbound_session( return std::size_t(-1); } bool matches = from_c(session)->matches_inbound_session( - from_c(one_time_key_message), raw_length + nullptr, from_c(one_time_key_message), raw_length + ); + return matches ? 1 : 0; +} + + +size_t olm_matches_inbound_session_from( + OlmSession * session, + void const * their_identity_key, size_t their_identity_key_length, + void * one_time_key_message, size_t message_length +) { + if (olm::decode_base64_length(their_identity_key_length) != 32) { + from_c(session)->last_error = olm::ErrorCode::INVALID_BASE64; + return std::size_t(-1); + } + olm::Curve25519PublicKey identity_key; + olm::decode_base64( + from_c(their_identity_key), their_identity_key_length, + identity_key.public_key + ); + + std::size_t raw_length = b64_input( + from_c(one_time_key_message), message_length, from_c(session)->last_error + ); + if (raw_length == std::size_t(-1)) { + return std::size_t(-1); + } + bool matches = from_c(session)->matches_inbound_session( + &identity_key, from_c(one_time_key_message), raw_length ); return matches ? 1 : 0; } -- cgit v1.2.3