Skip to content

Commit

Permalink
Use SSLEngine, SSLSocket for extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman committed Mar 26, 2019
1 parent afe8867 commit 53dba88
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
6 changes: 4 additions & 2 deletions tls/src/main/java/org/bouncycastle/jsse/BCSSLEngine.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.bouncycastle.jsse;

import javax.net.ssl.SSLEngine;

/**
* A BCJSSE-specific interface to expose extended functionality on {@link javax.net.ssl.SSLEngine}
* implementations.
*/
public interface BCSSLEngine
{
BCApplicationProtocolSelector<BCSSLEngine> getBCHandshakeApplicationProtocolSelector();
BCApplicationProtocolSelector<SSLEngine> getBCHandshakeApplicationProtocolSelector();

void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLEngine> selector);
void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<SSLEngine> selector);

BCExtendedSSLSession getBCHandshakeSession();

Expand Down
5 changes: 3 additions & 2 deletions tls/src/main/java/org/bouncycastle/jsse/BCSSLSocket.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.bouncycastle.jsse;

import javax.net.SocketFactory;
import javax.net.ssl.SSLSocket;

/**
* A BCJSSE-specific interface to expose extended functionality on {@link javax.net.ssl.SSLSocket}
* implementations.
*/
public interface BCSSLSocket
{
BCApplicationProtocolSelector<BCSSLSocket> getBCHandshakeApplicationProtocolSelector();
BCApplicationProtocolSelector<SSLSocket> getBCHandshakeApplicationProtocolSelector();

void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLSocket> selector);
void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<SSLSocket> selector);

BCExtendedSSLSession getBCHandshakeSession();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import java.util.Collections;
import java.util.List;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;

import org.bouncycastle.jsse.BCApplicationProtocolSelector;
import org.bouncycastle.jsse.BCSNIMatcher;
import org.bouncycastle.jsse.BCSNIServerName;
import org.bouncycastle.jsse.BCSSLEngine;
import org.bouncycastle.jsse.BCSSLSocket;
import org.bouncycastle.jsse.java.security.BCAlgorithmConstraints;

final class ProvSSLParameters
Expand Down Expand Up @@ -39,8 +40,8 @@ private static <T> List<T> copyList(Collection<T> list)
private List<BCSNIMatcher> sniMatchers;
private List<BCSNIServerName> sniServerNames;
private String[] applicationProtocols = new String[0];
private BCApplicationProtocolSelector<BCSSLEngine> engineAPSelector;
private BCApplicationProtocolSelector<BCSSLSocket> socketAPSelector;
private BCApplicationProtocolSelector<SSLEngine> engineAPSelector;
private BCApplicationProtocolSelector<SSLSocket> socketAPSelector;

ProvSSLParameters(ProvSSLContextSpi context, String[] cipherSuites, String[] protocols)
{
Expand Down Expand Up @@ -185,22 +186,22 @@ public void setApplicationProtocols(String[] applicationProtocols)
this.applicationProtocols = applicationProtocols.clone();
}

public BCApplicationProtocolSelector<BCSSLEngine> getEngineAPSelector()
public BCApplicationProtocolSelector<SSLEngine> getEngineAPSelector()
{
return engineAPSelector;
}

public void setEngineAPSelector(BCApplicationProtocolSelector<BCSSLEngine> engineAPSelector)
public void setEngineAPSelector(BCApplicationProtocolSelector<SSLEngine> engineAPSelector)
{
this.engineAPSelector = engineAPSelector;
}

public BCApplicationProtocolSelector<BCSSLSocket> getSocketAPSelector()
public BCApplicationProtocolSelector<SSLSocket> getSocketAPSelector()
{
return socketAPSelector;
}

public void setSocketAPSelector(BCApplicationProtocolSelector<BCSSLSocket> socketAPSelector)
public void setSocketAPSelector(BCApplicationProtocolSelector<SSLSocket> socketAPSelector)
{
this.socketAPSelector = socketAPSelector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

import org.bouncycastle.jsse.BCApplicationProtocolSelector;
import org.bouncycastle.jsse.BCExtendedSSLSession;
import org.bouncycastle.jsse.BCSSLConnection;
import org.bouncycastle.jsse.BCSSLParameters;
import org.bouncycastle.jsse.BCSSLSocket;
import org.bouncycastle.tls.AlertDescription;
import org.bouncycastle.tls.TlsClientProtocol;
import org.bouncycastle.tls.TlsFatalAlert;
Expand Down Expand Up @@ -182,12 +182,12 @@ public void connect(SocketAddress endpoint, int timeout) throws IOException
notifyConnected();
}

public synchronized BCApplicationProtocolSelector<BCSSLSocket> getBCHandshakeApplicationProtocolSelector()
public synchronized BCApplicationProtocolSelector<SSLSocket> getBCHandshakeApplicationProtocolSelector()
{
return sslParameters.getSocketAPSelector();
}

public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLSocket> selector)
public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<SSLSocket> selector)
{
sslParameters.setSocketAPSelector(selector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

import org.bouncycastle.jsse.BCApplicationProtocolSelector;
import org.bouncycastle.jsse.BCExtendedSSLSession;
import org.bouncycastle.jsse.BCSSLConnection;
import org.bouncycastle.jsse.BCSSLParameters;
import org.bouncycastle.jsse.BCSSLSocket;
import org.bouncycastle.tls.AlertDescription;
import org.bouncycastle.tls.TlsClientProtocol;
import org.bouncycastle.tls.TlsFatalAlert;
Expand Down Expand Up @@ -189,12 +189,12 @@ public SocketChannel getChannel()
return wrapSocket.getChannel();
}

public synchronized BCApplicationProtocolSelector<BCSSLSocket> getBCHandshakeApplicationProtocolSelector()
public synchronized BCApplicationProtocolSelector<SSLSocket> getBCHandshakeApplicationProtocolSelector()
{
return sslParameters.getSocketAPSelector();
}

public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLSocket> selector)
public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<SSLSocket> selector)
{
sslParameters.setSocketAPSelector(selector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.bouncycastle.jsse.BCApplicationProtocolSelector;
import org.bouncycastle.jsse.BCExtendedSSLSession;
import org.bouncycastle.jsse.BCSSLConnection;
import org.bouncycastle.jsse.BCSSLEngine;
import org.bouncycastle.jsse.BCSSLParameters;
import org.bouncycastle.tls.AlertDescription;
import org.bouncycastle.tls.RecordFormat;
Expand Down Expand Up @@ -197,12 +196,12 @@ public String getApplicationProtocol()
return connection == null ? null : connection.getApplicationProtocol();
}

public synchronized BCApplicationProtocolSelector<BCSSLEngine> getBCHandshakeApplicationProtocolSelector()
public synchronized BCApplicationProtocolSelector<SSLEngine> getBCHandshakeApplicationProtocolSelector()
{
return sslParameters.getEngineAPSelector();
}

public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLEngine> selector)
public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<SSLEngine> selector)
{
sslParameters.setEngineAPSelector(selector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.bouncycastle.jsse.BCApplicationProtocolSelector;
import org.bouncycastle.jsse.BCExtendedSSLSession;
import org.bouncycastle.jsse.BCSSLConnection;
import org.bouncycastle.jsse.BCSSLEngine;
import org.bouncycastle.jsse.BCSSLParameters;
import org.bouncycastle.tls.AlertDescription;
import org.bouncycastle.tls.RecordFormat;
Expand Down Expand Up @@ -199,12 +198,12 @@ public String getApplicationProtocol()
return connection == null ? null : connection.getApplicationProtocol();
}

public synchronized BCApplicationProtocolSelector<BCSSLEngine> getBCHandshakeApplicationProtocolSelector()
public synchronized BCApplicationProtocolSelector<SSLEngine> getBCHandshakeApplicationProtocolSelector()
{
return sslParameters.getEngineAPSelector();
}

public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLEngine> selector)
public synchronized void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<SSLEngine> selector)
{
sslParameters.setEngineAPSelector(selector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;

import junit.framework.TestCase;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jsse.BCApplicationProtocolSelector;
import org.bouncycastle.jsse.BCSSLConnection;
Expand All @@ -22,6 +21,8 @@
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import org.bouncycastle.util.Arrays;

import junit.framework.TestCase;

public class CipherSuitesTestCase extends TestCase
{
protected final CipherSuitesTestConfig config;
Expand Down Expand Up @@ -187,9 +188,9 @@ public Exception call()
//
// bcSock.setParameters(bcParams);

bcSock.setBCHandshakeApplicationProtocolSelector(new BCApplicationProtocolSelector<BCSSLSocket>()
bcSock.setBCHandshakeApplicationProtocolSelector(new BCApplicationProtocolSelector<SSLSocket>()
{
public String select(BCSSLSocket transport, List<String> protocols)
public String select(SSLSocket transport, List<String> protocols)
{
if (protocols.contains("h2"))
{
Expand Down

0 comments on commit 53dba88

Please sign in to comment.