From 29e0287ef381ff674edc85bee403c0e95a9fd91c Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 19 Nov 2021 21:43:27 -0500 Subject: [PATCH] add function to forget the old fallback key --- include/olm/account.hh | 3 +++ include/olm/olm.h | 9 +++++++++ javascript/olm_post.js | 4 ++-- src/account.cpp | 7 +++++++ src/olm.cpp | 7 +++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/olm/account.hh b/include/olm/account.hh index 88302ba..dd115f5 100644 --- a/include/olm/account.hh +++ b/include/olm/account.hh @@ -169,6 +169,9 @@ struct Account { std::uint8_t * fallback_json, std::size_t fallback_json_length ); + /** Forget about the old fallback key */ + void forget_old_fallback_key(); + /** Lookup a one time key with the given public key */ OneTimeKey const * lookup_key( _olm_curve25519_public_key const & public_key diff --git a/include/olm/olm.h b/include/olm/olm.h index cdb35a2..9e02440 100644 --- a/include/olm/olm.h +++ b/include/olm/olm.h @@ -310,6 +310,15 @@ OLM_EXPORT size_t olm_account_unpublished_fallback_key( void * fallback_key, size_t fallback_key_size ); +/** Forget about the old fallback key. This should be called once you are + * reasonably certain that you will not receive any more messages that use + * the old fallback key (e.g. 5 minutes after the new fallback key has been + * published). + */ +OLM_EXPORT void olm_account_forget_old_fallback_key( + OlmAccount * account +); + /** The number of random bytes needed to create an outbound session */ OLM_EXPORT size_t olm_create_outbound_session_random_length( diff --git a/javascript/olm_post.js b/javascript/olm_post.js index 305e4c5..634753c 100644 --- a/javascript/olm_post.js +++ b/javascript/olm_post.js @@ -194,8 +194,8 @@ Account.prototype['unpublished_fallback_key'] = restore_stack(function() { return UTF8ToString(keys, keys_length); }); -Account.prototype['forget_previous_fallback'] = restore_stack(function() { - account_method(Module['_olm_account_forget_previous_fallback_key'])( +Account.prototype['forget_old_fallback'] = restore_stack(function() { + account_method(Module['_olm_account_forget_old_fallback_key'])( this.ptr ); }); diff --git a/src/account.cpp b/src/account.cpp index 80768ae..5056d5f 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -398,6 +398,13 @@ std::size_t olm::Account::get_unpublished_fallback_key_json( return pos - fallback_json; } +void olm::Account::forget_old_fallback_key( +) { + if (num_fallback_keys >= 2) { + num_fallback_keys = 1; + } +} + namespace olm { static std::size_t pickle_length( diff --git a/src/olm.cpp b/src/olm.cpp index f7fbc42..3a30f7a 100644 --- a/src/olm.cpp +++ b/src/olm.cpp @@ -512,6 +512,13 @@ size_t olm_account_unpublished_fallback_key( } +void olm_account_forget_old_fallback_key( + OlmAccount * account +) { + return from_c(account)->forget_old_fallback_key(); +} + + size_t olm_create_outbound_session_random_length( OlmSession const * session ) {