use of com.github.jh3nd3rs0n.jargyle.client.Properties in project jargyle by jh3nd3rs0n.
the class DtlsDatagramSocketFactoryImpl method getDtlsContext.
private SSLContext getDtlsContext() throws IOException {
KeyManager[] keyManagers = null;
TrustManager[] trustManagers = null;
Properties properties = this.socksClient.getProperties();
File keyStoreFile = properties.getValue(DtlsPropertySpecConstants.DTLS_KEY_STORE_FILE);
if (keyStoreFile != null) {
char[] keyStorePassword = properties.getValue(DtlsPropertySpecConstants.DTLS_KEY_STORE_PASSWORD).getPassword();
String keyStoreType = properties.getValue(DtlsPropertySpecConstants.DTLS_KEY_STORE_TYPE);
keyManagers = KeyManagerHelper.getKeyManagers(keyStoreFile, keyStorePassword, keyStoreType);
Arrays.fill(keyStorePassword, '\0');
}
File trustStoreFile = properties.getValue(DtlsPropertySpecConstants.DTLS_TRUST_STORE_FILE);
if (trustStoreFile != null) {
char[] trustStorePassword = properties.getValue(DtlsPropertySpecConstants.DTLS_TRUST_STORE_PASSWORD).getPassword();
String trustStoreType = properties.getValue(DtlsPropertySpecConstants.DTLS_TRUST_STORE_TYPE);
trustManagers = TrustManagerHelper.getTrustManagers(trustStoreFile, trustStorePassword, trustStoreType);
Arrays.fill(trustStorePassword, '\0');
}
SSLContext context = null;
try {
context = SslContextHelper.getSslContext(properties.getValue(DtlsPropertySpecConstants.DTLS_PROTOCOL), keyManagers, trustManagers);
} catch (KeyManagementException e) {
throw new IOException(e);
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e);
}
return context;
}
use of com.github.jh3nd3rs0n.jargyle.client.Properties in project jargyle by jh3nd3rs0n.
the class DtlsDatagramSocketFactoryImpl method newDatagramSocket.
@Override
public DatagramSocket newDatagramSocket(final DatagramSocket datagramSocket, final String peerHost, final int peerPort) throws IOException {
synchronized (this) {
if (this.dtlsContext == null) {
this.dtlsContext = this.getDtlsContext();
}
}
DtlsDatagramSocketFactory factory = DtlsDatagramSocketFactory.newInstance(this.dtlsContext);
DtlsDatagramSocket dtlsDatagramSocket = (DtlsDatagramSocket) factory.newDatagramSocket(datagramSocket, peerHost, peerPort);
dtlsDatagramSocket.setUseClientMode(true);
Properties properties = this.socksClient.getProperties();
Words enabledCipherSuites = properties.getValue(DtlsPropertySpecConstants.DTLS_ENABLED_CIPHER_SUITES);
String[] cipherSuites = enabledCipherSuites.toStringArray();
if (cipherSuites.length > 0) {
dtlsDatagramSocket.setEnabledCipherSuites(cipherSuites);
}
Words enabledProtocols = properties.getValue(DtlsPropertySpecConstants.DTLS_ENABLED_PROTOCOLS);
String[] protocols = enabledProtocols.toStringArray();
if (protocols.length > 0) {
dtlsDatagramSocket.setEnabledProtocols(protocols);
}
PositiveInteger maxPacketSize = properties.getValue(DtlsPropertySpecConstants.DTLS_MAX_PACKET_SIZE);
dtlsDatagramSocket.setMaximumPacketSize(maxPacketSize.intValue());
return dtlsDatagramSocket;
}
use of com.github.jh3nd3rs0n.jargyle.client.Properties in project jargyle by jh3nd3rs0n.
the class Socks5HostResolver method resolve.
@Override
public InetAddress resolve(final String host) throws IOException {
if (host == null) {
return InetAddress.getLoopbackAddress();
}
Properties properties = this.socks5Client.getProperties();
AddressType addressType = AddressType.valueForString(host);
if (!addressType.equals(AddressType.DOMAINNAME) || !properties.getValue(Socks5PropertySpecConstants.SOCKS5_RESOLVE_USE_RESOLVE_COMMAND).booleanValue()) {
return InetAddress.getByName(host);
}
Socket socket = this.socks5Client.newInternalSocket();
this.socks5Client.configureInternalSocket(socket);
Socket sock = this.socks5Client.getConnectedInternalSocket(socket, true);
Method method = this.socks5Client.negotiateMethod(sock);
MethodEncapsulation methodEncapsulation = this.socks5Client.doMethodSubnegotiation(method, sock);
Socket sck = methodEncapsulation.getSocket();
Socks5Request socks5Req = Socks5Request.newInstance(Command.RESOLVE, host, 0);
this.socks5Client.sendSocks5Request(socks5Req, sck);
Socks5Reply socks5Rep = null;
try {
socks5Rep = this.socks5Client.receiveSocks5Reply(sck);
} catch (FailureSocks5ReplyException e) {
Reply reply = e.getFailureSocks5Reply().getReply();
if (reply.equals(Reply.HOST_UNREACHABLE)) {
throw new UnknownHostException(host);
} else {
throw e;
}
}
InetAddress inetAddress = InetAddress.getByName(socks5Rep.getServerBoundAddress());
return InetAddress.getByAddress(host, inetAddress.getAddress());
}
Aggregations