0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 20:03:07 +02:00

Merge pull request #132 from signalapp/jack/remove-java-session-state

Remove SessionState
This commit is contained in:
Jack Lloyd 2021-01-06 13:20:41 -05:00 committed by GitHub
commit 239534e062
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 24 additions and 116 deletions

View File

@ -215,7 +215,6 @@ public final class Native {
public static native byte[] SessionRecord_GetRemoteIdentityKeyPublic(long handle);
public static native int SessionRecord_GetRemoteRegistrationId(long handle);
public static native byte[] SessionRecord_GetSenderChainKeyValue(long handle);
public static native long SessionRecord_GetSessionState(long sessionRecord);
public static native int SessionRecord_GetSessionVersion(long handle);
public static native boolean SessionRecord_HasSenderChain(long handle);
public static native long SessionRecord_InitializeAliceSession(long identityKeyPrivate, long identityKeyPublic, long basePrivate, long basePublic, long theirIdentityKey, long theirSignedPrekey, long theirRatchetKey);
@ -223,12 +222,6 @@ public final class Native {
public static native long SessionRecord_NewFresh();
public static native byte[] SessionRecord_Serialize(long handle);
public static native long SessionState_Deserialize(byte[] data);
public static native void SessionState_Destroy(long handle);
public static native int SessionState_GetSessionVersion(long handle);
public static native boolean SessionState_HasSenderChain(long handle);
public static native byte[] SessionState_Serialized(long handle);
public static native long SignalMessage_Deserialize(byte[] data);
public static native void SignalMessage_Destroy(long handle);
public static native byte[] SignalMessage_GetBody(long handle);

View File

@ -44,9 +44,8 @@ public class SessionRecord {
}
/**
* Move the current {@link SessionState} into the list of "previous" session states, and replace
* the current {@link org.whispersystems.libsignal.state.SessionState} with a fresh reset
* instance.
* Move the current SessionState into the list of "previous" session states, and replace
* the current SessionState with a fresh reset instance.
*/
public void archiveCurrentState() {
Native.SessionRecord_ArchiveCurrentState(this.handle);
@ -98,10 +97,6 @@ public class SessionRecord {
// Following functions are for internal or testing use and may be removed in the future:
public SessionState getSessionState() {
return new SessionState(Native.SessionRecord_GetSessionState(this.handle));
}
public byte[] getReceiverChainKeyValue(ECPublicKey senderEphemeral) {
return Native.SessionRecord_GetReceiverChainKeyValue(
this.handle, senderEphemeral.nativeHandle());

View File

@ -1,45 +0,0 @@
/**
* Copyright (C) 2014-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/
package org.whispersystems.libsignal.state;
import org.signal.client.internal.Native;
import java.io.IOException;
public class SessionState {
private long handle;
@Override
protected void finalize() {
Native.SessionState_Destroy(this.handle);
}
public SessionState(byte[] serialized) throws IOException {
this.handle = Native.SessionState_Deserialize(serialized);
}
SessionState(long handle) {
this.handle = handle;
}
// Used by Android
public int getSessionVersion() {
return Native.SessionState_GetSessionVersion(this.handle);
}
// Used by Android
public boolean hasSenderChain() {
return Native.SessionState_HasSenderChain(this.handle);
}
public byte[] serialize() {
return Native.SessionState_Serialized(this.handle);
}
long nativeHandle() {
return this.handle;
}
}

View File

@ -1510,20 +1510,7 @@ pub unsafe extern "C" fn Java_org_signal_client_internal_Native_SessionRecord_1F
) -> ObjectHandle {
run_ffi_safe(&env, || {
let session_state = env.convert_byte_array(session_state)?;
let session_state = SessionState::deserialize(&session_state)?;
box_object::<SessionRecord>(Ok(SessionRecord::new(session_state)))
})
}
#[no_mangle]
pub unsafe extern "C" fn Java_org_signal_client_internal_Native_SessionRecord_1GetSessionState(
env: JNIEnv,
_class: JClass,
session_record: ObjectHandle,
) -> ObjectHandle {
run_ffi_safe(&env, || {
let session_record = native_handle_cast::<SessionRecord>(session_record)?;
box_object::<SessionState>(session_record.session_state().map(|s| s.clone()))
box_object::<SessionRecord>(SessionRecord::from_single_session_state(&session_state))
})
}
@ -1533,10 +1520,6 @@ jni_fn_get_jint!(Java_org_signal_client_internal_Native_SessionRecord_1GetSessio
jni_fn_get_jboolean!(Java_org_signal_client_internal_Native_SessionRecord_1HasSenderChain(SessionRecord) using SessionRecord::has_sender_chain);
// SessionState
jni_fn_get_jint!(Java_org_signal_client_internal_Native_SessionState_1GetSessionVersion(SessionState) using SessionState::session_version);
jni_fn_get_jboolean!(Java_org_signal_client_internal_Native_SessionState_1HasSenderChain(SessionState) using SessionState::has_sender_chain);
// The following are just exposed to make it possible to retain some of the Java tests:
#[no_mangle]

View File

@ -187,8 +187,4 @@ bridge_get_bytearray!(get_sender_chain_key_value(SessionRecord), ffi = None =>
SessionRecord::get_sender_chain_key_bytes
);
bridge_destroy!(SessionState, ffi = None);
bridge_deserialize!(SessionState::deserialize, ffi = None);
bridge_get_bytearray!(serialized(SessionState) => SessionState::serialize);
bridge_destroy!(Aes256GcmSiv);

View File

@ -54,7 +54,7 @@ pub use {
session_cipher::{
message_decrypt, message_decrypt_prekey, message_decrypt_signal, message_encrypt,
},
state::{PreKeyBundle, PreKeyRecord, SessionRecord, SessionState, SignedPreKeyRecord},
state::{PreKeyBundle, PreKeyRecord, SessionRecord, SignedPreKeyRecord},
storage::{
Context, Direction, IdentityKeyStore, InMemIdentityKeyStore, InMemPreKeyStore,
InMemSenderKeyStore, InMemSessionStore, InMemSignalProtocolStore, InMemSignedPreKeyStore,

View File

@ -10,5 +10,6 @@ mod signed_prekey;
pub use bundle::PreKeyBundle;
pub use prekey::{PreKeyId, PreKeyRecord};
pub use session::{SessionRecord, SessionState};
pub use session::SessionRecord;
pub(crate) use session::SessionState;
pub use signed_prekey::{SignedPreKeyId, SignedPreKeyRecord};

View File

@ -17,7 +17,7 @@ use prost::Message;
use std::collections::VecDeque;
#[derive(Debug, Clone)]
pub struct UnacknowledgedPreKeyMessageItems {
pub(crate) struct UnacknowledgedPreKeyMessageItems {
pre_key_id: Option<u32>,
signed_pre_key_id: u32,
base_key: curve::PublicKey,
@ -32,30 +32,25 @@ impl UnacknowledgedPreKeyMessageItems {
}
}
pub fn pre_key_id(&self) -> Result<Option<u32>> {
pub(crate) fn pre_key_id(&self) -> Result<Option<u32>> {
Ok(self.pre_key_id)
}
pub fn signed_pre_key_id(&self) -> Result<u32> {
pub(crate) fn signed_pre_key_id(&self) -> Result<u32> {
Ok(self.signed_pre_key_id)
}
pub fn base_key(&self) -> Result<&curve::PublicKey> {
pub(crate) fn base_key(&self) -> Result<&curve::PublicKey> {
Ok(&self.base_key)
}
}
#[derive(Clone, Debug)]
pub struct SessionState {
pub(crate) struct SessionState {
session: SessionStructure,
}
impl SessionState {
pub fn deserialize(bytes: &[u8]) -> Result<Self> {
let session = SessionStructure::decode(bytes)?;
Ok(Self { session })
}
pub(crate) fn new(session: SessionStructure) -> Self {
Self { session }
}
@ -407,12 +402,6 @@ impl SessionState {
pub(crate) fn local_registration_id(&self) -> Result<u32> {
Ok(self.session.local_registration_id)
}
pub fn serialize(&self) -> Result<Vec<u8>> {
let mut buf = vec![];
self.session.encode(&mut buf)?;
Ok(buf)
}
}
impl From<SessionStructure> for SessionState {
@ -435,8 +424,8 @@ impl From<&SessionState> for SessionStructure {
#[derive(Clone, Debug)]
pub struct SessionRecord {
pub current_session: Option<SessionState>,
pub previous_sessions: VecDeque<SessionState>,
current_session: Option<SessionState>,
previous_sessions: VecDeque<SessionState>,
}
impl SessionRecord {
@ -447,7 +436,7 @@ impl SessionRecord {
}
}
pub fn new(state: SessionState) -> Self {
pub(crate) fn new(state: SessionState) -> Self {
Self {
current_session: Some(state),
previous_sessions: VecDeque::new(),
@ -468,6 +457,14 @@ impl SessionRecord {
})
}
pub fn from_single_session_state(bytes: &[u8]) -> Result<Self> {
let session = SessionState::new(SessionStructure::decode(bytes)?);
Ok(Self {
current_session: Some(session),
previous_sessions: VecDeque::new(),
})
}
pub(crate) fn has_session_state(&self, version: u32, alice_base_key: &[u8]) -> Result<bool> {
if let Some(current_session) = &self.current_session {
if current_session.session_version()? == version
@ -488,7 +485,7 @@ impl SessionRecord {
Ok(false)
}
pub fn session_state(&self) -> Result<&SessionState> {
pub(crate) fn session_state(&self) -> Result<&SessionState> {
if let Some(ref session) = self.current_session {
Ok(session)
} else {

View File

@ -113,10 +113,7 @@ fn test_basic_prekey_v3() -> Result<(), SignalProtocolError> {
.await?
.is_some());
let bobs_session_with_alice = bob_store.load_session(&alice_address, None).await?.unwrap();
assert_eq!(
bobs_session_with_alice.session_state()?.session_version()?,
3
);
assert_eq!(bobs_session_with_alice.session_version()?, 3);
assert_eq!(bobs_session_with_alice.alice_base_key()?.len(), 32 + 1);
let bob_outgoing = encrypt(&mut bob_store, &alice_address, bobs_response).await?;
@ -380,7 +377,6 @@ fn repeat_bundle_message_v3() -> Result<(), SignalProtocolError> {
.load_session(&bob_address, None)
.await?
.unwrap()
.session_state()?
.session_version()?,
3
);
@ -522,7 +518,6 @@ fn bad_message_bundle() -> Result<(), SignalProtocolError> {
.load_session(&bob_address, None)
.await?
.unwrap()
.session_state()?
.session_version()?,
3
);
@ -614,7 +609,6 @@ fn optional_one_time_prekey() -> Result<(), SignalProtocolError> {
.load_session(&bob_address, None)
.await?
.unwrap()
.session_state()?
.session_version()?,
3
);

View File

@ -92,8 +92,6 @@ typedef struct SignalServerCertificate SignalServerCertificate;
typedef struct SignalSessionRecord SignalSessionRecord;
typedef struct SignalSessionState SignalSessionState;
typedef struct SignalFfiError SignalFfiError;
typedef struct SignalMessage SignalMessage;
@ -841,10 +839,6 @@ SignalFfiError *signal_session_record_serialize(const SignalSessionRecord *obj,
const unsigned char **out,
size_t *out_len);
SignalFfiError *signal_session_state_serialized(const SignalSessionState *obj,
const unsigned char **out,
size_t *out_len);
SignalFfiError *signal_aes256_gcm_siv_destroy(SignalAes256GcmSiv *p);
#endif /* SIGNAL_FFI_H_ */