Search in sources :

Example 1 with Properties

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;
}
Also used : SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) KeyManager(javax.net.ssl.KeyManager) File(java.io.File)

Example 2 with Properties

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;
}
Also used : PositiveInteger(com.github.jh3nd3rs0n.jargyle.common.number.PositiveInteger) Words(com.github.jh3nd3rs0n.jargyle.common.text.Words) DtlsDatagramSocketFactory(com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocketFactory) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) DtlsDatagramSocket(com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocket)

Example 3 with Properties

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());
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) AddressType(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)3 DtlsDatagramSocket (com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocket)1 DtlsDatagramSocketFactory (com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocketFactory)1 PositiveInteger (com.github.jh3nd3rs0n.jargyle.common.number.PositiveInteger)1 Words (com.github.jh3nd3rs0n.jargyle.common.text.Words)1 AddressType (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType)1 Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)1 MethodEncapsulation (com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation)1 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)1 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)1 Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)1 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 KeyManager (javax.net.ssl.KeyManager)1 SSLContext (javax.net.ssl.SSLContext)1