Skip to content

Commit 72f1da1

Browse files
committed
feat(binding-opcua): move OPCUA security schema to binding-opcua #1401
1 parent 250be6e commit 72f1da1

File tree

5 files changed

+106
-92
lines changed

5 files changed

+106
-92
lines changed

packages/binding-opcua/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
export * from "./factory";
1717
export * from "./codec";
1818
export * from "./opcua-protocol-client";
19+
export * from "./security_scheme";
1920
// no protocol_client here => get access from factor

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
Form,
2727
SecurityScheme,
2828
createLoggers,
29-
OPCUACAuthenticationScheme,
30-
OPCUAChannelSecurityScheme,
3129
AllOfSecurityScheme,
3230
OneOfSecurityScheme,
3331
} from "@node-wot/core";
@@ -64,12 +62,13 @@ import { AttributeIds, BrowseDirection, makeResultMask } from "node-opcua-data-m
6462
import { makeBrowsePath } from "node-opcua-service-translate-browse-path";
6563
import { StatusCodes } from "node-opcua-status-code";
6664
import { coercePrivateKeyPem, convertPEMtoDER, readPrivateKey } from "node-opcua-crypto";
67-
68-
import { schemaDataValue } from "./codec";
6965
import { opcuaJsonEncodeVariant } from "node-opcua-json";
7066
import { Argument, BrowseDescription, BrowseResult, MessageSecurityMode, UserTokenType } from "node-opcua-types";
7167
import { isGoodish2, OPCUACertificateManager, ReferenceTypeIds } from "node-opcua";
7268

69+
import { schemaDataValue } from "./codec";
70+
import { OPCUACAuthenticationScheme, OPCUAChannelSecurityScheme } from "./security_scheme";
71+
7372
const { debug } = createLoggers("binding-opcua", "opcua-protocol-client");
7473

7574
const env = envPath("binding-opcua", { suffix: "node-wot" });
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License v. 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
10+
* Document License (2015-05-13) which is available at
11+
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
12+
*
13+
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
14+
********************************************************************************/
15+
16+
// global W3C WoT Scripting API definitions
17+
import * as TDT from "wot-thing-description-types";
18+
import { SecurityScheme } from "@node-wot/core";
19+
export interface OPCUASecuritySchemeBase extends SecurityScheme, TDT.AdditionalSecurityScheme {
20+
scheme: "uav:channel-security" | "uav:authentication";
21+
}
22+
23+
export type ValidOPCUASecurityPolicy =
24+
| "Basic128"
25+
| "http://opcfoundation.org/UA/SecurityPolicy#Basic128"
26+
| "Basic192"
27+
| "http://opcfoundation.org/UA/SecurityPolicy#Basic192"
28+
| "Basic192Rsa15"
29+
| "http://opcfoundation.org/UA/SecurityPolicy#Basic192Rsa15"
30+
| "Basic256Rsa15"
31+
| "http://opcfoundation.org/UA/SecurityPolicy#Basic256Rsa15"
32+
| "Basic256Sha256"
33+
| "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"
34+
| "Aes128_Sha256_RsaOaep"
35+
| "http://opcfoundation.org/UASecurityPolicy#Aes128_Sha256_RsaOaep"
36+
| "Aes256_Sha256_RsaPss"
37+
| "http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss"
38+
| "PubSub_Aes128_CTR"
39+
| "http://opcfoundation.org/UA/SecurityPolicy#PubSub_Aes128_CTR"
40+
| "PubSub_Aes256_CTR"
41+
| "http://opcfoundation.org/UA/SecurityPolicy#PubSub_Aes256_CTR";
42+
// deprecated | "Basic128Rsa15" | "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15"
43+
// deprecated | "Basic256" | "http://opcfoundation.org/UA/SecurityPolicy#Basic256"
44+
45+
/**
46+
*
47+
*/
48+
export interface OPCUASecureSecurityScheme extends OPCUASecuritySchemeBase {
49+
scheme: "uav:channel-security";
50+
policy: ValidOPCUASecurityPolicy;
51+
messageMode: "sign" | "sign_encrypt";
52+
}
53+
export interface OPCUAUnsecureChannelScheme extends OPCUASecuritySchemeBase {
54+
scheme: "uav:channel-security";
55+
policy: never;
56+
messageMode: "none";
57+
}
58+
59+
export type OPCUAChannelSecurityScheme = OPCUASecureSecurityScheme | OPCUAUnsecureChannelScheme;
60+
export interface OPCUACAuthenticationSchemeBase extends OPCUASecuritySchemeBase {
61+
scheme: "uav:authentication";
62+
tokenType: "username" | "certificate" | "anonymous";
63+
}
64+
65+
export interface OPCUACUserNameAuthenticationScheme extends OPCUACAuthenticationSchemeBase {
66+
scheme: "uav:authentication";
67+
tokenType: "username";
68+
userName: string;
69+
password?: string;
70+
}
71+
export interface OPCUACertificateAuthenticationScheme extends OPCUACAuthenticationSchemeBase {
72+
scheme: "uav:authentication";
73+
tokenType: "certificate";
74+
// the certificate in PEM format
75+
// -----BEGIN CERTIFICATE----
76+
// ...
77+
// -----END CERTIFICATE-----
78+
certificate: string;
79+
// the private key in PEM format that is associated with the certificate
80+
// For instance
81+
// -----BEGIN PRIVATE KEY-----
82+
// ...
83+
// -----END PRIVATE KEY-----
84+
privateKey?: string;
85+
}
86+
export interface OPCUAAnonymousAuthenticationScheme extends OPCUACAuthenticationSchemeBase {
87+
scheme: "uav:authentication";
88+
tokenType: "anonymous";
89+
}
90+
export type OPCUACAuthenticationScheme =
91+
| OPCUAAnonymousAuthenticationScheme
92+
| OPCUACertificateAuthenticationScheme
93+
| OPCUACUserNameAuthenticationScheme;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717

1818
import { expect } from "chai";
1919
import path from "path";
20+
import { Servient, createLoggers } from "@node-wot/core";
21+
import { InteractionOptions } from "wot-typescript-definitions";
22+
23+
import { MessageSecurityMode, OPCUAClient, OPCUAServer, SecurityPolicy } from "node-opcua";
24+
import { coercePrivateKeyPem, readCertificate, readCertificatePEM, readPrivateKey } from "node-opcua-crypto";
2025
import {
26+
OPCUAClientFactory,
27+
OPCUAProtocolClient,
2128
OPCUACUserNameAuthenticationScheme,
2229
OPCUACertificateAuthenticationScheme,
2330
OPCUAChannelSecurityScheme,
24-
Servient,
25-
createLoggers,
26-
} from "@node-wot/core";
27-
import { InteractionOptions } from "wot-typescript-definitions";
31+
} from "../src";
2832

29-
import { MessageSecurityMode, OPCUAClient, OPCUAServer, SecurityPolicy } from "node-opcua";
30-
import { coercePrivateKeyPem, readCertificate, readCertificatePEM, readPrivateKey } from "node-opcua-crypto";
31-
import { OPCUAClientFactory, OPCUAProtocolClient } from "../src";
3233
import { startServer } from "./fixture/basic-opcua-server";
3334
const endpoint = "opc.tcp://localhost:7890";
3435

@@ -428,7 +429,6 @@ describe("Testing OPCUA Security Combination", () => {
428429

429430
const expected = inferExpectedSecurityMode(security);
430431
expect(whoAmI).to.eql(expected);
431-
// infer expected result from security string
432432
} finally {
433433
await servient.shutdown();
434434
}

packages/core/src/thing-description.ts

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ export type SecurityType =
144144
| OAuth2SecurityScheme
145145
| PSKSecurityScheme
146146
| AllOfSecurityScheme
147-
| OneOfSecurityScheme
148-
| OPCUAChannelSecurityScheme
149-
| OPCUACUserNameAuthenticationScheme
150-
| OPCUACertificateAuthenticationScheme;
147+
| OneOfSecurityScheme;
151148

152149
export interface SecurityScheme {
153150
scheme: string;
@@ -196,82 +193,6 @@ export interface AllOfSecurityScheme extends SecurityScheme {
196193
}
197194
export type ComboSecurityScheme = AllOfSecurityScheme | OneOfSecurityScheme;
198195

199-
export interface OPCUASecuritySchemeBase extends SecurityScheme, TDT.AdditionalSecurityScheme {
200-
scheme: "uav:channel-security" | "uav:authentication";
201-
}
202-
203-
export type ValidOPCUASecurityPolicy =
204-
| "Basic128"
205-
| "http://opcfoundation.org/UA/SecurityPolicy#Basic128"
206-
| "Basic192"
207-
| "http://opcfoundation.org/UA/SecurityPolicy#Basic192"
208-
| "Basic192Rsa15"
209-
| "http://opcfoundation.org/UA/SecurityPolicy#Basic192Rsa15"
210-
| "Basic256Rsa15"
211-
| "http://opcfoundation.org/UA/SecurityPolicy#Basic256Rsa15"
212-
| "Basic256Sha256"
213-
| "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"
214-
| "Aes128_Sha256_RsaOaep"
215-
| "http://opcfoundation.org/UASecurityPolicy#Aes128_Sha256_RsaOaep"
216-
| "Aes256_Sha256_RsaPss"
217-
| "http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss"
218-
| "PubSub_Aes128_CTR"
219-
| "http://opcfoundation.org/UA/SecurityPolicy#PubSub_Aes128_CTR"
220-
| "PubSub_Aes256_CTR"
221-
| "http://opcfoundation.org/UA/SecurityPolicy#PubSub_Aes256_CTR";
222-
// deprecated | "Basic128Rsa15" | "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15"
223-
// deprecated | "Basic256" | "http://opcfoundation.org/UA/SecurityPolicy#Basic256"
224-
225-
/**
226-
*
227-
*/
228-
export interface OPCUASecureSecurityScheme extends OPCUASecuritySchemeBase {
229-
scheme: "uav:channel-security";
230-
policy: ValidOPCUASecurityPolicy;
231-
messageMode: "sign" | "sign_encrypt";
232-
}
233-
export interface OPCUAUnsecureChannelScheme extends OPCUASecuritySchemeBase {
234-
scheme: "uav:channel-security";
235-
policy: never;
236-
messageMode: "none";
237-
}
238-
239-
export type OPCUAChannelSecurityScheme = OPCUASecureSecurityScheme | OPCUAUnsecureChannelScheme;
240-
export interface OPCUACAuthenticationSchemeBase extends OPCUASecuritySchemeBase {
241-
scheme: "uav:authentication";
242-
tokenType: "username" | "certificate" | "anonymous";
243-
}
244-
245-
export interface OPCUACUserNameAuthenticationScheme extends OPCUACAuthenticationSchemeBase {
246-
scheme: "uav:authentication";
247-
tokenType: "username";
248-
userName: string;
249-
password?: string;
250-
}
251-
export interface OPCUACertificateAuthenticationScheme extends OPCUACAuthenticationSchemeBase {
252-
scheme: "uav:authentication";
253-
tokenType: "certificate";
254-
// the certificate in PEM format
255-
// -----BEGIN CERTIFICATE----
256-
// ...
257-
// -----END CERTIFICATE-----
258-
certificate: string;
259-
// the private key in PEM format that is associated with the certificate
260-
// For instance
261-
// -----BEGIN PRIVATE KEY-----
262-
// ...
263-
// -----END PRIVATE KEY-----
264-
privateKey?: string;
265-
}
266-
export interface OPCUAAnonymousAuthenticationScheme extends OPCUACAuthenticationSchemeBase {
267-
scheme: "uav:authentication";
268-
tokenType: "anonymous";
269-
}
270-
export type OPCUACAuthenticationScheme =
271-
| OPCUAAnonymousAuthenticationScheme
272-
| OPCUACertificateAuthenticationScheme
273-
| OPCUACUserNameAuthenticationScheme;
274-
275196
/** Implements the Thing Property description */
276197
export abstract class ThingProperty extends BaseSchema {
277198
// writable: boolean;

0 commit comments

Comments
 (0)