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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target/
.idea/
dependencies/
conf/*.json
sync/
out/
generated/
uid2-optout.iml
6 changes: 3 additions & 3 deletions conf/integ-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"optout_internal_api_token": "test-optout-internal-key",
"optout_replica_uris": "http://localhost:8081/optout/write,http://localhost:8081/optout/write,http://localhost:8081/optout/write",
"partners_config_path": "/com.uid2.core/test/partners/config.json",
"clients_metadata_path": "http://localhost:8088/clients/refresh",
"core_attest_url": "http://localhost:8088/attest/get_token",
"core_api_token": "test-partner-key"
"operators_metadata_path": "http://localhost:8088/operators/refresh",
"core_attest_url": "http://localhost:8088/attest",
"core_api_token": "trusted-partner-key"
}
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<vertx.version>3.9.4</vertx.version>
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
<micrometer.version>1.1.0</micrometer.version>
<image.version>${project.version}</image.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -161,6 +162,22 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/${project.artifactId}.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down
42 changes: 15 additions & 27 deletions src/main/java/com/uid2/optout/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.uid2.optout.vertx.OptOutLogProducer;
import com.uid2.optout.vertx.OptOutServiceVerticle;
import com.uid2.optout.vertx.PartnerConfigMonitor;
import com.uid2.shared.ApplicationVersion;
import com.uid2.shared.Utils;
import com.uid2.shared.attest.UidCoreClient;
import com.uid2.shared.auth.MultisourceAuthProvider;
Expand Down Expand Up @@ -80,10 +81,8 @@ public class Main {
private final JsonObject config;
private final ICloudStorage fsLocal = new LocalStorageMock();
private final ICloudStorage fsOptOut;
private final ICloudStorage fsClientKeyConfig;
private final ICloudStorage fsOperatorKeyConfig;
private final ICloudStorage fsPartnerConfig;
private final RotatingClientKeyProvider clientKeyProvider;
private final RotatingOperatorKeyProvider operatorKeyProvider;
private final boolean observeOnly;

Expand Down Expand Up @@ -133,34 +132,32 @@ public Main(Vertx vertx, JsonObject config) throws Exception {
LOGGER.info("Using CloudStorage for partners config: s3://" + optoutBucket);
}

ApplicationVersion appVersion = ApplicationVersion.load("uid2-optout", "uid2-shared", "enclave-attestation-api");

String coreAttestUrl = this.config.getString(Const.Config.CoreAttestUrlProp);
final ICloudStorage contentStorage;
if (coreAttestUrl != null) {
String coreApiToken = this.config.getString(Const.Config.CoreApiTokenProp);
this.fsClientKeyConfig = UidCoreClient.createNoAttest(coreAttestUrl, coreApiToken);
LOGGER.info("Client api-keys - Using uid2-core attestation endpoint: " + coreAttestUrl);

// need separate s3 creds - currently disabled
String optoutS3Bucket = this.config.getString(Const.Config.OptOutS3BucketProp);
this.fsOperatorKeyConfig = CloudUtils.createStorage(optoutS3Bucket, config);
LOGGER.info("Using CloudStorage for operator api-key config: s3://" + optoutS3Bucket);
boolean enforceHttps = this.config.getBoolean("enforce_https", true);
UidCoreClient uidCoreClient = UidCoreClient.createNoAttest(coreAttestUrl, coreApiToken, appVersion, enforceHttps);
if (useStorageMock) uidCoreClient.setAllowContentFromLocalFileSystem(true);
this.fsOperatorKeyConfig = uidCoreClient;
contentStorage = uidCoreClient.getContentStorage();
LOGGER.info("Operator api-keys - Using uid2-core attestation endpoint: " + coreAttestUrl);
} else if (useStorageMock) {
this.fsClientKeyConfig = new EmbeddedResourceStorage(Main.class);
this.fsOperatorKeyConfig = new EmbeddedResourceStorage(Main.class);
contentStorage = this.fsOperatorKeyConfig;
LOGGER.info("Client api-keys - Using EmbeddedResourceStorage");
} else {
String coreBucket = this.config.getString(Const.Config.CoreS3BucketProp);
this.fsClientKeyConfig = CloudUtils.createStorage(coreBucket, config);
String optoutS3Bucket = this.config.getString(Const.Config.OptOutS3BucketProp);
this.fsOperatorKeyConfig = CloudUtils.createStorage(optoutS3Bucket, config);
LOGGER.info("Using CloudStorage for client api-key at s3://" + coreBucket + ", and operator api-key at s3://" + optoutS3Bucket);
contentStorage = this.fsOperatorKeyConfig;
LOGGER.info("Using CloudStorage for operator api-key at s3://" + optoutS3Bucket);
}

String clientsMdPath = this.config.getString(Const.Config.ClientsMetadataPathProp);
this.clientKeyProvider = new RotatingClientKeyProvider(this.fsClientKeyConfig, clientsMdPath);
String operatorsMdPath = this.config.getString(Const.Config.OperatorsMetadataPathProp);
this.operatorKeyProvider = new RotatingOperatorKeyProvider(this.fsOperatorKeyConfig, this.fsOperatorKeyConfig, operatorsMdPath);
this.operatorKeyProvider = new RotatingOperatorKeyProvider(this.fsOperatorKeyConfig, contentStorage, operatorsMdPath);
if (useStorageMock) {
this.clientKeyProvider.loadContent();
this.operatorKeyProvider.loadContent(this.operatorKeyProvider.getMetadata());
}
}
Expand Down Expand Up @@ -258,9 +255,6 @@ public void run(String[] args) throws IOException {
// deploy optout cloud sync verticle
futs.add(this.deploySingleInstance(cloudSyncVerticle));

// deploy client key rotator
futs.add(this.createClientKeyRotator());

// deploy operator key rotator
futs.add(this.createOperatorKeyRotator());

Expand All @@ -281,8 +275,7 @@ public void run(String[] args) throws IOException {
}

Supplier<Verticle> svcSupplier = () -> {
MultisourceAuthProvider authProvider = new MultisourceAuthProvider(this.operatorKeyProvider, this.clientKeyProvider);
OptOutServiceVerticle svc = new OptOutServiceVerticle(vertx, authProvider, this.fsOptOut, this.config);
OptOutServiceVerticle svc = new OptOutServiceVerticle(vertx, this.operatorKeyProvider, this.fsOptOut, this.config);
// configure where OptOutService receives the latest cloud paths
cs.registerNewCloudPathsHandler(ps -> svc.setCloudPaths(ps));
return svc;
Expand Down Expand Up @@ -371,11 +364,6 @@ private Future uploadLastDelta(OptOutCloudSync cs, OptOutLogProducer logProducer
return promise.future();
}

private Future<String> createClientKeyRotator() {
RotatingStoreVerticle rotatingStore = new RotatingStoreVerticle("clients", 10000, clientKeyProvider);
return this.deploySingleInstance(rotatingStore);
}

private Future<String> createOperatorKeyRotator() {
RotatingStoreVerticle rotatingStore = new RotatingStoreVerticle("operators", 10000, operatorKeyProvider);
return this.deploySingleInstance(rotatingStore);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/uid2/optout/vertx/OptOutLogProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public void stop(Promise<Void> stopPromise) throws Exception {
}

public String getLastDelta() {
Optional<String> last = Arrays.stream((new File(this.deltaProducerDir)).list())
String[] deltaList = (new File(this.deltaProducerDir)).list();
if (deltaList == null) return null;
Optional<String> last = Arrays.stream(deltaList)
.sorted(OptOutUtils.DeltaFilenameComparatorDescending)
.findFirst();
if (last.isPresent()) return Paths.get(this.deltaProducerDir, last.get()).toString();
Expand Down