Skip to content

Commit

Permalink
Finishing salts and clientside keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-constine-ttd committed Dec 13, 2024
1 parent 5383c0b commit bfe7849
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.uid2</groupId>
<artifactId>uid2-operator</artifactId>
<version>5.42.7-alpha-139-SNAPSHOT</version>
<version>6.0.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -22,7 +22,7 @@
<enclave-aws.version>2.1.0</enclave-aws.version>
<enclave-azure.version>2.1.0</enclave-azure.version>
<enclave-gcp.version>2.1.0</enclave-gcp.version>
<uid2-shared.version>8.0.13-alpha-175-SNAPSHOT</uid2-shared.version>
<uid2-shared.version>8.0.14-alpha-176-SNAPSHOT</uid2-shared.version>
<image.version>${project.version}</image.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/operator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public Main(Vertx vertx, JsonObject config) throws Exception {
String keysetMdPath = this.config.getString(Const.Config.KeysetsMetadataPathProp);
this.keysetProvider = new RotatingKeysetProvider(fsStores, new GlobalScope(new CloudPath(keysetMdPath)), cloudEncryptionKeyProvider);
String saltsMdPath = this.config.getString(Const.Config.SaltsMetadataPathProp);
this.saltProvider = new EncryptedRotatingSaltProvider(fsStores, saltsMdPath, cloudEncryptionKeyProvider);
this.saltProvider = new EncryptedRotatingSaltProvider(fsStores, cloudEncryptionKeyProvider, new GlobalScope(new CloudPath(saltsMdPath)));
this.optOutStore = new CloudSyncOptOutStore(vertx, fsLocal, this.config, operatorKey, Clock.systemUTC());

if (this.validateServiceLinks) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/uid2/operator/reader/ApiStoreReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

Expand All @@ -21,13 +22,19 @@ public ApiStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope,
super(fileStreamProvider, scope, parser, dataTypeName);
}


public long loadContent(JsonObject contents) throws Exception {
return loadContent(contents, dataTypeName);
}

@Override
public long loadContent(JsonObject contents, String dataType) throws IOException {
if (contents == null) {
throw new IllegalArgumentException(String.format("No contents provided for loading data type %s, cannot load content", dataTypeName));
throw new IllegalArgumentException(String.format("No contents provided for loading data type %s, cannot load content", dataType));
}

try {
JsonArray dataArray = contents.getJsonArray(dataTypeName);
JsonArray dataArray = contents.getJsonArray(dataType);
if (dataArray == null) {
throw new IllegalArgumentException("No array found in the contents");
}
Expand All @@ -40,10 +47,10 @@ public long loadContent(JsonObject contents) throws Exception {

final int count = parsed.getCount();
latestEntryCount.set(count);
LOGGER.info(String.format("Loaded %d %s", count, dataTypeName));
LOGGER.info(String.format("Loaded %d %s", count, dataType));
return count;
} catch (Exception e) {
LOGGER.error(String.format("Unable to load %s", dataTypeName));
LOGGER.error(String.format("Unable to load %s", dataType));
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,19 @@
public class RotatingCloudEncryptionKeyApiProvider extends RotatingCloudEncryptionKeyProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(RotatingCloudEncryptionKeyApiProvider.class);

public ApiStoreReader<Map<Integer, CloudEncryptionKey>> apiStoreReader;

public RotatingCloudEncryptionKeyApiProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) {
super(fileStreamProvider, scope);
this.apiStoreReader = new ApiStoreReader<>(fileStreamProvider, scope, new CloudEncryptionKeyParser(), "cloud_encryption_keys");
}

@Override
public JsonObject getMetadata() throws Exception {
return apiStoreReader.getMetadata();
this.reader = new ApiStoreReader<>(fileStreamProvider, scope, new CloudEncryptionKeyParser(), "cloud_encryption_keys");
}

@Override
public CloudPath getMetadataPath() {
return apiStoreReader.getMetadataPath();
public RotatingCloudEncryptionKeyApiProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope, ApiStoreReader<Map<Integer, CloudEncryptionKey>> reader) {
super(fileStreamProvider, scope);
this.reader = reader;
}

@Override
public long loadContent(JsonObject metadata) throws Exception {
return apiStoreReader.loadContent(metadata);
}

@Override
public long getVersion(JsonObject metadata) {
return Instant.now().getEpochSecond();
}

@Override
public Map<Integer, CloudEncryptionKey> getAll() {
Map<Integer, CloudEncryptionKey> keys = apiStoreReader.getSnapshot();
return keys != null ? keys : new HashMap<>();
}

@Override
public void loadContent() throws Exception {
this.loadContent(this.getMetadata());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class RotatingCloudEncryptionKeyApiProviderTest {
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
rotatingCloudEncryptionKeyApiProvider = new RotatingCloudEncryptionKeyApiProvider(mockFileStreamProvider, mockScope);
rotatingCloudEncryptionKeyApiProvider.apiStoreReader = mockApiStoreReader;
rotatingCloudEncryptionKeyApiProvider = new RotatingCloudEncryptionKeyApiProvider(mockFileStreamProvider, mockScope, mockApiStoreReader);
}

@Test
Expand All @@ -61,11 +60,11 @@ void testGetMetadataPath() {
@Test
void testLoadContentWithMetadata() throws Exception {
JsonObject metadata = new JsonObject();
when(mockApiStoreReader.loadContent(metadata)).thenReturn(1L);
when(mockApiStoreReader.loadContent(metadata, "cloud_encryption_keys")).thenReturn(1L);

long version = rotatingCloudEncryptionKeyApiProvider.loadContent(metadata);
assertEquals(1L, version);
verify(mockApiStoreReader).loadContent(metadata);
verify(mockApiStoreReader).loadContent(metadata, "cloud_encryption_keys");
}

@Test
Expand Down Expand Up @@ -94,10 +93,10 @@ void testGetAllWithNullSnapshot() {
void testLoadContent() throws Exception {
JsonObject metadata = new JsonObject().put("version", 1L);
when(mockApiStoreReader.getMetadata()).thenReturn(metadata);
when(mockApiStoreReader.loadContent(metadata)).thenReturn(1L);
when(mockApiStoreReader.loadContent(metadata, "cloud_encryption_keys")).thenReturn(1L);

rotatingCloudEncryptionKeyApiProvider.loadContent();
verify(mockApiStoreReader).getMetadata();
verify(mockApiStoreReader).loadContent(metadata);
verify(mockApiStoreReader).loadContent(metadata, "cloud_encryption_keys");
}
}

0 comments on commit bfe7849

Please sign in to comment.