use of org.eclipse.californium.elements.config.Configuration in project leshan by eclipse.
the class SecureIntegrationTestHelper method createX509CertClient.
public void createX509CertClient(X509Certificate[] clientCertificate, PrivateKey privatekey, List<Certificate> clientTrustStore, X509Certificate serverCertificate, CertificateUsage certificateUsage) throws CertificateEncodingException {
/* Make sure there is only 1 certificate in chain before client certificate chains are supported */
assert (clientCertificate.length == 1);
ObjectsInitializer initializer = new TestObjectsInitializer();
initializer.setInstancesForObject(LwM2mId.SECURITY, Security.x509("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345, clientCertificate[0].getEncoded(), privatekey.getEncoded(), serverCertificate.getEncoded(), certificateUsage.code));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345"));
initializer.setClassForObject(LwM2mId.ACCESS_CONTROL, DummyInstanceEnabler.class);
List<LwM2mObjectEnabler> objects = initializer.createAll();
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
Configuration configuration = LeshanClientBuilder.createDefaultCoapConfiguration();
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setTrustStore(clientTrustStore);
Builder dtlsConfig = DtlsConnectorConfig.builder(configuration);
dtlsConfig.set(DtlsConfig.DTLS_ROLE, DtlsRole.CLIENT_ONLY);
builder.setDtlsConfig(dtlsConfig);
builder.setObjects(objects);
client = builder.build();
setupClientMonitoring();
}
use of org.eclipse.californium.elements.config.Configuration in project leshan by eclipse.
the class SecureIntegrationTestHelper method createPSKClient.
public void createPSKClient(boolean queueMode) {
ObjectsInitializer initializer = new TestObjectsInitializer();
initializer.setInstancesForObject(LwM2mId.SECURITY, Security.psk("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345, GOOD_PSK_ID.getBytes(StandardCharsets.UTF_8), GOOD_PSK_KEY));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345"));
initializer.setDummyInstancesForObject(LwM2mId.ACCESS_CONTROL);
List<LwM2mObjectEnabler> objects = initializer.createAll();
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
Configuration configuration = LeshanClientBuilder.createDefaultCoapConfiguration();
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setRegistrationEngineFactory(new DefaultRegistrationEngineFactory().setQueueMode(queueMode));
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setObjects(objects);
builder.setDtlsConfig(DtlsConnectorConfig.builder(configuration).setAsList(DtlsConfig.DTLS_CIPHER_SUITES, CipherSuite.TLS_PSK_WITH_AES_128_CCM_8));
// set an editable PSK store for tests
builder.setEndpointFactory(new EndpointFactory() {
@Override
public CoapEndpoint createUnsecuredEndpoint(InetSocketAddress address, Configuration coapConfig, ObservationStore store) {
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setInetSocketAddress(address);
builder.setConfiguration(coapConfig);
return builder.build();
}
@Override
public CoapEndpoint createSecuredEndpoint(DtlsConnectorConfig dtlsConfig, Configuration coapConfig, ObservationStore store) {
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
Builder dtlsConfigBuilder = DtlsConnectorConfig.builder(dtlsConfig);
// tricks to be able to change psk information on the fly
AdvancedPskStore pskStore = dtlsConfig.getAdvancedPskStore();
if (pskStore != null) {
PskPublicInformation identity = pskStore.getIdentity(null, null);
SecretKey key = pskStore.requestPskSecretResult(ConnectionId.EMPTY, null, identity, null, null, null, false).getSecret();
singlePSKStore = new SinglePSKStore(identity, key);
dtlsConfigBuilder.setAdvancedPskStore(singlePSKStore);
}
builder.setConnector(new DTLSConnector(dtlsConfigBuilder.build()));
builder.setConfiguration(coapConfig);
return builder.build();
}
});
// create client;
client = builder.build();
setupClientMonitoring();
}
use of org.eclipse.californium.elements.config.Configuration in project thingsboard by thingsboard.
the class DefaultCoapServerService method createCoapServer.
private CoapServer createCoapServer() throws UnknownHostException {
Configuration networkConfig = new Configuration();
networkConfig.set(CoapConfig.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
networkConfig.set(CoapConfig.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true);
networkConfig.set(CoapConfig.BLOCKWISE_STATUS_LIFETIME, DEFAULT_BLOCKWISE_STATUS_LIFETIME_IN_SECONDS, TimeUnit.SECONDS);
networkConfig.set(CoapConfig.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024);
networkConfig.set(CoapConfig.RESPONSE_MATCHING, CoapConfig.MatcherMode.RELAXED);
networkConfig.set(CoapConfig.PREFERRED_BLOCK_SIZE, 1024);
networkConfig.set(CoapConfig.MAX_MESSAGE_SIZE, 1024);
networkConfig.set(CoapConfig.MAX_RETRANSMIT, 4);
networkConfig.set(CoapConfig.COAP_PORT, coapServerContext.getPort());
server = new CoapServer(networkConfig);
CoapEndpoint.Builder noSecCoapEndpointBuilder = new CoapEndpoint.Builder();
InetAddress addr = InetAddress.getByName(coapServerContext.getHost());
InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort());
noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr);
noSecCoapEndpointBuilder.setConfiguration(networkConfig);
CoapEndpoint noSecCoapEndpoint = noSecCoapEndpointBuilder.build();
server.addEndpoint(noSecCoapEndpoint);
if (isDtlsEnabled()) {
CoapEndpoint.Builder dtlsCoapEndpointBuilder = new CoapEndpoint.Builder();
TbCoapDtlsSettings dtlsSettings = coapServerContext.getDtlsSettings();
DtlsConnectorConfig dtlsConnectorConfig = dtlsSettings.dtlsConnectorConfig(networkConfig);
networkConfig.set(CoapConfig.COAP_SECURE_PORT, dtlsConnectorConfig.getAddress().getPort());
dtlsCoapEndpointBuilder.setConfiguration(networkConfig);
DTLSConnector connector = new DTLSConnector(dtlsConnectorConfig);
dtlsCoapEndpointBuilder.setConnector(connector);
CoapEndpoint dtlsCoapEndpoint = dtlsCoapEndpointBuilder.build();
server.addEndpoint(dtlsCoapEndpoint);
tbDtlsCertificateVerifier = (TbCoapDtlsCertificateVerifier) dtlsConnectorConfig.getAdvancedCertificateVerifier();
dtlsSessionsExecutor = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName()));
dtlsSessionsExecutor.scheduleAtFixedRate(this::evictTimeoutSessions, new Random().nextInt((int) getDtlsSessionReportTimeout()), getDtlsSessionReportTimeout(), TimeUnit.MILLISECONDS);
}
Resource root = server.getRoot();
TbCoapServerMessageDeliverer messageDeliverer = new TbCoapServerMessageDeliverer(root);
server.setMessageDeliverer(messageDeliverer);
server.start();
return server;
}
use of org.eclipse.californium.elements.config.Configuration in project thingsboard by thingsboard.
the class SecureClientX509 method main.
public static void main(String[] args) throws URISyntaxException {
System.out.println("Usage: java -cp ... org.thingsboard.server.transport.coap.client.SecureClientX509 " + "host port keyStoreUriPath keyStoreAlias trustedAliasPattern clientKeys sharedKeys");
String host = args[0];
int port = Integer.parseInt(args[1]);
String clientKeys = args[6];
String sharedKeys = args[7];
String keyStoreUriPath = args[2];
String keyStoreAlias = args[3];
String trustedAliasPattern = args[4];
String keyStorePassword = args[5];
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new Configuration());
setupCredentials(builder, keyStoreUriPath, keyStoreAlias, trustedAliasPattern, keyStorePassword);
DTLSConnector dtlsConnector = new DTLSConnector(builder.build());
SecureClientX509 client = new SecureClientX509(dtlsConnector, host, port, clientKeys, sharedKeys);
client.test();
}
use of org.eclipse.californium.elements.config.Configuration in project californium by eclipse.
the class LibCoapClientMbedTlsInteroperabilityTest method start.
@Before
public void start() {
processUtil.setTag(name.getName());
// mbedtls v2.27 still supports only the deprecated MAC calculation.
// Ensure/adjust the extension id in mbedtls - include/mbedtls/ssl.h
// for compatibility to 53
//
// #define MBEDTLS_TLS_EXT_CID 53
//
// For libcoap enable the passive use of CID in src/coap_mbedtls.c,
// coap_dtls_new_mbedtls_env, before mbedtls_ssl_set_bio with
//
// mbedtls_ssl_set_cid(&m_env->ssl, MBEDTLS_SSL_CID_ENABLED, NULL, 0);
builder = DtlsConnectorConfig.builder(new Configuration()).set(DtlsConfig.DTLS_SUPPORT_DEPRECATED_CID, true);
}
Aggregations