Skip to content

Commit

Permalink
Use link from Security to find OSCORE object when creating ServerInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Rikard Höglund <rikard.hoglund@ri.se>
  • Loading branch information
rikard-sics committed Sep 18, 2019
1 parent ecebdfa commit 3e7db26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,34 @@ public static ServersInfo getInfo(Map<Integer, LwM2mObjectEnabler> objectEnabler
info.serverUri = new URI((String) security.getResource(SEC_SERVER_URI).getValue());
info.serverId = (long) security.getResource(SEC_SERVER_ID).getValue();
info.secureMode = getSecurityMode(security);
if (info.secureMode == SecurityMode.PSK) {

// find instance id of the associated oscore object (if any)
ObjectLink oscoreObjectLink = (ObjectLink) security.getResource(SEC_OSCORE_SECURITY_MODE).getValue();
int oscoreObjectInstanceId = oscoreObjectLink.getObjectInstanceId();
int oscoreObjectId = oscoreObjectLink.getObjectId();
boolean useOscore = false;
if(oscoreObjectId == OSCORE) {
useOscore = true;
}

if(useOscore) {
// search corresponding oscore object
LwM2mObjectInstance oscoreInstance = null;
for (LwM2mObjectInstance oscore : oscores.getInstances().values()) {
if (oscore.getId() == oscoreObjectInstanceId) {
oscoreInstance = oscore;
break;
}
}

info.masterSecret = getMasterSecret(oscoreInstance);
info.senderId = getSenderId(oscoreInstance);
info.recipientId = getRecipientId(oscoreInstance);
info.aeadAlgorithm = getAeadAlgorithm(oscoreInstance);
info.hkdfAlgorithm = getHkdfAlgorithm(oscoreInstance);
info.masterSalt = getMasterSalt(oscoreInstance);
info.idContext = getIdContext(oscoreInstance);
} else if (info.secureMode == SecurityMode.PSK) {
info.pskId = getPskIdentity(security);
info.pskKey = getPskKey(security);
} else if (info.secureMode == SecurityMode.RPK) {
Expand All @@ -121,18 +148,8 @@ public static ServersInfo getInfo(Map<Integer, LwM2mObjectEnabler> objectEnabler
info.clientCertificate = getClientCertificate(security);
info.serverCertificate = getServerCertificate(security);
info.privateKey = getPrivateKey(security);
} else if (info.secureMode == SecurityMode.OSCORE) {
//FIXME: Need proper way to find correct oscore instance corresponding to this security instance
LwM2mObjectInstance oscoreInstance = (LwM2mObjectInstance)oscores.getInstances().values().toArray()[0];
info.masterSecret = getMasterSecret(oscoreInstance);
info.senderId = getSenderId(oscoreInstance);
info.recipientId = getRecipientId(oscoreInstance);
info.aeadAlgorithm = getAeadAlgorithm(oscoreInstance);
info.hkdfAlgorithm = getHkdfAlgorithm(oscoreInstance);
info.masterSalt = getMasterSalt(oscoreInstance);
info.idContext = getIdContext(oscoreInstance);

}

// search corresponding device management server
for (LwM2mObjectInstance server : servers.getInstances().values()) {
if (info.serverId == (Long) server.getResource(SRV_SERVER_ID).getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public static void createAndStartClient(String endpoint, String localAddress, in
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
} else if (useOSCore) {
Oscore oscoreObject = new Oscore("11223344", "AA", "BB"); //Hardcoded values
oscoreObject.setId(12345);
oscoreObject.setId(12346);
initializer.setInstancesForObject(SECURITY, oscoreOnly(serverURI, 123, oscoreObject.getId()));
initializer.setInstancesForObject(OSCORE, oscoreObject);
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
Expand Down

0 comments on commit 3e7db26

Please sign in to comment.