-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
578 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
auth/client/src/main/java/org/wildfly/security/auth/client/DynamicSSLContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.wildfly.security.auth.client; | ||
|
||
import org.kohsuke.MetaInfServices; | ||
import org.wildfly.security.dynamic.ssl.ssl.DynamicSSLContextSPI; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import java.net.URI; | ||
import java.security.AccessController; | ||
import java.security.GeneralSecurityException; | ||
import java.security.PrivilegedAction; | ||
import java.util.List; | ||
|
||
@MetaInfServices(value = DynamicSSLContextSPI.class) | ||
public class DynamicSSLContextImpl implements DynamicSSLContextSPI { | ||
|
||
private SSLContext configuredDefaultSSLContext; | ||
private final AuthenticationContextConfigurationClient AUTH_CONTEXT_CLIENT = | ||
AccessController.doPrivileged((PrivilegedAction<AuthenticationContextConfigurationClient>) AuthenticationContextConfigurationClient::new); | ||
private AuthenticationContext authenticationContext = AuthenticationContext.captureCurrent(); | ||
private List<SSLContext> configuredSSLContexts; | ||
|
||
public DynamicSSLContextImpl() { | ||
this.configuredSSLContexts = AUTH_CONTEXT_CLIENT.getConfiguredSSLContexts(authenticationContext); | ||
} | ||
|
||
@Override | ||
public SSLContext getConfiguredDefault() { | ||
return this.configuredDefaultSSLContext; | ||
} | ||
|
||
@Override | ||
public List<SSLContext> getConfiguredSSLContexts() { | ||
return this.configuredSSLContexts; | ||
} | ||
|
||
@Override | ||
public SSLContext getSSLContext(URI uri) { | ||
try { | ||
return AUTH_CONTEXT_CLIENT.getSSLContext(uri, authenticationContext); | ||
} catch (GeneralSecurityException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...ent/src/test/java/org/wildfly/security/auth/client/DynamicSSLContextIntersectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.wildfly.security.auth.client; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.wildfly.security.dynamic.ssl.ssl.DynamicSSLContext; | ||
import org.wildfly.security.dynamic.ssl.ssl.DynamicSslContextSpi; | ||
import org.wildfly.security.SecurityFactory; | ||
import org.wildfly.security.auth.client.mocks.MockSSLContext; | ||
import org.wildfly.security.auth.client.mocks.MockSSLContextSPI; | ||
import org.wildfly.security.auth.client.mocks.MockSSLSocketFactory; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLSocketFactory; | ||
import java.security.GeneralSecurityException; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DynamicSSLContextIntersectionTest { | ||
|
||
@Test | ||
public void testIntersectionOfSupportedCipherSuites() throws GeneralSecurityException { | ||
|
||
SSLSocketFactory sslSocketFactory0Ciphers = new MockSSLSocketFactory() { | ||
@Override | ||
public String[] getSupportedCipherSuites() { | ||
return new String[0]; | ||
} | ||
}; | ||
|
||
SSLSocketFactory sslSocketFactory3Ciphers = new MockSSLSocketFactory() { | ||
@Override | ||
public String[] getSupportedCipherSuites() { | ||
return new String[]{"TLS_AES_128_GCM_SHA256", "TLS_CHACHA20_POLY1305_SHA256", "TLS_CIPHER_SUITE_NOT_COMMON"}; | ||
} | ||
}; | ||
|
||
SSLSocketFactory sslSocketFactory4Ciphers = new MockSSLSocketFactory() { | ||
@Override | ||
public String[] getSupportedCipherSuites() { | ||
return new String[]{"TLS_CHACHA20_POLY1305_SHA256", "TLS_AES_128_CCM_8_SHA256", "TLS_AES_128_GCM_SHA256", "TLS_AES_128_CCM_SHA256"}; | ||
} | ||
}; | ||
|
||
SSLContext sslContext0Ciphers = new MockSSLContext(new MockSSLContextSPI() { | ||
@Override | ||
protected SSLSocketFactory engineGetSocketFactory() { | ||
return sslSocketFactory0Ciphers; | ||
} | ||
}); | ||
|
||
SSLContext sslContext3Ciphers = new MockSSLContext(new MockSSLContextSPI() { | ||
@Override | ||
protected SSLSocketFactory engineGetSocketFactory() { | ||
return sslSocketFactory3Ciphers; | ||
} | ||
}); | ||
|
||
SSLContext sslContext4Ciphers = new MockSSLContext(new MockSSLContextSPI() { | ||
@Override | ||
protected SSLSocketFactory engineGetSocketFactory() { | ||
return sslSocketFactory4Ciphers; | ||
} | ||
}); | ||
|
||
|
||
SecurityFactory<SSLContext> sslContextSecurityFactory0Ciphers = mock(SecurityFactory.class); | ||
SecurityFactory<SSLContext> sslContextSecurityFactoryt3Ciphers = mock(SecurityFactory.class); | ||
SecurityFactory<SSLContext> sslContextSecurityFactory4Ciphers = mock(SecurityFactory.class); | ||
|
||
when(sslContextSecurityFactory0Ciphers.create()).thenReturn(sslContext0Ciphers); | ||
when(sslContextSecurityFactoryt3Ciphers.create()).thenReturn(sslContext3Ciphers); | ||
when(sslContextSecurityFactory4Ciphers.create()).thenReturn(sslContext4Ciphers); | ||
|
||
AuthenticationContext ctx = AuthenticationContext.empty() | ||
.withSsl(MatchRule.ALL.matchHost("host1"), sslContextSecurityFactory4Ciphers) | ||
.withSsl(MatchRule.ALL.matchHost("host2"), sslContextSecurityFactoryt3Ciphers); | ||
ctx.run(checkResultIntersectionSizeIs(2)); | ||
ctx = AuthenticationContext.empty() | ||
.withSsl(MatchRule.ALL.matchHost("host1"), sslContextSecurityFactory4Ciphers) | ||
.withSsl(MatchRule.ALL.matchHost("host2"), sslContextSecurityFactoryt3Ciphers) | ||
.withSsl(MatchRule.ALL.matchHost("host3"), sslContextSecurityFactory0Ciphers); | ||
ctx.run(checkResultIntersectionSizeIs(0)); | ||
ctx = AuthenticationContext.empty() | ||
.withSsl(MatchRule.ALL.matchHost("host3"), sslContextSecurityFactory0Ciphers) | ||
.withSsl(MatchRule.ALL.matchHost("host3"), sslContextSecurityFactory0Ciphers); | ||
ctx.run(checkResultIntersectionSizeIs(0)); | ||
ctx = AuthenticationContext.empty() | ||
.withSsl(MatchRule.ALL.matchHost("host1"), sslContextSecurityFactory4Ciphers) | ||
.withSsl(MatchRule.ALL.matchHost("host1"), sslContextSecurityFactory4Ciphers); | ||
ctx.run(checkResultIntersectionSizeIs(4)); | ||
} | ||
|
||
private Runnable checkResultIntersectionSizeIs(int intersectionSize) { | ||
return () -> { | ||
try { | ||
DynamicSslContextSpi dynamicSslContextSpi = new DynamicSslContextSpi(SSLContext.getDefault()); | ||
SSLContext dynamicSSLContext = new DynamicSSLContext(dynamicSslContextSpi, null, null); | ||
Assert.assertEquals(dynamicSSLContext.getSocketFactory().getSupportedCipherSuites().length, intersectionSize); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
}; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
auth/client/src/test/java/org/wildfly/security/auth/client/mocks/MockSSLContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.wildfly.security.auth.client.mocks; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLContextSpi; | ||
|
||
public class MockSSLContext extends SSLContext { | ||
public MockSSLContext(final SSLContextSpi mockContextSpi) { | ||
super(mockContextSpi, null, null); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
auth/client/src/test/java/org/wildfly/security/auth/client/mocks/MockSSLContextSPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.wildfly.security.auth.client.mocks; | ||
|
||
import javax.net.ssl.KeyManager; | ||
import javax.net.ssl.SSLContextSpi; | ||
import javax.net.ssl.SSLEngine; | ||
import javax.net.ssl.SSLServerSocketFactory; | ||
import javax.net.ssl.SSLSessionContext; | ||
import javax.net.ssl.TrustManager; | ||
import java.security.SecureRandom; | ||
|
||
public abstract class MockSSLContextSPI extends SSLContextSpi { | ||
@Override | ||
protected void engineInit(KeyManager[] keyManagers, TrustManager[] trustManagers, SecureRandom secureRandom) { | ||
} | ||
|
||
@Override | ||
protected SSLServerSocketFactory engineGetServerSocketFactory() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected SSLEngine engineCreateSSLEngine() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected SSLEngine engineCreateSSLEngine(String s, int i) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected SSLSessionContext engineGetServerSessionContext() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected SSLSessionContext engineGetClientSessionContext() { | ||
return null; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
auth/client/src/test/java/org/wildfly/security/auth/client/mocks/MockSSLSocketFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.wildfly.security.auth.client.mocks; | ||
|
||
import javax.net.ssl.SSLSocketFactory; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.Socket; | ||
import java.net.UnknownHostException; | ||
|
||
public abstract class MockSSLSocketFactory extends SSLSocketFactory { | ||
@Override | ||
public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(String s, int i) throws IOException, UnknownHostException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException, UnknownHostException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(InetAddress inetAddress, int i) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress1, int i1) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String[] getDefaultCipherSuites() { | ||
return new String[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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"> | ||
<parent> | ||
<groupId>org.wildfly.security</groupId> | ||
<artifactId>wildfly-elytron-parent</artifactId> | ||
<version>1.11.3.CR1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>wildfly-elytron-dynamic-ssl</artifactId> | ||
|
||
<name>WildFly Elytron - Dynamic SSL</name> | ||
<description>WildFly Security Dynamic SSL Implementation</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
dynamic-ssl/src/main/java/org/wildfly/security/dynamic/ssl/ssl/DynamicSSLContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.wildfly.security.dynamic.ssl.ssl; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import java.security.Provider; | ||
|
||
// TODO remove public and user will have to use AuthenticationContextConfigurationClient to get it | ||
public final class DynamicSSLContext extends SSLContext { | ||
|
||
public DynamicSSLContext(DynamicSslContextSpi contextSpi, Provider provider, String protocol) { | ||
super(contextSpi, provider, protocol); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
dynamic-ssl/src/main/java/org/wildfly/security/dynamic/ssl/ssl/DynamicSSLContextSPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.wildfly.security.dynamic.ssl.ssl; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import java.net.URI; | ||
import java.util.List; | ||
|
||
public interface DynamicSSLContextSPI { | ||
|
||
SSLContext getConfiguredDefault(); | ||
List<SSLContext> getConfiguredSSLContexts(); | ||
SSLContext getSSLContext(URI uri); | ||
} |
Oops, something went wrong.