Skip to content

Commit

Permalink
Making change to multiscope writer to not copy all salts for each site
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-constine-ttd committed Dec 11, 2024
1 parent 3883853 commit f820ccc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.uid2.shared.store.RotatingSaltProvider;

import java.util.Collection;
import java.util.List;

public class SaltEncryptionJob extends Job {
private final Collection<OperatorKey> globalOperators;
Expand All @@ -32,9 +33,9 @@ public String getId() {

@Override
public void execute() throws Exception {
PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> desiredPrivateState = PrivateSiteUtil.getPrivateSaltEntries(saltEntries, globalOperators);
multiScopeStoreWriter.uploadPrivateWithEncryption(desiredPrivateState, null);
PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> desiredPublicState = PublicSiteUtil.getPublicSaltEntries(saltEntries, globalOperators);
multiScopeStoreWriter.uploadPublicWithEncryption(desiredPublicState, null);
List<Integer> desiredPrivateState = PrivateSiteUtil.getPrivateSaltSites(globalOperators);
multiScopeStoreWriter.uploadPrivateWithEncryption(desiredPrivateState, saltEntries, null);
List<Integer> desiredPublicState = PublicSiteUtil.getPublicSaltSites(globalOperators);
multiScopeStoreWriter.uploadPublicWithEncryption(desiredPublicState, saltEntries, null);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/uid2/admin/store/MultiScopeStoreWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public void uploadPrivateWithEncryption(Map<Integer, T> desiredState, JsonObject
}
}

public void uploadPrivateWithEncryption(List<Integer> siteIds, T desiredState, JsonObject extraMeta) throws Exception {
EncryptedStoreFactory<T> encryptedFactory = (EncryptedStoreFactory<T>) factory;
for (Integer siteId : siteIds) {
encryptedFactory.getEncryptedWriter(siteId,false).upload(desiredState, extraMeta);
}
}

public void uploadPublicWithEncryption(Map<Integer, T> desiredPublicState, JsonObject extraMeta) throws Exception {
EncryptedStoreFactory<T> encryptedFactory = (EncryptedStoreFactory<T>) factory;
for (Map.Entry<Integer, T> entry : desiredPublicState.entrySet()) {
Expand All @@ -77,6 +84,13 @@ public void uploadPublicWithEncryption(Map<Integer, T> desiredPublicState, JsonO
}
}

public void uploadPublicWithEncryption(List<Integer> siteIds, T desiredState, JsonObject extraMeta) throws Exception {
EncryptedStoreFactory<T> encryptedFactory = (EncryptedStoreFactory<T>) factory;
for (Integer siteId : siteIds) {
encryptedFactory.getEncryptedWriter(siteId,true).upload(desiredState, extraMeta);
}
}

public static <K, V> boolean areMapsEqual(Map<K, V> a, Map<K, V> b) {
return a.size() == b.size() && a.entrySet().stream().allMatch(b.entrySet()::contains);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import com.uid2.shared.store.reader.StoreReader;
import com.uid2.shared.store.scope.EncryptedScope;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;

public class SaltStoreFactory implements EncryptedStoreFactory<Collection<RotatingSaltProvider.SaltSnapshot>> {
private static final Logger LOGGER = LoggerFactory.getLogger(SaltStoreFactory.class);

JsonObject config;
CloudPath rootMetadatapath;
FileManager fileManager;
Expand Down Expand Up @@ -45,6 +49,7 @@ public StoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> getEncryptedWr

@Override
public StoreReader<Collection<RotatingSaltProvider.SaltSnapshot>> getEncryptedReader(Integer siteId, boolean isPublic) {
LOGGER.warn("getEncryptedReader called on SaltStoreFactory. This method is not implemented.");
return null;
}

Expand All @@ -55,11 +60,13 @@ public RotatingCloudEncryptionKeyProvider getCloudEncryptionProvider() {

@Override
public StoreReader<Collection<RotatingSaltProvider.SaltSnapshot>> getReader(Integer siteId) {
LOGGER.warn("getReader called on SaltStoreFactory. This method is not implemented.");
return null;
}

@Override
public StoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> getWriter(Integer siteId) {
LOGGER.warn("getWriter called on SaltStoreFactory. This method is not implemented.");
return null;
}
}
13 changes: 2 additions & 11 deletions src/main/java/com/uid2/admin/util/PrivateSiteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,8 @@ public static PrivateSiteDataMap<KeysetKey> getKeysetKeys(Collection<OperatorKey
return result;
}

public static PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> getPrivateSaltEntries(
Collection<RotatingSaltProvider.SaltSnapshot> globalSaltEntries,
Collection<OperatorKey> operators) {
public static List<Integer> getPrivateSaltSites(Collection<OperatorKey> operators) {
final PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> result = getPrivateSites(operators);

globalSaltEntries.forEach(saltEntry -> {
result.forEach((publicSiteId, publicSiteData) -> {
publicSiteData.add(saltEntry);
});
});

return result;
return result.keySet().stream().toList();
}
}
18 changes: 3 additions & 15 deletions src/main/java/com/uid2/admin/util/PublicSiteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;

public class PublicSiteUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(PrivateSiteUtil.class);
Expand Down Expand Up @@ -128,18 +125,9 @@ public static PrivateSiteDataMap<KeysetKey> getPublicKeysetKeys(
return result;
}

public static PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> getPublicSaltEntries(
Collection<RotatingSaltProvider.SaltSnapshot> globalSaltEntries,
Collection<OperatorKey> operators) {
public static List<Integer> getPublicSaltSites(Collection<OperatorKey> operators) {
final PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> result = getPublicSitesMap(operators);

globalSaltEntries.forEach(saltEntry -> {
result.forEach((publicSiteId, publicSiteData) -> {
publicSiteData.add(saltEntry);
});
});

return result;
return result.keySet().stream().toList();
}

public static PrivateSiteDataMap<ClientSideKeypair> getPublicClientKeypairs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class EncryptedSaltStoreWriterTest {

@Captor
private ArgumentCaptor<String> pathCaptor;
@Captor
private ArgumentCaptor<String> cloudPathCaptor;

@BeforeEach
public void setUp() throws Exception {
Expand Down Expand Up @@ -118,7 +120,9 @@ public void testUploadNew() throws Exception {

encryptedSaltStoreWriter.upload(snapshot);

verify(taggableCloudStorage).upload(pathCaptor.capture(), any(), any());
verify(taggableCloudStorage).upload(pathCaptor.capture(), cloudPathCaptor.capture(), any());
assertEquals(cloudPathCaptor.getValue(), "test/path");

verifyFile(pathCaptor.getValue(), snapshot);
}
}

0 comments on commit f820ccc

Please sign in to comment.