Search in sources :

Example 6 with ObjectsInitializer

use of org.eclipse.leshan.client.resource.ObjectsInitializer in project leshan by eclipse.

the class SecureIntegrationTestHelper method createX509CertClient.

// TODO implement X509 support for client
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
    ObjectsInitializer initializer = new ObjectsInitializer();
    // TODO security instance with certificate info
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));
    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    config.setIdentity(privatekey, clientX509CertChain, false);
    config.setTrustStore(trustedCertificates);
    CoapServer coapServer = new CoapServer();
    CoapEndpoint.CoapEndpointBuilder coapBuilder = new CoapEndpoint.CoapEndpointBuilder();
    coapBuilder.setConnector(new DTLSConnector(config.build()));
    coapBuilder.setNetworkConfig(new NetworkConfig());
    coapServer.addEndpoint(coapBuilder.build());
    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) CoapServer(org.eclipse.californium.core.CoapServer) Server(org.eclipse.leshan.client.object.Server) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) InetSocketAddress(java.net.InetSocketAddress) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) CoapServer(org.eclipse.californium.core.CoapServer) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint)

Example 7 with ObjectsInitializer

use of org.eclipse.leshan.client.resource.ObjectsInitializer in project leshan by eclipse.

the class SecureIntegrationTestHelper method createRPKClient.

// TODO implement RPK support for client
public void createRPKClient() {
    ObjectsInitializer initializer = new ObjectsInitializer();
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.rpk("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345, clientPublicKey.getEncoded(), clientPrivateKey.getEncoded(), serverPublicKey.getEncoded()));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));
    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    // TODO no way to provide a dynamic config with the current scandium API
    config.setIdentity(clientPrivateKey, clientPublicKey);
    CoapServer coapServer = new CoapServer();
    CoapEndpoint.CoapEndpointBuilder coapBuilder = new CoapEndpoint.CoapEndpointBuilder();
    coapBuilder.setConnector(new DTLSConnector(config.build()));
    coapBuilder.setNetworkConfig(new NetworkConfig());
    coapServer.addEndpoint(coapBuilder.build());
    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) CoapServer(org.eclipse.californium.core.CoapServer) Server(org.eclipse.leshan.client.object.Server) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) InetSocketAddress(java.net.InetSocketAddress) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) CoapServer(org.eclipse.californium.core.CoapServer) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint)

Example 8 with ObjectsInitializer

use of org.eclipse.leshan.client.resource.ObjectsInitializer in project leshan by eclipse.

the class BootstrapIntegrationTestHelper method createClient.

private void createClient(Security security) {
    ObjectsInitializer initializer = new ObjectsInitializer();
    // Initialize LWM2M Object Tree
    initializer.setInstancesForObject(LwM2mId.SECURITY, security);
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", IntegrationTestHelper.MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));
    // Create Leshan Client
    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder)

Aggregations

LwM2mObjectEnabler (org.eclipse.leshan.client.resource.LwM2mObjectEnabler)8 ObjectsInitializer (org.eclipse.leshan.client.resource.ObjectsInitializer)8 LeshanClientBuilder (org.eclipse.leshan.client.californium.LeshanClientBuilder)7 Device (org.eclipse.leshan.client.object.Device)7 Server (org.eclipse.leshan.client.object.Server)7 InetSocketAddress (java.net.InetSocketAddress)4 CoapServer (org.eclipse.californium.core.CoapServer)3 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)3 NetworkConfig (org.eclipse.californium.core.network.config.NetworkConfig)3 DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)3 DtlsConnectorConfig (org.eclipse.californium.scandium.config.DtlsConnectorConfig)3 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)3 ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)2 File (java.io.File)1 Scanner (java.util.Scanner)1 Builder (org.eclipse.californium.scandium.config.DtlsConnectorConfig.Builder)1 LeshanClient (org.eclipse.leshan.client.californium.LeshanClient)1 SecurityObjectPskStore (org.eclipse.leshan.client.californium.impl.SecurityObjectPskStore)1 ObjectModel (org.eclipse.leshan.core.model.ObjectModel)1 LeshanServer (org.eclipse.leshan.server.californium.impl.LeshanServer)1