Search in sources :

Example 1 with PositiveInteger

use of com.github.jh3nd3rs0n.jargyle.common.number.PositiveInteger 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(false);
    Settings settings = this.configuration.getSettings();
    Words enabledCipherSuites = settings.getLastValue(DtlsSettingSpecConstants.DTLS_ENABLED_CIPHER_SUITES);
    String[] cipherSuites = enabledCipherSuites.toStringArray();
    if (cipherSuites.length > 0) {
        dtlsDatagramSocket.setEnabledCipherSuites(cipherSuites);
    }
    Words enabledProtocols = settings.getLastValue(DtlsSettingSpecConstants.DTLS_ENABLED_PROTOCOLS);
    String[] protocols = enabledProtocols.toStringArray();
    if (protocols.length > 0) {
        dtlsDatagramSocket.setEnabledProtocols(protocols);
    }
    PositiveInteger maxPacketSize = settings.getLastValue(DtlsSettingSpecConstants.DTLS_MAX_PACKET_SIZE);
    dtlsDatagramSocket.setMaximumPacketSize(maxPacketSize.intValue());
    if (settings.getLastValue(DtlsSettingSpecConstants.DTLS_NEED_CLIENT_AUTH).booleanValue()) {
        dtlsDatagramSocket.setNeedClientAuth(true);
    }
    if (settings.getLastValue(DtlsSettingSpecConstants.DTLS_WANT_CLIENT_AUTH).booleanValue()) {
        dtlsDatagramSocket.setWantClientAuth(true);
    }
    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) DtlsDatagramSocket(com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocket)

Example 2 with PositiveInteger

use of com.github.jh3nd3rs0n.jargyle.common.number.PositiveInteger 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)

Aggregations

DtlsDatagramSocket (com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocket)2 DtlsDatagramSocketFactory (com.github.jh3nd3rs0n.jargyle.common.net.ssl.DtlsDatagramSocketFactory)2 PositiveInteger (com.github.jh3nd3rs0n.jargyle.common.number.PositiveInteger)2 Words (com.github.jh3nd3rs0n.jargyle.common.text.Words)2 Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)1