|
|
|
@ -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); |
|
|
|
} |
|
|
|
|