libsignal-protocol-java icon indicating copy to clipboard operation
libsignal-protocol-java copied to clipboard

Update Readme.md code example to use proper methods

Open rupinderjeet opened this issue 6 years ago • 3 comments

// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
                                                   identityStore, recipientId, deviceId);

This is no longer valid. The new SessionBuilder requires a SignalProtocolAddress instead of recipientId and deviceId.

Suggested code:

// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
SignalProtocolAddress protocolAddress = new SignalProtocolAddress(recipientId, deviceId);
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
                                                   identityStore, protocolAddress);

Similarly, SessionCipher needs an update.

SessionCipher sessionCipher = new SessionCipher(...);

While you are reading this, can you slip in an explanation of how deviceId(integer) is used? Do you number them 1, 2, 3, 4...? Multiple devices are only possible if one user backup the private-keys and restores on another device, right? I feel I have wrong understanding for the use of deviceId because you just use DEFAULT_DEVICE_ID which is 1. Thanks anyway.

rupinderjeet avatar Oct 03 '18 11:10 rupinderjeet

Hi.. How to get sessionStore, preKeyStore, signedPreKeyStore, identityStore, recipientId...

In the documentation they given like this:

SessionStore sessionStore = new MySessionStore(); PreKeyStore preKeyStore = new MyPreKeyStore(); SignedPreKeyStore signedPreKeyStore = new MySignedPreKeyStore(); IdentityKeyStore identityStore = new MyIdentityKeyStore();

what are those MySessionStore(),MyPreKeyStore(),MySignedPreKeyStore(),MyIdentityKeyStore()...

If possible, can you provide detailed sample code..

smobiledev avatar Feb 04 '19 10:02 smobiledev

A libsignal client needs to implement four interfaces: IdentityKeyStore, PreKeyStore, SignedPreKeyStore, and SessionStore. These will manage loading and storing of identity, prekeys, signed prekeys, and session state.

You need to create implementations of those interfaces.

Pear0 avatar Feb 06 '19 07:02 Pear0

For a better understanding of these Store interfaces look through the code of libsignal-service-java and original Signal-Android implementation.

In Signal-Android, I think they stopped using libsignal-service-java, instead they integrated this library directly into the project. So, any updates for libsignal-service-java are less prioritized because all updates are in live Signal-Android repository perhaps.

Generally, you have to implement these Store interfaces and submit your implementation classes to the SessionBuilder. SessionBuilder, then, calls methods from your Store implementations to perform operations like "savePreKeys", "saveIdentityKeyPair", "getIdentityKeyPair", etc.. You are kind of giving SessionBuilder some indirect access to the database(or however you are storing the data). Look at storage package for an example of Store implementation.

Eventually, these Stores are used to create SessionCipher, then SessionBuilder builds the session.

rupinderjeet avatar Feb 12 '19 15:02 rupinderjeet