status-go/protocol/encryption
Andrea Maria Piana 23f71c1125 Fix encryption id && rekey with a single message
This commit changes the format of the encryption id to be based off 3
things:

1) The group id
2) The timestamp
3) The actual key

Previously this was solely based on the timestamp and the group id, but
this might lead to conflicts. Moreover the format of the key was an
uint32 and so it would wrap periodically.

The migration is a bit tricky, so first we cleared the cache of keys,
that's easier than migrating, and second we set the new field hash_id to
the concatenation of group_id / key_id.
This might lead on some duplication in case keys are re-received, but it
should not have an impact on the correctness of the code.

I have added 2 tests covering compatibility between old/new clients, as
this should not be a breaking change.

It also adds a new message to rekey in a single go, instead of having to
send multiple messages
2023-10-24 20:48:54 +01:00
..
github.com/protocol/encryption feat: display name 2022-03-14 13:48:34 -04:00
migrations Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
multidevice fix: use proper migrations for protocol's test database 2023-10-03 15:11:58 +02:00
publisher using zap.NewNop() ignores configured log level 2021-08-19 11:35:40 +02:00
sharedsecret fix: use proper migrations for protocol's test database 2023-10-03 15:11:58 +02:00
README.md Communities encryption 2021-11-30 20:52:47 +02:00
encryption_multi_device_test.go fix: use proper migrations for protocol's test database 2023-10-03 15:11:58 +02:00
encryption_test.go Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
encryptor.go Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
helpers.go Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
persistence.go Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
persistence_keys_storage_test.go fix: use proper migrations for protocol's test database 2023-10-03 15:11:58 +02:00
persistence_test.go fix: use proper migrations for protocol's test database 2023-10-03 15:11:58 +02:00
protocol.go Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
protocol_message.pb.go Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
protocol_message.proto Fix encryption id && rekey with a single message 2023-10-24 20:48:54 +01:00
protocol_test.go fix: use proper migrations for protocol's test database 2023-10-03 15:11:58 +02:00
x3dh.go Create a home submodule for Eth node bridges- Rename StatusBackend to GethStatusBackend 2019-11-27 17:02:09 +01:00
x3dh_test.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00

README.md

protocol/encryption package

Hash ratchet encryption

encryptor.GenerateHashRatchetKey() generates a hash ratchet key and stores it in in the DB. There, 2 new tables are created: hash_ratchet_encryption and hash_ratchet_encryption_cache. Each hash ratchet key is uniquely identified by the (groupId, keyId) pair, where keyId is derived from a clock value.

protocol.BuildHashRatchetKeyExchangeMessage builds an 1-on-1 message containing the hash ratchet key, given it's ID.

protocol.BuildHashRatchetMessage builds a hash ratchet message with arbitrary payload, given groupId. It will use the latest hash ratchet key available. encryptor.encryptWithHR encrypts the payload using Hash Ratchet algorithms. Intermediate hashes are stored in hash_ratchet_encryption_cache table.

protocol.HandleMessage uses encryptor.decryptWithHR fn for decryption.