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());
}
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());
}
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;
}
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);
}
}
}
}
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;
}
Aggregations