mirror of
https://github.com/oxen-io/session-android.git
synced 2025-07-02 21:08:29 +00:00
Better thread safety for session building <-> use.
This commit is contained in:
parent
7b1a37bd91
commit
3e287f930d
@ -205,7 +205,7 @@ public class SessionBuilder {
|
||||
* trusted.
|
||||
*/
|
||||
public void process(PreKeyBundle preKey) throws InvalidKeyException, UntrustedIdentityException {
|
||||
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
if (!identityKeyStore.isTrustedIdentity(recipientId, preKey.getIdentityKey())) {
|
||||
throw new UntrustedIdentityException();
|
||||
}
|
||||
@ -252,6 +252,7 @@ public class SessionBuilder {
|
||||
sessionStore.storeSession(recipientId, deviceId, sessionRecord);
|
||||
identityKeyStore.saveIdentity(recipientId, preKey.getIdentityKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new session from a {@link org.whispersystems.libaxolotl.protocol.KeyExchangeMessage}
|
||||
@ -264,7 +265,7 @@ public class SessionBuilder {
|
||||
public KeyExchangeMessage process(KeyExchangeMessage message)
|
||||
throws InvalidKeyException, UntrustedIdentityException, StaleKeyExchangeException
|
||||
{
|
||||
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
if (!identityKeyStore.isTrustedIdentity(recipientId, message.getIdentityKey())) {
|
||||
throw new UntrustedIdentityException();
|
||||
}
|
||||
@ -276,6 +277,7 @@ public class SessionBuilder {
|
||||
|
||||
return responseMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private KeyExchangeMessage processInitiate(KeyExchangeMessage message) throws InvalidKeyException {
|
||||
int flags = KeyExchangeMessage.RESPONSE_FLAG;
|
||||
@ -375,6 +377,7 @@ public class SessionBuilder {
|
||||
* @return the KeyExchangeMessage to deliver.
|
||||
*/
|
||||
public KeyExchangeMessage process() {
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
try {
|
||||
int sequence = KeyHelper.getRandomSequence(65534) + 1;
|
||||
int flags = KeyExchangeMessage.INITIATE_FLAG;
|
||||
@ -393,6 +396,7 @@ public class SessionBuilder {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ import static org.whispersystems.libaxolotl.state.SessionState.UnacknowledgedPre
|
||||
*/
|
||||
public class SessionCipher {
|
||||
|
||||
private static final Object SESSION_LOCK = new Object();
|
||||
public static final Object SESSION_LOCK = new Object();
|
||||
|
||||
private final SessionStore sessionStore;
|
||||
private final SessionBuilder sessionBuilder;
|
||||
|
Loading…
x
Reference in New Issue
Block a user