Skip to content

Commit bab6c15

Browse files
Starting with the rename of shared
1 parent cd3f23d commit bab6c15

17 files changed

+568
-580
lines changed

src/main/java/com/uid2/shared/Const.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static class Config {
6363
public static final String ServiceLinkMetadataPathProp = "service_links_metadata_path";
6464
public static final String SitesMetadataPathProp = "sites_metadata_path";
6565
public static final String OperatorsMetadataPathProp = "operators_metadata_path";
66-
public static final String S3keysMetadataPathProp = "s3_keys_metadata_path";
66+
public static final String CloudEncryptionKeysMetadataPathProp = "cloud_encryption_keys_metadata_path";
6767
public static final String SaltsMetadataPathProp = "salts_metadata_path";
6868
public static final String OptOutMetadataPathProp = "optout_metadata_path";
6969
public static final String CoreAttestUrlProp = "core_attest_url";

src/main/java/com/uid2/shared/model/S3Key.java renamed to src/main/java/com/uid2/shared/model/CloudEncryptionKey.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import java.util.Objects;
88

99
@JsonPropertyOrder({ "id", "siteId", "activates", "created", "secret" })
10-
public class S3Key {
10+
public class CloudEncryptionKey {
1111
private final int id;
1212
private final int siteId;
1313
private final long activates;
1414
private final long created;
1515
private final String secret;
1616

1717
@JsonCreator
18-
public S3Key(
18+
public CloudEncryptionKey(
1919
@JsonProperty("id") int id,
2020
@JsonProperty("site_id") int siteId,
2121
@JsonProperty("activates") long activates,
@@ -52,12 +52,12 @@ public String getSecret() {
5252
public boolean equals(Object o) {
5353
if (this == o) return true;
5454
if (o == null || getClass() != o.getClass()) return false;
55-
S3Key s3Key = (S3Key) o;
56-
return id == s3Key.id &&
57-
siteId == s3Key.siteId &&
58-
activates == s3Key.activates &&
59-
created == s3Key.created &&
60-
Objects.equals(secret, s3Key.secret);
55+
CloudEncryptionKey cloudEncryptionKey = (CloudEncryptionKey) o;
56+
return id == cloudEncryptionKey.id &&
57+
siteId == cloudEncryptionKey.siteId &&
58+
activates == cloudEncryptionKey.activates &&
59+
created == cloudEncryptionKey.created &&
60+
Objects.equals(secret, cloudEncryptionKey.secret);
6161
}
6262

6363
@Override

src/main/java/com/uid2/shared/store/EncryptedScopedStoreReader.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.uid2.shared.store;
22

33
import com.uid2.shared.cloud.DownloadCloudStorage;
4-
import com.uid2.shared.model.S3Key;
4+
import com.uid2.shared.model.CloudEncryptionKey;
55
import com.uid2.shared.store.parser.Parser;
66
import com.uid2.shared.store.parser.ParsingResult;
7-
import com.uid2.shared.store.scope.EncryptedScope;
87
import com.uid2.shared.store.scope.StoreScope;
9-
import com.uid2.shared.store.reader.RotatingS3KeyProvider;
8+
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
109
import io.vertx.core.json.JsonObject;
1110
import org.slf4j.Logger;
1211
import org.slf4j.LoggerFactory;
@@ -15,19 +14,18 @@
1514

1615
import com.uid2.shared.encryption.AesGcm;
1716

18-
import java.nio.charset.Charset;
1917
import java.nio.charset.StandardCharsets;
2018
import java.util.Base64;
2119
import java.util.Map;
2220

2321
public class EncryptedScopedStoreReader<T> extends ScopedStoreReader<T> {
2422
private static final Logger LOGGER = LoggerFactory.getLogger(EncryptedScopedStoreReader.class);
2523

26-
private final RotatingS3KeyProvider s3KeyProvider;
24+
private final RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider;
2725

28-
public EncryptedScopedStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope, Parser<T> parser, String dataTypeName, RotatingS3KeyProvider s3KeyProvider) {
26+
public EncryptedScopedStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope, Parser<T> parser, String dataTypeName, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) {
2927
super(fileStreamProvider, scope, parser, dataTypeName);
30-
this.s3KeyProvider = s3KeyProvider;
28+
this.cloudEncryptionKeyProvider = cloudEncryptionKeyProvider;
3129
}
3230

3331
@Override
@@ -52,9 +50,9 @@ protected String getDecryptedContent(String encryptedContent) throws Exception {
5250
JsonObject json = new JsonObject(encryptedContent);
5351
int keyId = json.getInteger("key_id");
5452
String encryptedPayload = json.getString("encrypted_payload");
55-
Map<Integer, S3Key> s3Keys = s3KeyProvider.getAll();
56-
S3Key decryptionKey = null;
57-
for (S3Key key : s3Keys.values()) {
53+
Map<Integer, CloudEncryptionKey> cloudEncryptionKeys = cloudEncryptionKeyProvider.getAll();
54+
CloudEncryptionKey decryptionKey = null;
55+
for (CloudEncryptionKey key : cloudEncryptionKeys.values()) {
5856
if (key.getId() == keyId) {
5957
decryptionKey = key;
6058
break;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.uid2.shared.store.parser;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.uid2.shared.model.CloudEncryptionKey;
5+
import com.uid2.shared.util.Mapper;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Arrays;
10+
import java.util.Map;
11+
import java.util.stream.Collectors;
12+
13+
public class CloudEncryptionKeyParser implements Parser<Map<Integer, CloudEncryptionKey>> {
14+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
15+
16+
@Override
17+
public ParsingResult<Map<Integer, CloudEncryptionKey>> deserialize(InputStream inputStream) throws IOException {
18+
CloudEncryptionKey[] cloudEncryptionKeys = OBJECT_MAPPER.readValue(inputStream, CloudEncryptionKey[].class);
19+
Map<Integer, CloudEncryptionKey> cloudEncryptionKeysMap = Arrays.stream(cloudEncryptionKeys)
20+
.collect(Collectors.toMap(CloudEncryptionKey::getId, s -> s));
21+
return new ParsingResult<>(cloudEncryptionKeysMap, cloudEncryptionKeysMap.size());
22+
}
23+
}

src/main/java/com/uid2/shared/store/parser/S3KeyParser.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/com/uid2/shared/store/reader/RotatingClientKeyProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.uid2.shared.store.IClientKeyProvider;
1010
import com.uid2.shared.store.ScopedStoreReader;
1111
import com.uid2.shared.store.parser.ClientParser;
12-
import com.uid2.shared.store.scope.EncryptedScope;
1312
import com.uid2.shared.store.scope.StoreScope;
1413
import io.vertx.core.json.JsonObject;
1514

@@ -49,8 +48,8 @@ public RotatingClientKeyProvider(DownloadCloudStorage fileStreamProvider, StoreS
4948
this.authorizableStore = new AuthorizableStore<>(ClientKey.class);
5049
}
5150

52-
public RotatingClientKeyProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope, RotatingS3KeyProvider s3KeyProvider) {
53-
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new ClientParser(), "auth keys", s3KeyProvider);
51+
public RotatingClientKeyProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) {
52+
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new ClientParser(), "auth keys", cloudEncryptionKeyProvider);
5453
this.authorizableStore = new AuthorizableStore<>(ClientKey.class);
5554
}
5655

src/main/java/com/uid2/shared/store/reader/RotatingS3KeyProvider.java renamed to src/main/java/com/uid2/shared/store/reader/RotatingCloudEncryptionKeyProvider.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.uid2.shared.cloud.DownloadCloudStorage;
44
import com.uid2.shared.store.CloudPath;
55
import com.uid2.shared.store.ScopedStoreReader;
6-
import com.uid2.shared.store.parser.S3KeyParser;
6+
import com.uid2.shared.store.parser.CloudEncryptionKeyParser;
77
import com.uid2.shared.store.scope.StoreScope;
8-
import com.uid2.shared.model.S3Key;
8+
import com.uid2.shared.model.CloudEncryptionKey;
99
import io.vertx.core.json.JsonObject;
1010

1111
import java.util.Set;
@@ -23,14 +23,14 @@
2323

2424
import java.time.Instant;
2525

26-
public class RotatingS3KeyProvider implements StoreReader<Map<Integer, S3Key>> {
27-
ScopedStoreReader<Map<Integer, S3Key>> reader;
26+
public class RotatingCloudEncryptionKeyProvider implements StoreReader<Map<Integer, CloudEncryptionKey>> {
27+
ScopedStoreReader<Map<Integer, CloudEncryptionKey>> reader;
2828

29-
private static final Logger LOGGER = LoggerFactory.getLogger(RotatingS3KeyProvider.class);
30-
public Map<Integer, List<S3Key>> siteToKeysMap = new HashMap<>();
29+
private static final Logger LOGGER = LoggerFactory.getLogger(RotatingCloudEncryptionKeyProvider.class);
30+
public Map<Integer, List<CloudEncryptionKey>> siteToKeysMap = new HashMap<>();
3131

32-
public RotatingS3KeyProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) {
33-
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new S3KeyParser(), "s3encryption_keys");
32+
public RotatingCloudEncryptionKeyProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) {
33+
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new CloudEncryptionKeyParser(), "cloud_encryption_keys");
3434
}
3535

3636
@Override
@@ -50,19 +50,19 @@ public long getVersion(JsonObject metadata) {
5050

5151
@Override
5252
public long loadContent(JsonObject metadata) throws Exception {
53-
long result = reader.loadContent(metadata, "s3encryption_keys");
53+
long result = reader.loadContent(metadata, "cloud_encryption_keys");
5454
updateSiteToKeysMapping();
5555
return result;
5656
}
5757

5858
@Override
59-
public Map<Integer, S3Key> getAll() {
60-
Map<Integer, S3Key> keys = reader.getSnapshot();
59+
public Map<Integer, CloudEncryptionKey> getAll() {
60+
Map<Integer, CloudEncryptionKey> keys = reader.getSnapshot();
6161
return keys != null ? keys : new HashMap<>();
6262
}
6363

6464
public void updateSiteToKeysMapping() {
65-
Map<Integer, S3Key> allKeys = getAll();
65+
Map<Integer, CloudEncryptionKey> allKeys = getAll();
6666
siteToKeysMap.clear();
6767
allKeys.values().forEach(key ->
6868
this.siteToKeysMap
@@ -85,28 +85,28 @@ public int getTotalSites() {
8585
return siteToKeysMap.size();
8686
}
8787

88-
public List<S3Key> getKeys(int siteId) {
88+
public List<CloudEncryptionKey> getKeys(int siteId) {
8989
//for s3 encryption keys retrieval
9090
return siteToKeysMap.getOrDefault(siteId, new ArrayList<>());
9191
}
9292

93-
public Collection<S3Key> getKeysForSite(Integer siteId) {
94-
Map<Integer, S3Key> allKeys = getAll();
93+
public Collection<CloudEncryptionKey> getKeysForSite(Integer siteId) {
94+
Map<Integer, CloudEncryptionKey> allKeys = getAll();
9595
return allKeys.values().stream()
9696
.filter(key -> key.getSiteId() == (siteId))
9797
.collect(Collectors.toList());
9898
}
9999

100-
public S3Key getEncryptionKeyForSite(Integer siteId) {
100+
public CloudEncryptionKey getEncryptionKeyForSite(Integer siteId) {
101101
//get the youngest activated key
102-
Collection<S3Key> keys = getKeysForSite(siteId);
102+
Collection<CloudEncryptionKey> keys = getKeysForSite(siteId);
103103
long now = Instant.now().getEpochSecond();
104104
if (keys.isEmpty()) {
105105
throw new IllegalStateException("No S3 keys available for encryption for site ID: " + siteId);
106106
}
107107
return keys.stream()
108108
.filter(key -> key.getActivates() <= now)
109-
.max(Comparator.comparingLong(S3Key::getCreated))
109+
.max(Comparator.comparingLong(CloudEncryptionKey::getCreated))
110110
.orElseThrow(() -> new IllegalStateException("No active keys found for site ID: " + siteId));
111111
}
112112
}

src/main/java/com/uid2/shared/store/reader/RotatingKeyAclProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.uid2.shared.auth.AclSnapshot;
44
import com.uid2.shared.auth.EncryptionKeyAcl;
55
import com.uid2.shared.cloud.DownloadCloudStorage;
6-
import com.uid2.shared.cloud.ICloudStorage;
76
import com.uid2.shared.store.CloudPath;
87
import com.uid2.shared.store.EncryptedScopedStoreReader;
98
import com.uid2.shared.store.IKeyAclProvider;
@@ -23,8 +22,8 @@ public RotatingKeyAclProvider(DownloadCloudStorage fileStreamProvider, StoreScop
2322
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new KeyAclParser(), "key acls");
2423
}
2524

26-
public RotatingKeyAclProvider(DownloadCloudStorage fileStreamProvider, EncryptedScope scope, RotatingS3KeyProvider s3KeyProvider) {
27-
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new KeyAclParser(), "key acls", s3KeyProvider);
25+
public RotatingKeyAclProvider(DownloadCloudStorage fileStreamProvider, EncryptedScope scope, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) {
26+
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new KeyAclParser(), "key acls", cloudEncryptionKeyProvider);
2827
}
2928

3029
@Override

src/main/java/com/uid2/shared/store/reader/RotatingKeyStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public RotatingKeyStore(DownloadCloudStorage fileStreamProvider, StoreScope scop
5252
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new KeyParser(), "keys");
5353
}
5454

55-
public RotatingKeyStore(DownloadCloudStorage fileStreamProvider, EncryptedScope scope, RotatingS3KeyProvider s3KeyProvider) {
56-
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new KeyParser(), "keys", s3KeyProvider);
55+
public RotatingKeyStore(DownloadCloudStorage fileStreamProvider, EncryptedScope scope, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) {
56+
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new KeyParser(), "keys", cloudEncryptionKeyProvider);
5757
}
5858

5959
@Override

src/main/java/com/uid2/shared/store/reader/RotatingKeysetKeyStore.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.uid2.shared.store.KeysetKeyStoreSnapshot;
88
import com.uid2.shared.store.ScopedStoreReader;
99
import com.uid2.shared.store.parser.KeysetKeyParser;
10-
import com.uid2.shared.store.scope.EncryptedScope;
1110
import com.uid2.shared.store.scope.StoreScope;
1211
import com.uid2.shared.store.EncryptedScopedStoreReader;
1312
import io.vertx.core.json.JsonObject;
@@ -22,8 +21,8 @@ public RotatingKeysetKeyStore(DownloadCloudStorage fileStreamProvider, StoreScop
2221
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new KeysetKeyParser(), "keyset_keys");
2322
}
2423

25-
public RotatingKeysetKeyStore(DownloadCloudStorage fileStreamProvider, StoreScope scope, RotatingS3KeyProvider s3KeyProvider) {
26-
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new KeysetKeyParser(), "keyset_keys", s3KeyProvider);
24+
public RotatingKeysetKeyStore(DownloadCloudStorage fileStreamProvider, StoreScope scope, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) {
25+
this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new KeysetKeyParser(), "keyset_keys", cloudEncryptionKeyProvider);
2726
}
2827

2928
@Override

0 commit comments

Comments
 (0)