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