Adds support for google's ssltcp.
This commit is contained in:
parent
618ce97c7c
commit
e497af1850
@ -880,9 +880,9 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
|
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;
|
return localCnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,11 @@ public abstract class LocalCandidate
|
|||||||
*/
|
*/
|
||||||
private String ufrag = null;
|
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
|
* The <tt>Logger</tt> used by the <tt>LocalCandidate</tt> class and its
|
||||||
* instances for logging output.
|
* instances for logging output.
|
||||||
@ -395,4 +400,22 @@ public abstract class LocalCandidate
|
|||||||
{
|
{
|
||||||
return getParentComponent().findLocalCandidate(relatedAddress);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,8 @@ public class TcpHostCandidate
|
|||||||
* @param parentComponent the <tt>Component</tt> that this candidate
|
* @param parentComponent the <tt>Component</tt> that this candidate
|
||||||
* belongs to.
|
* belongs to.
|
||||||
*/
|
*/
|
||||||
public TcpHostCandidate(TransportAddress transportAddress, Component parentComponent)
|
public TcpHostCandidate(TransportAddress transportAddress,
|
||||||
|
Component parentComponent)
|
||||||
{
|
{
|
||||||
super(transportAddress,
|
super(transportAddress,
|
||||||
parentComponent);
|
parentComponent);
|
||||||
|
|||||||
@ -100,7 +100,7 @@ public class GoogleTurnCandidateHarvest
|
|||||||
TransportAddress relayedAddress
|
TransportAddress relayedAddress
|
||||||
= ((MappedAddressAttribute) attribute).getAddress();
|
= ((MappedAddressAttribute) attribute).getAddress();
|
||||||
|
|
||||||
if(harvester.stunServer.getTransport() == Transport.TCP)
|
if (harvester.stunServer.getTransport() == Transport.TCP)
|
||||||
{
|
{
|
||||||
relayedAddress = new TransportAddress(
|
relayedAddress = new TransportAddress(
|
||||||
relayedAddress.getAddress(),
|
relayedAddress.getAddress(),
|
||||||
|
|||||||
@ -25,9 +25,9 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
extends GoogleTurnCandidateHarvester
|
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,
|
0x16, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00,
|
||||||
0x46, 0x03, 0x01, 0x42, (byte)0x85, 0x45, (byte)0xa7, 0x27,
|
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,
|
(byte)0x80, 0x46, 0x01, 0x03, 0x01, 0x00, 0x2d, 0x00,
|
||||||
0x00, 0x00, 0x10, 0x01, 0x00, (byte)0x80, 0x03, 0x00,
|
0x00, 0x00, 0x10, 0x01, 0x00, (byte)0x80, 0x03, 0x00,
|
||||||
|
|||||||
@ -79,6 +79,11 @@ public class MultiplexingTcpHostHarvester
|
|||||||
*/
|
*/
|
||||||
private boolean close = false;
|
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
|
* Channels pending to be added to the list that {@link #readThread} reads
|
||||||
* from.
|
* from.
|
||||||
@ -112,7 +117,42 @@ public class MultiplexingTcpHostHarvester
|
|||||||
public MultiplexingTcpHostHarvester(int port)
|
public MultiplexingTcpHostHarvester(int port)
|
||||||
throws IOException
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,8 +165,7 @@ public class MultiplexingTcpHostHarvester
|
|||||||
List<TransportAddress> transportAddresses)
|
List<TransportAddress> transportAddresses)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
this.localAddresses.addAll(transportAddresses);
|
this(transportAddresses, false);
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,9 +177,11 @@ public class MultiplexingTcpHostHarvester
|
|||||||
* @param interfaces the interfaces to listen on.
|
* @param interfaces the interfaces to listen on.
|
||||||
*/
|
*/
|
||||||
public MultiplexingTcpHostHarvester(int port,
|
public MultiplexingTcpHostHarvester(int port,
|
||||||
List<NetworkInterface> interfaces)
|
List<NetworkInterface> interfaces,
|
||||||
|
boolean ssltcp)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
this.ssltcp = ssltcp;
|
||||||
initializeLocalAddresses(port, interfaces);
|
initializeLocalAddresses(port, interfaces);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@ -212,7 +253,9 @@ public class MultiplexingTcpHostHarvester
|
|||||||
if((addr instanceof Inet4Address) || useIPv6)
|
if((addr instanceof Inet4Address) || useIPv6)
|
||||||
{
|
{
|
||||||
TransportAddress transportAddress
|
TransportAddress transportAddress
|
||||||
= new TransportAddress(addr, port, Transport.TCP);
|
= new TransportAddress(addr,
|
||||||
|
port,
|
||||||
|
Transport.TCP);
|
||||||
localAddresses.add(transportAddress);
|
localAddresses.add(transportAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,8 +335,10 @@ public class MultiplexingTcpHostHarvester
|
|||||||
TcpHostCandidate candidate
|
TcpHostCandidate candidate
|
||||||
= new TcpHostCandidate(transportAddress, component);
|
= new TcpHostCandidate(transportAddress, component);
|
||||||
candidate.setTcpType(CandidateTcpType.PASSIVE);
|
candidate.setTcpType(CandidateTcpType.PASSIVE);
|
||||||
|
if (ssltcp)
|
||||||
|
candidate.setSSL(true);
|
||||||
|
|
||||||
candidates.add(new TcpHostCandidate(transportAddress, component));
|
candidates.add(candidate);
|
||||||
}
|
}
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
@ -675,11 +720,36 @@ public class MultiplexingTcpHostHarvester
|
|||||||
// socket's input stream
|
// socket's input stream
|
||||||
channel.configureBlocking(true);
|
channel.configureBlocking(true);
|
||||||
|
|
||||||
// read an RFC4571 frame into datagramPacket
|
|
||||||
Socket socket = channel.socket();
|
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(
|
DelegatingSocket.receiveFromNetwork(
|
||||||
datagramPacket,
|
datagramPacket,
|
||||||
socket.getInputStream(),
|
inputStream,
|
||||||
socket.getLocalAddress(),
|
socket.getLocalAddress(),
|
||||||
socket.getLocalPort());
|
socket.getLocalPort());
|
||||||
|
|
||||||
|
|||||||
@ -416,7 +416,7 @@ public class StunCandidateHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the host candidate.
|
* 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
|
* However for TCP, we cannot return the same hostCandidate because in Java
|
||||||
* a "server" socket cannot connect to a destination with the same local
|
* a "server" socket cannot connect to a destination with the same local
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user