lwm2m tests add no trust and clear comments
This commit is contained in:
parent
c981ff4c55
commit
be23dd2f7c
@ -67,7 +67,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
@DaoSqlTest
|
||||
public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
|
||||
|
||||
@ -135,7 +134,6 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
|
||||
protected LwM2MTestClient client;
|
||||
private final LwM2MBootstrapClientCredentials defaultBootstrapCredentials;
|
||||
private String[] resources;
|
||||
// protected String endpoint;
|
||||
|
||||
public AbstractLwM2MIntegrationTest() {
|
||||
this.defaultBootstrapCredentials = new LwM2MBootstrapClientCredentials();
|
||||
@ -197,11 +195,9 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
|
||||
wsClient.waitForReply();
|
||||
|
||||
wsClient.registerWaitForUpdate();
|
||||
// this.endpoint = endpoint;
|
||||
createNewClient(security, coapConfig, false, endpoint);
|
||||
String msg = wsClient.waitForUpdate();
|
||||
|
||||
log.info("msg5555: [{}]", msg);
|
||||
EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
|
||||
Assert.assertEquals(1, update.getCmdId());
|
||||
List<EntityData> eData = update.getUpdate();
|
||||
@ -264,10 +260,6 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
// public void setEndpoint(String endpoint) {
|
||||
// this.endpoint = endpoint;
|
||||
// }
|
||||
|
||||
public void createNewClient(Security security, NetworkConfig coapConfig, boolean isRpc, String endpoint) throws Exception {
|
||||
clientDestroy();
|
||||
client = new LwM2MTestClient(this.executor, endpoint);
|
||||
|
||||
@ -25,18 +25,16 @@ public class Lwm2mTestHelper {
|
||||
// Server
|
||||
public static final int SECURE_PORT = 5686;
|
||||
public static final int SECURE_PORT_BS = 5688;
|
||||
public static final String HOST = "localhost";
|
||||
public static final String HOST_BS = "localhost";
|
||||
public static final NetworkConfig SECURE_COAP_CONFIG = new NetworkConfig().setString("COAP_SECURE_PORT", Integer.toString(SECURE_PORT));
|
||||
public static final String ENDPOINT_SECURITY = "deviceAEndpoint";
|
||||
public static final String SECURE_URI = "coaps://localhost:" + SECURE_PORT;
|
||||
|
||||
public static final int PORT = 5685;
|
||||
public static final int PORT_BS = 5687;
|
||||
public static final String HOST = "localhost";
|
||||
public static final String HOST_BS = "localhost";
|
||||
public static final int SHORT_SERVER_ID = 123;
|
||||
public static final int SHORT_SERVER_ID_BS = 111;
|
||||
|
||||
public static final Security SECURITY = noSec("coap://localhost:" + PORT, SHORT_SERVER_ID);
|
||||
public static final NetworkConfig SECURE_COAP_CONFIG = new NetworkConfig().setString("COAP_SECURE_PORT", Integer.toString(SECURE_PORT));
|
||||
public static final String SECURE_URI = "coaps://" + HOST + ":" + SECURE_PORT;
|
||||
public static final Security SECURITY = noSec("coap://"+ HOST +":" + PORT, SHORT_SERVER_ID);
|
||||
public static final NetworkConfig COAP_CONFIG = new NetworkConfig().setString("COAP_PORT", Integer.toString(PORT));
|
||||
|
||||
// Models
|
||||
@ -67,5 +65,4 @@ public class Lwm2mTestHelper {
|
||||
public static final String resourceIdName_3_14 = "UtfOffset";
|
||||
public static final String resourceIdName_19_0_0 = "dataRead";
|
||||
public static final String resourceIdName_19_1_0 = "dataWrite";
|
||||
|
||||
}
|
||||
|
||||
@ -138,8 +138,6 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile() throws Exception {
|
||||
// String endpoint = "WithoutFirmwareInfoDevice";
|
||||
// setEndpoint(endpoint);
|
||||
createDeviceProfile(transportConfiguration);
|
||||
NoSecClientCredential credentials = createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
|
||||
final Device device = createDevice(credentials);
|
||||
@ -165,8 +163,6 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testFirmwareUpdateByObject5() throws Exception {
|
||||
// String endpoint = "Ota5_Device";
|
||||
// setEndpoint(endpoint);
|
||||
createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
|
||||
NoSecClientCredential credentials = createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5);
|
||||
final Device device = createDevice(credentials);
|
||||
|
||||
@ -18,12 +18,10 @@ package org.thingsboard.server.transport.lwm2m.rpc;
|
||||
import org.junit.Before;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredential;
|
||||
import org.thingsboard.server.controller.TbTestWebSocketClient;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -53,8 +51,6 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractLwM2MInteg
|
||||
|
||||
protected String RPC_TRANSPORT_CONFIGURATION;
|
||||
|
||||
protected ScheduledExecutorService executor;
|
||||
protected TbTestWebSocketClient wsClient;
|
||||
protected String deviceId;
|
||||
public Set expectedObjects;
|
||||
public Set expectedObjectIdVers;
|
||||
@ -73,7 +69,7 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractLwM2MInteg
|
||||
protected String objectIdVer_50 = "/50";
|
||||
protected String objectIdVer_3303;
|
||||
protected static AtomicInteger endpointSequence = new AtomicInteger();
|
||||
protected static String endpointRpcPref = "deviceEndpointRpc";
|
||||
protected static String DEVICE_ENDPOINT_RPC_PREF = "deviceEndpointRpc";
|
||||
|
||||
public AbstractRpcLwM2MIntegrationTest(){
|
||||
setResources(resources);
|
||||
@ -81,8 +77,7 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractLwM2MInteg
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
String endpoint = endpointRpcPref + endpointSequence.incrementAndGet();
|
||||
// setEndpoint(endpoint);
|
||||
String endpoint = DEVICE_ENDPOINT_RPC_PREF + endpointSequence.incrementAndGet();
|
||||
init();
|
||||
createNewClient (SECURITY, COAP_CONFIG, true, endpoint);
|
||||
|
||||
|
||||
@ -33,36 +33,16 @@ import java.security.cert.X509Certificate;
|
||||
public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
||||
|
||||
protected final String CREDENTIALS_PATH = "lwm2m/credentials/"; // client public key or id used for PSK
|
||||
protected final String pskIdentity; // client public key or id used for PSK
|
||||
protected final String pskKey; // client private/secret key used for PSK
|
||||
// protected final PublicKey clientPublicKey; // client public key used for RPK
|
||||
// protected final PrivateKey clientPrivateKey; // client private key used for RPK
|
||||
|
||||
|
||||
|
||||
// // client certificate signed by rootCA but with bad CN (CN does not start by leshan_integration_test)
|
||||
// protected final X509Certificate clientX509CertWithBadCN;
|
||||
// // client certificate self-signed with a good CN (CN start by leshan_integration_test)
|
||||
// protected final X509Certificate clientX509CertSelfSigned;
|
||||
// // client certificate signed by another CA (not rootCA) with a good CN (CN start by leshan_integration_test)
|
||||
// protected final X509Certificate clientX509CertNotTrusted;
|
||||
|
||||
// self-signed server certificate
|
||||
// protected final X509Certificate serverX509CertSelfSigned;
|
||||
// // rootCA used by the server
|
||||
// protected final X509Certificate rootCAX509Cert;
|
||||
// certificates trustedby the server (should contain rootCA)
|
||||
// Get keys PSK
|
||||
protected final String CLIENT_PSK_IDENTITY = "SOME_PSK_ID"; // client public key or id used for PSK
|
||||
protected final String CLIENT_PSK_KEY = "73656372657450534b73656372657450"; // client private/secret key used for PSK
|
||||
|
||||
// Server
|
||||
protected static final String SERVER_JKS_FOR_TEST = "lwm2mserver";
|
||||
protected static final String SERVER_STORE_PWD = "server_ks_password";
|
||||
protected static final String SERVER_CERT_ALIAS = "server";
|
||||
protected final X509Certificate serverX509Cert; // server certificate signed by rootCA
|
||||
// protected final PrivateKey serverPrivateKeyFromCert; // server private key used for RPK and X509
|
||||
protected final PublicKey serverPublicKeyFromCert; // server public key used for RPK
|
||||
|
||||
// // Server Trust
|
||||
// protected final Certificate[] trustedCertificates = new Certificate[1];
|
||||
protected final X509Certificate serverX509Cert; // server certificate signed by rootCA
|
||||
protected final PublicKey serverPublicKeyFromCert; // server public key used for RPK
|
||||
|
||||
// Client
|
||||
protected LwM2MTestClient client;
|
||||
@ -92,45 +72,18 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
public AbstractSecurityLwM2MIntegrationTest() {
|
||||
// create client credentials
|
||||
setResources(this.resources);
|
||||
// setEndpoint(CLIENT_ENDPOINT_NO_TRUST);
|
||||
try {
|
||||
// Get keys PSK
|
||||
this.pskIdentity = "SOME_PSK_ID";
|
||||
this.pskKey = "73656372657450534b73656372657450";
|
||||
|
||||
// // Get point values
|
||||
// byte[] publicX = Hex
|
||||
// .decodeHex("89c048261979208666f2bfb188be1968fc9021c416ce12828c06f4e314c167b5".toCharArray());
|
||||
// byte[] publicY = Hex
|
||||
// .decodeHex("cbf1eb7587f08e01688d9ada4be859137ca49f79394bad9179326b3090967b68".toCharArray());
|
||||
// byte[] privateS = Hex
|
||||
// .decodeHex("e67b68d2aaeb6550f19d98cade3ad62b39532e02e6b422e1f7ea189dabaea5d2".toCharArray());
|
||||
//
|
||||
// // Get Elliptic Curve Parameter spec for secp256r1
|
||||
// AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC");
|
||||
// algoParameters.init(new ECGenParameterSpec("secp256r1"));
|
||||
// ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class);
|
||||
//
|
||||
// // Create key specs
|
||||
// KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)),
|
||||
// parameterSpec);
|
||||
// KeySpec privateKeySpec = new ECPrivateKeySpec(new BigInteger(privateS), parameterSpec);
|
||||
//
|
||||
// // Get keys RPK
|
||||
// clientPublicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec);
|
||||
// clientPrivateKey = KeyFactory.getInstance("EC").generatePrivate(privateKeySpec);
|
||||
|
||||
// Get certificates from key store
|
||||
char[] clientKeyStorePwd = CLIENT_STORE_PWD.toCharArray();
|
||||
KeyStore clientKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
try (InputStream clientKeyStoreFile = this.getClass().getClassLoader().getResourceAsStream(CREDENTIALS_PATH + CLIENT_JKS_FOR_TEST + ".jks")) {
|
||||
clientKeyStore.load(clientKeyStoreFile, clientKeyStorePwd);
|
||||
}
|
||||
|
||||
// Trust
|
||||
clientPrivateKeyFromCertTrust = (PrivateKey) clientKeyStore.getKey(CLIENT_ALIAS_CERT_TRUST, clientKeyStorePwd);
|
||||
clientX509CertTrust = (X509Certificate) clientKeyStore.getCertificate(CLIENT_ALIAS_CERT_TRUST);
|
||||
clientPublicKeyFromCertTrust = clientX509CertTrust != null ? clientX509CertTrust.getPublicKey() : null;
|
||||
|
||||
// No trust
|
||||
clientPrivateKeyFromCertTrustNo = (PrivateKey) clientKeyStore.getKey(CLIENT_ALIAS_CERT_TRUST_NO, clientKeyStorePwd);
|
||||
clientX509CertTrustNo = (X509Certificate) clientKeyStore.getCertificate(CLIENT_ALIAS_CERT_TRUST_NO);
|
||||
clientPublicKeyFromCertTrustNo = clientX509CertTrustNo != null ? clientX509CertTrustNo.getPublicKey() : null;
|
||||
@ -141,29 +94,6 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
|
||||
// create server credentials
|
||||
try {
|
||||
// // Get point values
|
||||
// byte[] publicX = Hex
|
||||
// .decodeHex("fcc28728c123b155be410fc1c0651da374fc6ebe7f96606e90d927d188894a73".toCharArray());
|
||||
// byte[] publicY = Hex
|
||||
// .decodeHex("d2ffaa73957d76984633fc1cc54d0b763ca0559a9dff9706e9f4557dacc3f52a".toCharArray());
|
||||
// byte[] privateS = Hex
|
||||
// .decodeHex("1dae121ba406802ef07c193c1ee4df91115aabd79c1ed7f4c0ef7ef6a5449400".toCharArray());
|
||||
//
|
||||
// // Get Elliptic Curve Parameter spec for secp256r1
|
||||
// AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC");
|
||||
// algoParameters.init(new ECGenParameterSpec("secp256r1"));
|
||||
// ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class);
|
||||
//
|
||||
// // Create key specs
|
||||
// KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)),
|
||||
// parameterSpec);
|
||||
// KeySpec privateKeySpec = new ECPrivateKeySpec(new BigInteger(privateS), parameterSpec);
|
||||
//
|
||||
// // Get keys
|
||||
// serverPublicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec);
|
||||
// serverPrivateKey = KeyFactory.getInstance("EC").generatePrivate(privateKeySpec);
|
||||
|
||||
|
||||
// Get certificates from key store
|
||||
char[] serverKeyStorePwd = SERVER_STORE_PWD.toCharArray();
|
||||
KeyStore serverKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
@ -171,13 +101,8 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
|
||||
serverKeyStore.load(serverKeyStoreFile, serverKeyStorePwd);
|
||||
}
|
||||
|
||||
// serverPrivateKeyFromCert = (PrivateKey) serverKeyStore.getKey("server", serverKeyStorePwd);
|
||||
serverX509Cert = (X509Certificate) serverKeyStore.getCertificate(SERVER_CERT_ALIAS);
|
||||
serverPublicKeyFromCert = serverX509Cert.getPublicKey();
|
||||
// rootCAX509Cert = (X509Certificate) serverKeyStore.getCertificate("rootCA");
|
||||
|
||||
// serverX509CertSelfSigned = (X509Certificate) serverKeyStore.getCertificate("server_self_signed");
|
||||
// trustedCertificates[0] = serverX509Cert;
|
||||
} catch (GeneralSecurityException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
package org.thingsboard.server.transport.lwm2m.security.sql;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredential;
|
||||
import org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest;
|
||||
|
||||
@ -17,7 +17,6 @@ package org.thingsboard.server.transport.lwm2m.security.sql;
|
||||
|
||||
import org.eclipse.leshan.client.object.Security;
|
||||
import org.eclipse.leshan.core.util.Hex;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential;
|
||||
import org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest;
|
||||
@ -35,12 +34,12 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes
|
||||
public void testConnectWithPSKAndObserveTelemetry() throws Exception {
|
||||
PSKClientCredential clientCredentials = new PSKClientCredential();
|
||||
clientCredentials.setEndpoint(CLIENT_ENDPOINT_PSK);
|
||||
clientCredentials.setKey(pskKey);
|
||||
clientCredentials.setIdentity(pskIdentity);
|
||||
clientCredentials.setKey(CLIENT_PSK_KEY);
|
||||
clientCredentials.setIdentity(CLIENT_PSK_IDENTITY);
|
||||
Security security = psk(SECURE_URI,
|
||||
SHORT_SERVER_ID,
|
||||
pskIdentity.getBytes(StandardCharsets.UTF_8),
|
||||
Hex.decodeHex(pskKey.toCharArray()));
|
||||
CLIENT_PSK_IDENTITY.getBytes(StandardCharsets.UTF_8),
|
||||
Hex.decodeHex(CLIENT_PSK_KEY.toCharArray()));
|
||||
super.basicTestConnectionObserveTelemetry(security, clientCredentials, SECURE_COAP_CONFIG, CLIENT_ENDPOINT_PSK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
package org.thingsboard.server.transport.lwm2m.security.sql;
|
||||
|
||||
import org.eclipse.leshan.client.object.Security;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential;
|
||||
import org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest;
|
||||
|
||||
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.lwm2m.security.sql;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.eclipse.leshan.client.object.Security;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredential;
|
||||
import org.thingsboard.server.common.transport.util.SslUtil;
|
||||
@ -34,7 +32,6 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg
|
||||
public void testConnectWithCertAndObserveTelemetry() throws Exception {
|
||||
X509ClientCredential credentials = new X509ClientCredential();
|
||||
credentials.setEndpoint(CLIENT_ENDPOINT_X509_TRUST_NO);
|
||||
// rpkClientCredentials.setKey(new String(Base64.encodeBase64(clientPublicKeyFromCertTrust.getEncoded())));
|
||||
credentials.setCert(SslUtil.getCertificateString(clientX509CertTrustNo));
|
||||
Security security = x509(SECURE_URI,
|
||||
SHORT_SERVER_ID,
|
||||
@ -43,5 +40,4 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg
|
||||
serverX509Cert.getEncoded());
|
||||
super.basicTestConnectionObserveTelemetry(security, credentials, SECURE_COAP_CONFIG, CLIENT_ENDPOINT_X509_TRUST_NO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
<!-- <logger name="org.thingsboard.server.service.subscription" level="TRACE"/>-->
|
||||
<logger name="org.thingsboard.server.controller.TbTestWebSocketClient" level="INFO"/>
|
||||
<logger name="org.thingsboard.server" level="WARN"/>
|
||||
<logger name="oorg.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest" level="INFO"/>
|
||||
<logger name="org.springframework" level="WARN"/>
|
||||
<logger name="org.springframework.boot.test" level="WARN"/>
|
||||
<logger name="org.apache.cassandra" level="WARN"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user