Skip to content

Commit

Permalink
Add proxy selector to httpclient in UidCore and AttestationRetriever
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalegbert-ttd committed Oct 3, 2023
1 parent cab5c3b commit 93f30df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.uid2.enclave.IAttestationProvider;
import com.uid2.shared.*;
import com.uid2.shared.cloud.CloudUtils;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.Json;
Expand Down Expand Up @@ -78,7 +79,7 @@ public AttestationTokenRetriever(Vertx vertx,
this.isExpiryCheckScheduled = false;
this.isAttesting = new AtomicBoolean(false);
if (httpClient == null) {
this.httpClient = HttpClient.newHttpClient();
this.httpClient = HttpClient.newBuilder().proxy(CloudUtils.defaultProxySelector).build();
} else {
this.httpClient = httpClient;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/shared/attest/UidCoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public UidCoreClient(String userToken,
this.contentStorage = new PreSignedURLStorage(proxy);
this.enforceHttps = enforceHttps;
if (httpClient == null) {
this.httpClient = HttpClient.newHttpClient();
this.httpClient = HttpClient.newBuilder().proxy(CloudUtils.defaultProxySelector).build();
} else {
this.httpClient = httpClient;
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/uid2/shared/cloud/CloudUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,35 @@
import software.amazon.awssdk.services.kms.KmsClientBuilder;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CloudUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(CloudUtils.class);
public static Proxy defaultProxy = getDefaultProxy();
public static ProxySelector defaultProxySelector = getDefaultProxySelector();

private static ProxySelector getDefaultProxySelector() {
return new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
if (defaultProxy != null) {
return List.of(defaultProxy);
}

return List.of();
}

@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
LOGGER.error("Failed to connect to proxy", ioe);
}
};
}

public static TaggableCloudStorage createStorage(String cloudBucket, JsonObject jsonConfig) {
var accessKeyId = jsonConfig.getString(Const.Config.AccessKeyIdProp);
Expand Down

0 comments on commit 93f30df

Please sign in to comment.