From 7896a5fd07ee02032dc8276d55261d705fe40ac8 Mon Sep 17 00:00:00 2001
From: Simon Bernard
Date: Thu, 12 May 2022 17:51:36 +0200
Subject: [PATCH] #1203: Add OSCORE support to leshan-bsserver-demo
---
.../src/components/bsconfig/ServerInput.vue | 53 +++++++++++++++++--
.../components/wizard/ClientConfigDialog.vue | 2 +-
.../src/components/wizard/DeleteStep.vue | 2 +-
.../webapp/src/js/bsconfigutil.js | 32 +++++++++--
.../webapp/src/views/Bootstrap.vue | 46 +++++++++++++++-
.../components/security/SecurityInfoChip.vue | 16 ++++--
.../webapp/src/js/securityutils.js | 12 ++++-
7 files changed, 149 insertions(+), 14 deletions(-)
diff --git a/leshan-bsserver-demo/webapp/src/components/bsconfig/ServerInput.vue b/leshan-bsserver-demo/webapp/src/components/bsconfig/ServerInput.vue
index 736abe1c9c..05e2d7e4b6 100644
--- a/leshan-bsserver-demo/webapp/src/components/bsconfig/ServerInput.vue
+++ b/leshan-bsserver-demo/webapp/src/components/bsconfig/ServerInput.vue
@@ -27,6 +27,7 @@
class="examplePatch"
>
+
+
+
+
diff --git a/leshan-bsserver-demo/webapp/src/components/wizard/ClientConfigDialog.vue b/leshan-bsserver-demo/webapp/src/components/wizard/ClientConfigDialog.vue
index c924a95a51..1d10ac32ab 100644
--- a/leshan-bsserver-demo/webapp/src/components/wizard/ClientConfigDialog.vue
+++ b/leshan-bsserver-demo/webapp/src/components/wizard/ClientConfigDialog.vue
@@ -193,7 +193,7 @@ export default {
security: null,
dm: { security: { mode: "no_sec" } },
bs: null,
- toDelete: ["/0", "/1"],
+ toDelete: ["/0", "/1", "/21"],
autoIdForSecurityObject: false,
};
this.currentStep = 1;
diff --git a/leshan-bsserver-demo/webapp/src/components/wizard/DeleteStep.vue b/leshan-bsserver-demo/webapp/src/components/wizard/DeleteStep.vue
index edf7760192..d939996d5a 100644
--- a/leshan-bsserver-demo/webapp/src/components/wizard/DeleteStep.vue
+++ b/leshan-bsserver-demo/webapp/src/components/wizard/DeleteStep.vue
@@ -18,7 +18,7 @@
existing configuration on the LWM2M client.
- By default, objects /0
and /1
are deleted,
+ By default, objects /0
, /1
and /21
are deleted,
then you will be able to define LWM2M Server and LWM2M Bootstrap Server
to add.
diff --git a/leshan-bsserver-demo/webapp/src/js/bsconfigutil.js b/leshan-bsserver-demo/webapp/src/js/bsconfigutil.js
index 1236ec5f52..fdcaa0b769 100644
--- a/leshan-bsserver-demo/webapp/src/js/bsconfigutil.js
+++ b/leshan-bsserver-demo/webapp/src/js/bsconfigutil.js
@@ -18,16 +18,33 @@ var configFromRestToUI = function (config) {
for (var i in config.security) {
var security = config.security[i];
if (security.bootstrapServer) {
- newConfig.bs.push({ security: security });
+ let bs = { security: security };
+
+ // add oscore object (if any) to bs
+ let oscoreObjectInstanceId = security.oscoreSecurityMode;
+ let oscore = config.oscore[oscoreObjectInstanceId];
+ if (oscore) {
+ bs.oscore = oscore;
+ }
+
+ newConfig.bs.push(bs);
} else {
// search for DM information;
+ var server;
for (var j in config.servers) {
- var server = config.servers[j];
+ server = config.servers[j];
if (server.shortId === security.serverId) {
newConfig.dm.push(server);
server.security = security;
}
}
+
+ // add oscore object (if any) to dm
+ let oscoreObjectInstanceId = security.oscoreSecurityMode;
+ let oscore = config.oscore[oscoreObjectInstanceId];
+ if (oscore) {
+ server.oscore = oscore;
+ }
}
}
newConfig.toDelete = config.toDelete;
@@ -49,10 +66,14 @@ var configFromUIToRest = function (c) {
// do a deep copy
// we should maybe rather use cloneDeep from lodashz
let config = JSON.parse(JSON.stringify(c));
- var newConfig = { servers: {}, security: {} };
+ var newConfig = { servers: {}, security: {}, oscore: {} };
for (var i = 0; i < config.bs.length; i++) {
var bs = config.bs[i];
newConfig.security[i] = bs.security;
+ if (bs.oscore) {
+ newConfig.security[i].oscoreSecurityMode = i;
+ newConfig.oscore[i] = bs.oscore;
+ }
}
if (i == 0) {
// To be sure that we are not using instance ID 0 for a DM server.
@@ -63,6 +84,11 @@ var configFromUIToRest = function (c) {
var dm = config.dm[j];
newConfig.security[i + j] = dm.security;
delete dm.security;
+ if (dm.oscore) {
+ newConfig.security[i + j].oscoreSecurityMode = i + j;
+ newConfig.oscore[i + j] = dm.oscore;
+ delete dm.oscore;
+ }
newConfig.servers[j] = dm;
}
newConfig.toDelete = config.toDelete;
diff --git a/leshan-bsserver-demo/webapp/src/views/Bootstrap.vue b/leshan-bsserver-demo/webapp/src/views/Bootstrap.vue
index f00745a165..e51c146278 100644
--- a/leshan-bsserver-demo/webapp/src/views/Bootstrap.vue
+++ b/leshan-bsserver-demo/webapp/src/views/Bootstrap.vue
@@ -88,6 +88,15 @@
{{ server.security.securityMode.toLowerCase() }}
+
+ with
+
+
+ {{ oscoreIcon() }}
+
+ OSCORE
+
+
@@ -102,6 +111,15 @@
{{ server.security.securityMode.toLowerCase() }}
+
+ with
+
+
+ {{ oscoreIcon() }}
+
+ OSCORE
+
+
@@ -119,7 +137,10 @@ import { configsFromRestToUI, configFromUIToRest } from "../js/bsconfigutil.js";
import { fromHex, fromAscii } from "@leshan-server-core-demo/js/byteutils.js";
import SecurityInfoChip from "@leshan-server-core-demo/components/security/SecurityInfoChip.vue";
import ClientConfigDialog from "../components/wizard/ClientConfigDialog.vue";
-import { getModeIcon } from "@leshan-server-core-demo/js/securityutils.js";
+import {
+ getModeIcon,
+ getOscoreIcon,
+} from "@leshan-server-core-demo/js/securityutils.js";
export default {
components: { ClientConfigDialog, SecurityInfoChip },
@@ -183,6 +204,9 @@ export default {
modeIcon(securitymode) {
return getModeIcon(securitymode);
},
+ oscoreIcon() {
+ return getOscoreIcon();
+ },
formatData(c) {
let s = {};
@@ -205,6 +229,12 @@ export default {
s.certificateUsage = c.security.details.certificate_usage;
break;
}
+ if (c.oscore) {
+ s.oscore = {};
+ s.oscore.oscoreSenderId = fromHex(c.oscore.sid);
+ s.oscore.oscoreMasterSecret = fromHex(c.oscore.msec);
+ s.oscore.oscoreRecipientId = fromHex(c.oscore.rid);
+ }
return s;
},
@@ -257,6 +287,13 @@ export default {
},
},
];
+ if (dmServer.oscore) {
+ c.dm[0].oscore = {
+ oscoreSenderId: dmServer.oscore.oscoreSenderId,
+ oscoreMasterSecret: dmServer.oscore.oscoreMasterSecret,
+ oscoreRecipientId: dmServer.oscore.oscoreRecipientId,
+ };
+ }
}
if (config.bs) {
let bsServer = this.formatData(config.bs);
@@ -278,6 +315,13 @@ export default {
},
},
];
+ if (bsServer.oscore) {
+ c.bs[0].oscore = {
+ oscoreSenderId: bsServer.oscore.oscoreSenderId,
+ oscoreMasterSecret: bsServer.oscore.oscoreMasterSecret,
+ oscoreRecipientId: bsServer.oscore.oscoreRecipientId,
+ };
+ }
}
if (config.security) {
diff --git a/leshan-server-core-demo/webapp/src/components/security/SecurityInfoChip.vue b/leshan-server-core-demo/webapp/src/components/security/SecurityInfoChip.vue
index 2e80875e3a..6995b984f3 100644
--- a/leshan-server-core-demo/webapp/src/components/security/SecurityInfoChip.vue
+++ b/leshan-server-core-demo/webapp/src/components/security/SecurityInfoChip.vue
@@ -19,19 +19,23 @@
{{ securityInfo.tls.mode }}
- {{$icons.mdiLockOutline}}
+ {{ oscoreIcon }}
oscore
- {{ $icons.mdiLockOpenRemove }}
+ {{ noSecIcon }}
Nothing
diff --git a/leshan-server-core-demo/webapp/src/js/securityutils.js b/leshan-server-core-demo/webapp/src/js/securityutils.js
index cbef4adf09..91fd564d5c 100644
--- a/leshan-server-core-demo/webapp/src/js/securityutils.js
+++ b/leshan-server-core-demo/webapp/src/js/securityutils.js
@@ -13,6 +13,8 @@
import {
mdiCertificate,
mdiLock,
+ mdiLockOpenRemove,
+ mdiLockOutline,
mdiKeyChange,
mdiHelpRhombusOutline,
} from "@mdi/js";
@@ -37,4 +39,12 @@ function getModeIcon(mode) {
}
}
-export { getMode, getModeIcon };
+function getOscoreIcon() {
+ return mdiLockOutline;
+}
+
+function getNoSecIcon() {
+ return mdiLockOpenRemove;
+}
+
+export { getMode, getModeIcon, getOscoreIcon, getNoSecIcon };