use of org.eclipse.californium.core.observe.ObservationStore in project hono by eclipse.
the class ConfigBasedCoapEndpointFactory method createSecureEndpoint.
private Future<Endpoint> createSecureEndpoint(final int port, final NetworkConfig networkConfig) {
if (deviceResolver == null) {
return Future.failedFuture(new IllegalStateException("infoSupplier property must be set for secure endpoint"));
}
if (pskStore == null) {
return Future.failedFuture(new IllegalStateException("pskStore property must be set for secure endpoint"));
}
LOG.info("creating secure endpoint");
final DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
// prevent session resumption
dtlsConfig.setNoServerSessionId(true);
dtlsConfig.setServerOnly(true);
dtlsConfig.setRecommendedCipherSuitesOnly(true);
dtlsConfig.setClientAuthenticationRequired(true);
dtlsConfig.setAddress(new InetSocketAddress(config.getBindAddress(), port));
dtlsConfig.setApplicationLevelInfoSupplier(deviceResolver);
dtlsConfig.setAdvancedPskStore(pskStore);
dtlsConfig.setRetransmissionTimeout(config.getDtlsRetransmissionTimeout());
dtlsConfig.setMaxConnections(networkConfig.getInt(Keys.MAX_ACTIVE_PEERS));
dtlsConfig.setSniEnabled(true);
addIdentity(dtlsConfig);
try {
final DtlsConnectorConfig dtlsConnectorConfig = dtlsConfig.build();
if (LOG.isInfoEnabled()) {
final String ciphers = dtlsConnectorConfig.getSupportedCipherSuites().stream().map(cipher -> cipher.name()).collect(Collectors.joining(", "));
LOG.info("creating secure endpoint supporting ciphers: {}", ciphers);
}
final DTLSConnector dtlsConnector = new DTLSConnector(dtlsConnectorConfig);
final CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setNetworkConfig(networkConfig);
builder.setConnector(dtlsConnector);
builder.setObservationStore(observationStore);
return Future.succeededFuture(builder.build());
} catch (final IllegalStateException ex) {
LOG.warn("failed to create secure endpoint", ex);
return Future.failedFuture(ex);
}
}
Aggregations