Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
<micrometer.version>1.12.2</micrometer.version>
<junit-jupiter.version>5.11.2</junit-jupiter.version>
<uid2-shared.version>9.1.0</uid2-shared.version>
<uid2-shared.version>9.2.0</uid2-shared.version>
<okta-jwt.version>0.5.10</okta-jwt.version>
<image.version>${project.version}</image.version>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/admin/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.uid2.shared.jmx.AdminApi;
import com.uid2.shared.model.Site;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import com.uid2.shared.store.reader.*;
import com.uid2.shared.store.scope.GlobalScope;
import com.uid2.shared.util.HTTPPathMetricFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.uid2.admin.util.PublicSiteUtil;
import com.uid2.shared.auth.OperatorKey;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;

import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.uid2.shared.model.Site;
import com.uid2.shared.store.CloudPath;
import com.uid2.admin.legacy.LegacyClientKey;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
import com.uid2.shared.store.scope.GlobalScope;
import io.vertx.core.json.JsonObject;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/admin/secret/ISaltRotation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.uid2.admin.secret;

import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;

import java.time.Duration;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/uid2/admin/secret/SaltRotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.secret.IKeyGenerator;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import io.vertx.core.json.JsonObject;

import java.time.Duration;
Expand Down Expand Up @@ -77,7 +77,7 @@ private void addIndexesToRotate(List<Integer> entryIndexes,
int maxIndexes) {
final SaltEntry[] entries = lastSnapshot.getAllRotatingSalts();
final List<Integer> candidateIndexes = IntStream.range(0, entries.length)
.filter(i -> isBetween(entries[i].getLastUpdated(), minLastUpdated, maxLastUpdated))
.filter(i -> isBetween(entries[i].lastUpdated(), minLastUpdated, maxLastUpdated))
.boxed().collect(toList());
if (candidateIndexes.size() <= maxIndexes) {
entryIndexes.addAll(candidateIndexes);
Expand All @@ -103,7 +103,7 @@ private RotatingSaltProvider.SaltSnapshot createRotatedSnapshot(RotatingSaltProv
for (Integer i : entryIndexes) {
final SaltEntry oldSalt = nextSnapshot.getAllRotatingSalts()[i];
final String secret = this.keyGenerator.generateRandomKeyString(32);
nextSnapshot.getAllRotatingSalts()[i] = new SaltEntry(oldSalt.getId(), oldSalt.getHashedId(), lastUpdated, secret);
nextSnapshot.getAllRotatingSalts()[i] = new SaltEntry(oldSalt.id(), oldSalt.hashedId(), lastUpdated, secret, null, null, null, null);
}
return nextSnapshot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import com.uid2.admin.store.version.VersionGenerator;
import com.uid2.admin.store.writer.EncryptedSaltStoreWriter;
import com.uid2.admin.store.writer.StoreWriter;
import com.uid2.shared.Const;
import com.uid2.shared.cloud.TaggableCloudStorage;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.EncryptedRotatingSaltProvider;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.EncryptedRotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
import com.uid2.shared.store.reader.StoreReader;
import com.uid2.shared.store.scope.EncryptedScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.uid2.shared.model.CloudEncryptionKey;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
import com.uid2.shared.store.scope.StoreScope;
import org.slf4j.Logger;
Expand Down Expand Up @@ -85,7 +85,7 @@ protected boolean tryUploadSaltsSnapshot(RotatingSaltProvider.SaltSnapshot snaps
StringBuilder stringBuilder = new StringBuilder();

for (SaltEntry entry: snapshot.getAllRotatingSalts()) {
stringBuilder.append(entry.getId()).append(",").append(entry.getLastUpdated()).append(",").append(entry.getSalt()).append("\n");
stringBuilder.append(entry.id()).append(",").append(entry.lastUpdated()).append(",").append(entry.currentSalt()).append("\n");
}

String data = stringBuilder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.uid2.shared.cloud.TaggableCloudStorage;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
Expand Down Expand Up @@ -54,7 +54,7 @@ private List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvide
List<RotatingSaltProvider.SaltSnapshot> snapshots = null;
snapshots = Stream.concat(currentSnapshots.stream(), Stream.of(data))
.sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective))
.collect(Collectors.toList());
.toList();
RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = snapshots.stream()
.filter(snapshot -> snapshot.isEffective(now))
.reduce((a, b) -> b).orElse(null);
Expand Down Expand Up @@ -203,7 +203,7 @@ protected boolean tryUploadSaltsSnapshot(RotatingSaltProvider.SaltSnapshot snaps
final Path newSaltsFile = Files.createTempFile("operators", ".txt");
try (BufferedWriter w = Files.newBufferedWriter(newSaltsFile)) {
for (SaltEntry entry : snapshot.getAllRotatingSalts()) {
w.write(entry.getId() + "," + entry.getLastUpdated() + "," + entry.getSalt() + "\n");
w.write(entry.id() + "," + entry.lastUpdated() + "," + entry.currentSalt() + "\n");
}
}
this.upload(newSaltsFile.toString(), location);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/admin/util/PrivateSiteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.uid2.shared.model.KeysetKey;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.model.Site;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/admin/util/PublicSiteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.uid2.shared.auth.OperatorKey;
import com.uid2.shared.auth.OperatorType;
import com.uid2.shared.model.*;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/uid2/admin/vertx/service/SaltService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.uid2.admin.vertx.WriteLock;
import com.uid2.shared.auth.Role;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -109,10 +109,10 @@ private JsonObject toJson(RotatingSaltProvider.SaltSnapshot snapshot) {
jo.put("expires", snapshot.getExpires().toEpochMilli());
jo.put("salts_count", snapshot.getAllRotatingSalts().length);
jo.put("min_last_updated", Arrays.stream(snapshot.getAllRotatingSalts())
.map(SaltEntry::getLastUpdated)
.map(SaltEntry::lastUpdated)
.min(Long::compare).orElse(null));
jo.put("max_last_updated", Arrays.stream(snapshot.getAllRotatingSalts())
.map(SaltEntry::getLastUpdated)
.map(SaltEntry::lastUpdated)
.max(Long::compare).orElse(null));
return jo;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/uid2/admin/secret/SaltRotationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.secret.IKeyGenerator;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import io.vertx.core.json.JsonObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -48,7 +48,7 @@ private SnapshotBuilder() {}

public SnapshotBuilder withEntries(int count, Instant lastUpdated) {
for (int i = 0; i < count; ++i) {
entries.add(new SaltEntry(entries.size(), "h", lastUpdated.toEpochMilli(), "salt" + entries.size()));
entries.add(new SaltEntry(entries.size(), "h", lastUpdated.toEpochMilli(), "salt" + entries.size(), null, null, null, null));
}
return this;
}
Expand All @@ -60,7 +60,7 @@ public RotatingSaltProvider.SaltSnapshot build(Instant effective, Instant expire
}

private int countEntriesWithLastUpdated(SaltEntry[] entries, Instant lastUpdated) {
return (int)Arrays.stream(entries).filter(e -> e.getLastUpdated() == lastUpdated.toEpochMilli()).count();
return (int)Arrays.stream(entries).filter(e -> e.lastUpdated() == lastUpdated.toEpochMilli()).count();
}

private static void assertEqualsClose(Instant expected, Instant actual, int withinSeconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.uid2.shared.model.CloudEncryptionKey;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
import com.uid2.shared.store.scope.StoreScope;
import io.vertx.core.json.JsonArray;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void setup() throws Exception {
private RotatingSaltProvider.SaltSnapshot makeSnapshot(Instant effective, Instant expires, int nsalts) {
SaltEntry[] entries = new SaltEntry[nsalts];
for (int i = 0; i < entries.length; ++i) {
entries[i] = new SaltEntry(i, "hashed_id", effective.toEpochMilli(), "salt");
entries[i] = new SaltEntry(i, "hashed_id", effective.toEpochMilli(), "salt", null, null, null, null);
}
return new RotatingSaltProvider.SaltSnapshot(effective, expires, entries, "test_first_level_salt");
}
Expand All @@ -96,8 +96,8 @@ private void verifyFile(String filelocation, RotatingSaltProvider.SaltSnapshot s
int idx = 0;
for (String line : contents.split("\n")) {
String[] entrySplit = line.split(",");
assertEquals(entries[idx].getId(), Long.parseLong(entrySplit[0]));
assertEquals(entries[idx].getSalt(), entrySplit[2]);
assertEquals(entries[idx].id(), Long.parseLong(entrySplit[0]));
assertEquals(entries[idx].currentSalt(), entrySplit[2]);
idx++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/uid2/admin/vertx/SaltServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.uid2.admin.vertx.test.ServiceTestBase;
import com.uid2.shared.auth.Role;
import com.uid2.shared.model.SaltEntry;
import com.uid2.shared.store.RotatingSaltProvider;
import com.uid2.shared.store.salt.RotatingSaltProvider;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.junit5.VertxTestContext;
Expand Down Expand Up @@ -47,7 +47,7 @@ private void setSnapshots(RotatingSaltProvider.SaltSnapshot... snapshots) {
private RotatingSaltProvider.SaltSnapshot makeSnapshot(Instant effective, Instant expires, int nsalts) {
SaltEntry[] entries = new SaltEntry[nsalts];
for (int i = 0; i < entries.length; ++i) {
entries[i] = new SaltEntry(i, "hashed_id", effective.toEpochMilli(), "salt");
entries[i] = new SaltEntry(i, "hashed_id", effective.toEpochMilli(), "salt", null, null, null, null);
}
return new RotatingSaltProvider.SaltSnapshot(effective, expires, entries, "test_first_level_salt");
}
Expand Down