Skip to content

Commit 8158bb8

Browse files
committed
chore(binding-opcua) #1401 use uav: prefix for new opcua security schemes
1 parent 82b0299 commit 8158bb8

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

packages/binding-opcua/src/opcua-protocol-client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,23 +599,24 @@ export class OPCUAProtocolClient implements ProtocolClient {
599599
for (const securityScheme of securitySchemes) {
600600
let success = true;
601601
switch (securityScheme.scheme) {
602-
case "opcua-channel-security":
602+
case "uav:channel-security":
603603
success = this.setChannelSecurity(securityScheme as OPCUAChannelSecurityScheme);
604604
break;
605-
case "opcua-authentication":
605+
case "uav:authentication":
606606
success = this.setAuthentication(securityScheme as OPCUACAuthenticationScheme);
607607
break;
608608
case "combo": {
609609
const combo = securityScheme as AllOfSecurityScheme | OneOfSecurityScheme;
610-
if (combo.allOf) {
610+
if (combo.allOf !== undefined) {
611611
success = this.setSecurity(combo.allOf, credentials);
612-
} else if (combo.oneOf) {
612+
} else if (combo.oneOf !== undefined) {
613613
// pick the first one for now
614614
// later we might use credentials to select the most appropriate one
615615
success = this.setSecurity([combo.oneOf[0]], credentials);
616616
} else {
617617
success = false;
618618
}
619+
break;
619620
}
620621
default:
621622
// not for us , ignored

packages/binding-opcua/test/opcua-security-test.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// node-wot implementation of W3C WoT Servient
1717

1818
import { expect } from "chai";
19-
import path, { resolve } from "path";
19+
import path from "path";
2020
import {
2121
OPCUACUserNameAuthenticationScheme,
2222
OPCUACertificateAuthenticationScheme,
@@ -26,14 +26,7 @@ import {
2626
} from "@node-wot/core";
2727
import { InteractionOptions } from "wot-typescript-definitions";
2828

29-
import {
30-
IBasicSessionCallAsync,
31-
MessageSecurityMode,
32-
ObjectIds,
33-
OPCUAClient,
34-
OPCUAServer,
35-
SecurityPolicy,
36-
} from "node-opcua";
29+
import { MessageSecurityMode, OPCUAClient, OPCUAServer, SecurityPolicy } from "node-opcua";
3730
import { coercePrivateKeyPem, readCertificate, readCertificatePEM, readPrivateKey } from "node-opcua-crypto";
3831
import { OPCUAClientFactory, OPCUAProtocolClient } from "../src";
3932
import { startServer } from "./fixture/basic-opcua-server";
@@ -57,52 +50,52 @@ const thingDescription: WoT.ThingDescription = {
5750
},
5851
// OPCUAChannelSecurityScheme
5952
"c:sign-encrypt_basic256Sha256": <OPCUAChannelSecurityScheme>{
60-
scheme: "opcua-channel-security",
53+
scheme: "uav:channel-security",
6154
messageMode: "sign_encrypt",
6255
policy: "Basic256Sha256", // deprecated
6356
},
6457
// Aes128_Sha256_RsaOaep
6558
"c:sign-encrypt_aes128Sha256RsaOaep": <OPCUAChannelSecurityScheme>{
66-
scheme: "opcua-channel-security",
59+
scheme: "uav:channel-security",
6760
messageMode: "sign_encrypt",
6861
policy: "Aes128_Sha256_RsaOaep",
6962
},
7063

7164
"c:sign_basic256Sha256": <OPCUAChannelSecurityScheme>{
72-
scheme: "opcua-channel-security",
65+
scheme: "uav:channel-security",
7366
messageMode: "sign",
7467
policy: "Basic256Sha256",
7568
},
7669
"c:invalid-sign": <OPCUAChannelSecurityScheme>{
77-
scheme: "opcua-channel-security",
70+
scheme: "uav:channel-security",
7871
messageMode: "sign",
7972
policy: "Basic192Rsa15", // Basic192Rsa15 valid policy but unsupported by server
8073
},
8174
"c:no_security": <OPCUAChannelSecurityScheme>{
82-
scheme: "opcua-channel-security",
75+
scheme: "uav:channel-security",
8376
messageMode: "none",
8477
},
8578
//
8679
"a:username-password": <OPCUACUserNameAuthenticationScheme>{
87-
scheme: "opcua-authentication",
80+
scheme: "uav:authentication",
8881
tokenType: "username",
8982
userName: "joe",
9083
password: "password_for_joe",
9184
},
9285
"a:username-invalid-password": <OPCUACUserNameAuthenticationScheme>{
93-
scheme: "opcua-authentication",
86+
scheme: "uav:authentication",
9487
tokenType: "username",
9588
userName: "joe",
9689
password: "**INVALID**password_for_joe",
9790
},
9891
"a:x509-certificate": <OPCUACertificateAuthenticationScheme>{
99-
scheme: "opcua-authentication",
92+
scheme: "uav:authentication",
10093
tokenType: "certificate",
10194
certificate: "....",
10295
privateKey: "....",
10396
},
10497
"a:x509-certificate-no-private-key": <OPCUACertificateAuthenticationScheme>{
105-
scheme: "opcua-authentication",
98+
scheme: "uav:authentication",
10699
tokenType: "certificate",
107100
certificate: "....",
108101
privateKey: undefined,
@@ -297,12 +290,12 @@ describe("verify test securityDefinitions", () => {
297290
for (const subKey of comboDef.allOf) {
298291
expect(definitions).to.have.property(subKey);
299292
}
300-
} else if (def.scheme === "opcua-channel-security") {
293+
} else if (def.scheme === "uav:channel-security") {
301294
const channelDef = def as OPCUAChannelSecurityScheme;
302295
expect(channelDef).to.have.property("messageMode");
303296
expect(["none", "sign", "sign_encrypt"]).to.include(channelDef.messageMode);
304297
// policy is optional
305-
} else if (def.scheme === "opcua-authentication") {
298+
} else if (def.scheme === "uav:authentication") {
306299
const authDef = def as OPCUACertificateAuthenticationScheme | OPCUACUserNameAuthenticationScheme;
307300
expect(authDef).to.have.property("tokenType");
308301
if (authDef.tokenType === "username") {

0 commit comments

Comments
 (0)