Skip to content

Commit

Permalink
BCJSSE: Support application-protocol selectors in BC extension API
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman committed Mar 26, 2019
1 parent 1a89021 commit afe8867
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 281 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.bouncycastle.jsse;

import java.util.List;

public interface BCApplicationProtocolSelector<T>
{
String select(T transport, List<String> protocols);
}
4 changes: 4 additions & 0 deletions tls/src/main/java/org/bouncycastle/jsse/BCSSLEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
public interface BCSSLEngine
{
BCApplicationProtocolSelector<BCSSLEngine> getBCHandshakeApplicationProtocolSelector();

void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLEngine> selector);

BCExtendedSSLSession getBCHandshakeSession();

/**
Expand Down
4 changes: 4 additions & 0 deletions tls/src/main/java/org/bouncycastle/jsse/BCSSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/
public interface BCSSLSocket
{
BCApplicationProtocolSelector<BCSSLSocket> getBCHandshakeApplicationProtocolSelector();

void setBCHandshakeApplicationProtocolSelector(BCApplicationProtocolSelector<BCSSLSocket> selector);

BCExtendedSSLSession getBCHandshakeSession();

/**
Expand Down
16 changes: 16 additions & 0 deletions tls/src/main/java/org/bouncycastle/jsse/provider/JsseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ public static Vector getProtocolNames(String[] applicationProtocols)
return protocolNames;
}

public static List<String> getProtocolNames(Vector applicationProtocols)
{
if (null == applicationProtocols || applicationProtocols.isEmpty())
{
return null;
}

ArrayList<String> protocolNames = new ArrayList<String>(applicationProtocols.size());
for (int i = 0; i < applicationProtocols.size(); ++i)
{
ProtocolName protocolName = (ProtocolName)applicationProtocols.elementAt(i);
protocolNames .add(protocolName.getUtf8Decoding());
}
return protocolNames;
}

public static X509Certificate[] getX509CertificateChain(TlsCrypto crypto, Certificate certificateMessage)
{
if (certificateMessage == null || certificateMessage.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import java.util.Collections;
import java.util.List;

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 @@ -36,6 +39,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;

ProvSSLParameters(ProvSSLContextSpi context, String[] cipherSuites, String[] protocols)
{
Expand All @@ -56,6 +61,8 @@ ProvSSLParameters copy()
p.sniMatchers = sniMatchers;
p.sniServerNames = sniServerNames;
p.applicationProtocols = applicationProtocols;
p.engineAPSelector = engineAPSelector;
p.socketAPSelector = socketAPSelector;
return p;
}

Expand Down Expand Up @@ -177,4 +184,24 @@ public void setApplicationProtocols(String[] applicationProtocols)
{
this.applicationProtocols = applicationProtocols.clone();
}

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

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

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

public void setSocketAPSelector(BCApplicationProtocolSelector<BCSSLSocket> socketAPSelector)
{
this.socketAPSelector = socketAPSelector;
}
}
264 changes: 0 additions & 264 deletions tls/src/main/java/org/bouncycastle/jsse/provider/ProvSSLSocket.java

This file was deleted.

Loading

0 comments on commit afe8867

Please sign in to comment.