From a81118209e3b1fc2dcf73f263affa16f59f4cf3f Mon Sep 17 00:00:00 2001 From: rikard-sics Date: Thu, 7 Jan 2021 18:10:08 +0100 Subject: [PATCH] Further updates to code for finding oscore instance from security object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rikard Höglund --- .../client/servers/ServersInfoExtractor.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/leshan-client-core/src/main/java/org/eclipse/leshan/client/servers/ServersInfoExtractor.java b/leshan-client-core/src/main/java/org/eclipse/leshan/client/servers/ServersInfoExtractor.java index cb7a4e27d2..a449c60dee 100644 --- a/leshan-client-core/src/main/java/org/eclipse/leshan/client/servers/ServersInfoExtractor.java +++ b/leshan-client-core/src/main/java/org/eclipse/leshan/client/servers/ServersInfoExtractor.java @@ -96,16 +96,22 @@ public static ServersInfo getInfo(Map objectEnabler 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) { + if (oscoreObjLink != null && !oscoreObjLink.isNullLink()) { + if (oscoreObjLink.getObjectId() != OSCORE) { LOG.warn( - "The security object's 'OSCORE Security Mode' links to an incorrect object type."); + "Invalid Security info for bootstrap server : 'OSCORE Security Mode' does not link to OSCORE Object but to {} object.", + oscoreObjLink.getObjectId()); } 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 (oscores == null) { + LOG.warn( + "Invalid Security info for bootstrap server : OSCORE object enabler is not available."); + } else { + oscoreInstance = oscores.getInstance(oscoreObjLink.getObjectInstanceId()); + if (oscoreInstance == null) { + LOG.warn( + "Invalid Security info for bootstrap server : OSCORE instance {} does not exist.", + oscoreObjLink.getObjectInstanceId()); + } } } } @@ -143,15 +149,22 @@ public static ServersInfo getInfo(Map objectEnabler // 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."); + if (oscoreObjLink != null && !oscoreObjLink.isNullLink()) { + if (oscoreObjLink.getObjectId() != OSCORE) { + LOG.warn( + "Invalid Security info for LWM2M server : 'OSCORE Security Mode' does not link to OSCORE Object but to {} object.", + oscoreObjLink.getObjectId()); } 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"); + if (oscores == null) { + LOG.warn( + "Invalid Security info for LWM2M server : OSCORE object enabler is not available."); + } else { + oscoreInstance = oscores.getInstance(oscoreObjLink.getObjectInstanceId()); + if (oscoreInstance == null) { + LOG.warn( + "Invalid Security info for LWM2M server : OSCORE instance {} does not exist.", + oscoreObjLink.getObjectInstanceId()); + } } } }