diff --git a/.gitignore b/.gitignore index 5d4b4fdb..cf37e932 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ avd/ build /captures .externalNativeBuild +/obv_messenger/.kotlin/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b666acf..23afb222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# Build 257 (3.4) +2024-11-28 + +- Olvid now targets Android 15 (API 35) +- Improved global search to also match link title/description +- Allow contact introduction directly from the discussion screen +- [optimization] attachment download/upload progresses are no longer written to database +- several small bug fixes + # Build 256 (3.3.1) 2024-11-16 diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/channel/datatypes/NetworkChannel.java b/obv_engine/engine/src/main/java/io/olvid/engine/channel/datatypes/NetworkChannel.java index 31d5dfce..6536ec66 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/channel/datatypes/NetworkChannel.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/channel/datatypes/NetworkChannel.java @@ -164,7 +164,7 @@ public static UID post(ChannelManagerSession channelManagerSession, ChannelMessa EncryptedBytes encryptedContent = authEnc.encrypt(messageKey, paddedPlaintext, prng); - messageToSend = new MessageToSend(message.getSendChannelInfo().getFromIdentity(), messageUid, server, encryptedContent, headers); + messageToSend = new MessageToSend(message.getSendChannelInfo().getFromIdentity(), messageUid, server, encryptedContent, headers, channelProtocolMessageToSend.hasUserContent()); break; } default: diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/Constants.java b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/Constants.java index c7647ce6..4971021c 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/Constants.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/Constants.java @@ -23,7 +23,7 @@ import java.nio.charset.StandardCharsets; public abstract class Constants { - public static final int CURRENT_ENGINE_DB_SCHEMA_VERSION = 41; + public static final int CURRENT_ENGINE_DB_SCHEMA_VERSION = 42; public static final int SERVER_API_VERSION = 18; public static final int CURRENT_BACKUP_JSON_VERSION = 0; diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/ExponentialBackoffRepeatingScheduler.java b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/ExponentialBackoffRepeatingScheduler.java index 65328c2f..bf56fde5 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/ExponentialBackoffRepeatingScheduler.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/ExponentialBackoffRepeatingScheduler.java @@ -112,11 +112,8 @@ public void retryScheduledRunnables() { } // for polling only -// public ScheduledFuture scheduleAtFixedRate(Runnable runnable, int i, long delay, TimeUnit timeUnit) { -// return scheduler.scheduleAtFixedRate(runnable, i, delay, timeUnit); -// } - protected long computeReschedulingDelay(int failedAttemptCount) { - return (long) ((Constants.BASE_RESCHEDULING_TIME << failedAttemptCount) * (1 + random.nextFloat())); + long base = Constants.BASE_RESCHEDULING_TIME << Math.min(failedAttemptCount, 32); + return (long) (base * (1 + random.nextFloat())); } } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/ChannelProtocolMessageToSend.java b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/ChannelProtocolMessageToSend.java index 81e7015e..d74cc15c 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/ChannelProtocolMessageToSend.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/ChannelProtocolMessageToSend.java @@ -26,11 +26,13 @@ public class ChannelProtocolMessageToSend implements ChannelMessageToSend { private final SendChannelInfo sendChannelInfo; private final Encoded encodedElements; private final boolean partOfFullRatchetProtocolOfTheSendSeed; + private final boolean hasUserContent; - public ChannelProtocolMessageToSend(SendChannelInfo sendChannelInfo, Encoded encodedElements, boolean partOfFullRatchetProtocolOfTheSendSeed) { + public ChannelProtocolMessageToSend(SendChannelInfo sendChannelInfo, Encoded encodedElements, boolean partOfFullRatchetProtocolOfTheSendSeed, boolean hasUserContent) { this.sendChannelInfo = sendChannelInfo; this.encodedElements = encodedElements; this.partOfFullRatchetProtocolOfTheSendSeed = partOfFullRatchetProtocolOfTheSendSeed; + this.hasUserContent = hasUserContent; } @Override @@ -50,4 +52,8 @@ public Encoded getEncodedElements() { public boolean isPartOfFullRatchetProtocolOfTheSendSeed() { return partOfFullRatchetProtocolOfTheSendSeed; } + + public boolean hasUserContent() { + return hasUserContent; + } } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/MessageToSend.java b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/MessageToSend.java index 46fd5d0c..65fa4a94 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/MessageToSend.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/MessageToSend.java @@ -36,8 +36,8 @@ public class MessageToSend { private final boolean isApplicationMessage; private final boolean isVoipMessage; - public MessageToSend(Identity ownedIdentity, UID uid, String server, EncryptedBytes encryptedContent, Header[] headers) { - this(ownedIdentity, uid, server, encryptedContent, null, headers, new Attachment[0], false, false); + public MessageToSend(Identity ownedIdentity, UID uid, String server, EncryptedBytes encryptedContent, Header[] headers, boolean hasUserContent) { + this(ownedIdentity, uid, server, encryptedContent, null, headers, new Attachment[0], hasUserContent, false); } public MessageToSend(Identity ownedIdentity, UID uid, String server, EncryptedBytes encryptedContent, EncryptedBytes encryptedExtendedContent, Header[] headers, Attachment[] attachments, boolean isApplicationMessage, boolean isVoipMessage) { diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/engine/Engine.java b/obv_engine/engine/src/main/java/io/olvid/engine/engine/Engine.java index 83c43396..eb924637 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/engine/Engine.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/engine/Engine.java @@ -807,6 +807,17 @@ public RegisterApiKeyResult registerOwnedIdentityApiKeyOnServer(byte[] bytesOwne } } + @Override + public void updateKeycloakTransferRestrictedIfNeeded(byte[] bytesOwnedIdentity, String serverUrl, boolean transferRestricted) { + try (EngineSession engineSession = getSession()) { + Identity ownedIdentity = Identity.of(bytesOwnedIdentity); + identityManager.updateKeycloakTransferRestrictedIfNeeded(engineSession.session, ownedIdentity, serverUrl, transferRestricted); + engineSession.session.commit(); + } catch (Exception e) { + Logger.x(e); + } + } + @Override public void updateKeycloakPushTopicsIfNeeded(byte[] bytesOwnedIdentity, String serverUrl, List pushTopics) { try (EngineSession engineSession = getSession()) { diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/EngineAPI.java b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/EngineAPI.java index 02dd8f4d..8085f61b 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/EngineAPI.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/EngineAPI.java @@ -93,6 +93,7 @@ enum ListenerPriority { void setOwnedIdentityKeycloakSignatureKey(byte[] bytesOwnedIdentity, JsonWebKey signatureKey) throws Exception; ObvIdentity bindOwnedIdentityToKeycloak(byte[] bytesOwnedIdentity, ObvKeycloakState keycloakState, String keycloakUserId); void unbindOwnedIdentityFromKeycloak(byte[] bytesOwnedIdentity); + void updateKeycloakTransferRestrictedIfNeeded(byte[] bytesOwnedIdentity, String serverUrl, boolean transferRestricted); void updateKeycloakPushTopicsIfNeeded(byte[] bytesOwnedIdentity, String serverUrl, List pushTopics); void updateKeycloakRevocationList(byte[] bytesOwnedIdentity, long latestRevocationListTimestamp, List signedRevocations); void setOwnedIdentityKeycloakSelfRevocationTestNonce(byte[] bytesOwnedIdentity, String serverUrl, String nonce); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/JsonIdentityDetails.java b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/JsonIdentityDetails.java index 92722d65..a9b13d55 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/JsonIdentityDetails.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/JsonIdentityDetails.java @@ -122,7 +122,7 @@ private static String nullOrTrim(String in) { return null; } String out = in.trim(); - if (out.length() == 0) { + if (out.isEmpty()) { return null; } return out; diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvDialog.java b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvDialog.java index d3eeb663..699a0e3b 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvDialog.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvDialog.java @@ -172,6 +172,17 @@ public void setTransferSasAndDeviceUid(String sas, byte[] deviceUidToKeepActive) } } + public void setTransferAuthenticationProof(String signature, String serializedAuthState) throws Exception { + if (this.category.id == Category.TRANSFER_DIALOG_CATEGORY && this.category.obvTransferStep.getStep() == ObvTransferStep.Step.TARGET_REQUESTS_KEYCLOAK_AUTHENTICATION_PROOF) { + encodedResponse = Encoded.of(new Encoded[]{ + Encoded.of(signature), + Encoded.of(serializedAuthState), + }); + } else { + throw new Exception(); + } + } + // endregion diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvTransferStep.java b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvTransferStep.java index 2eeac81b..b0de4012 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvTransferStep.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/ObvTransferStep.java @@ -60,6 +60,8 @@ public static ObvTransferStep of(Encoded encoded) throws DecodingException { return new SourceSnapshotSent(encodedParts); case TARGET_SNAPSHOT_RECEIVED: return new TargetSnapshotReceived(encodedParts); + case TARGET_REQUESTS_KEYCLOAK_AUTHENTICATION_PROOF: + return new TargetRequestsKeycloakAuthenticationProof(encodedParts); default: throw new DecodingException(); } @@ -82,7 +84,8 @@ public enum Step { SOURCE_SAS_INPUT(4), TARGET_SHOW_SAS(5), SOURCE_SNAPSHOT_SENT(6), - TARGET_SNAPSHOT_RECEIVED(7); + TARGET_SNAPSHOT_RECEIVED(7), + TARGET_REQUESTS_KEYCLOAK_AUTHENTICATION_PROOF(8); private static final Map valueMap = new HashMap<>(); static { @@ -298,6 +301,63 @@ public Encoded[] getEncodedParts() { } } + public static class TargetRequestsKeycloakAuthenticationProof extends ObvTransferStep { + public final String keycloakServerUrl; + public final String clientId; + public final String fullSas; + public final long sessionNumber; + public final String clientSecret; // may be null + + public TargetRequestsKeycloakAuthenticationProof(String keycloakServerUrl, String clientId, String clientSecret, String fullSas, long sessionNumber) { + this.keycloakServerUrl = keycloakServerUrl; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.fullSas = fullSas; + this.sessionNumber = sessionNumber; + } + + public TargetRequestsKeycloakAuthenticationProof(Encoded[] encodedParts) throws DecodingException { + if (encodedParts.length != 5 && encodedParts.length != 4) { + throw new DecodingException(); + } + this.keycloakServerUrl = encodedParts[0].decodeString(); + this.clientId = encodedParts[1].decodeString(); + this.fullSas = encodedParts[2].decodeString(); + this.sessionNumber = encodedParts[3].decodeLong(); + if (encodedParts.length == 5) { + this.clientSecret = encodedParts[4].decodeString(); + } else { + this.clientSecret = null; + } + } + + @Override + public Step getStep() { + return Step.TARGET_REQUESTS_KEYCLOAK_AUTHENTICATION_PROOF; + } + + @Override + public Encoded[] getEncodedParts() { + if (clientSecret == null) { + return new Encoded[]{ + Encoded.of(keycloakServerUrl), + Encoded.of(clientId), + Encoded.of(fullSas), + Encoded.of(sessionNumber), + }; + } else { + return new Encoded[]{ + Encoded.of(keycloakServerUrl), + Encoded.of(clientId), + Encoded.of(fullSas), + Encoded.of(sessionNumber), + Encoded.of(clientSecret), + }; + } + } + } + + public static class TargetSnapshotReceived extends ObvTransferStep { public TargetSnapshotReceived() { } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/identities/ObvKeycloakState.java b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/identities/ObvKeycloakState.java index 6b7fe201..4b57a152 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/identities/ObvKeycloakState.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/engine/types/identities/ObvKeycloakState.java @@ -37,17 +37,19 @@ public class ObvKeycloakState { public final JsonWebKeySet jwks; // non-null --> only set to null when sending to app and deserialization failed public final JsonWebKey signatureKey; // non-null --> only set to null when sending to app and deserialization failed public final String serializedAuthState; // device dependant --> do not share with other devices + public final boolean transferRestricted; public final String ownApiKey; // not included in the serialized version public final long latestRevocationListTimestamp; // not included in the serialized version public final long latestGroupUpdateTimestamp; // not included in the serialized version - public ObvKeycloakState(String keycloakServer, String clientId, String clientSecret, JsonWebKeySet jwks, JsonWebKey signatureKey, String serializedAuthState, String ownApiKey, long latestRevocationListTimestamp, long latestGroupUpdateTimestamp) { + public ObvKeycloakState(String keycloakServer, String clientId, String clientSecret, JsonWebKeySet jwks, JsonWebKey signatureKey, String serializedAuthState, boolean transferRestricted, String ownApiKey, long latestRevocationListTimestamp, long latestGroupUpdateTimestamp) { this.keycloakServer = keycloakServer; this.clientId = clientId; this.clientSecret = clientSecret; this.jwks = jwks; this.signatureKey = signatureKey; this.serializedAuthState = serializedAuthState; + this.transferRestricted = transferRestricted; this.ownApiKey = ownApiKey; this.latestRevocationListTimestamp = latestRevocationListTimestamp; this.latestGroupUpdateTimestamp = latestGroupUpdateTimestamp; @@ -73,6 +75,9 @@ public Encoded encode() { if (serializedAuthState != null) { dict.put(new DictionaryKey("sas"), Encoded.of(serializedAuthState)); } + if (transferRestricted) { + dict.put(new DictionaryKey("tr"), Encoded.of(transferRestricted)); + } return Encoded.of(dict); } @@ -83,6 +88,7 @@ public static ObvKeycloakState of(Encoded encoded) throws DecodingException { JsonWebKeySet jwks; JsonWebKey signatureKey; final String serializedAuthState; + boolean transferRestricted; HashMap dict = encoded.decodeDictionary(); DictionaryKey key = new DictionaryKey("ks"); @@ -135,7 +141,13 @@ public static ObvKeycloakState of(Encoded encoded) throws DecodingException { } else { serializedAuthState = null; } - - return new ObvKeycloakState(keycloakServer, clientId, clientSecret, jwks, signatureKey, serializedAuthState, null, 0, 0); + key = new DictionaryKey("tr"); + encodedValue = dict.get(key); + if (encodedValue != null) { + transferRestricted = encodedValue.decodeBoolean(); + } else { + transferRestricted = false; + } + return new ObvKeycloakState(keycloakServer, clientId, clientSecret, jwks, signatureKey, serializedAuthState, transferRestricted, null, 0, 0); } } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/identity/IdentityManager.java b/obv_engine/engine/src/main/java/io/olvid/engine/identity/IdentityManager.java index 5dbcd1c6..4cda8476 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/identity/IdentityManager.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/identity/IdentityManager.java @@ -545,7 +545,7 @@ public Identity generateOwnedIdentity(Session session, String server, JsonIdenti } if (keycloakState != null) { - KeycloakServer keycloakServer = KeycloakServer.create(wrapSession(session), keycloakState.keycloakServer, ownedIdentity.getOwnedIdentity(), keycloakState.jwks.toJson(), keycloakState.signatureKey == null ? null : keycloakState.signatureKey.toJson(), keycloakState.clientId, keycloakState.clientSecret); + KeycloakServer keycloakServer = KeycloakServer.create(wrapSession(session), keycloakState.keycloakServer, ownedIdentity.getOwnedIdentity(), keycloakState.jwks.toJson(), keycloakState.signatureKey == null ? null : keycloakState.signatureKey.toJson(), keycloakState.clientId, keycloakState.clientSecret, keycloakState.transferRestricted); if (keycloakServer == null) { return null; } @@ -890,7 +890,7 @@ public void verifyAndAddRevocationList(Session session, Identity ownedIdentity, } @Override - public JsonKeycloakUserDetails verifyKeycloakSignature(Session session, Identity ownedIdentity, String signature) { + public JsonKeycloakUserDetails verifyKeycloakIdentitySignature(Session session, Identity ownedIdentity, String signature) { try { OwnedIdentity ownedIdentityObject = OwnedIdentity.get(wrapSession(session), ownedIdentity); if (ownedIdentityObject == null || !ownedIdentityObject.isKeycloakManaged()) { @@ -953,6 +953,37 @@ public JsonKeycloakUserDetails verifyKeycloakSignature(Session session, Identity } + @Override + public String verifyKeycloakSignature(Session session, Identity ownedIdentity, String signature) { + try { + OwnedIdentity ownedIdentityObject = OwnedIdentity.get(wrapSession(session), ownedIdentity); + if (ownedIdentityObject == null || !ownedIdentityObject.isKeycloakManaged()) { + return null; + } + KeycloakServer keycloakServer = ownedIdentityObject.getKeycloakServer(); + + final JwksVerificationKeyResolver jwksResolver; + JsonWebKey signatureKey = keycloakServer.getSignatureKey(); + if (signatureKey != null) { + jwksResolver = new JwksVerificationKeyResolver(Collections.singletonList(signatureKey)); + } else { + JsonWebKeySet jwks = keycloakServer.getJwks(); + jwksResolver = new JwksVerificationKeyResolver(jwks.getJsonWebKeys()); + } + JwtConsumer jwtConsumer = new JwtConsumerBuilder() + .setExpectedAudience(false) + .setVerificationKeyResolver(jwksResolver) + .build(); + + JwtContext context = jwtConsumer.process(signature); + if (context.getJwtClaims() != null) { + // signature is valid + return context.getJwtClaims().getRawJson(); + } + } catch (Exception ignored) { } + return null; + } + @Override public String getOwnedIdentityKeycloakServerUrl(Session session, Identity ownedIdentity) throws SQLException { OwnedIdentity ownedIdentityObject = OwnedIdentity.get(wrapSession(session), ownedIdentity); @@ -1026,7 +1057,7 @@ public void bindOwnedIdentityToKeycloak(Session session, Identity ownedIdentity, session.addSessionCommitListener(backupNeededSessionCommitListener); - KeycloakServer keycloakServer = KeycloakServer.create(wrapSession(session), keycloakState.keycloakServer, ownedIdentity, keycloakState.jwks.toJson(), keycloakState.signatureKey == null ? null : keycloakState.signatureKey.toJson(), keycloakState.clientId, keycloakState.clientSecret); + KeycloakServer keycloakServer = KeycloakServer.create(wrapSession(session), keycloakState.keycloakServer, ownedIdentity, keycloakState.jwks.toJson(), keycloakState.signatureKey == null ? null : keycloakState.signatureKey.toJson(), keycloakState.clientId, keycloakState.clientSecret, keycloakState.transferRestricted); if (keycloakServer == null) { Logger.e("Unable to create new KeycloakServer db entry"); throw new Exception(); @@ -1092,6 +1123,16 @@ public JsonIdentityDetailsWithVersionAndPhoto[] getOwnedIdentityPublishedAndLate return null; } + @Override + public void updateKeycloakTransferRestrictedIfNeeded(Session session, Identity ownedIdentity, String serverUrl, boolean transferRestricted) throws SQLException { + KeycloakServer keycloakServer = KeycloakServer.get(wrapSession(session), serverUrl, ownedIdentity); + + if (keycloakServer != null) { + if (transferRestricted ^ keycloakServer.isTransferRestricted()) { + keycloakServer.setTransferRestricted(transferRestricted); + } + } + } @Override public boolean updateKeycloakPushTopicsIfNeeded(Session session, Identity ownedIdentity, String serverUrl, List pushTopics) throws SQLException { @@ -1720,7 +1761,7 @@ public void reCheckAllCertifiedByOwnKeycloakContacts(Session session, Identity o if (publishedDetails != null) { JsonIdentityDetails identityDetails = publishedDetails.getJsonIdentityDetails(); if (identityDetails != null && identityDetails.getSignedUserDetails() != null) { - JsonKeycloakUserDetails jsonKeycloakUserDetails = verifyKeycloakSignature(session, ownedIdentity, identityDetails.getSignedUserDetails()); + JsonKeycloakUserDetails jsonKeycloakUserDetails = verifyKeycloakIdentitySignature(session, ownedIdentity, identityDetails.getSignedUserDetails()); if (jsonKeycloakUserDetails != null) { // the contact has some valid signed details diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/ContactIdentity.java b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/ContactIdentity.java index 8120b04d..2710aa22 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/ContactIdentity.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/ContactIdentity.java @@ -289,7 +289,7 @@ public void updatePublishedDetails(JsonIdentityDetailsWithVersionAndPhoto jsonId identityManagerSession.session.addSessionCommitListener(this); } if (jsonIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails() != null) { - JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakSignature(identityManagerSession.session, ownedIdentity, jsonIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); + JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakIdentitySignature(identityManagerSession.session, ownedIdentity, jsonIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); if (jsonKeycloakUserDetails != null) { // the details are properly signed --> the call to markContactAsCertifiedByOwnKeycloak() will auto-trust the new details, so we can return JsonIdentityDetails certifiedJsonIdentityDetails = jsonKeycloakUserDetails.getIdentityDetails(jsonIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); @@ -609,7 +609,7 @@ public static ContactIdentity create(IdentityManagerSession identityManagerSessi contactIdentityObject.revokedAsCompromised = revokedAsCompromised; contactIdentityObject.insert(); - JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakSignature(identityManagerSession.session, ownedIdentity, jsonIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); + JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakIdentitySignature(identityManagerSession.session, ownedIdentity, jsonIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); if (jsonKeycloakUserDetails != null) { try { @@ -1300,7 +1300,7 @@ private static void restoreContact(IdentityManagerSession identityManagerSession contactIdentityObject.forcefullyTrustedByUser = pojo.forcefully_trusted; contactIdentityObject.insert(); - JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakSignature(identityManagerSession.session, ownedIdentity, trusted_details.getJsonIdentityDetailsWithVersionAndPhoto().getIdentityDetails().getSignedUserDetails()); + JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakIdentitySignature(identityManagerSession.session, ownedIdentity, trusted_details.getJsonIdentityDetailsWithVersionAndPhoto().getIdentityDetails().getSignedUserDetails()); if (jsonKeycloakUserDetails != null) { contactIdentityObject.setCertifiedByOwnKeycloak(true, null); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/KeycloakServer.java b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/KeycloakServer.java index e5c44c97..7d931f24 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/KeycloakServer.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/KeycloakServer.java @@ -33,12 +33,14 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import io.olvid.engine.Logger; import io.olvid.engine.datatypes.Identity; import io.olvid.engine.datatypes.ObvDatabase; import io.olvid.engine.datatypes.Session; +import io.olvid.engine.datatypes.notifications.IdentityNotifications; import io.olvid.engine.encoder.DecodingException; import io.olvid.engine.identity.datatypes.IdentityManagerSession; @@ -75,6 +77,8 @@ public class KeycloakServer implements ObvDatabase { static final String LATEST_GROUP_UPDATE_TIMESTAMP = "latest_group_update_timestamp"; private String ownApiKey; // the api key given to us by keycloak, non null only for the keycloak server of a managed identity static final String OWN_API_KEY = "own_api_key"; + private boolean transferRestricted; // true if transfer requires a re-authentication, may only be true for the keycloak server of a managed identity + static final String TRANSFER_RESTRICTED = "transfer_restricted"; public String getServerUrl() { return serverUrl; @@ -127,6 +131,10 @@ public String getOwnApiKey() { return ownApiKey; } + public boolean isTransferRestricted() { + return transferRestricted; + } + public List getPushTopics() { if (serializedPushTopics == null) { return new ArrayList<>(0); @@ -156,12 +164,12 @@ public long getLatestGroupUpdateTimestamp() { // region constructors - public static KeycloakServer create(IdentityManagerSession identityManagerSession, String serverUrl, Identity ownedIdentity, String serializedJwks, String serializedKey, String clientId, String clientSecret) { + public static KeycloakServer create(IdentityManagerSession identityManagerSession, String serverUrl, Identity ownedIdentity, String serializedJwks, String serializedKey, String clientId, String clientSecret, boolean transferRestricted) { if (serverUrl == null || ownedIdentity == null || serializedJwks == null) { return null; } try { - KeycloakServer keycloakServer = new KeycloakServer(identityManagerSession, serverUrl, ownedIdentity, serializedJwks, serializedKey, clientId, clientSecret); + KeycloakServer keycloakServer = new KeycloakServer(identityManagerSession, serverUrl, ownedIdentity, serializedJwks, serializedKey, clientId, clientSecret, transferRestricted); keycloakServer.insert(); return keycloakServer; } catch (SQLException e) { @@ -172,7 +180,7 @@ public static KeycloakServer create(IdentityManagerSession identityManagerSessio - public KeycloakServer(IdentityManagerSession identityManagerSession, String serverUrl, Identity ownedIdentity, String serializedJwks, String serializedSignatureKey, String clientId, String clientSecret) { + public KeycloakServer(IdentityManagerSession identityManagerSession, String serverUrl, Identity ownedIdentity, String serializedJwks, String serializedSignatureKey, String clientId, String clientSecret, boolean transferRestricted) { this.identityManagerSession = identityManagerSession; this.serverUrl = serverUrl; this.ownedIdentity = ownedIdentity; @@ -187,6 +195,7 @@ public KeycloakServer(IdentityManagerSession identityManagerSession, String serv this.latestRevocationListTimestamp = 0; this.latestGroupUpdateTimestamp = 0; this.ownApiKey = null; + this.transferRestricted = transferRestricted; } private KeycloakServer(IdentityManagerSession identityManagerSession, ResultSet res) throws SQLException { @@ -208,6 +217,7 @@ private KeycloakServer(IdentityManagerSession identityManagerSession, ResultSet this.latestRevocationListTimestamp = res.getLong(LATEST_REVOCATION_LIST_TIMESTAMP); this.latestGroupUpdateTimestamp = res.getLong(LATEST_GROUP_UPDATE_TIMESTAMP); this.ownApiKey = res.getString(OWN_API_KEY); + this.transferRestricted = res.getBoolean(TRANSFER_RESTRICTED); } // endregion @@ -231,6 +241,7 @@ public static void createTable(Session session) throws SQLException { LATEST_REVOCATION_LIST_TIMESTAMP + " BIGINT NOT NULL, " + LATEST_GROUP_UPDATE_TIMESTAMP + " BIGINT NOT NULL, " + OWN_API_KEY + " TEXT, " + + TRANSFER_RESTRICTED + " BIT NOT NULL, " + " CONSTRAINT PK_" + TABLE_NAME + " PRIMARY KEY(" + SERVER_URL + ", " + OWNED_IDENTITY + "), " + " FOREIGN KEY (" + OWNED_IDENTITY + ") REFERENCES " + OwnedIdentity.TABLE_NAME + " (" + OwnedIdentity.OWNED_IDENTITY + ") ON DELETE CASCADE);"); } @@ -280,11 +291,18 @@ public static void upgradeTable(Session session, int oldVersion, int newVersion) } oldVersion = 35; } + if (oldVersion < 42 && newVersion >= 42) { + Logger.d("MIGRATING `keycloak_server` DATABASE FROM VERSION " + oldVersion + " TO 42"); + try (Statement statement = session.createStatement()) { + statement.execute("ALTER TABLE keycloak_server ADD COLUMN `transfer_restricted` BIT NOT NULL DEFAULT 0;"); + } + oldVersion = 35; + } } @Override public void insert() throws SQLException { - try (PreparedStatement statement = identityManagerSession.session.prepareStatement("INSERT INTO " + TABLE_NAME + " VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?);")) { + try (PreparedStatement statement = identityManagerSession.session.prepareStatement("INSERT INTO " + TABLE_NAME + " VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?);")) { statement.setString(1, serverUrl); statement.setBytes(2, ownedIdentity.getBytes()); statement.setString(3, serializedJwks); @@ -300,6 +318,7 @@ public void insert() throws SQLException { statement.setLong(11, latestRevocationListTimestamp); statement.setLong(12, latestGroupUpdateTimestamp); statement.setString(13, ownApiKey); + statement.setBoolean(14, transferRestricted); statement.executeUpdate(); } } @@ -414,22 +433,22 @@ public void setKeycloakUserId(String userId) throws SQLException { } } - public void setOwnApiKey(String apiKey) throws SQLException { + public void setTransferRestricted(boolean transferRestricted) throws SQLException { try (PreparedStatement statement = identityManagerSession.session.prepareStatement("UPDATE " + TABLE_NAME + - " SET " + OWN_API_KEY + " = ? " + + " SET " + TRANSFER_RESTRICTED + " = ? " + " WHERE " + SERVER_URL + " = ? " + " AND " + OWNED_IDENTITY + " = ?;")) { - statement.setString(1, apiKey); + statement.setBoolean(1, transferRestricted); statement.setString(2, this.serverUrl); statement.setBytes(3, this.ownedIdentity.getBytes()); statement.executeUpdate(); - this.ownApiKey = apiKey; + this.transferRestricted = transferRestricted; } } public void setPushTopics(List pushTopics) throws SQLException { byte[] serializedPushTopics; - if (pushTopics == null || pushTopics.size() == 0) { + if (pushTopics == null || pushTopics.isEmpty()) { serializedPushTopics = null; } else { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { @@ -544,7 +563,7 @@ public static KeycloakServer restore(IdentityManagerSession identityManagerSessi return null; } - KeycloakServer keycloakServer = new KeycloakServer(identityManagerSession, pojo.server_url, ownedIdentity, pojo.jwks, pojo.serialized_signature_key, pojo.client_id, pojo.client_secret); + KeycloakServer keycloakServer = new KeycloakServer(identityManagerSession, pojo.server_url, ownedIdentity, pojo.jwks, pojo.serialized_signature_key, pojo.client_id, pojo.client_secret, false); keycloakServer.keycloakUserId = pojo.keycloak_user_id; keycloakServer.selfRevocationTestNonce = pojo.self_revocation_test_nonce; keycloakServer.insert(); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/OwnedIdentity.java b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/OwnedIdentity.java index 99c1b434..3e88309f 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/OwnedIdentity.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/OwnedIdentity.java @@ -175,7 +175,7 @@ public ObvKeycloakState getKeycloakState() throws SQLException { jwks = null; signatureKey = null; } - return new ObvKeycloakState(keycloakServer.getServerUrl(), keycloakServer.getClientId(), keycloakServer.getClientSecret(), jwks, signatureKey, keycloakServer.getSerializedAuthState(), keycloakServer.getOwnApiKey(), keycloakServer.getLatestRevocationListTimestamp(), keycloakServer.getLatestGroupUpdateTimestamp()); + return new ObvKeycloakState(keycloakServer.getServerUrl(), keycloakServer.getClientId(), keycloakServer.getClientSecret(), jwks, signatureKey, keycloakServer.getSerializedAuthState(), keycloakServer.isTransferRestricted(), keycloakServer.getOwnApiKey(), keycloakServer.getLatestRevocationListTimestamp(), keycloakServer.getLatestGroupUpdateTimestamp()); } } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/ContactSyncSnapshot.java b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/ContactSyncSnapshot.java index 7ca1c15a..f9e64a68 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/ContactSyncSnapshot.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/ContactSyncSnapshot.java @@ -120,7 +120,7 @@ public ContactIdentity restore(IdentityManagerSession identityManagerSession, Id contactIdentityObject.insert(); // check for keycloak badge - JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakSignature(identityManagerSession.session, ownedIdentity, trustedDetails.getJsonIdentityDetailsWithVersionAndPhoto().getIdentityDetails().getSignedUserDetails()); + JsonKeycloakUserDetails jsonKeycloakUserDetails = identityManagerSession.identityDelegate.verifyKeycloakIdentitySignature(identityManagerSession.session, ownedIdentity, trustedDetails.getJsonIdentityDetailsWithVersionAndPhoto().getIdentityDetails().getSignedUserDetails()); if (jsonKeycloakUserDetails != null) { contactIdentityObject.setCertifiedByOwnKeycloak(true, trustedDetails.getSerializedJsonDetails()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/KeycloakSyncSnapshot.java b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/KeycloakSyncSnapshot.java index 67c0c12c..2db27077 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/KeycloakSyncSnapshot.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/identity/databases/sync/KeycloakSyncSnapshot.java @@ -44,7 +44,8 @@ public class KeycloakSyncSnapshot implements ObvSyncSnapshotNode { public static final String JWKS = "jwks"; public static final String SIGNATURE_KEY = "signature_key"; public static final String SELF_REVOCATION_TEST_NONCE = "self_revocation_test_nonce"; - static HashSet DEFAULT_DOMAIN = new HashSet<>(Arrays.asList(SERVER_URL, CLIENT_ID, CLIENT_SECRET, KEYCLOAK_USER_ID, JWKS, SIGNATURE_KEY, SELF_REVOCATION_TEST_NONCE)); + public static final String TRANSFER_RESTRICTED = "transfer_restricted"; + static HashSet DEFAULT_DOMAIN = new HashSet<>(Arrays.asList(SERVER_URL, CLIENT_ID, CLIENT_SECRET, KEYCLOAK_USER_ID, JWKS, SIGNATURE_KEY, SELF_REVOCATION_TEST_NONCE, TRANSFER_RESTRICTED)); public String server_url; @@ -54,6 +55,7 @@ public class KeycloakSyncSnapshot implements ObvSyncSnapshotNode { public String jwks; public String signature_key; public String self_revocation_test_nonce; + public boolean transfer_restricted; public HashSet domain; @@ -66,6 +68,7 @@ public static KeycloakSyncSnapshot of(IdentityManagerSession identityManagerSess keycloakSyncSnapshot.jwks = keycloakServer.getSerializedJwks(); keycloakSyncSnapshot.signature_key = keycloakServer.getSerializedSignatureKey(); keycloakSyncSnapshot.self_revocation_test_nonce = keycloakServer.getSelfRevocationTestNonce(); + keycloakSyncSnapshot.transfer_restricted = keycloakServer.isTransferRestricted(); keycloakSyncSnapshot.domain = DEFAULT_DOMAIN; return keycloakSyncSnapshot; } @@ -81,7 +84,7 @@ public KeycloakServer restore(IdentityManagerSession identityManagerSession, Ide } try { - KeycloakServer keycloakServer = new KeycloakServer(identityManagerSession, server_url, ownedIdentity, jwks, domain.contains(SIGNATURE_KEY) ? signature_key : null, client_id, client_secret); + KeycloakServer keycloakServer = new KeycloakServer(identityManagerSession, server_url, ownedIdentity, jwks, domain.contains(SIGNATURE_KEY) ? signature_key : null, client_id, client_secret, domain.contains(TRANSFER_RESTRICTED) && transfer_restricted); keycloakServer.insert(); keycloakServer.setKeycloakUserId(keycloak_user_id); keycloakServer.setSelfRevocationTestNonce(self_revocation_test_nonce); @@ -149,6 +152,12 @@ public boolean areContentsTheSame(ObvSyncSnapshotNode otherSnapshotNode) { } break; } + case TRANSFER_RESTRICTED: { + if (transfer_restricted ^ other.transfer_restricted) { + return false; + } + break; + } } } return true; diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/metamanager/IdentityDelegate.java b/obv_engine/engine/src/main/java/io/olvid/engine/metamanager/IdentityDelegate.java index f4b45e83..453b7a14 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/metamanager/IdentityDelegate.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/metamanager/IdentityDelegate.java @@ -37,7 +37,6 @@ import io.olvid.engine.datatypes.PreKeyBlobOnServer; import io.olvid.engine.datatypes.containers.EncodedOwnedPreKey; import io.olvid.engine.datatypes.containers.OwnedDeviceAndPreKey; -import io.olvid.engine.datatypes.containers.PreKey; import io.olvid.engine.datatypes.Seed; import io.olvid.engine.datatypes.Session; import io.olvid.engine.datatypes.TrustLevel; @@ -95,7 +94,8 @@ public interface IdentityDelegate { void unCertifyExpiredSignedContactDetails(Session session, Identity ownedIdentity, long latestRevocationListTimestamp); List getKeycloakPushTopics(Session session, Identity ownedIdentity) throws SQLException; void verifyAndAddRevocationList(Session session, Identity ownedIdentity, List signedRevocations) throws Exception; - JsonKeycloakUserDetails verifyKeycloakSignature(Session session, Identity ownedIdentity, String signature); + String verifyKeycloakSignature(Session session, Identity ownedIdentity, String signature); + JsonKeycloakUserDetails verifyKeycloakIdentitySignature(Session session, Identity ownedIdentity, String signature); String getOwnedIdentityKeycloakServerUrl(Session session, Identity ownedIdentity) throws SQLException; void saveKeycloakAuthState(Session session, Identity ownedIdentity, String serializedAuthState) throws SQLException; @@ -105,6 +105,7 @@ public interface IdentityDelegate { void setOwnedIdentityKeycloakUserId(Session session, Identity ownedIdentity, String userId) throws SQLException; void bindOwnedIdentityToKeycloak(Session session, Identity ownedIdentity, String keycloakUserId, ObvKeycloakState keycloakState) throws Exception; int unbindOwnedIdentityFromKeycloak(Session session, Identity ownedIdentity) throws Exception; // return the version of the new details to publish + void updateKeycloakTransferRestrictedIfNeeded(Session session, Identity ownedIdentity, String serverUrl, boolean transferRestricted) throws SQLException; boolean updateKeycloakPushTopicsIfNeeded(Session session, Identity ownedIdentity, String serverUrl, List pushTopics) throws SQLException; void setOwnedIdentityKeycloakSelfRevocationTestNonce(Session session, Identity ownedIdentity, String serverUrl, String nonce) throws SQLException; String getOwnedIdentityKeycloakSelfRevocationTestNonce(Session session, Identity ownedIdentity, String serverUrl) throws SQLException; diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/coordinators/DownloadAttachmentCoordinator.java b/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/coordinators/DownloadAttachmentCoordinator.java index 6f285089..40e3a095 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/coordinators/DownloadAttachmentCoordinator.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/coordinators/DownloadAttachmentCoordinator.java @@ -108,8 +108,15 @@ public void initialQueueing() { InboxAttachment[] attachmentsToResume = InboxAttachment.getAllAttachmentsToResume(fetchManagerSession); for (InboxAttachment inboxAttachment: attachmentsToResume) { queueNewDownloadAttachmentOperation(inboxAttachment.getOwnedIdentity(), inboxAttachment.getMessageUid(), inboxAttachment.getAttachmentNumber(), inboxAttachment.getPriorityCategory(), inboxAttachment.getPriority()); + // post an initial progress value so the app directly has a progress to show, even if download does not progress + fetchManagerSession.inboxAttachmentListener.attachmentDownloadProgressed(inboxAttachment.getOwnedIdentity(), inboxAttachment.getMessageUid(), inboxAttachment.getAttachmentNumber(), inboxAttachment.getProgress()); + } + + InboxAttachment[] attachmentsNotToResume = InboxAttachment.getAllPartialAttachmentsNotToResume(fetchManagerSession); + for (InboxAttachment inboxAttachment: attachmentsNotToResume) { + // also post a progress value for attachments that won't be downloaded + fetchManagerSession.inboxAttachmentListener.attachmentDownloadProgressed(inboxAttachment.getOwnedIdentity(), inboxAttachment.getMessageUid(), inboxAttachment.getAttachmentNumber(), inboxAttachment.getProgress()); } - fetchManagerSession.session.commit(); } catch (Exception e) { Logger.x(e); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/databases/InboxAttachment.java b/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/databases/InboxAttachment.java index 6a142b5f..1d45fc61 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/databases/InboxAttachment.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/databases/InboxAttachment.java @@ -536,6 +536,26 @@ public static InboxAttachment[] getAllAttachmentsToResume(FetchManagerSession fe } } + public static InboxAttachment[] getAllPartialAttachmentsNotToResume(FetchManagerSession fetchManagerSession) { + try (PreparedStatement statement = fetchManagerSession.session.prepareStatement( + "SELECT * FROM " + TABLE_NAME + + " WHERE " + DOWNLOAD_REQUESTED + " = 0 " + + " AND " + KEY + " NOT NULL " + + " AND " + RECEIVED_LENGTH + " < " + EXPECTED_LENGTH + + " AND " + RECEIVED_LENGTH + " > 0 " + + " AND " + MARKED_FOR_DELETION + " = 0;")) { + try (ResultSet res = statement.executeQuery()) { + List list = new ArrayList<>(); + while (res.next()) { + list.add(new InboxAttachment(fetchManagerSession, res)); + } + return list.toArray(new InboxAttachment[0]); + } + } catch (SQLException e) { + return new InboxAttachment[0]; + } + } + // endregion // region database diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/operations/DownloadAttachmentOperation.java b/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/operations/DownloadAttachmentOperation.java index 748a5902..f6897612 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/operations/DownloadAttachmentOperation.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/networkfetch/operations/DownloadAttachmentOperation.java @@ -135,7 +135,7 @@ public void doExecute() { cancel(RFC_INVALID_SIGNED_URL); return; } - if (attachment.getChunkDownloadPrivateUrls()[attachment.getReceivedChunkCount()].length() == 0) { + if (attachment.getChunkDownloadPrivateUrls()[attachment.getReceivedChunkCount()].isEmpty()) { cancel(RFC_UPLOAD_CANCELLED_BY_SENDER); return; } @@ -144,7 +144,7 @@ public void doExecute() { attachment.getChunkDownloadPrivateUrls()[attachment.getReceivedChunkCount()] ); serverMethod.setSslSocketFactory(sslSocketFactory); - serverMethod.setProgressListener(200, new ServerMethodForS3.ServerMethodForS3ProgressListener() { + serverMethod.setProgressListener(150, new ServerMethodForS3.ServerMethodForS3ProgressListener() { final HashMap userInfo; { userInfo = new HashMap<>(); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/networksend/coordinators/SendAttachmentCoordinator.java b/obv_engine/engine/src/main/java/io/olvid/engine/networksend/coordinators/SendAttachmentCoordinator.java index 9277e206..bd1ac4d3 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/networksend/coordinators/SendAttachmentCoordinator.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/networksend/coordinators/SendAttachmentCoordinator.java @@ -103,6 +103,7 @@ public void initialQueueing() { for (OutboxAttachment attachment : message.getAttachments()) { if (!attachment.isAcknowledged()) { queueNewSendAttachmentCompositeOperation(attachment.getOwnedIdentity(), attachment.getMessageUid(), attachment.getAttachmentNumber(), attachment.getPriority()); + } } } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/networksend/operations/UploadAttachmentOperation.java b/obv_engine/engine/src/main/java/io/olvid/engine/networksend/operations/UploadAttachmentOperation.java index 667deba9..46e1d389 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/networksend/operations/UploadAttachmentOperation.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/networksend/operations/UploadAttachmentOperation.java @@ -155,7 +155,7 @@ public void doExecute() { authEnc.encrypt(outboxAttachment.getKey(), Encoded.encodeChunk(chunkNumber, buffer, bufferFullness), prng)); serverMethod.setSslSocketFactory(sslSocketFactory); - serverMethod.setProgressListener(100, new ServerMethodForS3.ServerMethodForS3ProgressListener() { + serverMethod.setProgressListener(150, new ServerMethodForS3.ServerMethodForS3ProgressListener() { final HashMap userInfo; final long totalLength; final long chunkLength; diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/ProtocolManager.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/ProtocolManager.java index 8cd5011f..a8509553 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/ProtocolManager.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/ProtocolManager.java @@ -530,8 +530,7 @@ public void startDeviceDiscoveryProtocol(Identity ownedIdentity, Identity contac UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); protocolManagerSession.session.commit(); @@ -548,8 +547,7 @@ public void startDeviceDiscoveryProtocolWithinTransaction(Session session, Ident UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); } @@ -560,8 +558,7 @@ public void startOwnedDeviceDiscoveryProtocol(Identity ownedIdentity) throws Exc UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.OWNED_DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedDeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); protocolManagerSession.session.commit(); @@ -574,8 +571,7 @@ public void startOwnedDeviceDiscoveryProtocolWithinTransaction(Session session, UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.OWNED_DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedDeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(session, message, prng); } @@ -586,8 +582,7 @@ public void startChannelCreationProtocolWithOwnedDevice(Session session, Identit UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CHANNEL_CREATION_WITH_OWNED_DEVICE_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ChannelCreationWithOwnedDeviceProtocol.InitialMessage(coreProtocolMessage, ownedDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(session, message, prng); } @@ -602,8 +597,7 @@ public void startChannelCreationProtocolWithContactDevice(Session session, Ident UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CHANNEL_CREATION_WITH_CONTACT_DEVICE_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ChannelCreationWithContactDeviceProtocol.InitialMessage(coreProtocolMessage, contactIdentity, contactDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(session, message, prng); } @@ -617,8 +611,7 @@ public void startDownloadIdentityPhotoProtocolWithinTransaction(Session session, UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, contactIdentity, jsonObjectMapper.writeValueAsString(jsonIdentityDetailsWithVersionAndPhoto)).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); } @@ -637,8 +630,7 @@ public void startDownloadGroupPhotoProtocolWithinTransaction(Session session, Id UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.DOWNLOAD_GROUP_PHOTO_CHILD_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new DownloadGroupPhotoChildProtocol.InitialMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); } @@ -653,8 +645,7 @@ public void startDownloadGroupV2PhotoProtocolWithinTransaction(Session session, UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.DOWNLOAD_GROUPS_V2_PHOTO_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new DownloadGroupV2PhotoProtocol.InitialMessage(coreProtocolMessage, groupIdentifier, serverPhotoInfo).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); } @@ -674,8 +665,7 @@ public void initiateGroupV2ReDownloadWithinTransaction(Session session, Identity CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.GroupReDownloadInitialMessage(coreProtocolMessage, groupIdentifier).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); @@ -692,8 +682,7 @@ public void initiateKeycloakGroupV2TargetedPing(Session session, Identity ownedI CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.InitiateTargetedPingMessage(coreProtocolMessage, groupIdentifier, contactIdentity).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); @@ -708,8 +697,7 @@ private void startTrustEstablishmentWithSasProtocol(Identity contactIdentity, St UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.TRUST_ESTABLISHMENT_WITH_SAS_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); String ownedIdentityDetails = identityDelegate.getSerializedPublishedDetailsOfOwnedIdentity(protocolManagerSession.session, ownedIdentity); if (ownedIdentityDetails == null) { Logger.e("Error finding own identity details in startTrustEstablishmentProtocol"); @@ -731,8 +719,7 @@ public void startMutualScanTrustEstablishmentProtocol(Identity ownedIdentity, Id UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.TRUST_ESTABLISHMENT_WITH_MUTUAL_SCAN_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new TrustEstablishmentWithMutualScanProtocol.InitialMessage(coreProtocolMessage, contactIdentity, signature).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -750,8 +737,7 @@ private void startChannelCreationWithContactDeviceProtocol(Identity ownedIdentit UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CHANNEL_CREATION_WITH_CONTACT_DEVICE_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ChannelCreationWithContactDeviceProtocol.InitialMessage(coreProtocolMessage, contactIdentity, contactDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); protocolManagerSession.session.commit(); @@ -763,8 +749,7 @@ public void startChannelCreationWithOwnedDeviceProtocol(Identity ownedIdentity, UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CHANNEL_CREATION_WITH_OWNED_DEVICE_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ChannelCreationWithOwnedDeviceProtocol.InitialMessage(coreProtocolMessage, ownedDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); protocolManagerSession.session.commit(); @@ -787,8 +772,7 @@ public void startContactMutualIntroductionProtocol(Identity ownedIdentity, Ident UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CONTACT_MUTUAL_INTRODUCTION_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ContactMutualIntroductionProtocol.InitialMessage(coreProtocolMessage, contactIdentityA, contactIdentityB).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); } @@ -814,8 +798,7 @@ public void startGroupCreationProtocol(Identity ownedIdentity, String serialized CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.InitiateGroupCreationMessage(coreProtocolMessage, groupInformation, absolutePhotoUrl, groupMemberIdentitiesAndSerializedDetails).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -844,8 +827,7 @@ public void startGroupV2CreationProtocol(Identity ownedIdentity, String serializ CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.GroupCreationInitialMessage(coreProtocolMessage, ownPermissions, otherGroupMembers, serializedGroupDetails, absolutePhotoUrl, serializedGroupType).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -864,8 +846,7 @@ public void initiateGroupV2Update(Identity ownedIdentity, GroupV2.Identifier gro CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.GroupUpdateInitialMessage(coreProtocolMessage, groupIdentifier, changeSet).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -884,8 +865,7 @@ public void initiateGroupV2Leave(Identity ownedIdentity, GroupV2.Identifier grou CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.GroupLeaveInitialMessage(coreProtocolMessage, groupIdentifier).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -904,8 +884,7 @@ public void initiateGroupV2Disband(Identity ownedIdentity, GroupV2.Identifier gr CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.GroupDisbandInitialMessage(coreProtocolMessage, groupIdentifier).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -925,8 +904,7 @@ public void initiateGroupV2ReDownload(Identity ownedIdentity, GroupV2.Identifier CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.GroupReDownloadInitialMessage(coreProtocolMessage, groupIdentifier).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -943,8 +921,7 @@ public void initiateGroupV2BatchKeysResend(Session session, Identity ownedIdenti UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.InitiateBatchKeysResendMessage(coreProtocolMessage, contactIdentity, contactDeviceUid).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); } @@ -958,8 +935,7 @@ public void createOrUpdateKeycloakGroupV2(Session session, Identity ownedIdentit UID protocolInstanceUid = groupIdentifier.computeProtocolInstanceUid(); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupsV2Protocol.CreateOrUpdateKeycloakGroupMessage(coreProtocolMessage, groupIdentifier, serializedKeycloakGroupBlob).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); } @@ -982,8 +958,7 @@ public void processDeviceManagementRequest(Session session, Identity ownedIdenti UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.OWNED_DEVICE_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedDeviceManagementProtocol.InitialMessage(coreProtocolMessage, deviceManagementRequest).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); } @@ -997,8 +972,7 @@ public void startIdentityDetailsPublicationProtocol(Session session, Identity ow UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.IDENTITY_DETAILS_PUBLICATION_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new IdentityDetailsPublicationProtocol.InitialMessage(coreProtocolMessage, version).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); } @@ -1017,9 +991,7 @@ public void startGroupDetailsPublicationProtocol(Session session, Identity owned CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false - ); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.GroupMembersOrDetailsChangedTriggerMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); } @@ -1034,8 +1006,7 @@ public void startOneToOneInvitationProtocol(Identity ownedIdentity, Identity con UID protocolInstanceUid = new UID(prng); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.ONE_TO_ONE_CONTACT_INVITATION_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OneToOneContactInvitationProtocol.InitialMessage(coreProtocolMessage, contactIdentity).generateChannelProtocolMessageToSend(); channelDelegate.post(protocolManagerSession.session, message, prng); protocolManagerSession.session.commit(); @@ -1080,8 +1051,7 @@ public void inviteContactsToGroup(byte[] groupOwnerAndUid, Identity ownedIdentit CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.AddGroupMembersMessage(coreProtocolMessage, groupInformation, newMembersIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1112,8 +1082,7 @@ public void reinvitePendingToGroup(byte[] groupOwnerAndUid, Identity ownedIdenti CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.ReinvitePendingMemberMessage(coreProtocolMessage, groupInformation, pendingMemberIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1154,8 +1123,7 @@ public void removeContactsFromGroup(byte[] groupOwnerAndUid, Identity ownedIdent CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.RemoveGroupMembersMessage(coreProtocolMessage, groupInformation, removedMemberIdentities).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1187,8 +1155,7 @@ public void leaveGroup(byte[] groupOwnerAndUid, Identity ownedIdentity) throws E CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.LeaveGroupMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1219,8 +1186,7 @@ public void disbandGroup(byte[] groupOwnerAndUid, Identity ownedIdentity) throws CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.DisbandGroupMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1250,8 +1216,7 @@ public void queryGroupMembers(byte[] groupOwnerAndUid, Identity ownedIdentity) t CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.InitiateGroupMembersQueryMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1283,8 +1248,7 @@ public void reinviteAndPushMembersToContact(byte[] groupOwnerAndUid, Identity ow CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.TriggerReinviteMessage(coreProtocolMessage, groupInformation, contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1309,8 +1273,7 @@ public void deleteContact(Identity ownedIdentity, Identity contactIdentity) thro CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CONTACT_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ContactManagementProtocol.InitiateContactDeletionMessage(coreProtocolMessage, contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1334,8 +1297,7 @@ public void downgradeOneToOneContact(Identity ownedIdentity, Identity contactIde CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.CONTACT_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new ContactManagementProtocol.InitiateContactDowngradeMessage(coreProtocolMessage, contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1354,8 +1316,7 @@ public void addKeycloakContact(Identity ownedIdentity, Identity contactIdentity, CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.KEYCLOAK_CONTACT_ADDITION_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new KeycloakContactAdditionProtocol.InitialMessage(coreProtocolMessage, contactIdentity, signedContactDetails).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1377,8 +1338,7 @@ public void startProtocolForBindingOwnedIdentityToKeycloakWithinTransaction(Sess CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.KEYCLOAK_BINDING_AND_UNBINDING_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new KeycloakBindingAndUnbindingProtocol.OwnedIdentityKeycloakBindingMessage(coreProtocolMessage, keycloakState, keycloakUserId).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); @@ -1394,8 +1354,7 @@ public void updateCurrentDeviceCapabilitiesForOwnedIdentity(Session session, Ide CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new DeviceCapabilitiesDiscoveryProtocol.InitialForAddingOwnCapabilitiesMessage(coreProtocolMessage, newOwnCapabilities).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); @@ -1412,8 +1371,7 @@ public void startProtocolForUnbindingOwnedIdentityFromKeycloak(Identity ownedIde CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.KEYCLOAK_BINDING_AND_UNBINDING_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new KeycloakBindingAndUnbindingProtocol.OwnedIdentityKeycloakUnbindingMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1431,8 +1389,7 @@ public void startOwnedIdentityDeletionProtocol(Session session, Identity ownedId CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.OWNED_IDENTITY_DELETION_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedIdentityDeletionProtocol.InitialMessage(coreProtocolMessage, deleteEverywhere).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); @@ -1449,8 +1406,7 @@ public void initiateSingleItemSync(Session session, Identity ownedIdentity, ObvS CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.SYNCHRONIZATION_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new SynchronizationProtocol.InitiateSingleItemSyncMessage(coreProtocolMessage, obvSyncAtom).generateChannelProtocolMessageToSend(); channelDelegate.post(session, message, prng); @@ -1484,8 +1440,7 @@ public void initiateOwnedIdentityTransferProtocolOnSourceDevice(Identity ownedId CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.OWNED_IDENTITY_TRANSFER_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedIdentityTransferProtocol.InitiateTransferOnSourceDeviceMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1509,8 +1464,7 @@ public void initiateOwnedIdentityTransferProtocolOnTargetDevice(String deviceNam CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ephemeralIdentity), ConcreteProtocol.OWNED_IDENTITY_TRANSFER_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedIdentityTransferProtocol.InitiateTransferOnTargetDeviceMessage(coreProtocolMessage, deviceName, (ServerAuthenticationPrivateKey) serverAuthKeyPair.getPrivateKey(), (EncryptionPrivateKey) encryptionKeyPair.getPrivateKey(), macKey).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); @@ -1532,7 +1486,8 @@ public void startFullRatchetProtocolForObliviousChannel(UID currentDeviceUid, UI CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(ownedIdentity), ConcreteProtocol.FULL_RATCHET_PROTOCOL_ID, protocolInstanceUid, - true); + true, + false); ChannelMessageToSend message = new FullRatchetProtocol.InitialMessage(coreProtocolMessage, remoteIdentity, remoteDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, prng); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/coordinators/ProtocolStepCoordinator.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/coordinators/ProtocolStepCoordinator.java index 6665eb46..51b56bb3 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/coordinators/ProtocolStepCoordinator.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/coordinators/ProtocolStepCoordinator.java @@ -165,7 +165,7 @@ public void onCancelCallback(Operation operation) { ReceivedMessage message = ReceivedMessage.get(protocolManagerSession, ((ProtocolOperation) operation).getReceivedMessageUid()); message.delete(); - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createUserInterfaceChannelInfo(message.getToIdentity(), DialogType.createDeleteDialog(), message.getUserDialogUuid()), message.getProtocolId(), message.getProtocolInstanceUid(), false); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createUserInterfaceChannelInfo(message.getToIdentity(), DialogType.createDeleteDialog(), message.getUserDialogUuid()), message.getProtocolId(), message.getProtocolInstanceUid()); ChannelMessageToSend messageToSend = new OneWayDialogProtocolMessage(coreProtocolMessage).generateChannelDialogMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, prng); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/LinkBetweenProtocolInstances.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/LinkBetweenProtocolInstances.java index 6d2d5aa4..f672642d 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/LinkBetweenProtocolInstances.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/LinkBetweenProtocolInstances.java @@ -244,6 +244,7 @@ public static GenericProtocolMessageToSend getGenericProtocolMessageToSendWhenCh parentProtocolInstance.getUid(), linkBetweenProtocolInstances.messageToSendId, inputs, + false, false); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/WaitingForOneToOneContactProtocolInstance.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/WaitingForOneToOneContactProtocolInstance.java index 36d44231..ba16504d 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/WaitingForOneToOneContactProtocolInstance.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/databases/WaitingForOneToOneContactProtocolInstance.java @@ -260,6 +260,7 @@ public GenericProtocolMessageToSend getGenericProtocolMessageToSendWhenTrustLeve protocolUid, messageId, new Encoded[]{Encoded.of(contactIdentity)}, + false, false); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/CoreProtocolMessage.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/CoreProtocolMessage.java index 8ee125f7..163d120a 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/CoreProtocolMessage.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/CoreProtocolMessage.java @@ -33,6 +33,7 @@ public class CoreProtocolMessage { private final int protocolId; private final UID protocolInstanceUid; private final boolean partOfFullRatchetProtocolOfTheSendSeed; + private final boolean hasUserContent; private final long serverTimestamp; public CoreProtocolMessage(ReceivedMessage message) { @@ -42,16 +43,29 @@ public CoreProtocolMessage(ReceivedMessage message) { this.protocolId = message.getProtocolId(); this.protocolInstanceUid = message.getProtocolInstanceUid(); this.partOfFullRatchetProtocolOfTheSendSeed = false; + this.hasUserContent = false; this.serverTimestamp = message.getServerTimestamp(); } - public CoreProtocolMessage(SendChannelInfo sendChannelInfo, int protocolId, UID protocolInstanceUid, boolean partOfFullRatchetProtocolOfTheSendSeed) { + public CoreProtocolMessage(SendChannelInfo sendChannelInfo, int protocolId, UID protocolInstanceUid) { + this.sendChannelInfo = sendChannelInfo; + this.receptionChannelInfo = null; + this.toIdentity = null; + this.protocolId = protocolId; + this.protocolInstanceUid = protocolInstanceUid; + this.partOfFullRatchetProtocolOfTheSendSeed = false; + this.hasUserContent = false; + this.serverTimestamp = System.currentTimeMillis(); + } + + public CoreProtocolMessage(SendChannelInfo sendChannelInfo, int protocolId, UID protocolInstanceUid, boolean partOfFullRatchetProtocolOfTheSendSeed, boolean hasUserContent) { this.sendChannelInfo = sendChannelInfo; this.receptionChannelInfo = null; this.toIdentity = null; this.protocolId = protocolId; this.protocolInstanceUid = protocolInstanceUid; this.partOfFullRatchetProtocolOfTheSendSeed = partOfFullRatchetProtocolOfTheSendSeed; + this.hasUserContent = hasUserContent; this.serverTimestamp = System.currentTimeMillis(); } @@ -79,6 +93,10 @@ public boolean isPartOfFullRatchetProtocolOfTheSendSeed() { return partOfFullRatchetProtocolOfTheSendSeed; } + public boolean hasUserContent() { + return hasUserContent; + } + public long getServerTimestamp() { return serverTimestamp; } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/GenericProtocolMessageToSend.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/GenericProtocolMessageToSend.java index ef4bb4f3..997e89dc 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/GenericProtocolMessageToSend.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/datatypes/GenericProtocolMessageToSend.java @@ -31,11 +31,13 @@ public class GenericProtocolMessageToSend { private final SendChannelInfo sendChannelInfo; private final Encoded encodedElements; private final boolean partOfFullRatchetProtocolOfTheSendSeed; + private final boolean hasUserContent; - public GenericProtocolMessageToSend(SendChannelInfo sendChannelInfo, int protocolId, UID protocolInstanceUid, int protocolMessageId, Encoded[] inputs, boolean partOfFullRatchetProtocolOfTheSendSeed) { + public GenericProtocolMessageToSend(SendChannelInfo sendChannelInfo, int protocolId, UID protocolInstanceUid, int protocolMessageId, Encoded[] inputs, boolean partOfFullRatchetProtocolOfTheSendSeed, boolean hasUserContent) { this.sendChannelInfo = sendChannelInfo; this.encodedElements = encode(protocolId, protocolInstanceUid, protocolMessageId, inputs); this.partOfFullRatchetProtocolOfTheSendSeed = partOfFullRatchetProtocolOfTheSendSeed; + this.hasUserContent = hasUserContent; } private static Encoded encode(int protocolId, UID protocolInstanceUid, int protocolMessageId, Encoded[] inputs) { @@ -56,7 +58,7 @@ public ChannelProtocolMessageToSend generateChannelProtocolMessageToSend() { case SendChannelInfo.ASYMMETRIC_BROADCAST_CHANNEL_TYPE: case SendChannelInfo.ALL_OWNED_CONFIRMED_OBLIVIOUS_CHANNELS_OR_PRE_KEY_TYPE: case SendChannelInfo.OBLIVIOUS_CHANNEL_OR_PRE_KEY_TYPE: - return new ChannelProtocolMessageToSend(sendChannelInfo, encodedElements, partOfFullRatchetProtocolOfTheSendSeed); + return new ChannelProtocolMessageToSend(sendChannelInfo, encodedElements, partOfFullRatchetProtocolOfTheSendSeed, hasUserContent); default: return null; } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ConcreteProtocolMessage.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ConcreteProtocolMessage.java index 31baed46..e88a37ff 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ConcreteProtocolMessage.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ConcreteProtocolMessage.java @@ -69,7 +69,8 @@ public GenericProtocolMessageToSend generateGenericProtocolMessageToSend() { coreProtocolMessage.getProtocolInstanceUid(), getProtocolMessageId(), getInputs(), - coreProtocolMessage.isPartOfFullRatchetProtocolOfTheSendSeed()); + coreProtocolMessage.isPartOfFullRatchetProtocolOfTheSendSeed(), + coreProtocolMessage.hasUserContent()); } public ChannelProtocolMessageToSend generateChannelProtocolMessageToSend() { diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ProtocolStep.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ProtocolStep.java index e50bb0fd..de81c215 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ProtocolStep.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocol_engine/ProtocolStep.java @@ -108,7 +108,7 @@ public int getProtocolId() { public abstract ConcreteProtocolState executeStep() throws Exception; public CoreProtocolMessage buildCoreProtocolMessage(SendChannelInfo sendChannelInfo) { - return new CoreProtocolMessage(sendChannelInfo, getProtocolId(), getProtocolInstanceUid(), false); + return new CoreProtocolMessage(sendChannelInfo, getProtocolId(), getProtocolInstanceUid()); } } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithContactDeviceProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithContactDeviceProtocol.java index c92db261..715f4676 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithContactDeviceProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithContactDeviceProtocol.java @@ -888,9 +888,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), CHANNEL_CREATION_WITH_CONTACT_DEVICE_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ChannelCreationWithContactDeviceProtocol.InitialMessage(coreProtocolMessage, receivedMessage.contactIdentity, receivedMessage.contactDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -971,8 +969,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (protocolManagerSession.identityDelegate.addDeviceForContactIdentity(protocolManagerSession.session, getOwnedIdentity(), startState.contactIdentity, startState.contactDeviceUid, null, true)) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -986,9 +983,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), CHANNEL_CREATION_WITH_CONTACT_DEVICE_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ChannelCreationWithContactDeviceProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity, startState.contactDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -1046,8 +1041,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (protocolManagerSession.identityDelegate.addDeviceForContactIdentity(protocolManagerSession.session, getOwnedIdentity(), startState.contactIdentity, startState.contactDeviceUid, null, true)) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1061,9 +1055,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), CHANNEL_CREATION_WITH_CONTACT_DEVICE_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ChannelCreationWithContactDeviceProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity, startState.contactDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -1130,9 +1122,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity, protocol.getJsonObjectMapper().writeValueAsString(newDetails)).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1159,9 +1149,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new DeviceCapabilitiesDiscoveryProtocol.InitialSingleContactDeviceMessage(coreProtocolMessage, startState.contactIdentity, startState.contactDeviceUid, false).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1202,9 +1190,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ONE_TO_ONE_CONTACT_INVITATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new OneToOneContactInvitationProtocol.InitiateOneToOneStatusSyncWithOneContactMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1241,9 +1227,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity, protocol.getJsonObjectMapper().writeValueAsString(newDetails)).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1270,9 +1254,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new DeviceCapabilitiesDiscoveryProtocol.InitialSingleContactDeviceMessage(coreProtocolMessage, startState.contactIdentity, startState.contactDeviceUid, false).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithOwnedDeviceProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithOwnedDeviceProtocol.java index 5ae4766c..6014ddee 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithOwnedDeviceProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ChannelCreationWithOwnedDeviceProtocol.java @@ -866,9 +866,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), CHANNEL_CREATION_WITH_OWNED_DEVICE_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ChannelCreationWithOwnedDeviceProtocol.InitialMessage(coreProtocolMessage, receivedMessage.remoteDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -945,8 +943,7 @@ public ConcreteProtocolState executeStep() throws Exception { UID protocolInstanceUid = new UID(getPrng()); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.OWNED_DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedDeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, getPrng()); } catch (Exception e) { @@ -959,9 +956,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), CHANNEL_CREATION_WITH_OWNED_DEVICE_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ChannelCreationWithOwnedDeviceProtocol.InitialMessage(coreProtocolMessage, startState.remoteDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -1016,8 +1011,7 @@ public ConcreteProtocolState executeStep() throws Exception { UID protocolInstanceUid = new UID(getPrng()); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.OWNED_DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedDeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, getPrng()); } catch (Exception e) { @@ -1030,9 +1024,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), CHANNEL_CREATION_WITH_OWNED_DEVICE_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ChannelCreationWithOwnedDeviceProtocol.InitialMessage(coreProtocolMessage, startState.remoteDeviceUid).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -1098,9 +1090,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, getOwnedIdentity(), receivedMessage.remoteSerializedIdentityWithVersionAndPhoto).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1126,9 +1116,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new DeviceCapabilitiesDiscoveryProtocol.InitialSingleOwnedDeviceMessage(coreProtocolMessage, startState.remoteDeviceUid, false).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1206,9 +1194,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, getOwnedIdentity(), receivedMessage.remoteSerializedIdentityWithVersionAndPhoto).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1234,9 +1220,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new DeviceCapabilitiesDiscoveryProtocol.InitialSingleOwnedDeviceMessage(coreProtocolMessage, startState.remoteDeviceUid, false).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactManagementProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactManagementProtocol.java index b8a58c8d..9f58141a 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactManagementProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactManagementProtocol.java @@ -388,8 +388,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - groupInformation.computeProtocolUid(), - false); + groupInformation.computeProtocolUid()); ChannelMessageToSend messageToSend = new GroupManagementProtocol.RemoveGroupMembersMessage(coreProtocolMessage, groupInformation, removedMemberIdentities).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -474,8 +473,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, - groupInformation.computeProtocolUid(), - false); + groupInformation.computeProtocolUid()); ChannelMessageToSend messageToSend = new GroupManagementProtocol.RemoveGroupMembersMessage(coreProtocolMessage, groupInformation, removedMemberIdentities).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -597,8 +595,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend message = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, receivedMessage.getReceptionChannelInfo().getRemoteIdentity()).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, getPrng()); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactMutualIntroductionProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactMutualIntroductionProtocol.java index 2d77c567..693d2142 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactMutualIntroductionProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/ContactMutualIntroductionProtocol.java @@ -661,7 +661,7 @@ public ConcreteProtocolState executeStep() throws Exception { { // post an invitation message to contact A String serializedDetailsB = protocolManagerSession.identityDelegate.getSerializedPublishedDetailsOfContactIdentity(protocolManagerSession.session, getOwnedIdentity(), receivedMessage.contactIdentityB); - CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(receivedMessage.contactIdentityA, getOwnedIdentity())); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(receivedMessage.contactIdentityA, getOwnedIdentity()), getProtocolId(), getProtocolInstanceUid(), false, true); ChannelMessageToSend messageToSend = new MediatorInvitationMessage(coreProtocolMessage, receivedMessage.contactIdentityB, serializedDetailsB).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -669,7 +669,7 @@ public ConcreteProtocolState executeStep() throws Exception { { // post an invitation message to contact B String serializedDetailsA = protocolManagerSession.identityDelegate.getSerializedPublishedDetailsOfContactIdentity(protocolManagerSession.session, getOwnedIdentity(), receivedMessage.contactIdentityA); - CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(receivedMessage.contactIdentityB, getOwnedIdentity())); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(receivedMessage.contactIdentityB, getOwnedIdentity()), getProtocolId(), getProtocolInstanceUid(), false, true); ChannelMessageToSend messageToSend = new MediatorInvitationMessage(coreProtocolMessage, receivedMessage.contactIdentityA, serializedDetailsA).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1045,8 +1045,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1104,8 +1103,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceCapabilitiesDiscoveryProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceCapabilitiesDiscoveryProtocol.java index cae5db89..c5f4b81f 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceCapabilitiesDiscoveryProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceCapabilitiesDiscoveryProtocol.java @@ -390,9 +390,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ONE_TO_ONE_CONTACT_INVITATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new OneToOneContactInvitationProtocol.InitiateOneToOneStatusSyncWithAllContactsMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -518,9 +516,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new InitialSingleContactDeviceMessage(coreProtocolMessage, receivedMessage.getReceptionChannelInfo().getRemoteIdentity(), receivedMessage.getReceptionChannelInfo().getRemoteDeviceUid(), true).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -558,9 +554,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_CAPABILITIES_DISCOVERY_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new InitialSingleOwnedDeviceMessage(coreProtocolMessage, receivedMessage.getReceptionChannelInfo().getRemoteDeviceUid(), true).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceDiscoveryProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceDiscoveryProtocol.java index 98a0a87a..55979ec1 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceDiscoveryProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/DeviceDiscoveryProtocol.java @@ -289,9 +289,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_DISCOVERY_CHILD_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new DeviceDiscoveryChildProtocol.InitialMessage(coreProtocolMessage, receivedMessage.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/FullRatchetProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/FullRatchetProtocol.java index 36b93d41..7707c09b 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/FullRatchetProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/FullRatchetProtocol.java @@ -500,7 +500,7 @@ public ConcreteProtocolState executeStep() throws Exception { throw new Exception(); } - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createObliviousChannelInfo(receivedMessage.contactIdentity, getOwnedIdentity(), new UID[]{receivedMessage.contactDeviceUid}, true), getProtocolId(), getProtocolInstanceUid(), true); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createObliviousChannelInfo(receivedMessage.contactIdentity, getOwnedIdentity(), new UID[]{receivedMessage.contactDeviceUid}, true), getProtocolId(), getProtocolInstanceUid(), true, false); ChannelMessageToSend messageToSend = new AliceEphemeralKeyMessage(coreProtocolMessage, (EncryptionPublicKey) keyPair.getPublicKey(), restartCounter).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -546,7 +546,7 @@ public ConcreteProtocolState executeStep() throws Exception { throw new Exception(); } - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createObliviousChannelInfo(receivedMessage.contactIdentity, getOwnedIdentity(), new UID[]{receivedMessage.contactDeviceUid}, true), getProtocolId(), getProtocolInstanceUid(), true); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createObliviousChannelInfo(receivedMessage.contactIdentity, getOwnedIdentity(), new UID[]{receivedMessage.contactDeviceUid}, true), getProtocolId(), getProtocolInstanceUid(), true, false); ChannelMessageToSend messageToSend = new AliceEphemeralKeyMessage(coreProtocolMessage, (EncryptionPublicKey) keyPair.getPublicKey(), restartCounter).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -646,7 +646,7 @@ public ConcreteProtocolState executeStep() throws Exception { Seed seed = Seed.of(k1, k2); - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createObliviousChannelInfo(startState.contactIdentity, getOwnedIdentity(), new UID[]{startState.contactDeviceUid}, true), getProtocolId(), getProtocolInstanceUid(), true); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createObliviousChannelInfo(startState.contactIdentity, getOwnedIdentity(), new UID[]{startState.contactDeviceUid}, true), getProtocolId(), getProtocolInstanceUid(), true, false); ChannelMessageToSend messageToSend = new AliceK2Message(coreProtocolMessage, c2, startState.restartCounter).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupInvitationProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupInvitationProtocol.java index 07101b85..e7f254da 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupInvitationProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupInvitationProtocol.java @@ -747,9 +747,7 @@ public void callback() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUP_MANAGEMENT_PROTOCOL_ID, - childProtocolUid, - false - ); + childProtocolUid); ChannelMessageToSend messageToSend = new GroupManagementProtocol.GroupMembersOrDetailsChangedTriggerMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -766,9 +764,7 @@ public void callback() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(contactIdentity, getOwnedIdentity()), GROUP_MANAGEMENT_PROTOCOL_ID, - groupManagementProtocolUid, - false - ); + groupManagementProtocolUid); ChannelMessageToSend messageToSend = new GroupManagementProtocol.KickFromGroupMessage(coreProtocolMessage, new GroupInformation(getOwnedIdentity(), receivedMessage.groupUid, JsonGroupDetailsWithVersionAndPhoto.DUMMY_GROUP_DETAILS)).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } else if (!receivedMessage.invitationAccepted && group != null && group.isMember(contactIdentity)){ @@ -784,9 +780,7 @@ public void callback() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(contactIdentity, getOwnedIdentity()), GROUP_MANAGEMENT_PROTOCOL_ID, - groupManagementProtocolUid, - false - ); + groupManagementProtocolUid); ChannelMessageToSend messageToSend = new GroupManagementProtocol.KickFromGroupMessage(coreProtocolMessage, new GroupInformation(getOwnedIdentity(), receivedMessage.groupUid, JsonGroupDetailsWithVersionAndPhoto.DUMMY_GROUP_DETAILS)).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } else if (receivedMessage.invitationAccepted && group.isMember(contactIdentity)) { @@ -796,8 +790,7 @@ public void callback() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUP_MANAGEMENT_PROTOCOL_ID, - groupManagementProtocolUid, - false); + groupManagementProtocolUid); ChannelMessageToSend messageToSend = new GroupManagementProtocol.TriggerUpdateMembersMessage( coreProtocolMessage, protocolManagerSession.identityDelegate.getGroupInformation(protocolManagerSession.session, getOwnedIdentity(), groupOwnerAndUid), diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupManagementProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupManagementProtocol.java index 00820c98..73d9e598 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupManagementProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupManagementProtocol.java @@ -865,9 +865,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUP_INVITATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new GroupInvitationProtocol.InitialMessage(coreProtocolMessage, identityWithSerializedDetails.identity, groupInformation, receivedMessage.groupMemberIdentitiesAndSerializedDetails).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -929,9 +927,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUP_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupPhotoChildProtocol.InitialMessage(coreProtocolMessage, receivedMessage.groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1111,9 +1107,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUP_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupPhotoChildProtocol.InitialMessage(coreProtocolMessage, receivedMessage.groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1183,9 +1177,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUP_INVITATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new GroupInvitationProtocol.InitialMessage(coreProtocolMessage, contactIdentity, receivedMessage.groupInformation, allGroupMembers).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1340,9 +1332,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUP_INVITATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new GroupInvitationProtocol.InitialMessage(coreProtocolMessage, receivedMessage.pendingMemberIdentity, receivedMessage.groupInformation, allGroupMembers).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1804,9 +1794,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUP_INVITATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new GroupInvitationProtocol.InitialMessage(coreProtocolMessage, receivedMessage.memberIdentity, receivedMessage.groupInformation, allGroupMembers).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupsV2Protocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupsV2Protocol.java index eef89bc1..1497f2fd 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupsV2Protocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/GroupsV2Protocol.java @@ -2036,8 +2036,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(groupMembersAndPermission.identity, getOwnedIdentity()), getProtocolId(), - invitationProtocolInstanceUid, - false); + invitationProtocolInstanceUid); ChannelMessageToSend messageToSend = new InvitationOrMembersUpdateMessage(coreProtocolMessage, startState.groupIdentifier, startState.groupVersion, keysToSend, contactDeviceUidsWithChannel).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } else { @@ -2070,8 +2069,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(getOwnedIdentity(), getOwnedIdentity()), getProtocolId(), - invitationProtocolInstanceUid, - false); + invitationProtocolInstanceUid); // we send the full set of owned devices, not only "other" own device uid, so that receiving devices know if all devices were notified ChannelMessageToSend messageToSend = new InvitationOrMembersUpdateMessage(coreProtocolMessage, startState.groupIdentifier, startState.groupVersion, keysToSend, allOwnedDeviceUids).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -2677,9 +2675,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUPS_V2_PHOTO_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupV2PhotoProtocol.InitialMessage(coreProtocolMessage, startState.groupIdentifier, serverBlob.serverPhotoInfo).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -2727,9 +2723,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUPS_V2_PHOTO_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupV2PhotoProtocol.InitialMessage(coreProtocolMessage, startState.groupIdentifier, serverBlob.serverPhotoInfo).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -3193,9 +3187,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUPS_V2_PHOTO_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupV2PhotoProtocol.InitialMessage(coreProtocolMessage, groupIdentifier, ((InvitationReceivedState) startState).serverBlob.serverPhotoInfo).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -4777,7 +4769,7 @@ public ConcreteProtocolState executeStep() throws Exception { for (GroupV2.IdentifierVersionAndKeys identifierVersionAndKeys : receivedMessage.groupInfos) { UID protocolInstanceUid = identifierVersionAndKeys.groupIdentifier.computeProtocolInstanceUid(); - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUPS_V2_PROTOCOL_ID, protocolInstanceUid, false); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), GROUPS_V2_PROTOCOL_ID, protocolInstanceUid); ChannelMessageToSend messageToSend = new BlobKeysAfterChannelCreationMessage(coreProtocolMessage, receivedMessage.getReceptionChannelInfo().getRemoteIdentity(), identifierVersionAndKeys.groupIdentifier, identifierVersionAndKeys.groupVersion, identifierVersionAndKeys.blobKeys).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -4838,9 +4830,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUPS_V2_PHOTO_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupV2PhotoProtocol.InitialMessage(coreProtocolMessage, receivedMessage.groupIdentifier, serverPhotoInfo).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } catch (Exception e) { @@ -4889,9 +4879,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_GROUPS_V2_PHOTO_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadGroupV2PhotoProtocol.InitialMessage(coreProtocolMessage, receivedMessage.groupIdentifier, serverPhotoInfo).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } catch (Exception e) { diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/IdentityDetailsPublicationProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/IdentityDetailsPublicationProtocol.java index 1c83c81d..a8f46173 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/IdentityDetailsPublicationProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/IdentityDetailsPublicationProtocol.java @@ -476,9 +476,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, contactIdentity, receivedMessage.jsonIdentityDetailsWithVersionAndPhoto).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -519,9 +517,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DOWNLOAD_IDENTITY_PHOTO_CHILD_PROTOCOL_ID, - new UID(getPrng()), - false - ); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DownloadIdentityPhotoChildProtocol.InitialMessage(coreProtocolMessage, getOwnedIdentity(), receivedMessage.jsonIdentityDetailsWithVersionAndPhoto).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakBindingAndUnbindingProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakBindingAndUnbindingProtocol.java index 9a23f763..4bf89b8d 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakBindingAndUnbindingProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakBindingAndUnbindingProtocol.java @@ -217,7 +217,7 @@ public PropagateKeycloakBindingMessage(ReceivedMessage receivedMessage) throws E this.keycloakServer = receivedMessage.getInputs()[1].decodeString(); this.clientId = receivedMessage.getInputs()[2].decodeString(); String clientSecret = receivedMessage.getInputs()[3].decodeString(); - this.clientSecret = clientSecret.length() == 0 ? null : clientSecret; + this.clientSecret = clientSecret.isEmpty() ? null : clientSecret; this.jwks = receivedMessage.getInputs()[4].decodeString(); this.signatureKey = receivedMessage.getInputs()[5].decodeString(); } @@ -285,6 +285,7 @@ public static class OwnedIdentityKeycloakBindingStep extends ProtocolStep { boolean propagationNeeded; + @SuppressWarnings("unused") public OwnedIdentityKeycloakBindingStep(InitialProtocolState startState, OwnedIdentityKeycloakBindingMessage receivedMessage, KeycloakBindingAndUnbindingProtocol protocol) throws Exception { super(ReceptionChannelInfo.createLocalChannelInfo(), receivedMessage, protocol); this.startState = startState; @@ -293,6 +294,7 @@ public OwnedIdentityKeycloakBindingStep(InitialProtocolState startState, OwnedId this.propagationNeeded = true; } + @SuppressWarnings("unused") public OwnedIdentityKeycloakBindingStep(InitialProtocolState startState, PropagateKeycloakBindingMessage receivedMessage, KeycloakBindingAndUnbindingProtocol protocol) throws Exception { super(ReceptionChannelInfo.createAnyObliviousChannelOrPreKeyWithOwnedDeviceInfo(), receivedMessage, protocol); this.startState = startState; @@ -304,6 +306,7 @@ public OwnedIdentityKeycloakBindingStep(InitialProtocolState startState, Propaga new JsonWebKeySet(receivedMessage.jwks), JsonWebKey.Factory.newJwk(receivedMessage.signatureKey), null, + false, null, 0, 0 @@ -370,12 +373,14 @@ public static class OwnedIdentityKeycloakUnbindingStep extends ProtocolStep { InitialProtocolState startState; boolean propagationNeeded; + @SuppressWarnings("unused") public OwnedIdentityKeycloakUnbindingStep(InitialProtocolState startState, OwnedIdentityKeycloakUnbindingMessage receivedMessage, KeycloakBindingAndUnbindingProtocol protocol) throws Exception { super(ReceptionChannelInfo.createLocalChannelInfo(), receivedMessage, protocol); this.startState = startState; this.propagationNeeded = true; } + @SuppressWarnings("unused") public OwnedIdentityKeycloakUnbindingStep(InitialProtocolState startState, PropagateKeycloakUnbindingMessage receivedMessage, KeycloakBindingAndUnbindingProtocol protocol) throws Exception { super(ReceptionChannelInfo.createAnyObliviousChannelOrPreKeyWithOwnedDeviceInfo(), receivedMessage, protocol); this.startState = startState; @@ -406,9 +411,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), IDENTITY_DETAILS_PUBLICATION_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new IdentityDetailsPublicationProtocol.InitialMessage(coreProtocolMessage, version).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakContactAdditionProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakContactAdditionProtocol.java index 9ea930fc..524ffec5 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakContactAdditionProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/KeycloakContactAdditionProtocol.java @@ -32,7 +32,6 @@ import io.olvid.engine.datatypes.Identity; import io.olvid.engine.datatypes.NoAcceptableChannelException; import io.olvid.engine.datatypes.PreKeyBlobOnServer; -import io.olvid.engine.datatypes.containers.PreKey; import io.olvid.engine.datatypes.UID; import io.olvid.engine.datatypes.containers.ChannelMessageToSend; import io.olvid.engine.datatypes.containers.ReceptionChannelInfo; @@ -532,8 +531,8 @@ public ConcreteProtocolState executeStep() throws Exception { return new FinishedProtocolState(); } - JsonKeycloakUserDetails ownUserDetails = protocolManagerSession.identityDelegate.verifyKeycloakSignature(protocolManagerSession.session, getOwnedIdentity(), ownedIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); - JsonKeycloakUserDetails contactUserDetails = protocolManagerSession.identityDelegate.verifyKeycloakSignature(protocolManagerSession.session, getOwnedIdentity(), receivedMessage.signedContactDetails); + JsonKeycloakUserDetails ownUserDetails = protocolManagerSession.identityDelegate.verifyKeycloakIdentitySignature(protocolManagerSession.session, getOwnedIdentity(), ownedIdentityDetailsWithVersionAndPhoto.getIdentityDetails().getSignedUserDetails()); + JsonKeycloakUserDetails contactUserDetails = protocolManagerSession.identityDelegate.verifyKeycloakIdentitySignature(protocolManagerSession.session, getOwnedIdentity(), receivedMessage.signedContactDetails); if (ownUserDetails == null || contactUserDetails == null) { return new FinishedProtocolState(); } @@ -564,9 +563,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage( SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), DEVICE_DISCOVERY_CHILD_PROTOCOL_ID, - childProtocolInstanceUid, - false - ); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new DeviceDiscoveryChildProtocol.InitialMessage(coreProtocolMessage, receivedMessage.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); @@ -711,8 +708,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, receivedMessage.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -742,7 +738,7 @@ public ConcreteProtocolState executeStep() throws Exception { //////// // verify the received contact signature //////// - JsonKeycloakUserDetails contactUserDetails = protocolManagerSession.identityDelegate.verifyKeycloakSignature(protocolManagerSession.session, getOwnedIdentity(), receivedMessage.signedContactDetails); + JsonKeycloakUserDetails contactUserDetails = protocolManagerSession.identityDelegate.verifyKeycloakIdentitySignature(protocolManagerSession.session, getOwnedIdentity(), receivedMessage.signedContactDetails); if (contactUserDetails == null) { // respond "rejected" @@ -820,8 +816,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OneToOneContactInvitationProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OneToOneContactInvitationProtocol.java index e8e3f75e..3ea12a58 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OneToOneContactInvitationProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OneToOneContactInvitationProtocol.java @@ -1141,8 +1141,7 @@ public ConcreteProtocolState executeStep() throws Exception { UID childProtocolInstanceUid = new UID(getPrng()); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.CONTACT_MANAGEMENT_PROTOCOL_ID, - childProtocolInstanceUid, - false); + childProtocolInstanceUid); ChannelMessageToSend messageToSend = new ContactManagementProtocol.InitiateContactDowngradeMessage(coreProtocolMessage, receivedMessage.getReceptionChannelInfo().getRemoteIdentity()).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -1288,8 +1287,7 @@ public ConcreteProtocolState executeStep() throws Exception { // we generate a new random UID as her protocol instance already reached a final state (and she may receive other responses for the same protocol Uid) CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(receivedMessage.getReceptionChannelInfo().getRemoteIdentity(), getOwnedIdentity()), getProtocolId(), - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new OneToOneStatusSyncRequestMessage(coreProtocolMessage, false).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedDeviceManagementProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedDeviceManagementProtocol.java index ca8b82b0..26e4ce29 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedDeviceManagementProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedDeviceManagementProtocol.java @@ -299,8 +299,7 @@ public ConcreteProtocolState executeStep() throws Exception { UID protocolInstanceUid = new UID(getPrng()); CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.OWNED_DEVICE_DISCOVERY_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new OwnedDeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, getPrng()); } @@ -312,8 +311,7 @@ public ConcreteProtocolState executeStep() throws Exception { try { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(sendChannelInfo, ConcreteProtocol.CONTACT_MANAGEMENT_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend message = new ContactManagementProtocol.PerformContactDeviceDiscoveryMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, getPrng()); } catch (NoAcceptableChannelException e) { diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityDeletionProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityDeletionProtocol.java index ed05ced6..3acceebf 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityDeletionProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityDeletionProtocol.java @@ -429,8 +429,7 @@ public ConcreteProtocolState executeStep() throws Exception { // trigger a device discovery on other devices CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAllOwnedConfirmedObliviousChannelsOrPreKeysInfo(getOwnedIdentity()), OWNED_DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new OwnedDeviceDiscoveryProtocol.TriggerOwnedDeviceDiscoveryMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } catch (NoAcceptableChannelException ignored) { @@ -464,8 +463,7 @@ public ConcreteProtocolState executeStep() throws Exception { try { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(sendChannelInfo, CONTACT_MANAGEMENT_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new ContactManagementProtocol.PerformContactDeviceDiscoveryMessage(coreProtocolMessage).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } catch (Exception ignored) { @@ -499,8 +497,7 @@ public ConcreteProtocolState executeStep() throws Exception { try { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(sendChannelInfo, GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend messageToSend = new GroupManagementProtocol.KickFromGroupMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } catch (Exception ignored) { @@ -519,8 +516,7 @@ public ConcreteProtocolState executeStep() throws Exception { try { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(sendChannelInfo, GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend messageToSend = new GroupManagementProtocol.KickFromGroupMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } catch (Exception ignored) { @@ -534,8 +530,7 @@ public ConcreteProtocolState executeStep() throws Exception { try { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAllConfirmedObliviousChannelsOrPreKeysInfo(group.getGroupOwner(), getOwnedIdentity()), GROUP_MANAGEMENT_PROTOCOL_ID, - protocolInstanceUid, - false); + protocolInstanceUid); ChannelMessageToSend message = new GroupManagementProtocol.NotifyGroupLeftMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, message, getPrng()); } catch (Exception ignored) { @@ -572,7 +567,7 @@ public ConcreteProtocolState executeStep() throws Exception { GroupV2.BlobKeys blobKeys = protocolManagerSession.identityDelegate.getGroupV2BlobKeys(protocolManagerSession.session, getOwnedIdentity(), groupV2.groupIdentifier); { byte[] signature = Signature.sign(Constants.SignatureContext.GROUP_DELETE_ON_SERVER, blobKeys.groupAdminServerAuthenticationPrivateKey.getSignaturePrivateKey(), getPrng()); - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.DeleteGroupBlobQuery(groupV2.groupIdentifier, signature)), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, new UID(getPrng()), false); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.DeleteGroupBlobQuery(groupV2.groupIdentifier, signature)), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, new UID(getPrng())); ChannelMessageToSend messageToSend = new GroupsV2Protocol.DeleteGroupBlobFromServerMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -595,7 +590,7 @@ public ConcreteProtocolState executeStep() throws Exception { byte[] signature = protocolManagerSession.identityDelegate.signBlock(protocolManagerSession.session, Constants.SignatureContext.GROUP_KICK, dataToSign, getOwnedIdentity(), getPrng()); - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAsymmetricBroadcastChannelInfo(member.identity, getOwnedIdentity()), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, groupV2.groupIdentifier.computeProtocolInstanceUid(), false); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createAsymmetricBroadcastChannelInfo(member.identity, getOwnedIdentity()), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, groupV2.groupIdentifier.computeProtocolInstanceUid()); ChannelMessageToSend messageToSend = new GroupsV2Protocol.KickMessage(coreProtocolMessage, groupV2.groupIdentifier, encryptedChain, signature).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -613,7 +608,7 @@ public ConcreteProtocolState executeStep() throws Exception { getOwnedIdentity(), getPrng()); - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.PutGroupLogQuery(groupV2.groupIdentifier, leaveSignature)), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, new UID(getPrng()), false); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.PutGroupLogQuery(groupV2.groupIdentifier, leaveSignature)), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, new UID(getPrng())); ChannelMessageToSend messageToSend = new GroupsV2Protocol.PutGroupLogOnServerMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -714,7 +709,7 @@ public ConcreteProtocolState executeStep() throws Exception { GroupInformation groupInformation = protocolManagerSession.identityDelegate.getGroupInformation(protocolManagerSession.session, getOwnedIdentity(), groupOwnerAndUid); GroupMembersChangedCallback groupMembersChangedCallback = () -> { - CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, groupInformation.computeProtocolUid(), false); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.GROUP_MANAGEMENT_PROTOCOL_ID, groupInformation.computeProtocolUid()); ChannelMessageToSend messageToSend = new GroupManagementProtocol.GroupMembersOrDetailsChangedTriggerMessage(coreProtocolMessage, groupInformation).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); }; @@ -744,8 +739,7 @@ public ConcreteProtocolState executeStep() throws Exception { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.GROUPS_V2_PROTOCOL_ID, - identifierAndAdminStatus.groupIdentifier.computeProtocolInstanceUid(), - false); + identifierAndAdminStatus.groupIdentifier.computeProtocolInstanceUid()); ChannelMessageToSend messageToSend = new GroupsV2Protocol.GroupUpdateInitialMessage(coreProtocolMessage, identifierAndAdminStatus.groupIdentifier, changeSet).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityTransferProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityTransferProtocol.java index 43a61fd9..65350e00 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityTransferProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/OwnedIdentityTransferProtocol.java @@ -24,8 +24,10 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.UUID; @@ -57,6 +59,7 @@ import io.olvid.engine.engine.types.ObvDeviceManagementRequest; import io.olvid.engine.engine.types.ObvTransferStep; import io.olvid.engine.engine.types.identities.ObvIdentity; +import io.olvid.engine.engine.types.identities.ObvKeycloakState; import io.olvid.engine.engine.types.sync.ObvBackupAndSyncDelegate; import io.olvid.engine.engine.types.sync.ObvSyncSnapshot; import io.olvid.engine.engine.types.sync.ObvSyncSnapshotNode; @@ -92,6 +95,8 @@ public int getProtocolId() { public static final int TARGET_WAITING_FOR_DECOMMITMENT_STATE_ID = 6; public static final int SOURCE_WAITING_FOR_SAS_INPUT_STATE_ID = 7; public static final int TARGET_WAITING_FOR_SNAPSHOT_STATE_ID = 8; + public static final int SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID = 9; + public static final int TARGET_WAITING_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID = 10; public static final int FINAL_STATE_ID = 99; @Override @@ -120,6 +125,10 @@ protected Class getStateClass(int stateId) { return SourceWaitingForSasInputState.class; case TARGET_WAITING_FOR_SNAPSHOT_STATE_ID: return TargetWaitingForSnapshotState.class; + case SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID: + return SourceWaitForKeycloakAuthenticationProofState.class; + case TARGET_WAITING_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID: + return TargetWaitingForKeycloakAuthenticationProofState.class; case FINAL_STATE_ID: return FinalState.class; default: @@ -156,21 +165,25 @@ public Encoded encode() { public static class SourceWaitingForTargetConnectionState extends ConcreteProtocolState { private final UUID dialogUuid; private final String ownConnectionIdentifier; - protected SourceWaitingForTargetConnectionState(UUID dialogUuid, String ownConnectionIdentifier) { + private final long sessionNumber; + + protected SourceWaitingForTargetConnectionState(UUID dialogUuid, String ownConnectionIdentifier, long sessionNumber) { super(SOURCE_WAITING_FOR_TARGET_CONNECTION_STATE_ID); this.dialogUuid = dialogUuid; this.ownConnectionIdentifier = ownConnectionIdentifier; + this.sessionNumber = sessionNumber; } @SuppressWarnings("unused") public SourceWaitingForTargetConnectionState(Encoded encodedState) throws Exception { super(SOURCE_WAITING_FOR_TARGET_CONNECTION_STATE_ID); Encoded[] list = encodedState.decodeList(); - if (list.length != 2) { + if (list.length != 3) { throw new Exception(); } this.dialogUuid = list[0].decodeUuid(); this.ownConnectionIdentifier = list[1].decodeString(); + this.sessionNumber = list[2].decodeLong(); } @Override @@ -178,6 +191,7 @@ public Encoded encode() { return Encoded.of(new Encoded[]{ Encoded.of(dialogUuid), Encoded.of(ownConnectionIdentifier), + Encoded.of(sessionNumber), }); } } @@ -232,21 +246,23 @@ public static class TargetWaitingForTransferredIdentityState extends ConcretePro private final ServerAuthenticationPrivateKey serverAuthenticationPrivateKey; private final EncryptionPrivateKey encryptionPrivateKey; private final MACKey macKey; + private final long sessionNumber; - protected TargetWaitingForTransferredIdentityState(UUID dialogUuid, String deviceName, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey) { + protected TargetWaitingForTransferredIdentityState(UUID dialogUuid, String deviceName, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey, long sessionNumber) { super(TARGET_WAITING_FOR_TRANSFERRED_IDENTITY_STATE_ID); this.dialogUuid = dialogUuid; this.deviceName = deviceName; this.serverAuthenticationPrivateKey = serverAuthenticationPrivateKey; this.encryptionPrivateKey = encryptionPrivateKey; this.macKey = macKey; + this.sessionNumber = sessionNumber; } @SuppressWarnings("unused") public TargetWaitingForTransferredIdentityState(Encoded encodedState) throws Exception { super(TARGET_WAITING_FOR_TRANSFERRED_IDENTITY_STATE_ID); Encoded[] list = encodedState.decodeList(); - if (list.length != 5) { + if (list.length != 6) { throw new Exception(); } this.dialogUuid = list[0].decodeUuid(); @@ -254,6 +270,7 @@ public TargetWaitingForTransferredIdentityState(Encoded encodedState) throws Exc this.serverAuthenticationPrivateKey = (ServerAuthenticationPrivateKey) list[2].decodePrivateKey(); this.encryptionPrivateKey = (EncryptionPrivateKey) list[3].decodePrivateKey(); this.macKey = (MACKey) list[4].decodeSymmetricKey(); + this.sessionNumber = list[5].decodeLong(); } @Override @@ -264,6 +281,7 @@ public Encoded encode() { Encoded.of(serverAuthenticationPrivateKey), Encoded.of(encryptionPrivateKey), Encoded.of(macKey), + Encoded.of(sessionNumber), }); } } @@ -275,21 +293,23 @@ public static class SourceWaitingForTargetSeedState extends ConcreteProtocolStat private final Identity ephemeralIdentity; private final Seed seedSourceForSas; private final byte[] decommitment; + private final long sessionNumber; - public SourceWaitingForTargetSeedState(UUID dialogUuid, String otherConnectionIdentifier, Identity ephemeralIdentity, Seed seedSourceForSas, byte[] decommitment) { + public SourceWaitingForTargetSeedState(UUID dialogUuid, String otherConnectionIdentifier, Identity ephemeralIdentity, Seed seedSourceForSas, byte[] decommitment, long sessionNumber) { super(SOURCE_WAITING_FOR_TARGET_SEED_STATE_ID); this.dialogUuid = dialogUuid; this.otherConnectionIdentifier = otherConnectionIdentifier; this.ephemeralIdentity = ephemeralIdentity; this.seedSourceForSas = seedSourceForSas; this.decommitment = decommitment; + this.sessionNumber = sessionNumber; } @SuppressWarnings("unused") public SourceWaitingForTargetSeedState(Encoded encodedState) throws Exception { super(SOURCE_WAITING_FOR_TARGET_SEED_STATE_ID); Encoded[] list = encodedState.decodeList(); - if (list.length != 5) { + if (list.length != 6) { throw new Exception(); } this.dialogUuid = list[0].decodeUuid(); @@ -297,6 +317,7 @@ public SourceWaitingForTargetSeedState(Encoded encodedState) throws Exception { this.ephemeralIdentity = list[2].decodeIdentity(); this.seedSourceForSas = list[3].decodeSeed(); this.decommitment = list[4].decodeBytes(); + this.sessionNumber = list[5].decodeLong(); } @Override @@ -307,6 +328,7 @@ public Encoded encode() { Encoded.of(ephemeralIdentity), Encoded.of(seedSourceForSas), Encoded.of(decommitment), + Encoded.of(sessionNumber), }); } } @@ -322,8 +344,9 @@ public static class TargetWaitingForDecommitmentState extends ConcreteProtocolSt private final ServerAuthenticationPrivateKey serverAuthenticationPrivateKey; private final EncryptionPrivateKey encryptionPrivateKey; private final MACKey macKey; + private final long sessionNumber; - public TargetWaitingForDecommitmentState(UUID dialogUuid, String deviceName, String otherConnectionIdentifier, Identity transferredIdentity, byte[] commitment, Seed seedTargetForSas, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey) { + public TargetWaitingForDecommitmentState(UUID dialogUuid, String deviceName, String otherConnectionIdentifier, Identity transferredIdentity, byte[] commitment, Seed seedTargetForSas, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey, long sessionNumber) { super(TARGET_WAITING_FOR_DECOMMITMENT_STATE_ID); this.dialogUuid = dialogUuid; this.deviceName = deviceName; @@ -334,13 +357,14 @@ public TargetWaitingForDecommitmentState(UUID dialogUuid, String deviceName, Str this.serverAuthenticationPrivateKey = serverAuthenticationPrivateKey; this.encryptionPrivateKey = encryptionPrivateKey; this.macKey = macKey; + this.sessionNumber = sessionNumber; } @SuppressWarnings("unused") public TargetWaitingForDecommitmentState(Encoded encodedState) throws Exception { super(TARGET_WAITING_FOR_DECOMMITMENT_STATE_ID); Encoded[] list = encodedState.decodeList(); - if (list.length != 9) { + if (list.length != 10) { throw new Exception(); } this.dialogUuid = list[0].decodeUuid(); @@ -352,6 +376,7 @@ public TargetWaitingForDecommitmentState(Encoded encodedState) throws Exception this.serverAuthenticationPrivateKey = (ServerAuthenticationPrivateKey) list[6].decodePrivateKey(); this.encryptionPrivateKey = (EncryptionPrivateKey) list[7].decodePrivateKey(); this.macKey = (MACKey) list[8].decodeSymmetricKey(); + this.sessionNumber = list[9].decodeLong(); } @Override @@ -366,6 +391,7 @@ public Encoded encode() { Encoded.of(serverAuthenticationPrivateKey), Encoded.of(encryptionPrivateKey), Encoded.of(macKey), + Encoded.of(sessionNumber), }); } } @@ -377,21 +403,23 @@ public static class SourceWaitingForSasInputState extends ConcreteProtocolState private final String targetDeviceName; private final Identity ephemeralIdentity; private final String fullSas; + private final long sessionNumber; - public SourceWaitingForSasInputState(UUID dialogUuid, String otherConnectionIdentifier, String targetDeviceName, Identity ephemeralIdentity, String fullSas) { + public SourceWaitingForSasInputState(UUID dialogUuid, String otherConnectionIdentifier, String targetDeviceName, Identity ephemeralIdentity, String fullSas, long sessionNumber) { super(SOURCE_WAITING_FOR_SAS_INPUT_STATE_ID); this.dialogUuid = dialogUuid; this.otherConnectionIdentifier = otherConnectionIdentifier; this.targetDeviceName = targetDeviceName; this.ephemeralIdentity = ephemeralIdentity; this.fullSas = fullSas; + this.sessionNumber = sessionNumber; } @SuppressWarnings("unused") public SourceWaitingForSasInputState(Encoded encodedState) throws Exception { super(SOURCE_WAITING_FOR_SAS_INPUT_STATE_ID); Encoded[] list = encodedState.decodeList(); - if (list.length != 5) { + if (list.length != 6) { throw new Exception(); } this.dialogUuid = list[0].decodeUuid(); @@ -399,6 +427,7 @@ public SourceWaitingForSasInputState(Encoded encodedState) throws Exception { this.targetDeviceName = list[2].decodeString(); this.ephemeralIdentity = list[3].decodeIdentity(); this.fullSas = list[4].decodeString(); + this.sessionNumber = list[5].decodeLong(); } @Override @@ -409,12 +438,72 @@ public Encoded encode() { Encoded.of(targetDeviceName), Encoded.of(ephemeralIdentity), Encoded.of(fullSas), + Encoded.of(sessionNumber), }); } } + public static class SourceWaitForKeycloakAuthenticationProofState extends ConcreteProtocolState { + private final UUID dialogUuid; + private final String otherConnectionIdentifier; + private final Identity ephemeralIdentity; + private final String fullSas; + private final long sessionNumber; + private final UID deviceUidToKeepActive; // may be null + + public SourceWaitForKeycloakAuthenticationProofState(UUID dialogUuid, String otherConnectionIdentifier, Identity ephemeralIdentity, String fullSas, long sessionNumber, UID deviceUidToKeepActive) { + super(SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID); + this.dialogUuid = dialogUuid; + this.otherConnectionIdentifier = otherConnectionIdentifier; + this.ephemeralIdentity = ephemeralIdentity; + this.fullSas = fullSas; + this.sessionNumber = sessionNumber; + this.deviceUidToKeepActive = deviceUidToKeepActive; + } - public static class TargetWaitingForSnapshotState extends ConcreteProtocolState { + @SuppressWarnings("unused") + public SourceWaitForKeycloakAuthenticationProofState(Encoded encodedState) throws Exception { + super(SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID); + Encoded[] list = encodedState.decodeList(); + if (list.length != 6 && list.length != 5) { + throw new Exception(); + } + this.dialogUuid = list[0].decodeUuid(); + this.otherConnectionIdentifier = list[1].decodeString(); + this.ephemeralIdentity = list[2].decodeIdentity(); + this.fullSas = list[3].decodeString(); + this.sessionNumber = list[4].decodeLong(); + if (list.length == 6) { + this.deviceUidToKeepActive = list[5].decodeUid(); + } else { + this.deviceUidToKeepActive = null; + } + } + + @Override + public Encoded encode() { + if (deviceUidToKeepActive != null) { + return Encoded.of(new Encoded[]{ + Encoded.of(dialogUuid), + Encoded.of(otherConnectionIdentifier), + Encoded.of(ephemeralIdentity), + Encoded.of(fullSas), + Encoded.of(sessionNumber), + Encoded.of(deviceUidToKeepActive), + }); + } else { + return Encoded.of(new Encoded[]{ + Encoded.of(dialogUuid), + Encoded.of(otherConnectionIdentifier), + Encoded.of(ephemeralIdentity), + Encoded.of(fullSas), + Encoded.of(sessionNumber), + }); + } + } + } + + public static class TargetWaitingForKeycloakAuthenticationProofState extends ConcreteProtocolState { private final UUID dialogUuid; private final String deviceName; private final String otherConnectionIdentifier; @@ -422,9 +511,11 @@ public static class TargetWaitingForSnapshotState extends ConcreteProtocolState private final ServerAuthenticationPrivateKey serverAuthenticationPrivateKey; private final EncryptionPrivateKey encryptionPrivateKey; private final MACKey macKey; + private final String fullSas; + private final long sessionNumber; - public TargetWaitingForSnapshotState(UUID dialogUuid, String deviceName, String otherConnectionIdentifier, Identity transferredIdentity, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey) { - super(TARGET_WAITING_FOR_SNAPSHOT_STATE_ID); + public TargetWaitingForKeycloakAuthenticationProofState(UUID dialogUuid, String deviceName, String otherConnectionIdentifier, Identity transferredIdentity, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey, String fullSas, long sessionNumber) { + super(TARGET_WAITING_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID); this.dialogUuid = dialogUuid; this.deviceName = deviceName; this.otherConnectionIdentifier = otherConnectionIdentifier; @@ -432,13 +523,15 @@ public TargetWaitingForSnapshotState(UUID dialogUuid, String deviceName, String this.serverAuthenticationPrivateKey = serverAuthenticationPrivateKey; this.encryptionPrivateKey = encryptionPrivateKey; this.macKey = macKey; + this.fullSas = fullSas; + this.sessionNumber = sessionNumber; } @SuppressWarnings("unused") - public TargetWaitingForSnapshotState(Encoded encodedState) throws Exception { - super(TARGET_WAITING_FOR_SNAPSHOT_STATE_ID); + public TargetWaitingForKeycloakAuthenticationProofState(Encoded encodedState) throws Exception { + super(TARGET_WAITING_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID); Encoded[] list = encodedState.decodeList(); - if (list.length != 7) { + if (list.length != 9) { throw new Exception(); } this.dialogUuid = list[0].decodeUuid(); @@ -448,6 +541,8 @@ public TargetWaitingForSnapshotState(Encoded encodedState) throws Exception { this.serverAuthenticationPrivateKey = (ServerAuthenticationPrivateKey) list[4].decodePrivateKey(); this.encryptionPrivateKey = (EncryptionPrivateKey) list[5].decodePrivateKey(); this.macKey = (MACKey) list[6].decodeSymmetricKey(); + this.fullSas = list[7].decodeString(); + this.sessionNumber = list[8].decodeLong(); } @Override @@ -460,11 +555,94 @@ public Encoded encode() { Encoded.of(serverAuthenticationPrivateKey), Encoded.of(encryptionPrivateKey), Encoded.of(macKey), + Encoded.of(fullSas), + Encoded.of(sessionNumber), }); } } + public static class TargetWaitingForSnapshotState extends ConcreteProtocolState { + private final UUID dialogUuid; + private final String deviceName; + private final String otherConnectionIdentifier; + private final Identity transferredIdentity; + private final ServerAuthenticationPrivateKey serverAuthenticationPrivateKey; + private final EncryptionPrivateKey encryptionPrivateKey; + private final MACKey macKey; + private final String fullSas; + private final long sessionNumber; + private final String serializedKeycloakAuthState; // non-null only after getting an transfer proof from keycloak + + public TargetWaitingForSnapshotState(UUID dialogUuid, String deviceName, String otherConnectionIdentifier, Identity transferredIdentity, ServerAuthenticationPrivateKey serverAuthenticationPrivateKey, EncryptionPrivateKey encryptionPrivateKey, MACKey macKey, String fullSas, long sessionNumber, String serializedKeycloakAuthState) { + super(TARGET_WAITING_FOR_SNAPSHOT_STATE_ID); + this.dialogUuid = dialogUuid; + this.deviceName = deviceName; + this.otherConnectionIdentifier = otherConnectionIdentifier; + this.transferredIdentity = transferredIdentity; + this.serverAuthenticationPrivateKey = serverAuthenticationPrivateKey; + this.encryptionPrivateKey = encryptionPrivateKey; + this.macKey = macKey; + this.fullSas = fullSas; + this.sessionNumber = sessionNumber; + this.serializedKeycloakAuthState = serializedKeycloakAuthState; + } + + @SuppressWarnings("unused") + public TargetWaitingForSnapshotState(Encoded encodedState) throws Exception { + super(TARGET_WAITING_FOR_SNAPSHOT_STATE_ID); + Encoded[] list = encodedState.decodeList(); + if (list.length != 10 && list.length != 9) { + throw new Exception(); + } + this.dialogUuid = list[0].decodeUuid(); + this.deviceName = list[1].decodeString(); + this.otherConnectionIdentifier = list[2].decodeString(); + this.transferredIdentity = list[3].decodeIdentity(); + this.serverAuthenticationPrivateKey = (ServerAuthenticationPrivateKey) list[4].decodePrivateKey(); + this.encryptionPrivateKey = (EncryptionPrivateKey) list[5].decodePrivateKey(); + this.macKey = (MACKey) list[6].decodeSymmetricKey(); + this.fullSas = list[7].decodeString(); + this.sessionNumber = list[8].decodeLong(); + if (list.length == 10) { + this.serializedKeycloakAuthState = list[9].decodeString(); + } else { + this.serializedKeycloakAuthState = null; + } + } + + @Override + public Encoded encode() { + if (serializedKeycloakAuthState == null) { + return Encoded.of(new Encoded[]{ + Encoded.of(dialogUuid), + Encoded.of(deviceName), + Encoded.of(otherConnectionIdentifier), + Encoded.of(transferredIdentity), + Encoded.of(serverAuthenticationPrivateKey), + Encoded.of(encryptionPrivateKey), + Encoded.of(macKey), + Encoded.of(fullSas), + Encoded.of(sessionNumber), + }); + } else { + return Encoded.of(new Encoded[]{ + Encoded.of(dialogUuid), + Encoded.of(deviceName), + Encoded.of(otherConnectionIdentifier), + Encoded.of(transferredIdentity), + Encoded.of(serverAuthenticationPrivateKey), + Encoded.of(encryptionPrivateKey), + Encoded.of(macKey), + Encoded.of(fullSas), + Encoded.of(sessionNumber), + Encoded.of(serializedKeycloakAuthState), + }); + } + } + } + + public static class FinalState extends ConcreteProtocolState { protected FinalState() { super(FINAL_STATE_ID); @@ -496,8 +674,8 @@ public Encoded encode() { public static final int SOURCE_DECOMMITMENT_MESSAGE_ID = 10; public static final int TARGET_WAIT_FOR_SNAPSHOT_MESSAGE_ID = 11; public static final int SOURCE_SNAPSHOT_MESSAGE_ID = 12; - - + public static final int SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_MESSAGE_ID = 13; + public static final int TARGET_RETRIEVE_KEYCLOAK_AUTHENTICATION_PROOF_MESSAGE_ID = 14; @Override @@ -529,6 +707,10 @@ protected Class getMessageClass(int protocolMessageId) { return TargetWaitForSnapshotMessage.class; case SOURCE_SNAPSHOT_MESSAGE_ID: return SourceSnapshotMessage.class; + case SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_MESSAGE_ID: + return SourceWaitForKeycloakAuthenticationProofMessage.class; + case TARGET_RETRIEVE_KEYCLOAK_AUTHENTICATION_PROOF_MESSAGE_ID: + return TargetRetrieveKeycloakAuthenticationProofMessage.class; default: return null; } @@ -840,6 +1022,56 @@ public int getProtocolMessageId() { } } + public static class SourceWaitForKeycloakAuthenticationProofMessage extends WaitOrRelayMessage { + protected SourceWaitForKeycloakAuthenticationProofMessage(CoreProtocolMessage coreProtocolMessage) { + super(coreProtocolMessage); + } + + @SuppressWarnings("unused") + public SourceWaitForKeycloakAuthenticationProofMessage(ReceivedMessage receivedMessage) throws Exception { + super(receivedMessage); + } + + @Override + public int getProtocolMessageId() { + return SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_MESSAGE_ID; + } + } + + public static class TargetRetrieveKeycloakAuthenticationProofMessage extends EmptyProtocolMessage { + private final String signature; + private final String serializedKeycloakAuthState; + + public TargetRetrieveKeycloakAuthenticationProofMessage(CoreProtocolMessage coreProtocolMessage) { + super(coreProtocolMessage); + this.signature = null; + this.serializedKeycloakAuthState = null; + } + + @SuppressWarnings("unused") + public TargetRetrieveKeycloakAuthenticationProofMessage(ReceivedMessage receivedMessage) throws Exception { + super(receivedMessage); + if (receivedMessage.getEncodedResponse() == null) { + this.signature = null; + this.serializedKeycloakAuthState = null; + } else { + Encoded[] list = receivedMessage.getEncodedResponse().decodeList(); + if (list.length == 2) { + this.signature = list[0].decodeString(); + this.serializedKeycloakAuthState = list[1].decodeString(); + } else { + this.signature = null; + this.serializedKeycloakAuthState = null; + } + } + } + + @Override + public int getProtocolMessageId() { + return TARGET_RETRIEVE_KEYCLOAK_AUTHENTICATION_PROOF_MESSAGE_ID; + } + } + // endregion @@ -869,6 +1101,10 @@ protected Class[] getPossibleStepClasses(int stateId) { return new Class[]{SourceCheckSasInputAndSendSnapshotStep.class}; case TARGET_WAITING_FOR_SNAPSHOT_STATE_ID: return new Class[]{TargetProcessesSnapshotStep.class, UserInitiatedAbortProtocolStep.class}; + case SOURCE_WAIT_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID: + return new Class[]{SourceCheckTransferProofAndSendSnapshotStep.class}; + case TARGET_WAITING_FOR_KEYCLOAK_AUTHENTICATION_PROOF_STATE_ID: + return new Class[]{TargetSendKeycloakAuthenticationProofStep.class}; case FINAL_STATE_ID: default: return new Class[0]; @@ -961,7 +1197,7 @@ public ConcreteProtocolState executeStep() throws Exception { protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } - return new SourceWaitingForTargetConnectionState(dialogUuid, ownConnectionIdentifier); + return new SourceWaitingForTargetConnectionState(dialogUuid, ownConnectionIdentifier, sessionNumber); } } @@ -1026,7 +1262,7 @@ public ConcreteProtocolState executeStep() throws Exception { protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } - return new TargetWaitingForTransferredIdentityState(startState.dialogUuid, startState.deviceName, startState.serverAuthenticationPrivateKey, startState.encryptionPrivateKey, startState.macKey); + return new TargetWaitingForTransferredIdentityState(startState.dialogUuid, startState.deviceName, startState.serverAuthenticationPrivateKey, startState.encryptionPrivateKey, startState.macKey, receivedMessage.sessionNumber); } } @@ -1106,7 +1342,7 @@ public ConcreteProtocolState executeStep() throws Exception { protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } - return new SourceWaitingForTargetSeedState(startState.dialogUuid, jsonResponse.otherConnectionId, ephemeralIdentity, seedSourceForSas, commitmentOutput.decommitment); + return new SourceWaitingForTargetSeedState(startState.dialogUuid, jsonResponse.otherConnectionId, ephemeralIdentity, seedSourceForSas, commitmentOutput.decommitment, startState.sessionNumber); } } @@ -1203,7 +1439,7 @@ public ConcreteProtocolState executeStep() throws Exception { protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } - return new TargetWaitingForDecommitmentState(startState.dialogUuid, startState.deviceName, otherConnectionIdentifier, transferredIdentity, commitment, seedTargetForSas, startState.serverAuthenticationPrivateKey, startState.encryptionPrivateKey, startState.macKey); + return new TargetWaitingForDecommitmentState(startState.dialogUuid, startState.deviceName, otherConnectionIdentifier, transferredIdentity, commitment, seedTargetForSas, startState.serverAuthenticationPrivateKey, startState.encryptionPrivateKey, startState.macKey, startState.sessionNumber); } private static Seed getDeterministicSeed(MACKey macKey, byte[] commitment) throws Exception { @@ -1293,7 +1529,7 @@ public ConcreteProtocolState executeStep() throws Exception { protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } - return new SourceWaitingForSasInputState(startState.dialogUuid, startState.otherConnectionIdentifier, targetDeviceName, startState.ephemeralIdentity, fullSas); + return new SourceWaitingForSasInputState(startState.dialogUuid, startState.otherConnectionIdentifier, targetDeviceName, startState.ephemeralIdentity, fullSas, startState.sessionNumber); } } @@ -1378,7 +1614,7 @@ public ConcreteProtocolState executeStep() throws Exception { protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } - return new TargetWaitingForSnapshotState(startState.dialogUuid, startState.deviceName, startState.otherConnectionIdentifier, startState.transferredIdentity, startState.serverAuthenticationPrivateKey, startState.encryptionPrivateKey, startState.macKey); + return new TargetWaitingForSnapshotState(startState.dialogUuid, startState.deviceName, startState.otherConnectionIdentifier, startState.transferredIdentity, startState.serverAuthenticationPrivateKey, startState.encryptionPrivateKey, startState.macKey, new String(fullSas, StandardCharsets.UTF_8), startState.sessionNumber, null); } } @@ -1411,43 +1647,160 @@ public ConcreteProtocolState executeStep() throws Exception { return startState; } + // check if owned identity is keycloak managed and transfer restricted + ObvKeycloakState keycloakState = protocolManagerSession.identityDelegate.getOwnedIdentityKeycloakState(protocolManagerSession.session, getOwnedIdentity()); + if (keycloakState != null && keycloakState.transferRestricted) { + // sas is correct --> send keycloak parameters so the target device can authenticate and respond with a transferProof + JsonKeycloakConfiguration configuration = new JsonKeycloakConfiguration(); + configuration.server = keycloakState.keycloakServer; + configuration.cid = keycloakState.clientId; + configuration.secret = keycloakState.clientSecret; - { - // sas is correct --> we can send a snapshot - ObvBackupAndSyncDelegate wrappedIdentityDelegate = protocolManagerSession.identityDelegate.getSyncDelegateWithinTransaction(protocolManagerSession.session); - - ObvSyncSnapshot syncSnapshot = ObvSyncSnapshot.get(getOwnedIdentity(), wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate); - byte[] cleartext; - if (receivedMessage.deviceUidToKeepActive == null) { - cleartext = Encoded.of(new Encoded[]{ - Encoded.of(syncSnapshot.toEncodedDictionary(wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate)), - }).getBytes(); - } else { - cleartext = Encoded.of(new Encoded[]{ - Encoded.of(syncSnapshot.toEncodedDictionary(wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate)), - Encoded.of(receivedMessage.deviceUidToKeepActive), - }).getBytes(); - } - EncryptedBytes payload = Suite.getPublicKeyEncryption(startState.ephemeralIdentity.getEncryptionPublicKey()).encrypt(startState.ephemeralIdentity.getEncryptionPublicKey(), cleartext, getPrng()); - CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.TransferRelayQuery(startState.otherConnectionIdentifier, payload.getBytes(), true))); - ChannelMessageToSend messageToSend = new SourceSnapshotMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); + byte[] dataToSend = getJsonObjectMapper().writeValueAsBytes(configuration); + EncryptedBytes payload = Suite.getPublicKeyEncryption(startState.ephemeralIdentity.getEncryptionPublicKey()).encrypt(startState.ephemeralIdentity.getEncryptionPublicKey(), dataToSend, getPrng()); + + CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.TransferRelayQuery(startState.otherConnectionIdentifier, payload.getBytes(), false))); + ChannelMessageToSend messageToSend = new SourceWaitForKeycloakAuthenticationProofMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); + + return new SourceWaitForKeycloakAuthenticationProofState(startState.dialogUuid, startState.otherConnectionIdentifier, startState.ephemeralIdentity, startState.fullSas, startState.sessionNumber, receivedMessage.deviceUidToKeepActive); + } else { + // sas is correct --> we can send a snapshot + sendSnapshotAndCloseWebsocket( + protocolManagerSession, + getProtocolInstanceUid(), + getOwnedIdentity(), + receivedMessage.deviceUidToKeepActive, + startState.otherConnectionIdentifier, + startState.ephemeralIdentity, + startState.dialogUuid, + getPrng()); + + return new FinalState(); } + } + } - { - // close the websocket - CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.TransferCloseQuery(false))); - ChannelMessageToSend messageToSend = new CloseWebSocketMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); - protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); + private static void sendSnapshotAndCloseWebsocket( + ProtocolManagerSession protocolManagerSession, + UID protocolInstanceUid, + Identity ownedIdentity, + UID deviceUidToKeepActive, + String otherConnectionIdentifier, + Identity ephemeralIdentity, + UUID dialogUuid, + PRNGService prng) throws Exception { + + { + ObvBackupAndSyncDelegate wrappedIdentityDelegate = protocolManagerSession.identityDelegate.getSyncDelegateWithinTransaction(protocolManagerSession.session); + + ObvSyncSnapshot syncSnapshot = ObvSyncSnapshot.get(ownedIdentity, wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate); + byte[] cleartext; + if (deviceUidToKeepActive == null) { + cleartext = Encoded.of(new Encoded[]{ + Encoded.of(syncSnapshot.toEncodedDictionary(wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate)), + }).getBytes(); + } else { + cleartext = Encoded.of(new Encoded[]{ + Encoded.of(syncSnapshot.toEncodedDictionary(wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate)), + Encoded.of(deviceUidToKeepActive), + }).getBytes(); } + EncryptedBytes payload = Suite.getPublicKeyEncryption(ephemeralIdentity.getEncryptionPublicKey()).encrypt(ephemeralIdentity.getEncryptionPublicKey(), cleartext, prng); + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(ownedIdentity, new ServerQuery.TransferRelayQuery(otherConnectionIdentifier, payload.getBytes(), true)), OWNED_IDENTITY_TRANSFER_PROTOCOL_ID, protocolInstanceUid); + ChannelMessageToSend messageToSend = new SourceSnapshotMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); + protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, prng); + } - { - // notify the app to end - CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createUserInterfaceChannelInfo(getOwnedIdentity(), DialogType.createTransferDialog(new ObvTransferStep.SourceSnapshotSent()), startState.dialogUuid)); - ChannelMessageToSend messageToSend = new OneWayDialogProtocolMessage(coreProtocolMessage).generateChannelDialogMessageToSend(); - protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); + { + // close the websocket + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(ownedIdentity, new ServerQuery.TransferCloseQuery(false)), OWNED_IDENTITY_TRANSFER_PROTOCOL_ID, protocolInstanceUid); + ChannelMessageToSend messageToSend = new CloseWebSocketMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); + protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, prng); + } + + { + // notify the app to end + CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createUserInterfaceChannelInfo(ownedIdentity, DialogType.createTransferDialog(new ObvTransferStep.SourceSnapshotSent()), dialogUuid), OWNED_IDENTITY_TRANSFER_PROTOCOL_ID, protocolInstanceUid); + ChannelMessageToSend messageToSend = new OneWayDialogProtocolMessage(coreProtocolMessage).generateChannelDialogMessageToSend(); + protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, prng); + } + } + + + public static class SourceCheckTransferProofAndSendSnapshotStep extends ProtocolStep { + private final SourceWaitForKeycloakAuthenticationProofState startState; + private final SourceWaitForKeycloakAuthenticationProofMessage receivedMessage; + + public SourceCheckTransferProofAndSendSnapshotStep(SourceWaitForKeycloakAuthenticationProofState startState, SourceWaitForKeycloakAuthenticationProofMessage receivedMessage, OwnedIdentityTransferProtocol protocol) throws Exception { + super(ReceptionChannelInfo.createLocalChannelInfo(), receivedMessage, protocol); + this.startState = startState; + this.receivedMessage = receivedMessage; + } + + private ConcreteProtocolState restartStep(ProtocolManagerSession protocolManagerSession) throws Exception { + CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.TransferWaitQuery())); + ChannelMessageToSend messageToSend = new SourceWaitForKeycloakAuthenticationProofMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); + protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); + return startState; + } + + @Override + public ConcreteProtocolState executeStep() throws Exception { + ProtocolManagerSession protocolManagerSession = getProtocolManagerSession(); + + if (receivedMessage.serializedJsonResponse == null) { + return failProtocol(this, startState.dialogUuid, ObvTransferStep.Fail.FAIL_REASON_NETWORK_ERROR); + } + + JsonResponse jsonResponse; + String signature; + try { + jsonResponse = getJsonObjectMapper().readValue(receivedMessage.serializedJsonResponse, JsonResponse.class); + byte[] cleartextPayload = protocolManagerSession.encryptionForIdentityDelegate.decrypt(protocolManagerSession.session, new EncryptedBytes(jsonResponse.payload), getOwnedIdentity()); + + signature = new String(cleartextPayload, StandardCharsets.UTF_8); + } catch (Exception e) { + // failed to parse the response --> send a Wait message and return to start state + Logger.w("OwnedIdentityTransferProtocol.SourceCheckTransferProofAndSendSnapshotStep failed to parse response"); + return restartStep(protocolManagerSession); + + } + + if (!Objects.equals(jsonResponse.otherConnectionId, startState.otherConnectionIdentifier)) { + // invalid response --> send a Wait message and return to start state + Logger.w("OwnedIdentityTransferProtocol.SourceCheckTransferProofAndSendSnapshotStep invalid response"); + return restartStep(protocolManagerSession); + } + + + // validate the received signature + try { + String signedContent = protocolManagerSession.identityDelegate.verifyKeycloakSignature(protocolManagerSession.session, getOwnedIdentity(), signature); + JsonTransferProof transferProof = getJsonObjectMapper().readValue(signedContent, JsonTransferProof.class); + + String keycloakUserId = protocolManagerSession.identityDelegate.getOwnedIdentityKeycloakUserId(protocolManagerSession.session, getOwnedIdentity()); + + if (!Objects.equals(transferProof.session_id, String.format(Locale.ENGLISH, "%08d", startState.sessionNumber)) + || !Objects.equals(transferProof.sas, startState.fullSas) + || !Arrays.equals(transferProof.identity, getOwnedIdentity().getBytes()) + || !Objects.equals(transferProof.keycloak_id, keycloakUserId)) { + return failProtocol(this, startState.dialogUuid, ObvTransferStep.Fail.FAIL_REASON_INVALID_RESPONSE); + } + } catch (Exception ignored) { + return failProtocol(this, startState.dialogUuid, ObvTransferStep.Fail.FAIL_REASON_INVALID_RESPONSE); } + sendSnapshotAndCloseWebsocket( + protocolManagerSession, + getProtocolInstanceUid(), + getOwnedIdentity(), + startState.deviceUidToKeepActive, + startState.otherConnectionIdentifier, + startState.ephemeralIdentity, + startState.dialogUuid, + getPrng()); + return new FinalState(); } } @@ -1500,11 +1853,15 @@ public ConcreteProtocolState executeStep() throws Exception { ObvBackupAndSyncDelegate wrappedIdentityDelegate = protocolManagerSession.identityDelegate.getSyncDelegateWithinTransaction(protocolManagerSession.session); + byte[] plaintext = null; ObvSyncSnapshot syncSnapshot; UID deviceUidToKeepActive; try { - // decrypt and parse relayed message - Encoded[] list = new Encoded(Suite.getPublicKeyEncryption(startState.encryptionPrivateKey).decrypt(startState.encryptionPrivateKey, new EncryptedBytes(jsonResponse.payload))).decodeList(); + // decrypt + plaintext = Suite.getPublicKeyEncryption(startState.encryptionPrivateKey).decrypt(startState.encryptionPrivateKey, new EncryptedBytes(jsonResponse.payload)); + + // parse relayed message + Encoded[] list = new Encoded(plaintext).decodeList(); // make sure we can parse the snapshot, but don't do anything with it, the app will take care of this syncSnapshot = ObvSyncSnapshot.fromEncodedDictionary(list[0].decodeDictionary(), wrappedIdentityDelegate, protocolManagerSession.appBackupAndSyncDelegate); @@ -1518,6 +1875,35 @@ public ConcreteProtocolState executeStep() throws Exception { deviceUidToKeepActive = null; } } catch (Exception e) { + // parsing failed, try to parse it as a keycloak configuration + if (plaintext != null) { + try { + JsonKeycloakConfiguration jsonKeycloakConfiguration = getJsonObjectMapper().readValue(plaintext, JsonKeycloakConfiguration.class); + if (jsonKeycloakConfiguration != null && jsonKeycloakConfiguration.server != null && jsonKeycloakConfiguration.cid != null) { + // we have received a JsonKeycloakConfiguration that needs to be passed to the app to force authentication + { + // send keycloak config to app + CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createUserInterfaceChannelInfo(getOwnedIdentity(), DialogType.createTransferDialog(new ObvTransferStep.TargetRequestsKeycloakAuthenticationProof(jsonKeycloakConfiguration.server, jsonKeycloakConfiguration.cid, jsonKeycloakConfiguration.secret, startState.fullSas, startState.sessionNumber)), startState.dialogUuid)); + ChannelMessageToSend messageToSend = new TargetRetrieveKeycloakAuthenticationProofMessage(coreProtocolMessage).generateChannelDialogMessageToSend(); + protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); + } + + return new TargetWaitingForKeycloakAuthenticationProofState( + startState.dialogUuid, + startState.deviceName, + startState.otherConnectionIdentifier, + startState.transferredIdentity, + startState.serverAuthenticationPrivateKey, + startState.encryptionPrivateKey, + startState.macKey, + startState.fullSas, + startState.sessionNumber + ); + } + } catch (Exception ignored) { } + } + + // invalid response --> send a Wait message and return to start state Logger.w("OwnedIdentityTransferProtocol.TargetProcessesSnapshotStep failed to decrypt and parse response"); return restartStep(protocolManagerSession); @@ -1540,6 +1926,9 @@ public ConcreteProtocolState executeStep() throws Exception { ObvIdentity obvOwnedIdentity; if (node instanceof IdentityManagerSyncSnapshot) { obvOwnedIdentity = protocolManagerSession.identityDelegate.restoreTransferredOwnedIdentity(protocolManagerSession.session, startState.deviceName, ((IdentityManagerSyncSnapshot) node)); + if (startState.serializedKeycloakAuthState != null) { + protocolManagerSession.identityDelegate.saveKeycloakAuthState(protocolManagerSession.session, obvOwnedIdentity.getIdentity(), startState.serializedKeycloakAuthState); + } } else { throw new Exception(); } @@ -1611,7 +2000,6 @@ public ConcreteProtocolState executeStep() throws Exception { - { // close the websocket CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.TransferCloseQuery(false))); @@ -1638,7 +2026,48 @@ public ConcreteProtocolState executeStep() throws Exception { } + public static class TargetSendKeycloakAuthenticationProofStep extends ProtocolStep { + + private final TargetWaitingForKeycloakAuthenticationProofState startState; + private final TargetRetrieveKeycloakAuthenticationProofMessage receivedMessage; + + public TargetSendKeycloakAuthenticationProofStep(TargetWaitingForKeycloakAuthenticationProofState startState, TargetRetrieveKeycloakAuthenticationProofMessage receivedMessage, OwnedIdentityTransferProtocol protocol) throws Exception { + super(ReceptionChannelInfo.createLocalChannelInfo(), receivedMessage, protocol); + this.startState = startState; + this.receivedMessage = receivedMessage; + } + + @Override + public ConcreteProtocolState executeStep() throws Exception { + ProtocolManagerSession protocolManagerSession = getProtocolManagerSession(); + + if (receivedMessage.signature == null) { + return failProtocol(this, startState.dialogUuid, ObvTransferStep.Fail.FAIL_REASON_INVALID_RESPONSE); + } + + + { + // send the signature to the source + EncryptedBytes payload = Suite.getPublicKeyEncryption(startState.transferredIdentity.getEncryptionPublicKey()).encrypt(startState.transferredIdentity.getEncryptionPublicKey(), receivedMessage.signature.getBytes(StandardCharsets.UTF_8), getPrng()); + CoreProtocolMessage coreProtocolMessage = buildCoreProtocolMessage(SendChannelInfo.createServerQueryChannelInfo(getOwnedIdentity(), new ServerQuery.TransferRelayQuery(startState.otherConnectionIdentifier, payload.getBytes(), false))); + ChannelMessageToSend messageToSend = new TargetWaitForSnapshotMessage(coreProtocolMessage).generateChannelServerQueryMessageToSend(); + protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); + } + return new TargetWaitingForSnapshotState( + startState.dialogUuid, + startState.deviceName, + startState.otherConnectionIdentifier, + startState.transferredIdentity, + startState.serverAuthenticationPrivateKey, + startState.encryptionPrivateKey, + startState.macKey, + startState.fullSas, + startState.sessionNumber, + receivedMessage.serializedKeycloakAuthState + ); + } + } @@ -1743,4 +2172,20 @@ public static class JsonResponse { public String otherConnectionId; public byte[] payload; } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class JsonKeycloakConfiguration { + public String server; + public String cid; + public String secret; + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class JsonTransferProof { + public String session_id; + public String sas; + public byte[] identity; + public String keycloak_id; + } + } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithMutualScanProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithMutualScanProtocol.java index cabc190e..7207f13e 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithMutualScanProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithMutualScanProtocol.java @@ -502,8 +502,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, receivedMessage.aliceIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -599,8 +598,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, receivedMessage.aliceIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } @@ -650,8 +648,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.bobIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithSasProtocol.java b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithSasProtocol.java index 70b17e68..190b2f99 100644 --- a/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithSasProtocol.java +++ b/obv_engine/engine/src/main/java/io/olvid/engine/protocol/protocols/TrustEstablishmentWithSasProtocol.java @@ -1438,8 +1438,7 @@ public ConcreteProtocolState executeStep() throws Exception { if (triggerDeviceDiscovery) { CoreProtocolMessage coreProtocolMessage = new CoreProtocolMessage(SendChannelInfo.createLocalChannelInfo(getOwnedIdentity()), ConcreteProtocol.DEVICE_DISCOVERY_PROTOCOL_ID, - new UID(getPrng()), - false); + new UID(getPrng())); ChannelMessageToSend messageToSend = new DeviceDiscoveryProtocol.InitialMessage(coreProtocolMessage, startState.contactIdentity).generateChannelProtocolMessageToSend(); protocolManagerSession.channelDelegate.post(protocolManagerSession.session, messageToSend, getPrng()); } diff --git a/obv_messenger/.idea/inspectionProfiles/Project_Default.xml b/obv_messenger/.idea/inspectionProfiles/Project_Default.xml index 18daa719..25a831c9 100644 --- a/obv_messenger/.idea/inspectionProfiles/Project_Default.xml +++ b/obv_messenger/.idea/inspectionProfiles/Project_Default.xml @@ -35,6 +35,16 @@