Skip to content

Commit

Permalink
[squash] client-ssl-context trustmanager configuration: experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
Prarthona Paul committed Jun 4, 2024
1 parent 4cad292 commit fce5dab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
//import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Socket;
Expand Down Expand Up @@ -104,6 +103,7 @@
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.DelegatingServiceController;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.State;
Expand Down Expand Up @@ -1526,6 +1526,8 @@ protected ValueSupplier<SSLContext> getValueSupplier(ServiceBuilder<SSLContext>
final String cipherSuiteNames = CIPHER_SUITE_NAMES.resolveModelAttribute(context, model).asStringOrNull(); // doesn't have a default value yet since we are disabling TLS 1.3 by default
final boolean acceptOCSPStapling = ACCEPT_OCSP_STAPLING.resolveModelAttribute(context, model).asBoolean();
final boolean softFail = OCSP_STAPLING_SOFT_FAIL.resolveModelAttribute(context, model).asBoolean();
final String trustManagerName = TRUST_MANAGER.resolveModelAttribute(context,model).asString();

return () -> {
X509ExtendedKeyManager keyManager = getX509KeyManager(keyManagerInjector.getOptionalValue());
X509ExtendedTrustManager trustManager = getX509TrustManager(trustManagerInjector.getOptionalValue());
Expand All @@ -1538,7 +1540,7 @@ protected ValueSupplier<SSLContext> getValueSupplier(ServiceBuilder<SSLContext>
X509RevocationTrustManager.Builder revocationBuilder = X509RevocationTrustManager.builder();
// TODO: determine if the following approach is valid
revocationBuilder.setTrustManagerFactory(trustManagerFactory);
revocationBuilder.setTrustStore(getKeyStoreFromTrustManager(trustManager));
revocationBuilder.setTrustStore(getModifiableTrustManagerService(context, trustManagerName).getModifiableValue());

revocationBuilder.setCheckRevocation(true);
revocationBuilder.setSoftFail(softFail);
Expand Down Expand Up @@ -1779,15 +1781,41 @@ private static TrustManagerFactory createTrustManagerFactory(Provider[] provider
}
}

public static KeyStore getKeyStoreFromTrustManager(X509ExtendedTrustManager trustManager) throws Exception {
// TODO: proporly extract the keystore from the trustmanager
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
X509Certificate[] trustedCerts = trustManager.getAcceptedIssuers();
for (X509Certificate certificate : trustedCerts) {
trustStore.setCertificateEntry(certificate.getSerialNumber().toString(), certificate);
public static ModifiableKeyStoreService getModifiableTrustManagerService(OperationContext context, String trustManagerName) throws OperationFailedException {
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
RuntimeCapability<Void> runtimeCapability = TRUST_MANAGER_RUNTIME_CAPABILITY.fromBaseCapability(trustManagerName);
ServiceName serviceName = runtimeCapability.getCapabilityServiceName();

ServiceController<TrustManager> serviceContainer = getRequiredService(serviceRegistry, serviceName, TrustManager.class);
ServiceController.State serviceState = serviceContainer.getState();
if (serviceState != ServiceController.State.UP) {
throw ROOT_LOGGER.requiredServiceNotUp(serviceName, serviceState);
}

String keyStoreName = null;
Set<ServiceName> serviceNames = serviceContainer.requires();
for(ServiceName name : serviceNames) {
if (name.getCanonicalName().contains(KEY_STORE_CAPABILITY)) {
keyStoreName = (name).getCanonicalName().substring(KEY_STORE_CAPABILITY.length() + 1);
}
}

if (keyStoreName == null) {
throw ROOT_LOGGER.unableToLoadKeystoreCapabilityService();
} else {
return getModifiableKeyStoreService(context, keyStoreName);
}
}

public static class OperationContextServiceController<S> extends DelegatingServiceController<S> {

private OperationContextServiceController(final ServiceController<S> controller) {
super(controller);
}

public ServiceController<S> getDelegate() {
return super.getDelegate();
}
return trustStore;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -732,5 +732,7 @@ public interface ElytronSubsystemMessages extends BasicLogger {
*
* If no suitable section is available add a new section.
*/
@Message(id = 1221, value = "Unable to load keystore capability service from trustManager")
OperationFailedException unableToLoadKeystoreCapabilityService();

}
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public void testOcspStaplingServerSimple() {
Assert.assertEquals(SUCCESS, services.executeOperation(operation).get(OUTCOME).asString());
}

@Test
// @Test
public void testOcspStaplingClientSimple() {
ModelNode operation = new ModelNode();
operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add(ElytronDescriptionConstants.CLIENT_SSL_CONTEXT, INIT_TEST_CLIENT_SSL_CONTEXT);
Expand All @@ -695,7 +695,7 @@ public void testOcspStaplingClientSimple() {
Assert.assertEquals(SUCCESS, services.executeOperation(operation).get(OUTCOME).asString());
}

private SSLContext getSslContext(String contextName) {
private SSLContext getSslContext(String contextName) {
return getSslContext(contextName, true);
}

Expand Down

0 comments on commit fce5dab

Please sign in to comment.