Search in sources :

Example 1 with ObservationStore

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);
    }
}
Also used : AdvancedPskStore(org.eclipse.californium.scandium.dtls.pskstore.AdvancedPskStore) ObservationStore(org.eclipse.californium.core.observe.ObservationStore) LoggerFactory(org.slf4j.LoggerFactory) KeyLoader(org.eclipse.hono.config.KeyLoader) Constants(org.eclipse.hono.util.Constants) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) Keys(org.eclipse.californium.core.network.config.NetworkConfig.Keys) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceInfoSupplier(org.eclipse.hono.adapter.coap.DeviceInfoSupplier) CoapEndpointFactory(org.eclipse.hono.adapter.coap.CoapEndpointFactory) NewAdvancedCertificateVerifier(org.eclipse.californium.scandium.dtls.x509.NewAdvancedCertificateVerifier) Strings(org.eclipse.hono.util.Strings) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) Logger(org.slf4j.Logger) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) CoapAdapterProperties(org.eclipse.hono.adapter.coap.CoapAdapterProperties) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) Objects(java.util.Objects) Certificate(java.security.cert.Certificate) MemoryBasedConnectionLimitStrategy(org.eclipse.hono.adapter.limiting.MemoryBasedConnectionLimitStrategy) PrivateKey(java.security.PrivateKey) CoAP(org.eclipse.californium.core.coap.CoAP) Endpoint(org.eclipse.californium.core.network.Endpoint) Optional(java.util.Optional) ApplicationLevelInfoSupplier(org.eclipse.californium.scandium.auth.ApplicationLevelInfoSupplier) InputStream(java.io.InputStream) InetSocketAddress(java.net.InetSocketAddress) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector)

Aggregations

Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 Vertx (io.vertx.core.Vertx)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 PrivateKey (java.security.PrivateKey)1 Certificate (java.security.cert.Certificate)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CoAP (org.eclipse.californium.core.coap.CoAP)1 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)1 Endpoint (org.eclipse.californium.core.network.Endpoint)1 NetworkConfig (org.eclipse.californium.core.network.config.NetworkConfig)1 Keys (org.eclipse.californium.core.network.config.NetworkConfig.Keys)1 ObservationStore (org.eclipse.californium.core.observe.ObservationStore)1 DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)1 ApplicationLevelInfoSupplier (org.eclipse.californium.scandium.auth.ApplicationLevelInfoSupplier)1