2020import static org .eclipse .leshan .integration .tests .util .Credentials .GOOD_ENDPOINT ;
2121import static org .eclipse .leshan .integration .tests .util .Credentials .GOOD_PSK_ID ;
2222import 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 ;
2333import static org .junit .jupiter .api .Assertions .fail ;
2434
2535import org .eclipse .leshan .core .endpoint .Protocol ;
36+ import org .eclipse .leshan .core .oscore .OscoreSetting ;
2637import org .eclipse .leshan .integration .tests .util .Credentials ;
2738import org .eclipse .leshan .integration .tests .util .LeshanTestServer ;
2839import org .eclipse .leshan .integration .tests .util .LeshanTestServerBuilder ;
3445import org .junit .jupiter .api .BeforeEach ;
3546import 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}
0 commit comments