mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-10 17:12:16 +02:00
Make some changes on the road to removing SessionState from Java
This commit is contained in:
@@ -133,7 +133,7 @@ public class SessionCipher {
|
||||
public int getRemoteRegistrationId() {
|
||||
synchronized (SESSION_LOCK) {
|
||||
SessionRecord record = sessionStore.loadSession(remoteAddress);
|
||||
return record.getSessionState().getRemoteRegistrationId();
|
||||
return record.getRemoteRegistrationId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class SessionCipher {
|
||||
}
|
||||
|
||||
SessionRecord record = sessionStore.loadSession(remoteAddress);
|
||||
return record.getSessionState().getSessionVersion();
|
||||
return record.getSessionVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
package org.whispersystems.libsignal.state;
|
||||
|
||||
import org.signal.client.internal.Native;
|
||||
import org.whispersystems.libsignal.state.SessionState;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.ecc.ECPrivateKey;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -26,18 +32,14 @@ public class SessionRecord {
|
||||
this.handle = Native.SessionRecord_NewFresh();
|
||||
}
|
||||
|
||||
public SessionRecord(SessionState sessionState) {
|
||||
this.handle = Native.SessionRecord_FromSessionState(sessionState.nativeHandle());
|
||||
public static SessionRecord fromSingleSessionState(byte[] sessionStateBytes) throws IOException {
|
||||
return new SessionRecord(new SessionState(sessionStateBytes));
|
||||
}
|
||||
|
||||
public SessionRecord(byte[] serialized) throws IOException {
|
||||
this.handle = Native.SessionRecord_Deserialize(serialized);
|
||||
}
|
||||
|
||||
public SessionState getSessionState() {
|
||||
return new SessionState(Native.SessionRecord_GetSessionState(this.handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current {@link SessionState} into the list of "previous" session states,
|
||||
* and replace the current {@link org.whispersystems.libsignal.state.SessionState}
|
||||
@@ -47,6 +49,35 @@ public class SessionRecord {
|
||||
Native.SessionRecord_ArchiveCurrentState(this.handle);
|
||||
}
|
||||
|
||||
public int getSessionVersion() {
|
||||
// return Native.SessionRecord_GetSessionVersion(this.handle);
|
||||
return getSessionState().getSessionVersion();
|
||||
}
|
||||
|
||||
public int getRemoteRegistrationId() {
|
||||
// return Native.SessionRecord_GetRemoteRegistrationId(this.handle);
|
||||
return getSessionState().getRemoteRegistrationId();
|
||||
}
|
||||
|
||||
public int getLocalRegistrationId() {
|
||||
// return Native.SessionRecord_GetLocalRegistrationId(this.handle);
|
||||
return getSessionState().getLocalRegistrationId();
|
||||
}
|
||||
|
||||
public IdentityKey getRemoteIdentityKey() {
|
||||
// return Native.SessionRecord_GetRemoteIdentityKey(this.handle);
|
||||
return getSessionState().getRemoteIdentityKey();
|
||||
}
|
||||
|
||||
public IdentityKey getLocalIdentityKey() {
|
||||
// return Native.SessionRecord_GetLocalIdentityKey(this.handle);
|
||||
return getSessionState().getLocalIdentityKey();
|
||||
}
|
||||
|
||||
public boolean hasSenderChain() {
|
||||
return getSessionState().hasSenderChain();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a serialized version of the current SessionRecord.
|
||||
*/
|
||||
@@ -54,6 +85,52 @@ public class SessionRecord {
|
||||
return Native.SessionRecord_Serialize(this.handle);
|
||||
}
|
||||
|
||||
// Following functions are for internal or testing use and may be removed in the future:
|
||||
|
||||
public byte[] getReceiverChainKeyValue(ECPublicKey senderEphemeral) {
|
||||
return getSessionState().getReceiverChainKeyValue(senderEphemeral);
|
||||
}
|
||||
|
||||
public byte[] getSenderChainKeyValue() {
|
||||
return getSessionState().getSenderChainKeyValue();
|
||||
}
|
||||
|
||||
public SessionRecord(SessionState sessionState) {
|
||||
this.handle = Native.SessionRecord_FromSessionState(sessionState.nativeHandle());
|
||||
}
|
||||
|
||||
public SessionState getSessionState() {
|
||||
return new SessionState(Native.SessionRecord_GetSessionState(this.handle));
|
||||
}
|
||||
|
||||
public byte[] getAliceBaseKey() {
|
||||
return getSessionState().getAliceBaseKey();
|
||||
}
|
||||
|
||||
static public SessionRecord initializeAliceSession(IdentityKeyPair identityKey,
|
||||
ECKeyPair baseKey,
|
||||
IdentityKey theirIdentityKey,
|
||||
ECPublicKey theirSignedPreKey,
|
||||
ECPublicKey theirRatchetKey) {
|
||||
return new SessionRecord(SessionState.initializeAliceSession(identityKey, baseKey,
|
||||
theirIdentityKey,
|
||||
theirSignedPreKey,
|
||||
theirRatchetKey));
|
||||
}
|
||||
|
||||
static public SessionRecord initializeBobSession(IdentityKeyPair identityKey,
|
||||
ECKeyPair signedPreKey,
|
||||
ECKeyPair ephemeralKey,
|
||||
IdentityKey theirIdentityKey,
|
||||
ECPublicKey theirBaseKey) {
|
||||
|
||||
return new SessionRecord(SessionState.initializeBobSession(identityKey,
|
||||
signedPreKey,
|
||||
ephemeralKey,
|
||||
theirIdentityKey,
|
||||
theirBaseKey));
|
||||
}
|
||||
|
||||
long nativeHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SessionState {
|
||||
this.handle = copy.handle;
|
||||
}
|
||||
|
||||
public byte[] getAliceBaseKey() {
|
||||
byte[] getAliceBaseKey() {
|
||||
return Native.SessionState_GetAliceBaseKey(this.handle);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class SessionState {
|
||||
return Native.SessionState_GetSessionVersion(this.handle);
|
||||
}
|
||||
|
||||
public IdentityKey getRemoteIdentityKey() {
|
||||
IdentityKey getRemoteIdentityKey() {
|
||||
byte[] keyBytes = Native.SessionState_GetRemoteIdentityKeyPublic(this.handle);
|
||||
|
||||
if (keyBytes == null){
|
||||
@@ -100,7 +100,7 @@ public class SessionState {
|
||||
}
|
||||
}
|
||||
|
||||
public IdentityKey getLocalIdentityKey() {
|
||||
IdentityKey getLocalIdentityKey() {
|
||||
byte[] keyBytes = Native.SessionState_GetLocalIdentityKeyPublic(this.handle);
|
||||
try {
|
||||
return new IdentityKey(keyBytes);
|
||||
@@ -114,19 +114,19 @@ public class SessionState {
|
||||
return Native.SessionState_HasSenderChain(this.handle);
|
||||
}
|
||||
|
||||
public byte[] getReceiverChainKeyValue(ECPublicKey senderEphemeral) {
|
||||
byte[] getReceiverChainKeyValue(ECPublicKey senderEphemeral) {
|
||||
return Native.SessionState_GetReceiverChainKeyValue(this.handle, senderEphemeral.nativeHandle());
|
||||
}
|
||||
|
||||
public byte[] getSenderChainKeyValue() {
|
||||
byte[] getSenderChainKeyValue() {
|
||||
return Native.SessionState_GetSenderChainKeyValue(this.handle);
|
||||
}
|
||||
|
||||
public int getRemoteRegistrationId() {
|
||||
int getRemoteRegistrationId() {
|
||||
return Native.SessionState_GetRemoteRegistrationId(this.handle);
|
||||
}
|
||||
|
||||
public int getLocalRegistrationId() {
|
||||
int getLocalRegistrationId() {
|
||||
return Native.SessionState_GetLocalRegistrationId(this.handle);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user