diff options
author | hrxi <hrrrxi@gmail.com> | 2023-06-19 14:08:57 +0200 |
---|---|---|
committer | fiaxh <fiaxh@users.noreply.github.com> | 2023-10-06 15:25:12 +0200 |
commit | 6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2 (patch) | |
tree | 13a13ef08fcd74bc1685454730b72693806b76f0 /plugins/omemo/src/signal/simple_iks.vala | |
parent | e2d801b5f74b60c38a75310066c48468c8a4bc93 (diff) | |
download | dino-6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2.tar.gz dino-6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2.zip |
Merge `signal-protocol` into `omemo` plugin
Same reasoning as for the `openpgp` plugin.
Diffstat (limited to 'plugins/omemo/src/signal/simple_iks.vala')
-rw-r--r-- | plugins/omemo/src/signal/simple_iks.vala | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/omemo/src/signal/simple_iks.vala b/plugins/omemo/src/signal/simple_iks.vala new file mode 100644 index 00000000..5247c455 --- /dev/null +++ b/plugins/omemo/src/signal/simple_iks.vala @@ -0,0 +1,40 @@ +using Gee; + +namespace Signal { + +public class SimpleIdentityKeyStore : IdentityKeyStore { + public override Bytes identity_key_private { get; set; } + public override Bytes identity_key_public { get; set; } + public override uint32 local_registration_id { get; set; } + private Map<string, Map<int, IdentityKeyStore.TrustedIdentity>> trusted_identities = new HashMap<string, Map<int, IdentityKeyStore.TrustedIdentity>>(); + + public override void save_identity(Address address, uint8[] key) throws Error { + string name = address.name; + if (trusted_identities.has_key(name)) { + if (trusted_identities[name].has_key(address.device_id)) { + trusted_identities[name][address.device_id].key = key; + trusted_identity_updated(trusted_identities[name][address.device_id]); + } else { + trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); + trusted_identity_added(trusted_identities[name][address.device_id]); + } + } else { + trusted_identities[name] = new HashMap<int, IdentityKeyStore.TrustedIdentity>(); + trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); + trusted_identity_added(trusted_identities[name][address.device_id]); + } + } + + public override bool is_trusted_identity(Address address, uint8[] key) throws Error { + if (!trusted_identities.has_key(address.name)) return true; + if (!trusted_identities[address.name].has_key(address.device_id)) return true; + uint8[] other_key = trusted_identities[address.name][address.device_id].key; + if (other_key.length != key.length) return false; + for (int i = 0; i < key.length; i++) { + if (other_key[i] != key[i]) return false; + } + return true; + } +} + +} |