Skip to content

Commit

Permalink
Updated code for finding associated oscore instance from security object
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 Dec 18, 2020
1 parent 149b248 commit af75452
Showing 1 changed file with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,25 @@ public static ServersInfo getInfo(Map<Integer, LwM2mObjectEnabler> objectEnabler
info.serverUri = new URI((String) security.getResource(SEC_SERVER_URI).getValue());
info.secureMode = getSecurityMode(security);

// find instance id of the associated oscore object (if any)
ObjectLink oscoreObjLink = (ObjectLink) security.getResource(SEC_OSCORE_SECURITY_MODE).getValue();
int oscoreObjectInstanceId = oscoreObjLink.getObjectInstanceId();

if (!oscoreObjLink.isNullLink() && oscoreObjLink.getObjectId() != OSCORE) {
LOG.warn("The security object's 'OSCORE Security Mode' links to an incorrect object type.");
}

boolean useOscore = oscoreObjLink.getObjectId() == OSCORE;
if (useOscore) {
// get corresponding oscore object
LwM2mObjectInstance oscoreInstance = oscores.getInstance(oscoreObjectInstanceId);
if (oscoreInstance == null) {
LOG.error("Failed to retrieve OSCORE object linked from BS security object");
// find associated oscore instance (if any)
LwM2mObjectInstance oscoreInstance = null;
ObjectLink oscoreObjLink = (ObjectLink) security.getResource(SEC_OSCORE_SECURITY_MODE)
.getValue();
if (oscoreObjLink != null) {
int oscoreObjectInstanceId = oscoreObjLink.getObjectInstanceId();
if (!oscoreObjLink.isNullLink() && oscoreObjLink.getObjectId() != OSCORE) {
LOG.warn(
"The security object's 'OSCORE Security Mode' links to an incorrect object type.");
} else {
oscoreInstance = oscores.getInstance(oscoreObjectInstanceId);
if (oscoreInstance == null) {
// maybe we should use same log level for this one and the other just above
LOG.error("Failed to retrieve OSCORE object linked from BS security object");
}
}
}

if (oscoreInstance != null) {
info.useOscore = true;
info.masterSecret = getMasterSecret(oscoreInstance);
info.senderId = getSenderId(oscoreInstance);
Expand Down Expand Up @@ -137,21 +140,23 @@ public static ServersInfo getInfo(Map<Integer, LwM2mObjectEnabler> objectEnabler
info.serverId = (long) security.getResource(SEC_SERVER_ID).getValue();
info.secureMode = getSecurityMode(security);

// find instance id of the associated oscore object (if any)
// find associated oscore instance (if any)
LwM2mObjectInstance oscoreInstance = null;
ObjectLink oscoreObjLink = (ObjectLink) security.getResource(SEC_OSCORE_SECURITY_MODE).getValue();
int oscoreObjectInstanceId = oscoreObjLink.getObjectInstanceId();

if (!oscoreObjLink.isNullLink() && oscoreObjLink.getObjectId() != OSCORE) {
LOG.warn("The security object's 'OSCORE Security Mode' links to an incorrect object type.");
if (oscoreObjLink != null) {
int oscoreObjectInstanceId = oscoreObjLink.getObjectInstanceId();
if (!oscoreObjLink.isNullLink() && oscoreObjLink.getObjectId() != OSCORE) {
LOG.warn("The security object's 'OSCORE Security Mode' links to an incorrect object type.");
} else {
oscoreInstance = oscores.getInstance(oscoreObjectInstanceId);
if (oscoreInstance == null) {
// maybe we should use same log level for this one and the other just above
LOG.error("Failed to retrieve OSCORE object linked from DM security object");
}
}
}

boolean useOscore = oscoreObjLink.getObjectId() == OSCORE;
if (useOscore) {
// get corresponding oscore object
LwM2mObjectInstance oscoreInstance = oscores.getInstance(oscoreObjectInstanceId);
if (oscoreInstance == null) {
LOG.error("Failed to retrieve OSCORE object linked from DM security object");
}
if (oscoreInstance != null) {
info.useOscore = true;
info.masterSecret = getMasterSecret(oscoreInstance);
info.senderId = getSenderId(oscoreInstance);
Expand Down

0 comments on commit af75452

Please sign in to comment.