Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public void run() {
private EventHubProducerAsyncClient getForwardProducer() {
final TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
final EventHubClientBuilder builder = new EventHubClientBuilder()
.credential(options.getEventHubsFullyQualifiedNamespace(), forwardEventHubName,
tokenCredential)
.credential(options.getEventHubsFullyQualifiedNamespace(), forwardEventHubName, tokenCredential)
.retryOptions(new AmqpRetryOptions().setTryTimeout(Duration.ofSeconds(10)))
.transportType(options.getAmqpTransportType())
.consumerGroup(options.getEventHubsConsumerGroup());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public TelemetryHelper(Class<?> scenarioClass) {
*/
private static OpenTelemetry init() {
System.setProperty("otel.java.global-autoconfigure.enabled", "true");

AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
String applicationInsightsConnectionString = System.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (applicationInsightsConnectionString == null) {
Expand Down
108 changes: 55 additions & 53 deletions sdk/keyvault/azure-security-keyvault-jca/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ while (true) {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

String body = "Hello, this is server.";
String response =
"HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: " + body.getBytes("UTF-8").length + "\r\n" + "Connection: close\r\n" + "\r\n" + body;
String response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: "
+ body.getBytes(StandardCharsets.UTF_8).length + "\r\nConnection: close\r\n\r\n" + body;

out.write(response);
out.flush();
Expand All @@ -207,34 +207,35 @@ Security.addProvider(provider);

KeyStore keyStore = KeyVaultKeyStore.getKeyVaultKeyStoreBySystemProperty();

SSLContext sslContext = SSLContexts
.custom()
.loadTrustMaterial(keyStore, new TrustSelfSignedStrategy())
.build();

SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
sslContext, (hostname, session) -> true);

PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslConnectionSocketFactory)
.build());
// This section initializing SSLContext can be replaced with implementation specific consumption of 'KeyStore',
// if the library being used has convenience methods for that.
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManager[] trustManagers = SampleUtils.loadTrustMaterial(keyStore);
sslContext.init(null, trustManagers, null);

String result = null;

try (CloseableHttpClient client = HttpClients.custom().setConnectionManager(manager).build()) {
HttpGet httpGet = new HttpGet("https://localhost:8765");
HttpClientResponseHandler<String> responseHandler = (ClassicHttpResponse response) -> {
int status = response.getCode();
String result1 = "Not success";
if (status == 200) {
result1 = EntityUtils.toString(response.getEntity());
}
return result1;
};
result = client.execute(httpGet, responseHandler);
HttpsURLConnection connection = null;
try {
// openConnection will return HttpsURLConnection when the protocol is 'https'.
connection = (HttpsURLConnection) URI.create("https://localhost:8765").toURL().openConnection();

// Have the HttpsURLConnection use the SSLSocketFactory returned by SSLContext.
connection.setSSLSocketFactory(sslContext.getSocketFactory());

connection.setRequestMethod("GET");
int status = connection.getResponseCode();
if (status == 200) {
result = SampleUtils.readResponse(connection);
} else {
result = "Not success";
}
} catch (IOException ioe) {
ioe.printStackTrace();
result = "Not success";
} finally {
if (connection != null) {
connection.disconnect();
}
}
System.out.println(result);
```
Expand Down Expand Up @@ -280,8 +281,8 @@ while (true) {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

String body = "Hello, this is server.";
String response =
"HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: " + body.getBytes("UTF-8").length + "\r\n" + "Connection: close\r\n" + "\r\n" + body;
String response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: "
+ body.getBytes(StandardCharsets.UTF_8).length + "\r\nConnection: close\r\n\r\n" + body;

out.write(response);
out.flush();
Expand Down Expand Up @@ -310,35 +311,36 @@ System.setProperty("azure.keyvault.client-id", "<server-azure-keyvault-client-id
System.setProperty("azure.keyvault.client-secret", "<server-azure-keyvault-client-secret>");
KeyStore trustStore = KeyVaultKeyStore.getKeyVaultKeyStoreBySystemProperty();

SSLContext sslContext = SSLContexts
.custom()
.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
.loadKeyMaterial(keyStore, "".toCharArray())
.build();

SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
sslContext, (hostname, session) -> true);

PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslConnectionSocketFactory)
.build());
// This section initializing SSLContext can be replaced with implementation specific consumption of 'KeyStore',
// if the library being used has convenience methods for that.
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManager[] trustManagers = SampleUtils.loadTrustMaterial(keyStore);
KeyManager[] keyManagers = SampleUtils.loadKeyMaterial(keyStore, "".toCharArray());
sslContext.init(keyManagers, trustManagers, null);

String result = null;

try (CloseableHttpClient client = HttpClients.custom().setConnectionManager(manager).build()) {
HttpGet httpGet = new HttpGet("https://localhost:8765");
HttpClientResponseHandler<String> responseHandler = (ClassicHttpResponse response) -> {
int status = response.getCode();
String result1 = "Not success";
if (status == 200) {
result1 = EntityUtils.toString(response.getEntity());
}
return result1;
};
result = client.execute(httpGet, responseHandler);
HttpsURLConnection connection = null;
try {
// openConnection will return HttpsURLConnection when the protocol is 'https'.
connection = (HttpsURLConnection) URI.create("https://localhost:8765").toURL().openConnection();

// Have the HttpsURLConnection use the SSLSocketFactory returned by SSLContext.
connection.setSSLSocketFactory(sslContext.getSocketFactory());

connection.setRequestMethod("GET");
int status = connection.getResponseCode();
if (status == 200) {
result = SampleUtils.readResponse(connection);
} else {
result = "Not success";
}
} catch (IOException ioe) {
ioe.printStackTrace();
result = "Not success";
} finally {
if (connection != null) {
connection.disconnect();
}
}
System.out.println(result);
```
Expand Down
36 changes: 1 addition & 35 deletions sdk/keyvault/azure-security-keyvault-jca/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -35,12 +34,6 @@
<version>2.73.11</version> <!-- {x-version-update;org.bouncycastle:bcpkix-lts8on;external_dependency} -->
<optional>true</optional>
</dependency>
<!-- Apache HttpClient -->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.4.3</version> <!-- {x-version-update;org.apache.httpcomponents.client5:httpclient5;external_dependency} -->
</dependency>
<!-- Conscrypt -->
<dependency>
<groupId>org.conscrypt</groupId>
Expand All @@ -61,34 +54,7 @@
<artifactId>slf4j-nop</artifactId>
<version>1.7.36</version> <!-- {x-version-update;org.slf4j:slf4j-nop;external_dependency} -->
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.11.0</version> <!-- {x-version-update;org.mockito:mockito-inline;external_dependency} -->
<scope>test</scope>
</dependency>
<!-- bytebuddy dependencies are required for mockito 4.11.0 to work with Java 21. Mockito 4.11.0 is the last release -->
<!-- of Mockito supporting Java 8 as a baseline. -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.17.7</version> <!-- {x-version-update;testdep_net.bytebuddy:byte-buddy;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.17.7</version> <!-- {x-version-update;testdep_net.bytebuddy:byte-buddy-agent;external_dependency} -->
<scope>test</scope>
</dependency>
<!-- For some reason upgrading past Mockito 4.6.1 requires this to be added. -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>4.8.3</version> <!-- {x-version-update;com.github.spotbugs:spotbugs-annotations;external_dependency} -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@

package com.azure.security.keyvault.jca;

import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessRsa256Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessRsa512Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessEcSha256Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessEcSha384Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessEcSha512Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessEcSha256Signature;
import com.azure.security.keyvault.jca.implementation.signature.AbstractKeyVaultKeylessSignature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessRsa256Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessRsa512Signature;
import com.azure.security.keyvault.jca.implementation.signature.KeyVaultKeylessRsaSsaPssSignature;

import java.lang.reflect.InvocationTargetException;
import java.security.PrivilegedAction;
import java.security.Provider;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Stream;

/**
* The Azure Key Vault security provider.
Expand Down Expand Up @@ -48,6 +45,7 @@ public final class KeyVaultJcaProvider extends Provider {
/**
* Constructor.
*/
@SuppressWarnings("deprecation")
public KeyVaultJcaProvider() {
super(PROVIDER_NAME, VERSION, INFO);
initialize();
Expand All @@ -74,21 +72,20 @@ private void initialize() {
Collections.singletonList("DKS"), null));
putService(new Provider.Service(this, "KeyStore", KeyVaultKeyStore.ALGORITHM_NAME,
KeyVaultKeyStore.class.getName(), Collections.singletonList(KeyVaultKeyStore.ALGORITHM_NAME), null));
Stream
.of(KeyVaultKeylessRsaSsaPssSignature.class, KeyVaultKeylessRsa256Signature.class,
KeyVaultKeylessRsa512Signature.class, KeyVaultKeylessEcSha256Signature.class,
KeyVaultKeylessEcSha384Signature.class, KeyVaultKeylessEcSha512Signature.class)
.forEach(c -> putService(new Service(this, "Signature", getAlgorithmName(c), c.getName(), null, null)));

putService(new Service(this, "Signature", KeyVaultKeylessRsaSsaPssSignature.ALGORITHM_NAME,
KeyVaultKeylessRsaSsaPssSignature.class.getName(), null, null));
putService(new Service(this, "Signature", KeyVaultKeylessRsa256Signature.ALGORITHM_NAME,
KeyVaultKeylessRsa256Signature.class.getName(), null, null));
putService(new Service(this, "Signature", KeyVaultKeylessRsa512Signature.ALGORITHM_NAME,
KeyVaultKeylessRsa512Signature.class.getName(), null, null));
putService(new Service(this, "Signature", KeyVaultKeylessEcSha256Signature.ALGORITHM_NAME,
KeyVaultKeylessEcSha256Signature.class.getName(), null, null));
putService(new Service(this, "Signature", KeyVaultKeylessEcSha384Signature.ALGORITHM_NAME,
KeyVaultKeylessEcSha384Signature.class.getName(), null, null));
putService(new Service(this, "Signature", KeyVaultKeylessEcSha512Signature.ALGORITHM_NAME,
KeyVaultKeylessEcSha512Signature.class.getName(), null, null));
return null;
});
}

private String getAlgorithmName(Class<? extends AbstractKeyVaultKeylessSignature> c) {
try {
return c.getDeclaredConstructor().newInstance().getAlgorithmName();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException
| NoSuchMethodException e) {
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class KeyVaultTrustManagerFactoryProvider extends Provider {
/**
* Constructor.
*/
@SuppressWarnings("deprecation")
public KeyVaultTrustManagerFactoryProvider() {
super(NAME, VERSION, INFO);
initialize();
Expand Down
Loading
Loading