Skip to content

Commit 36a29df

Browse files
authored
fix: Issue #115 - fix for SSL Context for IDP and plaintext platform (#116)
fix for #115 Note, to repro the error run the new test _testPlatformPlainTextAndIDPWithSSL_ without the fix in SDKBuilder.
1 parent 33b5982 commit 36a29df

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public SDK build() {
224224
*/
225225
private ManagedChannelBuilder<?> getManagedChannelBuilder(String endpoint) {
226226
ManagedChannelBuilder<?> channelBuilder;
227-
if (sslFactory != null) {
227+
if (sslFactory != null && !usePlainText) {
228228
channelBuilder = Grpc.newChannelBuilder(endpoint, TlsChannelCredentials.newBuilder()
229229
.trustManager(sslFactory.getTrustManager().get()).build());
230230
}else{

sdk/src/test/java/io/opentdf/platform/sdk/SDKBuilderTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.protobuf.Struct;
44
import com.google.protobuf.Value;
5-
import io.grpc.ClientInterceptor;
65
import io.grpc.Metadata;
76
import io.grpc.Server;
87
import io.grpc.ServerBuilder;
@@ -89,17 +88,23 @@ void testKeystoreSSLContext() throws Exception{
8988

9089
}
9190

91+
92+
@Test
93+
public void testPlatformPlainTextAndIDPWithSSL() throws Exception{
94+
sdkServicesSetup(false, true);
95+
}
96+
9297
@Test
9398
void testSDKServicesWithTruststore() throws Exception{
94-
sdkServicesSetup(true);
99+
sdkServicesSetup(true, true);
95100
}
96101

97102
@Test
98103
void testCreatingSDKServicesPlainText() throws Exception {
99-
sdkServicesSetup(false);
104+
sdkServicesSetup(false, false);
100105
}
101106

102-
void sdkServicesSetup(boolean useSSL) throws Exception{
107+
void sdkServicesSetup(boolean useSSLPlatform, boolean useSSLIDP) throws Exception{
103108

104109
HeldCertificate rootCertificate = new HeldCertificate.Builder()
105110
.certificateAuthority(0)
@@ -122,7 +127,7 @@ void sdkServicesSetup(boolean useSSL) throws Exception{
122127
// * it returns the OIDC configuration we use at bootstrapping time
123128
// * it fakes out being an IDP and returns an access token when need to retrieve an access token
124129
try (MockWebServer httpServer = new MockWebServer()) {
125-
if (useSSL){
130+
if (useSSLIDP){
126131
httpServer.useHttps(serverHandshakeCertificates.sslSocketFactory(), false);
127132
}
128133
String oidcConfig;
@@ -179,7 +184,7 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, Re
179184
return next.startCall(call, headers);
180185
}
181186
});
182-
if (useSSL){
187+
if (useSSLPlatform){
183188
platformServicesServerBuilder = platformServicesServerBuilder.useTransportSecurity(
184189
new ByteArrayInputStream(serverCertificate.certificatePem().getBytes()),
185190
new ByteArrayInputStream(serverCertificate.privateKeyPkcs8Pem().getBytes()));
@@ -207,7 +212,7 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, Re
207212
}
208213
});
209214

210-
if(useSSL){
215+
if(useSSLPlatform){
211216
kasServerBuilder = kasServerBuilder.useTransportSecurity(
212217
new ByteArrayInputStream(serverCertificate.certificatePem().getBytes()),
213218
new ByteArrayInputStream(serverCertificate.privateKeyPkcs8Pem().getBytes()));
@@ -220,15 +225,16 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, Re
220225
.clientSecret("client-id", "client-secret")
221226
.platformEndpoint("localhost:" + platformServicesServer.getPort());
222227

223-
if(!useSSL) {
228+
if(!useSSLPlatform) {
224229
servicesBuilder = servicesBuilder.useInsecurePlaintextConnection(true);
225-
}else{
230+
}
231+
if (useSSLPlatform || useSSLIDP){
226232
servicesBuilder = servicesBuilder.sslFactory(SSLFactory.builder().withTrustMaterial(rootCertificate.
227233
certificate()).build());
228234
}
229235

230236
var servicesAndComponents = servicesBuilder.buildServices();
231-
if (useSSL) {
237+
if (useSSLPlatform || useSSLIDP) {
232238
assertThat(servicesAndComponents.trustManager).isNotNull();
233239
}
234240
assertThat(servicesAndComponents.interceptor).isNotNull();

0 commit comments

Comments
 (0)