node-opcua-role-set-common 2.174.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +142 -0
  3. package/dist/archive.d.ts +71 -0
  4. package/dist/archive.js +189 -0
  5. package/dist/archive.js.map +1 -0
  6. package/dist/binary_persistence.d.ts +31 -0
  7. package/dist/binary_persistence.js +119 -0
  8. package/dist/binary_persistence.js.map +1 -0
  9. package/dist/identity_mapping_store.d.ts +36 -0
  10. package/dist/identity_mapping_store.js +3 -0
  11. package/dist/identity_mapping_store.js.map +1 -0
  12. package/dist/in_memory_store.d.ts +20 -0
  13. package/dist/in_memory_store.js +129 -0
  14. package/dist/in_memory_store.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.js +41 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/role_restriction_store.d.ts +93 -0
  19. package/dist/role_restriction_store.js +205 -0
  20. package/dist/role_restriction_store.js.map +1 -0
  21. package/dist/user_management_store.d.ts +83 -0
  22. package/dist/user_management_store.js +208 -0
  23. package/dist/user_management_store.js.map +1 -0
  24. package/dist/well_known_role_ids.d.ts +36 -0
  25. package/dist/well_known_role_ids.js +44 -0
  26. package/dist/well_known_role_ids.js.map +1 -0
  27. package/dist/x509_subject.d.ts +44 -0
  28. package/dist/x509_subject.js +78 -0
  29. package/dist/x509_subject.js.map +1 -0
  30. package/package.json +51 -0
  31. package/source/archive.ts +231 -0
  32. package/source/binary_persistence.ts +119 -0
  33. package/source/identity_mapping_store.ts +42 -0
  34. package/source/in_memory_store.ts +150 -0
  35. package/source/index.ts +55 -0
  36. package/source/role_restriction_store.ts +270 -0
  37. package/source/user_management_store.ts +288 -0
  38. package/source/well_known_role_ids.ts +42 -0
  39. package/source/x509_subject.ts +84 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-role-set-common
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InMemoryIdentityMappingStore = void 0;
7
+ const node_opcua_crypto_1 = require("node-opcua-crypto");
8
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
9
+ const node_opcua_types_1 = require("node-opcua-types");
10
+ const x509_subject_js_1 = require("./x509_subject.js");
11
+ /**
12
+ * In-memory implementation of {@link IIdentityMappingStore}.
13
+ *
14
+ * Uses a `Map<string, IdentityMappingRuleType[]>` keyed by
15
+ * the role NodeId string representation.
16
+ */
17
+ class InMemoryIdentityMappingStore {
18
+ _map = new Map();
19
+ addIdentity(roleId, rule) {
20
+ const key = roleId.toString();
21
+ let arr = this._map.get(key);
22
+ if (!arr) {
23
+ arr = [];
24
+ this._map.set(key, arr);
25
+ }
26
+ // Idempotent: skip if already present
27
+ if (arr.some((r) => r.criteriaType === rule.criteriaType && r.criteria === rule.criteria)) {
28
+ return false;
29
+ }
30
+ arr.push(new node_opcua_types_1.IdentityMappingRuleType({
31
+ criteriaType: rule.criteriaType,
32
+ criteria: rule.criteria
33
+ }));
34
+ return true;
35
+ }
36
+ removeIdentity(roleId, rule) {
37
+ const key = roleId.toString();
38
+ const arr = this._map.get(key);
39
+ if (!arr) {
40
+ return false;
41
+ }
42
+ const idx = arr.findIndex((r) => r.criteriaType === rule.criteriaType && r.criteria === rule.criteria);
43
+ if (idx < 0) {
44
+ return false;
45
+ }
46
+ arr.splice(idx, 1);
47
+ if (arr.length === 0) {
48
+ this._map.delete(key);
49
+ }
50
+ return true;
51
+ }
52
+ getIdentitiesForRole(roleId) {
53
+ const arr = this._map.get(roleId.toString());
54
+ if (!arr) {
55
+ return [];
56
+ }
57
+ return arr.map((r) => new node_opcua_types_1.IdentityMappingRuleType({
58
+ criteriaType: r.criteriaType,
59
+ criteria: r.criteria
60
+ }));
61
+ }
62
+ getRoleIds() {
63
+ const result = [];
64
+ for (const key of this._map.keys()) {
65
+ result.push((0, node_opcua_nodeid_1.resolveNodeId)(key));
66
+ }
67
+ return result;
68
+ }
69
+ resolveRoles(token) {
70
+ const matched = [];
71
+ for (const [key, rules] of this._map) {
72
+ for (const rule of rules) {
73
+ if (matchesRule(rule, token)) {
74
+ const roleId = (0, node_opcua_nodeid_1.resolveNodeId)(key);
75
+ if (!matched.find((r) => (0, node_opcua_nodeid_1.sameNodeId)(r, roleId))) {
76
+ matched.push(roleId);
77
+ }
78
+ break; // one match per role is enough
79
+ }
80
+ }
81
+ }
82
+ return matched;
83
+ }
84
+ }
85
+ exports.InMemoryIdentityMappingStore = InMemoryIdentityMappingStore;
86
+ /**
87
+ * Check if a single identity mapping rule matches a user identity token.
88
+ *
89
+ * For `X509Subject` criteria, see {@link matchX509Subject}: both the full
90
+ * ordered DN format (OPC 10000-18 §4.4.3) and a plain Common Name are accepted.
91
+ *
92
+ * @see OPC 10000-18 §4.4 IdentityMappingRuleType
93
+ */
94
+ function matchesRule(rule, token) {
95
+ switch (rule.criteriaType) {
96
+ case node_opcua_types_1.IdentityCriteriaType.Anonymous:
97
+ return token instanceof node_opcua_types_1.AnonymousIdentityToken;
98
+ case node_opcua_types_1.IdentityCriteriaType.AuthenticatedUser:
99
+ return !(token instanceof node_opcua_types_1.AnonymousIdentityToken);
100
+ case node_opcua_types_1.IdentityCriteriaType.UserName:
101
+ return token instanceof node_opcua_types_1.UserNameIdentityToken && token.userName === rule.criteria;
102
+ case node_opcua_types_1.IdentityCriteriaType.Thumbprint: {
103
+ if (!(token instanceof node_opcua_types_1.X509IdentityToken) || !token.certificateData) {
104
+ return false;
105
+ }
106
+ const certBuffer = token.certificateData instanceof Buffer ? token.certificateData : Buffer.from(token.certificateData);
107
+ const thumbprint = (0, node_opcua_crypto_1.makeSHA1Thumbprint)(certBuffer).toString("hex").toUpperCase();
108
+ const expected = (rule.criteria ?? "").toUpperCase().replace(/[\s:]/g, "");
109
+ return thumbprint === expected;
110
+ }
111
+ case node_opcua_types_1.IdentityCriteriaType.X509Subject: {
112
+ if (!(token instanceof node_opcua_types_1.X509IdentityToken) || !token.certificateData) {
113
+ return false;
114
+ }
115
+ try {
116
+ const certBuffer = token.certificateData instanceof Buffer ? token.certificateData : Buffer.from(token.certificateData);
117
+ const info = (0, node_opcua_crypto_1.exploreCertificate)(certBuffer);
118
+ const subject = info.tbsCertificate.subject ?? {};
119
+ return (0, x509_subject_js_1.matchX509Subject)(rule.criteria ?? "", subject);
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ }
125
+ default:
126
+ return false;
127
+ }
128
+ }
129
+ //# sourceMappingURL=in_memory_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in_memory_store.js","sourceRoot":"","sources":["../source/in_memory_store.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yDAA2E;AAC3E,yDAA2E;AAC3E,uDAM0B;AAG1B,uDAAqD;AAErD;;;;;GAKG;AACH,MAAa,4BAA4B;IACpB,IAAI,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE9D,WAAW,CAAC,MAAc,EAAE,IAA6B;QAC5D,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC9B,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,GAAG,GAAG,EAAE,CAAC;YACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC;QACD,sCAAsC;QACtC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxF,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,GAAG,CAAC,IAAI,CACJ,IAAI,0CAAuB,CAAC;YACxB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,QAAQ,EAAE,I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C;YAC1D,CAAC;YAAC,MAAM,CAAC;gBACL,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED;YACI,OAAO,KAAK,CAAC;IACrB,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module node-opcua-role-set-common
3
+ */
4
+ export { type ArchiveIO, ArchiveStore, identitiesFromBase64, identitiesToBase64, type PersistedCustomRole, ROLE_SET_ARCHIVE_VERSION, type RoleSetArchive, readArchive, writeArchive } from "./archive.js";
5
+ export { decodeIdentityStore, encodeIdentityStore, identityStoreBinaryStoreSize, loadFromBinaryFile, saveToBinaryFile } from "./binary_persistence.js";
6
+ export type { AnyUserIdentityToken, IIdentityMappingStore } from "./identity_mapping_store.js";
7
+ export { InMemoryIdentityMappingStore } from "./in_memory_store.js";
8
+ export { applicationComplies, deserializeRestrictions, type EndpointCriteria, endpointComplies, InMemoryRoleRestrictionStore, type IRoleRestrictionStore, loadRestrictionsFromFile, type ResolutionContext, type SerializedRoleRestriction, saveRestrictionsToFile, serializeRestrictions } from "./role_restriction_store.js";
9
+ export { type AuthenticationResult, InMemoryUserManagementStore, type IUserManagementStore, type ModifyUserOptions, type PasswordPolicy, type SerializedUserRecord, type UserRecord } from "./user_management_store.js";
10
+ export { WellKnownRoleIds, WellKnownRoles } from "./well_known_role_ids.js";
11
+ export { canonicalizeX509Subject, certificateSubjectPairs, matchX509Subject, parseX509SubjectCriteria, X509_SUBJECT_ORDER, type X509SubjectName } from "./x509_subject.js";
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-role-set-common
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.X509_SUBJECT_ORDER = exports.parseX509SubjectCriteria = exports.matchX509Subject = exports.certificateSubjectPairs = exports.canonicalizeX509Subject = exports.WellKnownRoles = exports.WellKnownRoleIds = exports.InMemoryUserManagementStore = exports.serializeRestrictions = exports.saveRestrictionsToFile = exports.loadRestrictionsFromFile = exports.InMemoryRoleRestrictionStore = exports.endpointComplies = exports.deserializeRestrictions = exports.applicationComplies = exports.InMemoryIdentityMappingStore = exports.saveToBinaryFile = exports.loadFromBinaryFile = exports.identityStoreBinaryStoreSize = exports.encodeIdentityStore = exports.decodeIdentityStore = exports.writeArchive = exports.readArchive = exports.ROLE_SET_ARCHIVE_VERSION = exports.identitiesToBase64 = exports.identitiesFromBase64 = exports.ArchiveStore = void 0;
7
+ var archive_js_1 = require("./archive.js");
8
+ Object.defineProperty(exports, "ArchiveStore", { enumerable: true, get: function () { return archive_js_1.ArchiveStore; } });
9
+ Object.defineProperty(exports, "identitiesFromBase64", { enumerable: true, get: function () { return archive_js_1.identitiesFromBase64; } });
10
+ Object.defineProperty(exports, "identitiesToBase64", { enumerable: true, get: function () { return archive_js_1.identitiesToBase64; } });
11
+ Object.defineProperty(exports, "ROLE_SET_ARCHIVE_VERSION", { enumerable: true, get: function () { return archive_js_1.ROLE_SET_ARCHIVE_VERSION; } });
12
+ Object.defineProperty(exports, "readArchive", { enumerable: true, get: function () { return archive_js_1.readArchive; } });
13
+ Object.defineProperty(exports, "writeArchive", { enumerable: true, get: function () { return archive_js_1.writeArchive; } });
14
+ var binary_persistence_js_1 = require("./binary_persistence.js");
15
+ Object.defineProperty(exports, "decodeIdentityStore", { enumerable: true, get: function () { return binary_persistence_js_1.decodeIdentityStore; } });
16
+ Object.defineProperty(exports, "encodeIdentityStore", { enumerable: true, get: function () { return binary_persistence_js_1.encodeIdentityStore; } });
17
+ Object.defineProperty(exports, "identityStoreBinaryStoreSize", { enumerable: true, get: function () { return binary_persistence_js_1.identityStoreBinaryStoreSize; } });
18
+ Object.defineProperty(exports, "loadFromBinaryFile", { enumerable: true, get: function () { return binary_persistence_js_1.loadFromBinaryFile; } });
19
+ Object.defineProperty(exports, "saveToBinaryFile", { enumerable: true, get: function () { return binary_persistence_js_1.saveToBinaryFile; } });
20
+ var in_memory_store_js_1 = require("./in_memory_store.js");
21
+ Object.defineProperty(exports, "InMemoryIdentityMappingStore", { enumerable: true, get: function () { return in_memory_store_js_1.InMemoryIdentityMappingStore; } });
22
+ var role_restriction_store_js_1 = require("./role_restriction_store.js");
23
+ Object.defineProperty(exports, "applicationComplies", { enumerable: true, get: function () { return role_restriction_store_js_1.applicationComplies; } });
24
+ Object.defineProperty(exports, "deserializeRestrictions", { enumerable: true, get: function () { return role_restriction_store_js_1.deserializeRestrictions; } });
25
+ Object.defineProperty(exports, "endpointComplies", { enumerable: true, get: function () { return role_restriction_store_js_1.endpointComplies; } });
26
+ Object.defineProperty(exports, "InMemoryRoleRestrictionStore", { enumerable: true, get: function () { return role_restriction_store_js_1.InMemoryRoleRestrictionStore; } });
27
+ Object.defineProperty(exports, "loadRestrictionsFromFile", { enumerable: true, get: function () { return role_restriction_store_js_1.loadRestrictionsFromFile; } });
28
+ Object.defineProperty(exports, "saveRestrictionsToFile", { enumerable: true, get: function () { return role_restriction_store_js_1.saveRestrictionsToFile; } });
29
+ Object.defineProperty(exports, "serializeRestrictions", { enumerable: true, get: function () { return role_restriction_store_js_1.serializeRestrictions; } });
30
+ var user_management_store_js_1 = require("./user_management_store.js");
31
+ Object.defineProperty(exports, "InMemoryUserManagementStore", { enumerable: true, get: function () { return user_management_store_js_1.InMemoryUserManagementStore; } });
32
+ var well_known_role_ids_js_1 = require("./well_known_role_ids.js");
33
+ Object.defineProperty(exports, "WellKnownRoleIds", { enumerable: true, get: function () { return well_known_role_ids_js_1.WellKnownRoleIds; } });
34
+ Object.defineProperty(exports, "WellKnownRoles", { enumerable: true, get: function () { return well_known_role_ids_js_1.WellKnownRoles; } });
35
+ var x509_subject_js_1 = require("./x509_subject.js");
36
+ Object.defineProperty(exports, "canonicalizeX509Subject", { enumerable: true, get: function () { return x509_subject_js_1.canonicalizeX509Subject; } });
37
+ Object.defineProperty(exports, "certificateSubjectPairs", { enumerable: true, get: function () { return x509_subject_js_1.certificateSubjectPairs; } });
38
+ Object.defineProperty(exports, "matchX509Subject", { enumerable: true, get: function () { return x509_subject_js_1.matchX509Subject; } });
39
+ Object.defineProperty(exports, "parseX509SubjectCriteria", { enumerable: true, get: function () { return x509_subject_js_1.parseX509SubjectCriteria; } });
40
+ Object.defineProperty(exports, "X509_SUBJECT_ORDER", { enumerable: true, get: function () { return x509_subject_js_1.X509_SUBJECT_ORDER; } });
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2CAUsB;AARlB,0GAAA,YAAY,OAAA;AACZ,kHAAA,oBAAoB,OAAA;AACpB,gHAAA,kBAAkB,OAAA;AAElB,sHAAA,wBAAwB,OAAA;AAExB,yGAAA,WAAW,OAAA;AACX,0GAAA,YAAY,OAAA;AAEhB,iEAMiC;AAL7B,4HAAA,mBAAmB,OAAA;AACnB,4HAAA,mBAAmB,OAAA;AACnB,qIAAA,4BAA4B,OAAA;AAC5B,2HAAA,kBAAkB,OAAA;AAClB,yHAAA,gBAAgB,OAAA;AAGpB,2DAAoE;AAA3D,kIAAA,4BAA4B,OAAA;AACrC,yEAYqC;AAXjC,gIAAA,mBAAmB,OAAA;AACnB,oIAAA,uBAAuB,OAAA;AAEvB,6HAAA,gBAAgB,OAAA;AAChB,yIAAA,4BAA4B,OAAA;AAE5B,qIAAA,wBAAwB,OAAA;AAGxB,mIAAA,sBAAsB,OAAA;AACtB,kIAAA,qBAAqB,OAAA;AAEzB,uEAQoC;AANhC,uIAAA,2BAA2B,OAAA;AAO/B,mEAA4E;AAAnE,0HAAA,gBAAgB,OAAA;AAAE,wHAAA,cAAc,OAAA;AACzC,qDAO2B;AANvB,0HAAA,uBAAuB,OAAA;AACvB,0HAAA,uBAAuB,OAAA;AACvB,mHAAA,gBAAgB,OAAA;AAChB,2HAAA,wBAAwB,OAAA;AACxB,qHAAA,kBAAkB,OAAA"}
@@ -0,0 +1,93 @@
1
+ import { type NodeId } from "node-opcua-nodeid";
2
+ import { MessageSecurityMode } from "node-opcua-types";
3
+ /** An endpoint restriction entry (mirrors the EndpointType DataType, §4.4.2). */
4
+ export interface EndpointCriteria {
5
+ endpointUrl?: string;
6
+ securityMode?: MessageSecurityMode;
7
+ securityPolicyUri?: string;
8
+ transportProfileUri?: string;
9
+ }
10
+ /**
11
+ * The Session attributes evaluated against a Role's application/endpoint
12
+ * restrictions. Built from the SessionContext (client certificate ApplicationUri,
13
+ * SecureChannel security mode/policy, the Endpoint used).
14
+ */
15
+ export interface ResolutionContext {
16
+ applicationUri?: string | null;
17
+ securityMode?: MessageSecurityMode;
18
+ endpointUrl?: string;
19
+ securityPolicyUri?: string;
20
+ transportProfileUri?: string;
21
+ }
22
+ /** Per-Role application & endpoint restriction configuration. */
23
+ export interface IRoleRestrictionStore {
24
+ /** Add an ApplicationUri to a Role's Applications list. @returns false if already present. */
25
+ addApplication(roleId: NodeId, applicationUri: string): boolean;
26
+ /** Remove an ApplicationUri. @returns false if not present. */
27
+ removeApplication(roleId: NodeId, applicationUri: string): boolean;
28
+ getApplications(roleId: NodeId): string[];
29
+ /** Set ApplicationsExclude (include-list when false, exclude-list when true). */
30
+ setApplicationsExclude(roleId: NodeId, exclude: boolean): void;
31
+ /** ApplicationsExclude — defaults to TRUE when the Applications list is empty (§4.4.1). */
32
+ getApplicationsExclude(roleId: NodeId): boolean;
33
+ addEndpoint(roleId: NodeId, endpoint: EndpointCriteria): boolean;
34
+ removeEndpoint(roleId: NodeId, endpoint: EndpointCriteria): boolean;
35
+ getEndpoints(roleId: NodeId): EndpointCriteria[];
36
+ setEndpointsExclude(roleId: NodeId, exclude: boolean): void;
37
+ getEndpointsExclude(roleId: NodeId): boolean;
38
+ /** NodeIds of the Roles that have any restriction configured. */
39
+ getRestrictedRoleIds(): NodeId[];
40
+ /** True when the Session complies with the Role's application & endpoint restrictions. */
41
+ complies(roleId: NodeId, context: ResolutionContext): boolean;
42
+ }
43
+ /**
44
+ * Does the Session's application comply with an `Applications` restriction?
45
+ *
46
+ * - Empty list → no restriction (granted).
47
+ * - Non-empty list → the Session must use at least a **signed** channel (§4.4.1).
48
+ * Then, with `exclude=false` the ApplicationUri must be **in** the list;
49
+ * with `exclude=true` it must **not** be in the list.
50
+ */
51
+ export declare function applicationComplies(applications: string[], exclude: boolean, context: ResolutionContext): boolean;
52
+ /**
53
+ * Does the Session's endpoint comply with an `Endpoints` restriction?
54
+ * Empty list → no restriction. `exclude=false` → the endpoint must match one
55
+ * entry; `exclude=true` → it must match none.
56
+ */
57
+ export declare function endpointComplies(endpoints: EndpointCriteria[], exclude: boolean, context: ResolutionContext): boolean;
58
+ /** In-memory implementation of {@link IRoleRestrictionStore}. */
59
+ export declare class InMemoryRoleRestrictionStore implements IRoleRestrictionStore {
60
+ private readonly _map;
61
+ /** Get-or-create the entry — for mutations only. */
62
+ private getOrCreate;
63
+ /** Read the entry without creating one. */
64
+ private peek;
65
+ getRestrictedRoleIds(): NodeId[];
66
+ addApplication(roleId: NodeId, applicationUri: string): boolean;
67
+ removeApplication(roleId: NodeId, applicationUri: string): boolean;
68
+ getApplications(roleId: NodeId): string[];
69
+ setApplicationsExclude(roleId: NodeId, exclude: boolean): void;
70
+ getApplicationsExclude(roleId: NodeId): boolean;
71
+ addEndpoint(roleId: NodeId, endpoint: EndpointCriteria): boolean;
72
+ removeEndpoint(roleId: NodeId, endpoint: EndpointCriteria): boolean;
73
+ getEndpoints(roleId: NodeId): EndpointCriteria[];
74
+ setEndpointsExclude(roleId: NodeId, exclude: boolean): void;
75
+ getEndpointsExclude(roleId: NodeId): boolean;
76
+ complies(roleId: NodeId, context: ResolutionContext): boolean;
77
+ }
78
+ /** Serializable form of a Role's restrictions (for persistence). */
79
+ export interface SerializedRoleRestriction {
80
+ nodeId: string;
81
+ applications: string[];
82
+ applicationsExclude: boolean;
83
+ endpoints: EndpointCriteria[];
84
+ endpointsExclude: boolean;
85
+ }
86
+ /** Snapshot the restriction store to a JSON-serializable array. */
87
+ export declare function serializeRestrictions(store: IRoleRestrictionStore): SerializedRoleRestriction[];
88
+ /** Load a serialized snapshot into the restriction store (merges). */
89
+ export declare function deserializeRestrictions(store: IRoleRestrictionStore, data: SerializedRoleRestriction[]): void;
90
+ /** Persist the restriction store to a JSON file. */
91
+ export declare function saveRestrictionsToFile(store: IRoleRestrictionStore, filePath: string): Promise<void>;
92
+ /** Load the restriction store from a JSON file (missing file → no-op). */
93
+ export declare function loadRestrictionsFromFile(store: IRoleRestrictionStore, filePath: string): Promise<void>;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryRoleRestrictionStore = void 0;
4
+ exports.applicationComplies = applicationComplies;
5
+ exports.endpointComplies = endpointComplies;
6
+ exports.serializeRestrictions = serializeRestrictions;
7
+ exports.deserializeRestrictions = deserializeRestrictions;
8
+ exports.saveRestrictionsToFile = saveRestrictionsToFile;
9
+ exports.loadRestrictionsFromFile = loadRestrictionsFromFile;
10
+ /**
11
+ * @module node-opcua-role-set-common
12
+ *
13
+ * Per-Role application & endpoint restrictions (OPC 10000-18 §4.4.1, §4.4.7-10)
14
+ * and the matching rules that decide whether a Session complies with them.
15
+ *
16
+ * A Role is granted only if the UserIdentityToken matches **and** the Client
17
+ * application complies with the `Applications` restriction **and** the Endpoint
18
+ * used complies with the `Endpoints` restriction.
19
+ */
20
+ const node_fs_1 = require("node:fs");
21
+ const node_path_1 = require("node:path");
22
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
23
+ const node_opcua_types_1 = require("node-opcua-types");
24
+ const isSigned = (mode) => mode === node_opcua_types_1.MessageSecurityMode.Sign || mode === node_opcua_types_1.MessageSecurityMode.SignAndEncrypt;
25
+ function sameEndpoint(a, b) {
26
+ return ((a.endpointUrl ?? "") === (b.endpointUrl ?? "") &&
27
+ (a.securityMode ?? node_opcua_types_1.MessageSecurityMode.Invalid) === (b.securityMode ?? node_opcua_types_1.MessageSecurityMode.Invalid) &&
28
+ (a.securityPolicyUri ?? "") === (b.securityPolicyUri ?? "") &&
29
+ (a.transportProfileUri ?? "") === (b.transportProfileUri ?? ""));
30
+ }
31
+ /**
32
+ * Does the Session's application comply with an `Applications` restriction?
33
+ *
34
+ * - Empty list → no restriction (granted).
35
+ * - Non-empty list → the Session must use at least a **signed** channel (§4.4.1).
36
+ * Then, with `exclude=false` the ApplicationUri must be **in** the list;
37
+ * with `exclude=true` it must **not** be in the list.
38
+ */
39
+ function applicationComplies(applications, exclude, context) {
40
+ if (applications.length === 0) {
41
+ return true;
42
+ }
43
+ if (!isSigned(context.securityMode)) {
44
+ return false;
45
+ }
46
+ const inList = context.applicationUri != null && applications.includes(context.applicationUri);
47
+ return exclude ? !inList : inList;
48
+ }
49
+ /** Does an endpoint entry match the Session's endpoint? Default-valued fields are ignored (§4.4.2). */
50
+ function endpointEntryMatches(entry, context) {
51
+ if (entry.endpointUrl && entry.endpointUrl !== context.endpointUrl)
52
+ return false;
53
+ if (entry.securityMode !== undefined &&
54
+ entry.securityMode !== node_opcua_types_1.MessageSecurityMode.Invalid &&
55
+ entry.securityMode !== context.securityMode) {
56
+ return false;
57
+ }
58
+ if (entry.securityPolicyUri && entry.securityPolicyUri !== context.securityPolicyUri)
59
+ return false;
60
+ if (entry.transportProfileUri && entry.transportProfileUri !== context.transportProfileUri)
61
+ return false;
62
+ return true;
63
+ }
64
+ /**
65
+ * Does the Session's endpoint comply with an `Endpoints` restriction?
66
+ * Empty list → no restriction. `exclude=false` → the endpoint must match one
67
+ * entry; `exclude=true` → it must match none.
68
+ */
69
+ function endpointComplies(endpoints, exclude, context) {
70
+ if (endpoints.length === 0) {
71
+ return true;
72
+ }
73
+ const anyMatch = endpoints.some((e) => endpointEntryMatches(e, context));
74
+ return exclude ? !anyMatch : anyMatch;
75
+ }
76
+ /** In-memory implementation of {@link IRoleRestrictionStore}. */
77
+ class InMemoryRoleRestrictionStore {
78
+ _map = new Map();
79
+ /** Get-or-create the entry — for mutations only. */
80
+ getOrCreate(roleId) {
81
+ const key = roleId.toString();
82
+ let r = this._map.get(key);
83
+ if (!r) {
84
+ r = { applications: [], endpoints: [] };
85
+ this._map.set(key, r);
86
+ }
87
+ return r;
88
+ }
89
+ /** Read the entry without creating one. */
90
+ peek(roleId) {
91
+ return this._map.get(roleId.toString());
92
+ }
93
+ getRestrictedRoleIds() {
94
+ return [...this._map.keys()].map((k) => (0, node_opcua_nodeid_1.resolveNodeId)(k));
95
+ }
96
+ addApplication(roleId, applicationUri) {
97
+ const r = this.getOrCreate(roleId);
98
+ if (r.applications.includes(applicationUri))
99
+ return false;
100
+ r.applications.push(applicationUri);
101
+ return true;
102
+ }
103
+ removeApplication(roleId, applicationUri) {
104
+ const r = this.peek(roleId);
105
+ const i = r ? r.applications.indexOf(applicationUri) : -1;
106
+ if (!r || i < 0)
107
+ return false;
108
+ r.applications.splice(i, 1);
109
+ return true;
110
+ }
111
+ getApplications(roleId) {
112
+ return [...(this.peek(roleId)?.applications ?? [])];
113
+ }
114
+ setApplicationsExclude(roleId, exclude) {
115
+ this.getOrCreate(roleId).applicationsExclude = exclude;
116
+ }
117
+ getApplicationsExclude(roleId) {
118
+ const r = this.peek(roleId);
119
+ // default TRUE when the list is empty (§4.4.1), otherwise FALSE (include list)
120
+ return r?.applicationsExclude ?? (r?.applications.length ?? 0) === 0;
121
+ }
122
+ addEndpoint(roleId, endpoint) {
123
+ const r = this.getOrCreate(roleId);
124
+ if (r.endpoints.some((e) => sameEndpoint(e, endpoint)))
125
+ return false;
126
+ r.endpoints.push({ ...endpoint });
127
+ return true;
128
+ }
129
+ removeEndpoint(roleId, endpoint) {
130
+ const r = this.peek(roleId);
131
+ const i = r ? r.endpoints.findIndex((e) => sameEndpoint(e, endpoint)) : -1;
132
+ if (!r || i < 0)
133
+ return false;
134
+ r.endpoints.splice(i, 1);
135
+ return true;
136
+ }
137
+ getEndpoints(roleId) {
138
+ return (this.peek(roleId)?.endpoints ?? []).map((e) => ({ ...e }));
139
+ }
140
+ setEndpointsExclude(roleId, exclude) {
141
+ this.getOrCreate(roleId).endpointsExclude = exclude;
142
+ }
143
+ getEndpointsExclude(roleId) {
144
+ const r = this.peek(roleId);
145
+ return r?.endpointsExclude ?? (r?.endpoints.length ?? 0) === 0;
146
+ }
147
+ complies(roleId, context) {
148
+ const r = this.peek(roleId);
149
+ if (!r) {
150
+ return true; // no restriction configured
151
+ }
152
+ return (applicationComplies(r.applications, this.getApplicationsExclude(roleId), context) &&
153
+ endpointComplies(r.endpoints, this.getEndpointsExclude(roleId), context));
154
+ }
155
+ }
156
+ exports.InMemoryRoleRestrictionStore = InMemoryRoleRestrictionStore;
157
+ /** Snapshot the restriction store to a JSON-serializable array. */
158
+ function serializeRestrictions(store) {
159
+ return store.getRestrictedRoleIds().map((roleId) => ({
160
+ nodeId: roleId.toString(),
161
+ applications: store.getApplications(roleId),
162
+ applicationsExclude: store.getApplicationsExclude(roleId),
163
+ endpoints: store.getEndpoints(roleId),
164
+ endpointsExclude: store.getEndpointsExclude(roleId)
165
+ }));
166
+ }
167
+ /** Load a serialized snapshot into the restriction store (merges). */
168
+ function deserializeRestrictions(store, data) {
169
+ for (const r of data) {
170
+ const roleId = (0, node_opcua_nodeid_1.resolveNodeId)(r.nodeId);
171
+ for (const app of r.applications) {
172
+ store.addApplication(roleId, app);
173
+ }
174
+ store.setApplicationsExclude(roleId, r.applicationsExclude);
175
+ for (const ep of r.endpoints) {
176
+ store.addEndpoint(roleId, ep);
177
+ }
178
+ store.setEndpointsExclude(roleId, r.endpointsExclude);
179
+ }
180
+ }
181
+ /** Persist the restriction store to a JSON file. */
182
+ async function saveRestrictionsToFile(store, filePath) {
183
+ await node_fs_1.promises.mkdir((0, node_path_1.dirname)(filePath), { recursive: true });
184
+ await node_fs_1.promises.writeFile(filePath, JSON.stringify(serializeRestrictions(store), null, 2), "utf8");
185
+ }
186
+ /** Load the restriction store from a JSON file (missing file → no-op). */
187
+ async function loadRestrictionsFromFile(store, filePath) {
188
+ let text;
189
+ try {
190
+ text = await node_fs_1.promises.readFile(filePath, "utf8");
191
+ }
192
+ catch (err) {
193
+ if (err.code === "ENOENT") {
194
+ return;
195
+ }
196
+ throw err;
197
+ }
198
+ try {
199
+ deserializeRestrictions(store, JSON.parse(text));
200
+ }
201
+ catch (err) {
202
+ throw new Error(`loadRestrictionsFromFile: '${filePath}' appears to be corrupt: ${err.message}`);
203
+ }
204
+ }
205
+ //# sourceMappingURL=role_restriction_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role_restriction_store.js","sourceRoot":"","sources":["../source/role_restriction_store.ts"],"names":[],"mappings":";;;AAiFA,kDASC;AAsBD,4CAMC;AAwGD,sDAQC;AAGD,0DAYC;AAGD,wDAGC;AAGD,4DAeC;AA7QD;;;;;;;;;GASG;AACH,qCAAyC;AACzC,yCAAoC;AACpC,yDAA+D;AAC/D,uDAAuD;AAgDvD,MAAM,QAAQ,GAAG,CAAC,IAAqC,EAAW,EAAE,CAChE,IAAI,KAAK,sCAAmB,CAAC,IAAI,IAAI,IAAI,KAAK,sCAAmB,CAAC,cAAc,CAAC;AAErF,SAAS,YAAY,CAAC,CAAmB,EAAE,CAAmB;IAC1D,OAAO,CACH,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC,YAAY,IAAI,sCAAmB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,IAAI,sCAAmB,CAAC,OAAO,CAAC;QACnG,CAAC,CAAC,CAAC,iBAAiB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,IAAI,EAAE,CAAC;QAC3D,CAAC,CAAC,CAAC,mBAAmB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAClE,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,YAAsB,EAAE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types";
3
+ /**
4
+ * Password requirements (OPC 10000-18 §5.2.1-2: PasswordLength range and
5
+ * PasswordOptionsMask). A length of 0 means "no limit".
6
+ */
7
+ export interface PasswordPolicy {
8
+ minLength?: number;
9
+ maxLength?: number;
10
+ requireUpperCase?: boolean;
11
+ requireLowerCase?: boolean;
12
+ requireDigit?: boolean;
13
+ requireSpecial?: boolean;
14
+ }
15
+ /** Public view of a configured user (no secret material). */
16
+ export interface UserRecord {
17
+ userName: string;
18
+ userConfiguration: UserConfigurationMask;
19
+ description: string;
20
+ }
21
+ /**
22
+ * Persisted user record — includes the salted scrypt hash (base64), never the
23
+ * clear password. Suitable for storing in the consolidated archive.
24
+ */
25
+ export interface SerializedUserRecord {
26
+ userName: string;
27
+ salt: string;
28
+ hash: string;
29
+ userConfiguration: UserConfigurationMask;
30
+ description: string;
31
+ }
32
+ /** Result of authenticating a user at ActivateSession time. */
33
+ export interface AuthenticationResult {
34
+ /** `Good`, `GoodPasswordChangeRequired`, or a `Bad_` code on failure. */
35
+ statusCode: StatusCode;
36
+ /** True when the user must change the password before gaining roles. */
37
+ mustChangePassword: boolean;
38
+ }
39
+ export interface ModifyUserOptions {
40
+ modifyPassword?: boolean;
41
+ password?: string;
42
+ modifyUserConfiguration?: boolean;
43
+ userConfiguration?: UserConfigurationMask;
44
+ modifyDescription?: boolean;
45
+ description?: string;
46
+ }
47
+ export interface IUserManagementStore {
48
+ addUser(userName: string, password: string, userConfiguration: UserConfigurationMask, description: string): StatusCode;
49
+ modifyUser(userName: string, options: ModifyUserOptions, callerUserName?: string): StatusCode;
50
+ removeUser(userName: string, callerUserName?: string): StatusCode;
51
+ changePassword(userName: string, oldPassword: string, newPassword: string): StatusCode;
52
+ authenticate(userName: string, password: string): AuthenticationResult;
53
+ getUsers(): UserRecord[];
54
+ hasUser(userName: string): boolean;
55
+ /** Export every user (with salted hash) for persistence. Optional: only stores that support persistence. */
56
+ exportUsers?(): SerializedUserRecord[];
57
+ /** Load persisted users (with salted hash), replacing any existing entry of the same name. */
58
+ importUsers?(records: SerializedUserRecord[]): void;
59
+ }
60
+ /**
61
+ * In-memory implementation of {@link IUserManagementStore}.
62
+ *
63
+ * @see OPC 10000-18 §5.2
64
+ */
65
+ export declare class InMemoryUserManagementStore implements IUserManagementStore {
66
+ private readonly _users;
67
+ private readonly _policy;
68
+ constructor(policy?: PasswordPolicy);
69
+ get policy(): PasswordPolicy;
70
+ hasUser(userName: string): boolean;
71
+ getUsers(): UserRecord[];
72
+ exportUsers(): SerializedUserRecord[];
73
+ importUsers(records: SerializedUserRecord[]): void;
74
+ addUser(userName: string, password: string, userConfiguration: UserConfigurationMask, description: string): StatusCode;
75
+ modifyUser(userName: string, options: ModifyUserOptions, callerUserName?: string): StatusCode;
76
+ removeUser(userName: string, callerUserName?: string): StatusCode;
77
+ changePassword(userName: string, oldPassword: string, newPassword: string): StatusCode;
78
+ authenticate(userName: string, password: string): AuthenticationResult;
79
+ /** Validate a candidate password against the configured policy. */
80
+ isPasswordValid(password: string): boolean;
81
+ private hashPassword;
82
+ private verify;
83
+ }