Skip to content

Commit

Permalink
v0.15.0 (build 207)
Browse files Browse the repository at this point in the history
  • Loading branch information
finiasz committed Jul 31, 2023
1 parent ad70fa8 commit 39df8c4
Show file tree
Hide file tree
Showing 330 changed files with 25,938 additions and 9,001 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Build 207 (0.15.0)
2023-07-31

- Minor fixes for group types

# ~~Build 206 (0.15.0)~~
2023-07-28

- introduction of group "types" allowing, for example, the creation of read-only discussions
- preliminary support for multi-device (device re-synchronization not fully implemented yet)

# Build 205 (0.14.2)
2023-07-13

Expand All @@ -14,7 +25,6 @@
- Some markdown fixes
- Fix discussion background image rotation issue


# ~~Build 203 (0.14.2)~~
2023-06-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;

Expand All @@ -50,7 +48,6 @@
import io.olvid.engine.datatypes.BackupSeed;
import io.olvid.engine.datatypes.Constants;
import io.olvid.engine.datatypes.EncryptedBytes;
import io.olvid.engine.datatypes.Identity;
import io.olvid.engine.datatypes.NoExceptionSingleThreadExecutor;
import io.olvid.engine.datatypes.NotificationListener;
import io.olvid.engine.datatypes.Session;
Expand Down Expand Up @@ -410,15 +407,15 @@ public void backupSuccess(String tag, UID backupKeyUid, int version, String back
EncryptionPublicKey encryptionPublicKey = backupKey.getEncryptionPublicKey();
MACKey macKey = backupKey.getMacKey();

// TODO: once all olvid clients can handle uncompressed backups, remove the DeflaterOutputStream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream deflater = new DeflaterOutputStream(baos, new Deflater(5, true));
deflater.write(fullBackupContent.getBytes(StandardCharsets.UTF_8));
deflater.close();
byte[] compressedBackup = baos.toByteArray();
baos.close();
// we no longer compress backups as all up-to-date Olvid clients can handle it.
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// DeflaterOutputStream deflater = new DeflaterOutputStream(baos, new Deflater(5, true));
// deflater.write(fullBackupContent.getBytes(StandardCharsets.UTF_8));
// deflater.close();
// byte[] compressedBackup = baos.toByteArray();
// baos.close();

EncryptedBytes encryptedBackup = Suite.getPublicKeyEncryption(encryptionPublicKey).encrypt(encryptionPublicKey, compressedBackup, prng);
EncryptedBytes encryptedBackup = Suite.getPublicKeyEncryption(encryptionPublicKey).encrypt(encryptionPublicKey, fullBackupContent.getBytes(StandardCharsets.UTF_8), prng);
byte[] mac = Suite.getMAC(macKey).digest(macKey, encryptedBackup.getBytes());

byte[] macedEncryptedBackup = new byte[encryptedBackup.getBytes().length + mac.length];
Expand Down Expand Up @@ -616,7 +613,7 @@ private BackupContentAndDerivedKeys decryptBackupContent(String seedString, byte
}

@Override
public ObvIdentity[] restoreOwnedIdentitiesFromBackup(String seedString, byte[] backupContent) {
public ObvIdentity[] restoreOwnedIdentitiesFromBackup(String seedString, byte[] backupContent, String deviceDisplayName) {
try {
BackupContentAndDerivedKeys backupContentAndDerivedKeys = decryptBackupContent(seedString, backupContent, jsonObjectMapper);
if (backupContentAndDerivedKeys == null) {
Expand All @@ -637,7 +634,8 @@ public ObvIdentity[] restoreOwnedIdentitiesFromBackup(String seedString, byte[]
backupManagerSession.session.commit();
}
}
return identityDelegate.restoreOwnedIdentitiesFromBackup(backupContentAndDerivedKeys.pojo.engine.identity_manager, prng);

return identityDelegate.restoreOwnedIdentitiesFromBackup(backupContentAndDerivedKeys.pojo.engine.identity_manager, deviceDisplayName, prng);
} catch (Exception e) {
e.printStackTrace();
return null;
Expand All @@ -646,7 +644,7 @@ public ObvIdentity[] restoreOwnedIdentitiesFromBackup(String seedString, byte[]


@Override
public void restoreContactsAndGroupsFromBackup(String seedString, byte[] backupContent, Identity[] restoredOwnedIdentities) {
public void restoreContactsAndGroupsFromBackup(String seedString, byte[] backupContent, ObvIdentity[] restoredOwnedIdentities) {
try {
BackupContentAndDerivedKeys backupContentAndDerivedKeys = decryptBackupContent(seedString, backupContent, jsonObjectMapper);
if (backupContentAndDerivedKeys == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@


import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import io.olvid.engine.Logger;
Expand Down Expand Up @@ -106,10 +109,19 @@ public void initialisationComplete() {
// at the same time, try to detect contact devices without a channel
ObliviousChannel[] obliviousChannels = ObliviousChannel.getAll(channelManagerSession);
Map<Identity, Map<Identity, Set<UID>>> deviceUidsMap = identityDelegate.getAllDeviceUidsOfAllContactsOfAllOwnedIdentities(channelManagerSession.session);
for (Identity ownedIdentity : identityDelegate.getOwnedIdentities(channelManagerSession.session)) {
UID[] ownedDeviceUids = identityDelegate.getDeviceUidsOfOwnedIdentity(channelManagerSession.session, ownedIdentity);
if (!deviceUidsMap.containsKey(ownedIdentity)) {
deviceUidsMap.put(ownedIdentity, new HashMap<>());
}
Map<Identity, Set<UID>> ownedIdentityMap = deviceUidsMap.get(ownedIdentity);
ownedIdentityMap.put(ownedIdentity, new HashSet<>(Arrays.asList(ownedDeviceUids)));
}

for (ObliviousChannel obliviousChannel : obliviousChannels) {
Identity ownedIdentity = ownedIdentityFromDeviceUid.get(obliviousChannel.getCurrentDeviceUid());
if (ownedIdentity == null) {
ownedIdentity = identityDelegate.getOwnedIdentityForDeviceUid(channelManagerSession.session, obliviousChannel.getCurrentDeviceUid());
ownedIdentity = identityDelegate.getOwnedIdentityForCurrentDeviceUid(channelManagerSession.session, obliviousChannel.getCurrentDeviceUid());
if (ownedIdentity == null) {
continue;
}
Expand All @@ -130,17 +142,48 @@ public void initialisationComplete() {
}
}

// now that we have removed all devices for which we have a channel, we walk through the deviceUidsMap to check for channel-less deviceUids
// now that we have removed (from the HashMap) all devices for which we have a channel, we walk through the deviceUidsMap to check for channel-less deviceUids
for (Identity ownedIdentity: deviceUidsMap.keySet()) {
// first check if some channels with owned devices should be restarted
boolean deviceDiscoveryNeeded = false;
if (identityDelegate.isActiveOwnedIdentity(channelManagerSession.session, ownedIdentity)) {
for (UID ownedDeviceUid : identityDelegate.getOtherDeviceUidsOfOwnedIdentity(channelManagerSession.session, ownedIdentity)) {
try {
boolean channelExists = checkIfObliviousChannelExists(channelManagerSession.session, ownedIdentity, ownedDeviceUid, ownedIdentity);
boolean channelCreationInProgress = protocolDelegate.isChannelCreationInProgress(channelManagerSession.session, ownedIdentity, ownedIdentity, ownedDeviceUid);
if (!channelExists && !channelCreationInProgress) {
// we found a device without a channel and no channel creation is in progress
// --> we delete the device and start a device discovery protocol
Logger.i("Found an owned device with no channel and no channel creation. Restarting device discovery.");
identityDelegate.removeDeviceForOwnedIdentity(channelManagerSession.session, ownedIdentity, ownedDeviceUid);
deviceDiscoveryNeeded = true;
}
} catch (Exception e) {
// nothing to do
}
}
if (deviceDiscoveryNeeded) {
try {
protocolStarterDelegate.startOwnedDeviceDiscoveryProtocolWithinTransaction(channelManagerSession.session, ownedIdentity);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Map<Identity, Set<UID>> ownedIdentityMap = deviceUidsMap.get(ownedIdentity);
if (ownedIdentityMap == null) {
continue;
}
for (Identity contactIdentity: ownedIdentityMap.keySet()) {
if (contactIdentity.equals(ownedIdentity)) {
continue;
}
Set<UID> deviceUidSet = ownedIdentityMap.get(contactIdentity);
if (deviceUidSet == null) {
continue;
}
deviceDiscoveryNeeded = false;
for (UID contactDeviceUid: deviceUidSet) {
// check if a ChannelCreationProtocolInstance exists for this device
try {
Expand All @@ -149,15 +192,23 @@ public void initialisationComplete() {
// --> we delete the device and start a device discovery protocol
Logger.i("Found a contact device with no channel and no channel creation. Restarting device discovery.");
identityDelegate.removeDeviceForContactIdentity(channelManagerSession.session, ownedIdentity, contactIdentity, contactDeviceUid);
protocolStarterDelegate.startDeviceDiscoveryProtocolWithinTransaction(channelManagerSession.session, ownedIdentity, contactIdentity);
deviceDiscoveryNeeded = true;
}
} catch (Exception e) {
// nothing to do
}
}
if (deviceDiscoveryNeeded) {
try {
protocolStarterDelegate.startDeviceDiscoveryProtocolWithinTransaction(channelManagerSession.session, ownedIdentity, contactIdentity);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

channelManagerSession.session.commit();
} catch (SQLException e) {
e.printStackTrace();
Expand Down Expand Up @@ -282,7 +333,12 @@ private ObliviousChannel getObliviousChannel(Session session, Identity ownedIden

@Override
public UID[] getConfirmedObliviousChannelDeviceUids(Session session, Identity ownedIdentity, Identity remoteIdentity) throws Exception {
UID[] remoteUids = identityDelegate.getDeviceUidsOfContactIdentity(session, ownedIdentity, remoteIdentity);
UID[] remoteUids;
if (Objects.equals(ownedIdentity, remoteIdentity)) { // channels with owned devices
remoteUids = identityDelegate.getOtherDeviceUidsOfOwnedIdentity(session, ownedIdentity);
} else {
remoteUids = identityDelegate.getDeviceUidsOfContactIdentity(session, ownedIdentity, remoteIdentity);
}
if ((remoteUids == null) || (remoteUids.length == 0)) {
return new UID[0];
}
Expand All @@ -308,24 +364,31 @@ public void deleteObliviousChannelsWithContact(Session session, Identity ownedId
@Override
public void deleteObliviousChannelIfItExists(Session session, Identity ownedIdentity, UID remoteDeviceUid, Identity remoteIdentity) throws Exception {
UID currentDeviceUid = identityDelegate.getCurrentDeviceUidOfOwnedIdentity(session, ownedIdentity);
// delete the channel
ObliviousChannel obliviousChannel = ObliviousChannel.get(wrapSession(session), currentDeviceUid, remoteDeviceUid, remoteIdentity, false);
if (obliviousChannel != null) {
// delete the channel
obliviousChannel.delete();
}
}

public boolean checkIfObliviousChannelExists(Session session, Identity ownedIdentity, UID remoteDeviceUid, Identity remoteIdentity) throws Exception {
@Override
public void deleteAllChannelsForOwnedIdentity(Session session, Identity ownedIdentity) throws SQLException {
UID currentDeviceUid = identityDelegate.getCurrentDeviceUidOfOwnedIdentity(session, ownedIdentity);
ObliviousChannel.deleteAll(wrapSession(session), currentDeviceUid);
}

public boolean checkIfObliviousChannelExists(Session session, Identity ownedIdentity, UID remoteDeviceUid, Identity remoteIdentity) throws SQLException {
UID currentDeviceUid = identityDelegate.getCurrentDeviceUidOfOwnedIdentity(session, ownedIdentity);
// delete the channel
ObliviousChannel obliviousChannel = ObliviousChannel.get(wrapSession(session), currentDeviceUid, remoteDeviceUid, remoteIdentity, false);
return obliviousChannel != null;
}

@Override
public void deleteAllChannelsForOwnedIdentity(Session session, Identity ownedIdentity) throws SQLException {
public boolean checkIfObliviousChannelIsConfirmed(Session session, Identity ownedIdentity, UID remoteDeviceUid, Identity remoteIdentity) throws SQLException {
UID currentDeviceUid = identityDelegate.getCurrentDeviceUidOfOwnedIdentity(session, ownedIdentity);
ObliviousChannel.deleteAll(wrapSession(session), currentDeviceUid);
ObliviousChannel obliviousChannel = ObliviousChannel.get(wrapSession(session), currentDeviceUid, remoteDeviceUid, remoteIdentity, true);
return obliviousChannel != null;

}

// endregion
Expand Down
Loading

0 comments on commit 39df8c4

Please sign in to comment.