Adds support for google's ssltcp.

This commit is contained in:
boris 2014-09-04 13:28:04 +00:00
parent 618ce97c7c
commit e497af1850
7 changed files with 112 additions and 18 deletions

View File

@ -880,9 +880,9 @@ public class Component
*/
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
{
for( LocalCandidate localCnd : localCandidates)
for (LocalCandidate localCnd : localCandidates)
{
if(localCnd.getTransportAddress().equals(localAddress))
if (localCnd.getTransportAddress().equals(localAddress))
return localCnd;
}

View File

@ -37,6 +37,11 @@ public abstract class LocalCandidate
*/
private String ufrag = null;
/**
* Whether this <tt>LocalCandidate</tt> uses SSL.
*/
private boolean isSSL = false;
/**
* The <tt>Logger</tt> used by the <tt>LocalCandidate</tt> class and its
* instances for logging output.
@ -395,4 +400,22 @@ public abstract class LocalCandidate
{
return getParentComponent().findLocalCandidate(relatedAddress);
}
/**
* Gets the value of the 'ssl' flag.
* @return the value of the 'ssl' flag.
*/
public boolean isSSL()
{
return isSSL;
}
/**
* Sets the value of the 'ssl' flag.
* @param isSSL the value to set.
*/
public void setSSL(boolean isSSL)
{
this.isSSL = isSSL;
}
}

View File

@ -37,7 +37,8 @@ public class TcpHostCandidate
* @param parentComponent the <tt>Component</tt> that this candidate
* belongs to.
*/
public TcpHostCandidate(TransportAddress transportAddress, Component parentComponent)
public TcpHostCandidate(TransportAddress transportAddress,
Component parentComponent)
{
super(transportAddress,
parentComponent);

View File

@ -100,7 +100,7 @@ public class GoogleTurnCandidateHarvest
TransportAddress relayedAddress
= ((MappedAddressAttribute) attribute).getAddress();
if(harvester.stunServer.getTransport() == Transport.TCP)
if (harvester.stunServer.getTransport() == Transport.TCP)
{
relayedAddress = new TransportAddress(
relayedAddress.getAddress(),

View File

@ -25,9 +25,9 @@ public class GoogleTurnSSLCandidateHarvester
extends GoogleTurnCandidateHarvester
{
/**
* Data for the SSL server handshake.
* Data for the SSL message sent by the server.
*/
private static final byte SSL_SERVER_HANDSHAKE[] =
static final byte SSL_SERVER_HANDSHAKE[] =
{
0x16, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00,
0x46, 0x03, 0x01, 0x42, (byte)0x85, 0x45, (byte)0xa7, 0x27,
@ -43,9 +43,9 @@ public class GoogleTurnSSLCandidateHarvester
};
/**
* Data for the SSL client handshake.
* Data for the SSL message sent by the client.
*/
private static final byte SSL_CLIENT_HANDSHAKE[] =
static final byte SSL_CLIENT_HANDSHAKE[] =
{
(byte)0x80, 0x46, 0x01, 0x03, 0x01, 0x00, 0x2d, 0x00,
0x00, 0x00, 0x10, 0x01, 0x00, (byte)0x80, 0x03, 0x00,

View File

@ -79,6 +79,11 @@ public class MultiplexingTcpHostHarvester
*/
private boolean close = false;
/**
* Whether or not to use ssltcp.
*/
private boolean ssltcp = false;
/**
* Channels pending to be added to the list that {@link #readThread} reads
* from.
@ -112,7 +117,42 @@ public class MultiplexingTcpHostHarvester
public MultiplexingTcpHostHarvester(int port)
throws IOException
{
this(port, Collections.list(NetworkInterface.getNetworkInterfaces()));
this(port,
Collections.list(NetworkInterface.getNetworkInterfaces()),
false);
}
/**
* Initializes a new <tt>MultiplexingTcpHostHarvester</tt>, which is to
* listen on port number <tt>port</tt> on all IP addresses on all
* available interfaces.
*
* @param port the port to listen on.
* @param ssltcp whether to use ssltcp or not.
*/
public MultiplexingTcpHostHarvester(int port, boolean ssltcp)
throws IOException
{
this(port,
Collections.list(NetworkInterface.getNetworkInterfaces()),
ssltcp);
}
/**
* Initializes a new <tt>MultiplexingTcpHostHarvester</tt>, which is to
* listen on the specified list of <tt>TransportAddress</tt>es.
*
* @param transportAddresses the transport addresses to listen on.
* @param ssltcp whether to use ssltcp or not.
*/
public MultiplexingTcpHostHarvester(
List<TransportAddress> transportAddresses,
boolean ssltcp)
throws IOException
{
this.ssltcp = ssltcp;
this.localAddresses.addAll(transportAddresses);
init();
}
/**
@ -123,10 +163,9 @@ public class MultiplexingTcpHostHarvester
*/
public MultiplexingTcpHostHarvester(
List<TransportAddress> transportAddresses)
throws IOException
throws IOException
{
this.localAddresses.addAll(transportAddresses);
init();
this(transportAddresses, false);
}
/**
@ -138,9 +177,11 @@ public class MultiplexingTcpHostHarvester
* @param interfaces the interfaces to listen on.
*/
public MultiplexingTcpHostHarvester(int port,
List<NetworkInterface> interfaces)
List<NetworkInterface> interfaces,
boolean ssltcp)
throws IOException
{
this.ssltcp = ssltcp;
initializeLocalAddresses(port, interfaces);
init();
}
@ -212,7 +253,9 @@ public class MultiplexingTcpHostHarvester
if((addr instanceof Inet4Address) || useIPv6)
{
TransportAddress transportAddress
= new TransportAddress(addr, port, Transport.TCP);
= new TransportAddress(addr,
port,
Transport.TCP);
localAddresses.add(transportAddress);
}
}
@ -292,8 +335,10 @@ public class MultiplexingTcpHostHarvester
TcpHostCandidate candidate
= new TcpHostCandidate(transportAddress, component);
candidate.setTcpType(CandidateTcpType.PASSIVE);
if (ssltcp)
candidate.setSSL(true);
candidates.add(new TcpHostCandidate(transportAddress, component));
candidates.add(candidate);
}
return candidates;
}
@ -675,11 +720,36 @@ public class MultiplexingTcpHostHarvester
// socket's input stream
channel.configureBlocking(true);
// read an RFC4571 frame into datagramPacket
Socket socket = channel.socket();
InputStream inputStream = socket.getInputStream();
// If we use ssltcp we wait for a pseudo-ssl handshake from the
// client.
if (ssltcp)
{
byte[] buf
= new byte[GoogleTurnSSLCandidateHarvester
.SSL_CLIENT_HANDSHAKE.length];
socket.getInputStream().read(buf);
if (Arrays.equals(buf,
GoogleTurnSSLCandidateHarvester
.SSL_CLIENT_HANDSHAKE))
{
socket.getOutputStream().write(
GoogleTurnSSLCandidateHarvester
.SSL_SERVER_HANDSHAKE);
}
else
{
throw new ReadThreadException(
"Expected a pseudo ssl handshake, didn't get one.");
}
}
// read an RFC4571 frame into datagramPacket
DelegatingSocket.receiveFromNetwork(
datagramPacket,
socket.getInputStream(),
inputStream,
socket.getLocalAddress(),
socket.getLocalPort());

View File

@ -416,7 +416,7 @@ public class StunCandidateHarvester
/**
* Returns the host candidate.
* For UDP it simply returns the candidate passed as paramter
* For UDP it simply returns the candidate passed as a parameter.
*
* However for TCP, we cannot return the same hostCandidate because in Java
* a "server" socket cannot connect to a destination with the same local