Search in sources :

Example 11 with DTLSConnector

use of org.eclipse.californium.scandium.DTLSConnector in project californium by eclipse.

the class ServerService method setupDtls.

private void setupDtls(CoapServer server, Configuration config) {
    DtlsConnectorConfig.Builder dtlsConfig = DtlsConnectorConfig.builder(config);
    dtlsConfig.setAddress(new InetSocketAddress(DTLS_PORT));
    ConfigureDtls.loadCredentials(dtlsConfig, SERVER_NAME);
    DTLSConnector connector = new DTLSConnector(dtlsConfig.build());
    CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
    builder.setConfiguration(config);
    builder.setConnector(connector);
    server.addEndpoint(builder.build());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector)

Example 12 with DTLSConnector

use of org.eclipse.californium.scandium.DTLSConnector in project californium by eclipse.

the class SecureObserveTest method createSecureServer.

private void createSecureServer(MatcherMode mode, ConnectionIdGenerator cidGenerator) {
    serverPskStore = new TestUtilPskStore();
    Configuration config = network.createTestConfig().set(CoapConfig.ACK_TIMEOUT, 200, TimeUnit.MILLISECONDS).set(CoapConfig.ACK_INIT_RANDOM, 1f).set(CoapConfig.ACK_TIMEOUT_SCALE, 1f).set(CoapConfig.EXCHANGE_LIFETIME, 10, TimeUnit.SECONDS).set(CoapConfig.RESPONSE_MATCHING, mode).set(DtlsConfig.DTLS_RECEIVER_THREAD_COUNT, 2).set(DtlsConfig.DTLS_CONNECTOR_THREAD_COUNT, 2);
    DtlsConnectorConfig dtlsConfig = DtlsConnectorConfig.builder(config).setAddress(TestTools.LOCALHOST_EPHEMERAL).setLoggingTag("server").setConnectionIdGenerator(cidGenerator).setAdvancedPskStore(serverPskStore).build();
    serverConnector = new DTLSConnector(dtlsConfig);
    CoapEndpoint.Builder builder = CoapEndpoint.builder();
    builder.setConnector(serverConnector);
    if (mode == MatcherMode.PRINCIPAL) {
        builder.setEndpointContextMatcher(new PrincipalEndpointContextMatcher(true));
    }
    builder.setConfiguration(config);
    serverEndpoint = builder.build();
    CoapServer server = new CoapServer();
    server.addEndpoint(serverEndpoint);
    resource = new MyResource(TARGET);
    server.add(resource);
    server.start();
    cleanup.add(server);
    uri = TestTools.getUri(serverEndpoint, TARGET);
    // prepare secure client endpoint
    clientPskStore = new TestUtilPskStore();
    DtlsConnectorConfig clientdtlsConfig = DtlsConnectorConfig.builder(config).setAddress(TestTools.LOCALHOST_EPHEMERAL).setLoggingTag("client").setConnectionIdGenerator(cidGenerator).setAdvancedPskStore(clientPskStore).build();
    clientConnector = new DTLSConnector(clientdtlsConfig);
    builder = new CoapEndpoint.Builder();
    builder.setConnector(clientConnector);
    builder.setConfiguration(config);
    clientEndpoint = builder.build();
    EndpointManager.getEndpointManager().setDefaultEndpoint(clientEndpoint);
    setPskCredentials(IDENITITY, KEY);
    System.out.println("coap-server " + uri);
    System.out.println("coap-client " + clientEndpoint.getUri());
}
Also used : PrincipalEndpointContextMatcher(org.eclipse.californium.elements.PrincipalEndpointContextMatcher) Configuration(org.eclipse.californium.elements.config.Configuration) CoapServer(org.eclipse.californium.core.CoapServer) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector)

Example 13 with DTLSConnector

use of org.eclipse.californium.scandium.DTLSConnector in project californium by eclipse.

the class SecureTest method createEndpoint.

private CoapEndpoint createEndpoint(String tag, String pskIdentity, int exchangeTimeout, int coapTimeout, int dtlsTimeout, int pskDelay) {
    // setup CoAP config
    Configuration config = network.createTestConfig().set(CoapConfig.ACK_TIMEOUT, coapTimeout, TimeUnit.MILLISECONDS).set(CoapConfig.EXCHANGE_LIFETIME, exchangeTimeout, TimeUnit.MILLISECONDS).set(DtlsConfig.DTLS_RETRANSMISSION_TIMEOUT, dtlsTimeout, TimeUnit.MILLISECONDS).set(DtlsConfig.DTLS_MAX_RETRANSMISSIONS, TEST_DTLS_RETRANSMISSIONS).set(DtlsConfig.DTLS_RECEIVER_THREAD_COUNT, 2).set(DtlsConfig.DTLS_CONNECTOR_THREAD_COUNT, 2);
    // setup DTLS Config
    TestUtilPskStore singlePskStore = new TestUtilPskStore();
    singlePskStore.set(pskIdentity, PSK_KEY.getBytes());
    singlePskStore.setCatchAll(true);
    AsyncAdvancedPskStore pskStore = new AsyncAdvancedPskStore(singlePskStore);
    pskStore.setDelay(-pskDelay);
    pskStores.add(pskStore);
    Builder builder = new DtlsConnectorConfig.Builder(config).setAddress(TestTools.LOCALHOST_EPHEMERAL).setLoggingTag(tag).setAdvancedPskStore(pskStore);
    DtlsConnectorConfig dtlsConfig = builder.build();
    // create endpoint for tests
    DTLSConnector connector = new DTLSConnector(dtlsConfig);
    CoapEndpoint.Builder coapBuilder = new CoapEndpoint.Builder();
    coapBuilder.setConnector(connector);
    coapBuilder.setConfiguration(config);
    CoapEndpoint coapEndpoint = coapBuilder.build();
    return coapEndpoint;
}
Also used : AsyncAdvancedPskStore(org.eclipse.californium.scandium.dtls.pskstore.AsyncAdvancedPskStore) Configuration(org.eclipse.californium.elements.config.Configuration) Builder(org.eclipse.californium.scandium.config.DtlsConnectorConfig.Builder) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) Builder(org.eclipse.californium.scandium.config.DtlsConnectorConfig.Builder) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector)

Example 14 with DTLSConnector

use of org.eclipse.californium.scandium.DTLSConnector in project californium by eclipse.

the class NatTestHelper method forceResumption.

void forceResumption(List<Integer> resumeEndpoints, int percent) throws InterruptedException {
    resumeEndpoints.clear();
    int num = clientEndpoints.size();
    for (int i = 0; i < num; ++i) {
        if (rand.nextInt(100) < percent) {
            CoapEndpoint endpoint = clientEndpoints.get(i);
            Connector connector = endpoint.getConnector();
            if (connector instanceof DTLSConnector) {
                ((DTLSConnector) connector).forceResumeAllSessions();
                resumeEndpoints.add(i);
            }
        }
    }
}
Also used : DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) DtlsManagedClusterConnector(org.eclipse.californium.scandium.DtlsManagedClusterConnector) DtlsClusterConnector(org.eclipse.californium.scandium.DtlsClusterConnector) Connector(org.eclipse.californium.elements.Connector) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) Endpoint(org.eclipse.californium.core.network.Endpoint) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector)

Example 15 with DTLSConnector

use of org.eclipse.californium.scandium.DTLSConnector in project californium by eclipse.

the class NatTestHelper method createClientEndpoint.

CoapEndpoint createClientEndpoint(Integer cidLength) throws IOException {
    String tag = "client";
    int size = clientEndpoints.size();
    if (size > 0) {
        tag += "." + size;
    }
    DtlsHealthLogger health = new DtlsHealthLogger(tag);
    this.clientStatistics.add(health);
    // prepare secure client endpoint
    DtlsConnectorConfig clientDtlsConfig = DtlsConnectorConfig.builder(config).set(DtlsConfig.DTLS_MAX_CONNECTIONS, 20).set(DtlsConfig.DTLS_RECEIVER_THREAD_COUNT, 2).set(DtlsConfig.DTLS_CONNECTOR_THREAD_COUNT, 2).set(DtlsConfig.DTLS_CONNECTION_ID_LENGTH, cidLength).setAddress(TestTools.LOCALHOST_EPHEMERAL).setLoggingTag(tag).setHealthHandler(health).setAsList(DtlsConfig.DTLS_CIPHER_SUITES, CipherSuite.TLS_PSK_WITH_AES_128_CCM_8).setAdvancedPskStore(new AdvancedSinglePskStore(IDENITITY + "." + size, KEY.getBytes())).build();
    DebugConnectionStore clientConnectionStore = ConnectorHelper.createDebugConnectionStore(clientDtlsConfig);
    DTLSConnector clientConnector = new MyDtlsConnector(clientDtlsConfig, clientConnectionStore);
    clientConnector.setAlertHandler(new MyAlertHandler(clientDtlsConfig.getLoggingTag()));
    CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
    builder.setConnector(clientConnector);
    builder.setConfiguration(config);
    CoapEndpoint clientEndpoint = builder.build();
    HealthStatisticLogger healthLogger = new HealthStatisticLogger(tag, true);
    clientCoapStatistics.add(healthLogger);
    clientEndpoint.addPostProcessInterceptor(healthLogger);
    clientEndpoint.start();
    clientConnections.add(clientConnectionStore);
    clientEndpoints.add(clientEndpoint);
    return clientEndpoint;
}
Also used : AdvancedSinglePskStore(org.eclipse.californium.scandium.dtls.pskstore.AdvancedSinglePskStore) DtlsHealthLogger(org.eclipse.californium.scandium.DtlsHealthLogger) HealthStatisticLogger(org.eclipse.californium.core.network.interceptors.HealthStatisticLogger) Endpoint(org.eclipse.californium.core.network.Endpoint) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) DebugConnectionStore(org.eclipse.californium.scandium.dtls.DebugConnectionStore) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint)

Aggregations

DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)39 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)29 DtlsConnectorConfig (org.eclipse.californium.scandium.config.DtlsConnectorConfig)28 InetSocketAddress (java.net.InetSocketAddress)15 Configuration (org.eclipse.californium.elements.config.Configuration)15 Endpoint (org.eclipse.californium.core.network.Endpoint)9 CoapServer (org.eclipse.californium.core.CoapServer)8 AdvancedSinglePskStore (org.eclipse.californium.scandium.dtls.pskstore.AdvancedSinglePskStore)7 URI (java.net.URI)5 Builder (org.eclipse.californium.scandium.config.DtlsConnectorConfig.Builder)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 StaticPskStore (org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore)4 CoapClient (org.eclipse.californium.core.CoapClient)3 NetworkConfig (org.eclipse.californium.core.network.config.NetworkConfig)3 Connector (org.eclipse.californium.elements.Connector)3 DtlsHealthLogger (org.eclipse.californium.scandium.DtlsHealthLogger)3 MdcConnectionListener (org.eclipse.californium.scandium.MdcConnectionListener)3 AdvancedPskStore (org.eclipse.californium.scandium.dtls.pskstore.AdvancedPskStore)3 AsyncAdvancedPskStore (org.eclipse.californium.scandium.dtls.pskstore.AsyncAdvancedPskStore)3