org.eclipse.californium.scandium.config.DtlsConnectorConfig Java Examples
The following examples show how to use
org.eclipse.californium.scandium.config.DtlsConnectorConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractVertxBasedCoapAdapter.java From hono with Eclipse Public License 2.0 | 6 votes |
private void addIdentity(final DtlsConnectorConfig.Builder dtlsConfig) { final KeyLoader keyLoader = KeyLoader.fromFiles(vertx, getConfig().getKeyPath(), getConfig().getCertPath()); final PrivateKey pk = keyLoader.getPrivateKey(); final Certificate[] certChain = keyLoader.getCertificateChain(); if (pk != null && certChain != null) { if (pk.getAlgorithm().equals("EC")) { // Californium's cipher suites support ECC based keys only log.info("using private key [{}] and certificate [{}] as server identity", getConfig().getKeyPath(), getConfig().getCertPath()); dtlsConfig.setIdentity(pk, certChain); } else { log.warn("configured key is not ECC based, certificate based cipher suites will be disabled"); } } }
Example #2
Source File: ManagerTradfri.java From helloiot with GNU General Public License v3.0 | 6 votes |
void connectBridge() { DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); builder.setAddress(new InetSocketAddress(0)); builder.setPskStore(new StaticPskStore(identity, psk.getBytes())); DTLSConnector dtlsConnector = new DTLSConnector(builder.build()); CoapEndpoint.CoapEndpointBuilder coapbuilder = new CoapEndpoint.CoapEndpointBuilder(); coapbuilder.setConnector(dtlsConnector); coapbuilder.setNetworkConfig(NetworkConfig.getStandard()); coapEndPoint = coapbuilder.build(); }
Example #3
Source File: TradfriGatewayHandler.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void establishConnection() { TradfriGatewayConfig configuration = getConfigAs(TradfriGatewayConfig.class); this.gatewayURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + DEVICES; this.gatewayInfoURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + GATEWAY + "/" + GATEWAY_DETAILS; try { URI uri = new URI(gatewayURI); deviceClient = new TradfriCoapClient(uri); } catch (URISyntaxException e) { logger.error("Illegal gateway URI '{}': {}", gatewayURI, e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage()); return; } DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0)); builder.setPskStore(new StaticPskStore(configuration.identity, configuration.preSharedKey.getBytes())); dtlsConnector = new DTLSConnector(builder.build(), new InMemoryConnectionStore(100, 60)); endPoint = new TradfriCoapEndpoint(dtlsConnector, NetworkConfig.getStandard()); deviceClient.setEndpoint(endPoint); updateStatus(ThingStatus.UNKNOWN); // schedule a new scan every minute scanJob = scheduler.scheduleWithFixedDelay(this::startScan, 0, 1, TimeUnit.MINUTES); }
Example #4
Source File: CoapTestBase.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Creates the client to use for uploading data to the secure endpoint * of the CoAP adapter. * * @param pskStoreToUse The store to retrieve shared secrets from. * @return The client. */ protected CoapClient getCoapsClient(final PskStore pskStoreToUse) { final DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); dtlsConfig.setAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); dtlsConfig.setPskStore(pskStoreToUse); dtlsConfig.setMaxRetransmissions(1); final CoapEndpoint.Builder builder = new CoapEndpoint.Builder(); builder.setNetworkConfig(NetworkConfig.createStandardWithoutFile()); builder.setConnector(new DTLSConnector(dtlsConfig.build())); return new CoapClient().setEndpoint(builder.build()); }
Example #5
Source File: TradfriGateway.java From ThingML-Tradfri with Apache License 2.0 | 4 votes |
protected void initCoap() { DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); //new InetSocketAddress(0) builder.setPskStore(new StaticPskStore("", security_key.getBytes())); coap = new CoapEndpoint(new DTLSConnector(builder.build()), NetworkConfig.getStandard()); }
Example #6
Source File: AbstractVertxBasedCoapAdapter.java From hono with Eclipse Public License 2.0 | 4 votes |
private Future<Endpoint> createSecureEndpoint(final NetworkConfig config) { final ApplicationLevelInfoSupplier deviceResolver = Optional.ofNullable(honoDeviceResolver) .orElse(new DefaultDeviceResolver(context, tracer, getTypeName(), getConfig(), getCredentialsClientFactory())); final PskStore store = Optional.ofNullable(pskStore) .orElseGet(() -> { if (deviceResolver instanceof PskStore) { return (PskStore) deviceResolver; } else { return new DefaultDeviceResolver(context, tracer, getTypeName(), getConfig(), getCredentialsClientFactory()); } }); final DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); dtlsConfig.setServerOnly(true); dtlsConfig.setRecommendedCipherSuitesOnly(true); dtlsConfig.setClientAuthenticationRequired(getConfig().isAuthenticationRequired()); dtlsConfig.setAddress( new InetSocketAddress(getConfig().getBindAddress(), getConfig().getPort(getPortDefaultValue()))); dtlsConfig.setApplicationLevelInfoSupplier(deviceResolver); dtlsConfig.setPskStore(store); dtlsConfig.setRetransmissionTimeout(getConfig().getDtlsRetransmissionTimeout()); dtlsConfig.setMaxConnections(config.getInt(Keys.MAX_ACTIVE_PEERS)); 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(config); builder.setConnector(dtlsConnector); return Future.succeededFuture(builder.build()); } catch (final IllegalStateException ex) { log.warn("failed to create secure endpoint", ex); return Future.failedFuture(ex); } }