Skip to content

Commit 35ebec2

Browse files
committed
Add OSCORE test in SecurityStoreTest
1 parent 94acbaa commit 35ebec2

3 files changed

Lines changed: 84 additions & 9 deletions

File tree

leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisSecurityStoreTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,28 @@
1717

1818
import org.eclipse.leshan.core.endpoint.Protocol;
1919
import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder;
20+
import org.eclipse.leshan.servers.security.NonUniqueSecurityInfoException;
21+
import org.junit.jupiter.api.Disabled;
22+
import org.junit.jupiter.api.Test;
2023

2124
public class RedisSecurityStoreTest extends SecurityStoreTest {
2225

2326
@Override
2427
protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) {
2528
return super.givenServerUsing(givenProtocol).withRedisRegistrationStore().withRedisSecurityStore();
2629
}
30+
31+
@Override
32+
@Test
33+
@Disabled("OSCORE not supported yet")
34+
void change_oscore_rid_cleanup() throws NonUniqueSecurityInfoException {
35+
// "OSCORE not supported yet"
36+
}
37+
38+
@Override
39+
@Test
40+
@Disabled("OSCORE not supported yet")
41+
void nonunique_oscore_rid() throws NonUniqueSecurityInfoException {
42+
// "OSCORE not supported yet"
43+
}
2744
}

leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/SecurityStoreTest.java

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@
2020
import static org.eclipse.leshan.integration.tests.util.Credentials.GOOD_ENDPOINT;
2121
import static org.eclipse.leshan.integration.tests.util.Credentials.GOOD_PSK_ID;
2222
import static org.eclipse.leshan.integration.tests.util.Credentials.GOOD_PSK_KEY;
23+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_AEAD_ALGORITHM;
24+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_HKDF_ALGORITHM;
25+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_MASTER_SALT;
26+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_MASTER_SECRET;
27+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_OTHER_MASTER_SALT;
28+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_OTHER_RECIPIENT_ID;
29+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_OTHER_SENDER_ID;
30+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_RECIPIENT_ID;
31+
import static org.eclipse.leshan.integration.tests.util.Credentials.OSCORE_SENDER_ID;
32+
import static org.junit.jupiter.api.Assertions.assertThrows;
2333
import static org.junit.jupiter.api.Assertions.fail;
2434

2535
import org.eclipse.leshan.core.endpoint.Protocol;
36+
import org.eclipse.leshan.core.oscore.OscoreSetting;
2637
import org.eclipse.leshan.integration.tests.util.Credentials;
2738
import org.eclipse.leshan.integration.tests.util.LeshanTestServer;
2839
import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder;
@@ -34,17 +45,17 @@
3445
import org.junit.jupiter.api.BeforeEach;
3546
import org.junit.jupiter.api.Test;
3647

37-
public class SecurityStoreTest {
48+
class SecurityStoreTest {
3849

3950
LeshanTestServer server;
4051

4152
@BeforeEach
42-
public void start() {
53+
void start() {
4354
server = givenServerUsing(Protocol.COAPS).with("Californium").build();
4455
}
4556

4657
@AfterEach
47-
public void stop() throws InterruptedException {
58+
void stop() {
4859
if (server != null)
4960
server.destroy();
5061
}
@@ -54,19 +65,18 @@ protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) {
5465
}
5566

5667
@Test
57-
public void nonunique_psk_identity() throws NonUniqueSecurityInfoException {
68+
void nonunique_psk_identity() throws NonUniqueSecurityInfoException {
5869
EditableSecurityStore ess = server.getSecurityStore();
5970

6071
ess.add(SecurityInfo.newPreSharedKeyInfo(GOOD_ENDPOINT, GOOD_PSK_ID, GOOD_PSK_KEY));
61-
try {
72+
// "Non-unique PSK identity should throw exception on add"
73+
assertThrows(NonUniqueSecurityInfoException.class, () -> {
6274
ess.add(SecurityInfo.newPreSharedKeyInfo(BAD_ENDPOINT, GOOD_PSK_ID, GOOD_PSK_KEY));
63-
fail("Non-unique PSK identity should throw exception on add");
64-
} catch (NonUniqueSecurityInfoException e) {
65-
}
75+
});
6676
}
6777

6878
@Test
69-
public void change_psk_identity_cleanup() throws NonUniqueSecurityInfoException {
79+
void change_psk_identity_cleanup() throws NonUniqueSecurityInfoException {
7080

7181
EditableSecurityStore ess = server.getSecurityStore();
7282

@@ -80,4 +90,47 @@ public void change_psk_identity_cleanup() throws NonUniqueSecurityInfoException
8090
fail("PSK identity change for existing endpoint should have cleaned up old PSK identity");
8191
}
8292
}
93+
94+
@Test
95+
void nonunique_oscore_rid() throws NonUniqueSecurityInfoException {
96+
EditableSecurityStore ess = server.getSecurityStore();
97+
98+
OscoreSetting firstOscoreSetting = new OscoreSetting(OSCORE_SENDER_ID, //
99+
OSCORE_RECIPIENT_ID, // we use same RID
100+
OSCORE_MASTER_SECRET, OSCORE_AEAD_ALGORITHM, OSCORE_HKDF_ALGORITHM, OSCORE_MASTER_SALT);
101+
102+
OscoreSetting secondOscoreSetting = new OscoreSetting(OSCORE_OTHER_SENDER_ID, //
103+
OSCORE_RECIPIENT_ID, // we use same RID
104+
OSCORE_MASTER_SECRET, OSCORE_AEAD_ALGORITHM, OSCORE_HKDF_ALGORITHM, OSCORE_OTHER_MASTER_SALT);
105+
106+
ess.add(SecurityInfo.newOscoreInfo(GOOD_ENDPOINT, firstOscoreSetting));
107+
// "Non-unique RID should throw exception on add"
108+
assertThrows(NonUniqueSecurityInfoException.class, () -> {
109+
ess.add(SecurityInfo.newOscoreInfo(BAD_ENDPOINT, secondOscoreSetting));
110+
});
111+
}
112+
113+
@Test
114+
void change_oscore_rid_cleanup() throws NonUniqueSecurityInfoException {
115+
116+
EditableSecurityStore ess = server.getSecurityStore();
117+
118+
OscoreSetting firstOscoreSetting = new OscoreSetting(OSCORE_SENDER_ID, //
119+
OSCORE_RECIPIENT_ID, // we use different RID
120+
OSCORE_MASTER_SECRET, OSCORE_AEAD_ALGORITHM, OSCORE_HKDF_ALGORITHM, OSCORE_MASTER_SALT);
121+
122+
OscoreSetting secondOscoreSetting = new OscoreSetting(OSCORE_OTHER_SENDER_ID, //
123+
OSCORE_OTHER_RECIPIENT_ID, // we use different RID
124+
OSCORE_MASTER_SECRET, OSCORE_AEAD_ALGORITHM, OSCORE_HKDF_ALGORITHM, OSCORE_OTHER_MASTER_SALT);
125+
126+
ess.add(SecurityInfo.newOscoreInfo(GOOD_ENDPOINT, firstOscoreSetting));
127+
// Change PSK id for endpoint
128+
ess.add(SecurityInfo.newOscoreInfo(GOOD_ENDPOINT, secondOscoreSetting));
129+
// Original/old PSK id should not be reserved any more
130+
try {
131+
ess.add(SecurityInfo.newOscoreInfo(BAD_ENDPOINT, firstOscoreSetting));
132+
} catch (NonUniqueSecurityInfoException e) {
133+
fail("PSK identity change for existing endpoint should have cleaned up old PSK identity");
134+
}
135+
}
83136
}

leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/Credentials.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public class Credentials {
5757
public static final byte[] OSCORE_SENDER_ID = "secret".getBytes();
5858
public static final byte[] OSCORE_RECIPIENT_ID = Hex.decodeHex("FEDCBA".toCharArray());
5959

60+
public static final byte[] OSCORE_OTHER_MASTER_SECRET = Hex.decodeHex("0012345678".toCharArray());
61+
public static final byte[] OSCORE_OTHER_MASTER_SALT = Hex.decodeHex("0009876543".toCharArray());
62+
public static final byte[] OSCORE_OTHER_SENDER_ID = "other".getBytes();
63+
public static final byte[] OSCORE_OTHER_RECIPIENT_ID = Hex.decodeHex("00FEDC".toCharArray());
64+
6065
public static final byte[] OSCORE_BOOTSTRAP_MASTER_SECRET = Hex.decodeHex("BB1234567890".toCharArray());
6166
public static final byte[] OSCORE_BOOTSTRAP_MASTER_SALT = Hex.decodeHex("BB0987654321".toCharArray());
6267
public static final byte[] OSCORE_BOOTSTRAP_SENDER_ID = Hex.decodeHex("BBABCDEF".toCharArray());

0 commit comments

Comments
 (0)