Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OSCORE Support to leshan-bsserver-demo #1254

Merged
merged 4 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,95 @@
class="examplePatch"
></v-text-field>
<security-input
:mode.sync="server.mode"
v-if="server"
:mode.sync="server.security.mode"
@update:mode="$emit('input', server)"
:details.sync="server.details"
:details.sync="server.security.details"
@update:details="$emit('input', server)"
:defaultrpk="defaultrpk"
:defaultx509="defaultx509"
/>
<!-- OSCORE Object -->
<v-switch
v-model="useOSCORE"
@change="useOSCOREChanged($event)"
label="Using OSCORE (Experimental - for now can not be used with DTLS)"
></v-switch>
<oscore-input
v-if="useOSCORE"
v-model="server.oscore"
@input="$emit('input', server)"
>
</oscore-input>
</div>
</template>
<script>
import securityInput from "./SecurityInput.vue";
import OscoreInput from "@leshan-server-core-demo/components/security/OscoreInput.vue";

export default {
components: { securityInput },
components: { securityInput, OscoreInput },
props: {
value: Object,
defaultNoSecValue: String,
defaultSecureValue: String,
defaultrpk: {
default: function() {
default: function () {
return {};
},
type: Object,
},
defaultx509: {
default: function() {
default: function () {
return {};
},
type: Object,
},
},
data() {
return {
server: { mode: "no_sec" }, // internal server Config
useOSCORE: false, // true if OSCORE is used
server: null, // internal server Config
};
},
beforeMount() {
this.initValue(this.value);
},
watch: {
value(v) {
if (!v) {
this.server = { mode: "no_sec" };
this.initValue(v);
},
},
methods: {
initValue(initialValue) {
if (!initialValue) {
this.server = { security: { mode: "no_sec" } };
this.useOSCORE = false;
} else {
this.server = v;
this.server = initialValue;
this.useOSCORE = initialValue.oscore ? true : false;
}
},
useOSCOREChanged(useOSCORE) {
if (useOSCORE) {
this.server.oscore = {};
} else {
this.server.oscore = undefined;
}
this.$emit("input", this.server);
},
/*exclusifTlsOrOSCORE() {
if (this.useDTLS) {
this.$emit("update:tls", { mode: "psk", details: {} });
this.$emit("update:oscore", undefined);
} else if (this.useOSCORE) {
this.$emit("update:tls", undefined);
this.$emit("update:oscore", {});
} else {
this.$emit("update:tls", undefined);
this.$emit("update:oscore", undefined);
}
},*/
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
<v-card-text class="pb-0">
<p>
This information will be used to add a
<strong>LWM2M Bootstrap Server</strong> to your LWM2M Client during the bootstrap
Session by writing 1 instance for object <code>/0</code>.
</p>
<p>
By default no LWM2M Bootstrap server is added.
<strong>LWM2M Bootstrap Server</strong> to your LWM2M Client during the
bootstrap Session by writing 1 instance for object <code>/0</code>.
</p>
<p>By default no LWM2M Bootstrap server is added.</p>
</v-card-text>
<v-form
ref="form"
Expand Down Expand Up @@ -60,14 +58,14 @@ export default {
data() {
return {
addServer: false,
internalServer: { mode: "no_sec" }, // internal Bootstrap server Config
internalServer: { security: { mode: "no_sec" } }, // internal Bootstrap server Config
};
},
watch: {
value(v) {
if (!v) {
this.addServer = false;
this.internalServer = { mode: "no_sec" };
this.internalServer = { security: { mode: "no_sec" } };
} else {
this.addServer = true;
this.internalServer = v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@
>
Previous
</v-btn>
<v-btn text @click="close">
Cancel
</v-btn>
<v-btn text @click="close"> Cancel </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
Expand Down Expand Up @@ -193,9 +191,9 @@ export default {
this.config = {
endpoint: null,
security: null,
dm: { mode: "no_sec" },
dm: { security: { mode: "no_sec" } },
bs: null,
toDelete: ["/0", "/1"],
toDelete: ["/0", "/1", "/21"],
autoIdForSecurityObject: false,
};
this.currentStep = 1;
Expand All @@ -217,7 +215,7 @@ export default {
if (res.dm) {
if (!res.dm.url) {
res.dm.url =
res.dm.mode == "no_sec"
res.dm.security.mode == "no_sec"
? this.defval.dm.url.nosec
: this.defval.dm.url.sec;
}
Expand All @@ -226,24 +224,24 @@ export default {
if (res.bs) {
if (!res.bs.url) {
res.bs.url =
res.bs.mode == "no_sec"
res.bs.security.mode == "no_sec"
? this.defval.bs.url.nosec
: this.defval.bs.url.sec;
}

// apply default rpk value for bs server
if (res.bs.mode == "rpk") {
if (res.bs.security.mode == "rpk") {
for (const key in this.defaultrpk) {
if (!res.bs.details[key]) {
res.bs.details[key] = this.defaultrpk[key];
if (!res.bs.security.details[key]) {
res.bs.security.details[key] = this.defaultrpk[key];
}
}
}
// apply default x509 value for bs server
if (res.bs.mode == "x509") {
if (res.bs.security.mode == "x509") {
for (const key in this.defaultx509) {
if (!res.bs.details[key]) {
res.bs.details[key] = this.defaultx509[key];
if (!res.bs.security.details[key]) {
res.bs.security.details[key] = this.defaultx509[key];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
existing configuration on the <strong>LWM2M client</strong>.
</p>
<p>
By default, objects <code>/0</code> and <code>/1</code> are deleted,
By default, objects <code>/0</code>, <code>/1</code> and <code>/21</code> are deleted,
then you will be able to define LWM2M Server and LWM2M Bootstrap Server
to add.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ export default {
data() {
return {
addServer: true,
internalServer: { mode: "no_sec" }, // internal server Config
internalServer: { security: { mode: "no_sec" } }, // internal server Config
};
},
watch: {
value(v) {
if (!v) {
this.addServer = false;
this.internalServer = { mode: "no_sec" };
this.internalServer = { security: { mode: "no_sec" } };
} else {
this.addServer = true;
this.internalServer = v;
Expand Down
32 changes: 29 additions & 3 deletions leshan-bsserver-demo/webapp/src/js/bsconfigutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand Down
Loading