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,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryUserManagementStore = void 0;
4
+ /**
5
+ * @module node-opcua-role-set-common
6
+ *
7
+ * User management store (OPC 10000-18 §5) — provides the local user list and
8
+ * password lifecycle used by the `UserName` identity criteria.
9
+ *
10
+ * The store implements the behaviour of the AddUser / ModifyUser / RemoveUser
11
+ * / ChangePassword Methods and the password policy (PasswordLength range and
12
+ * the password-option requirements). Passwords are never stored in clear:
13
+ * each is salted and hashed with scrypt.
14
+ */
15
+ const node_crypto_1 = require("node:crypto");
16
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
17
+ const node_opcua_types_1 = require("node-opcua-types");
18
+ const has = (mask, bit) => (mask & bit) === bit;
19
+ /**
20
+ * In-memory implementation of {@link IUserManagementStore}.
21
+ *
22
+ * @see OPC 10000-18 §5.2
23
+ */
24
+ class InMemoryUserManagementStore {
25
+ _users = new Map();
26
+ _policy;
27
+ constructor(policy) {
28
+ this._policy = policy ?? {};
29
+ }
30
+ get policy() {
31
+ return this._policy;
32
+ }
33
+ hasUser(userName) {
34
+ return this._users.has(userName);
35
+ }
36
+ getUsers() {
37
+ return [...this._users.values()].map((u) => ({
38
+ userName: u.userName,
39
+ userConfiguration: u.userConfiguration,
40
+ description: u.description
41
+ }));
42
+ }
43
+ exportUsers() {
44
+ return [...this._users.values()].map((u) => ({
45
+ userName: u.userName,
46
+ salt: u.salt.toString("base64"),
47
+ hash: u.hash.toString("base64"),
48
+ userConfiguration: u.userConfiguration,
49
+ description: u.description
50
+ }));
51
+ }
52
+ importUsers(records) {
53
+ for (const r of records) {
54
+ this._users.set(r.userName, {
55
+ userName: r.userName,
56
+ salt: Buffer.from(r.salt, "base64"),
57
+ hash: Buffer.from(r.hash, "base64"),
58
+ userConfiguration: r.userConfiguration,
59
+ description: r.description
60
+ });
61
+ }
62
+ }
63
+ addUser(userName, password, userConfiguration, description) {
64
+ if (this._users.has(userName)) {
65
+ return node_opcua_status_code_1.StatusCodes.BadAlreadyExists;
66
+ }
67
+ const configError = validateUserConfiguration(userConfiguration);
68
+ if (configError) {
69
+ return configError;
70
+ }
71
+ if (!this.isPasswordValid(password)) {
72
+ return node_opcua_status_code_1.StatusCodes.BadOutOfRange;
73
+ }
74
+ this._users.set(userName, { userName, ...this.hashPassword(password), userConfiguration, description });
75
+ return node_opcua_status_code_1.StatusCodes.Good;
76
+ }
77
+ modifyUser(userName, options, callerUserName) {
78
+ const user = this._users.get(userName);
79
+ if (!user) {
80
+ return node_opcua_status_code_1.StatusCodes.BadNotFound;
81
+ }
82
+ if (options.modifyPassword) {
83
+ if (!this.isPasswordValid(options.password ?? "")) {
84
+ return node_opcua_status_code_1.StatusCodes.BadOutOfRange;
85
+ }
86
+ }
87
+ let nextConfig = user.userConfiguration;
88
+ if (options.modifyUserConfiguration) {
89
+ nextConfig = options.userConfiguration ?? node_opcua_types_1.UserConfigurationMask.None;
90
+ const configError = validateUserConfiguration(nextConfig);
91
+ if (configError) {
92
+ return configError;
93
+ }
94
+ // Cannot disable the user that calls the Method (§5.2.6)
95
+ if (callerUserName === userName &&
96
+ has(nextConfig, node_opcua_types_1.UserConfigurationMask.Disabled) &&
97
+ !has(user.userConfiguration, node_opcua_types_1.UserConfigurationMask.Disabled)) {
98
+ return node_opcua_status_code_1.StatusCodes.BadInvalidSelfReference;
99
+ }
100
+ }
101
+ // All checks passed — apply the changes
102
+ if (options.modifyPassword) {
103
+ const { salt, hash } = this.hashPassword(options.password ?? "");
104
+ user.salt = salt;
105
+ user.hash = hash;
106
+ }
107
+ if (options.modifyUserConfiguration) {
108
+ user.userConfiguration = nextConfig;
109
+ }
110
+ if (options.modifyDescription) {
111
+ user.description = options.description ?? "";
112
+ }
113
+ return node_opcua_status_code_1.StatusCodes.Good;
114
+ }
115
+ removeUser(userName, callerUserName) {
116
+ const user = this._users.get(userName);
117
+ if (!user) {
118
+ return node_opcua_status_code_1.StatusCodes.BadNotFound;
119
+ }
120
+ if (callerUserName === userName) {
121
+ return node_opcua_status_code_1.StatusCodes.BadInvalidSelfReference;
122
+ }
123
+ if (has(user.userConfiguration, node_opcua_types_1.UserConfigurationMask.NoDelete)) {
124
+ return node_opcua_status_code_1.StatusCodes.BadNotSupported;
125
+ }
126
+ this._users.delete(userName);
127
+ return node_opcua_status_code_1.StatusCodes.Good;
128
+ }
129
+ changePassword(userName, oldPassword, newPassword) {
130
+ const user = this._users.get(userName);
131
+ // Unknown user is treated as an invalid old password (§5.2.8)
132
+ if (!user) {
133
+ return node_opcua_status_code_1.StatusCodes.BadIdentityTokenInvalid;
134
+ }
135
+ if (has(user.userConfiguration, node_opcua_types_1.UserConfigurationMask.NoChangeByUser)) {
136
+ return node_opcua_status_code_1.StatusCodes.BadNotSupported;
137
+ }
138
+ if (!this.verify(user, oldPassword)) {
139
+ return node_opcua_status_code_1.StatusCodes.BadIdentityTokenInvalid;
140
+ }
141
+ if (oldPassword === newPassword) {
142
+ return node_opcua_status_code_1.StatusCodes.BadAlreadyExists;
143
+ }
144
+ if (!this.isPasswordValid(newPassword)) {
145
+ return node_opcua_status_code_1.StatusCodes.BadOutOfRange;
146
+ }
147
+ const { salt, hash } = this.hashPassword(newPassword);
148
+ user.salt = salt;
149
+ user.hash = hash;
150
+ // A successful change clears the MustChangePassword flag (§5.2.8)
151
+ user.userConfiguration &= ~node_opcua_types_1.UserConfigurationMask.MustChangePassword;
152
+ return node_opcua_status_code_1.StatusCodes.Good;
153
+ }
154
+ authenticate(userName, password) {
155
+ const user = this._users.get(userName);
156
+ // A disabled user behaves like a user that does not exist (§5.2.3)
157
+ if (!user || has(user.userConfiguration, node_opcua_types_1.UserConfigurationMask.Disabled)) {
158
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied, mustChangePassword: false };
159
+ }
160
+ if (!this.verify(user, password)) {
161
+ return { statusCode: node_opcua_status_code_1.StatusCodes.BadUserAccessDenied, mustChangePassword: false };
162
+ }
163
+ if (has(user.userConfiguration, node_opcua_types_1.UserConfigurationMask.MustChangePassword)) {
164
+ return { statusCode: node_opcua_status_code_1.StatusCodes.GoodPasswordChangeRequired, mustChangePassword: true };
165
+ }
166
+ return { statusCode: node_opcua_status_code_1.StatusCodes.Good, mustChangePassword: false };
167
+ }
168
+ /** Validate a candidate password against the configured policy. */
169
+ isPasswordValid(password) {
170
+ const p = this._policy;
171
+ if (p.minLength && password.length < p.minLength)
172
+ return false;
173
+ if (p.maxLength && password.length > p.maxLength)
174
+ return false;
175
+ if (p.requireUpperCase && !/[A-Z]/.test(password))
176
+ return false;
177
+ if (p.requireLowerCase && !/[a-z]/.test(password))
178
+ return false;
179
+ if (p.requireDigit && !/[0-9]/.test(password))
180
+ return false;
181
+ if (p.requireSpecial && !/[^A-Za-z0-9]/.test(password))
182
+ return false;
183
+ return true;
184
+ }
185
+ hashPassword(password) {
186
+ const salt = (0, node_crypto_1.randomBytes)(16);
187
+ const hash = (0, node_crypto_1.scryptSync)(password, salt, 64);
188
+ return { salt, hash };
189
+ }
190
+ verify(user, password) {
191
+ const candidate = (0, node_crypto_1.scryptSync)(password, user.salt, 64);
192
+ return candidate.length === user.hash.length && (0, node_crypto_1.timingSafeEqual)(candidate, user.hash);
193
+ }
194
+ }
195
+ exports.InMemoryUserManagementStore = InMemoryUserManagementStore;
196
+ /**
197
+ * Validate a UserConfigurationMask combination (OPC 10000-18 §5.2.3):
198
+ * MustChangePassword is invalid when NoChangeByUser is also set.
199
+ *
200
+ * @returns a `Bad_ConfigurationError` StatusCode, or `null` if valid.
201
+ */
202
+ function validateUserConfiguration(mask) {
203
+ if (has(mask, node_opcua_types_1.UserConfigurationMask.MustChangePassword) && has(mask, node_opcua_types_1.UserConfigurationMask.NoChangeByUser)) {
204
+ return node_opcua_status_code_1.StatusCodes.BadConfigurationError;
205
+ }
206
+ return null;
207
+ }
208
+ //# sourceMappingURL=user_management_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user_management_store.js","sourceRoot":"","sources":["../source/user_management_store.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,6CAAuE;AACvE,mEAAsE;AAC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Ae,EAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1F,CAAC;CACJ;AArLD,kEAqLC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,IAA2B;IAC1D,IAAI,GAAG,CAAC,IAAI,EAAE,wCAAqB,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,wCAAqB,CAAC,cAAc,CAAC,EAAE,CAAC;QACzG,OAAO,oCAAW,CAAC,qBAAqB,CAAC;IAC7C,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @module node-opcua-role-set-common
3
+ *
4
+ * Pre-built NodeId objects for the OPC UA Well-Known Roles
5
+ * (OPC 10000-3 §4.8.2).
6
+ *
7
+ * These save callers from repeatedly calling `resolveNodeId(WellKnownRoles.X)`.
8
+ */
9
+ export { WellKnownRoles } from "node-opcua-constants";
10
+ /**
11
+ * Pre-built NodeId objects for OPC UA Well-Known Roles.
12
+ *
13
+ * Usage:
14
+ * ```ts
15
+ * import { WellKnownRoleIds } from "node-opcua-role-set-common";
16
+ * store.addIdentity(WellKnownRoleIds.SecurityAdmin, rule);
17
+ * ```
18
+ */
19
+ export declare const WellKnownRoleIds: {
20
+ /** Very limited access for anonymous Sessions. */
21
+ readonly Anonymous: import("node-opcua-nodeid").NodeId;
22
+ /** Limited access for valid non-anonymous credentials. */
23
+ readonly AuthenticatedUser: import("node-opcua-nodeid").NodeId;
24
+ /** Browse, read live/historical data, subscribe. */
25
+ readonly Observer: import("node-opcua-nodeid").NodeId;
26
+ /** Observer + write some live data, call some Methods. */
27
+ readonly Operator: import("node-opcua-nodeid").NodeId;
28
+ /** Browse, read/write config, read historical, call Methods, subscribe. */
29
+ readonly Engineer: import("node-opcua-nodeid").NodeId;
30
+ /** Browse, read live/historical data, call Methods, subscribe. */
31
+ readonly Supervisor: import("node-opcua-nodeid").NodeId;
32
+ /** Change non-security related configuration. */
33
+ readonly ConfigureAdmin: import("node-opcua-nodeid").NodeId;
34
+ /** Change security related settings. */
35
+ readonly SecurityAdmin: import("node-opcua-nodeid").NodeId;
36
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-role-set-common
4
+ *
5
+ * Pre-built NodeId objects for the OPC UA Well-Known Roles
6
+ * (OPC 10000-3 §4.8.2).
7
+ *
8
+ * These save callers from repeatedly calling `resolveNodeId(WellKnownRoles.X)`.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.WellKnownRoleIds = exports.WellKnownRoles = void 0;
12
+ const node_opcua_constants_1 = require("node-opcua-constants");
13
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
14
+ // Re-export so consumers only need to import from role-set-common
15
+ var node_opcua_constants_2 = require("node-opcua-constants");
16
+ Object.defineProperty(exports, "WellKnownRoles", { enumerable: true, get: function () { return node_opcua_constants_2.WellKnownRoles; } });
17
+ /**
18
+ * Pre-built NodeId objects for OPC UA Well-Known Roles.
19
+ *
20
+ * Usage:
21
+ * ```ts
22
+ * import { WellKnownRoleIds } from "node-opcua-role-set-common";
23
+ * store.addIdentity(WellKnownRoleIds.SecurityAdmin, rule);
24
+ * ```
25
+ */
26
+ exports.WellKnownRoleIds = {
27
+ /** Very limited access for anonymous Sessions. */
28
+ Anonymous: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.Anonymous),
29
+ /** Limited access for valid non-anonymous credentials. */
30
+ AuthenticatedUser: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.AuthenticatedUser),
31
+ /** Browse, read live/historical data, subscribe. */
32
+ Observer: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.Observer),
33
+ /** Observer + write some live data, call some Methods. */
34
+ Operator: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.Operator),
35
+ /** Browse, read/write config, read historical, call Methods, subscribe. */
36
+ Engineer: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.Engineer),
37
+ /** Browse, read live/historical data, call Methods, subscribe. */
38
+ Supervisor: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.Supervisor),
39
+ /** Change non-security related configuration. */
40
+ ConfigureAdmin: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.ConfigureAdmin),
41
+ /** Change security related settings. */
42
+ SecurityAdmin: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.WellKnownRoles.SecurityAdmin)
43
+ };
44
+ //# sourceMappingURL=well_known_role_ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"well_known_role_ids.js","sourceRoot":"","sources":["../source/well_known_role_ids.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,+DAAsD;AACtD,yDAA+C;AAE/C,kEAAkE;AAClE,6DAAsD;AAA7C,sHAAA,cAAc,OAAA;AAEvB;;;;;;;;GAQG;AACU,QAAA,gBAAgB,GAAG;IAC5B,kDAAkD;IAClD,SAAS,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,SAAS,CAAC;IAC/C,0DAA0D;IAC1D,iBAAiB,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,iBAAiB,CAAC;IAC/D,oDAAoD;IACpD,QAAQ,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,QAAQ,CAAC;IAC7C,0DAA0D;IAC1D,QAAQ,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,QAAQ,CAAC;IAC7C,2EAA2E;IAC3E,QAAQ,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,QAAQ,CAAC;IAC7C,kEAAkE;IAClE,UAAU,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,UAAU,CAAC;IACjD,iDAAiD;IACjD,cAAc,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,cAAc,CAAC;IACzD,wCAAwC;IACxC,aAAa,EAAE,IAAA,8BAAU,EAAC,qCAAc,CAAC,aAAa,CAAC;CACjD,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @module node-opcua-role-set-common
3
+ *
4
+ * Helpers for matching an `X509Subject` identity mapping rule against a
5
+ * certificate subject, following the ordered Distinguished Name format
6
+ * defined in OPC 10000-18 §4.4.3 (Table 10).
7
+ */
8
+ /**
9
+ * Subject attributes of a certificate, as exposed by
10
+ * `exploreCertificate(...).tbsCertificate.subject` (node-opcua-crypto).
11
+ */
12
+ export interface X509SubjectName {
13
+ commonName?: string;
14
+ organizationName?: string;
15
+ organizationUnitName?: string;
16
+ localityName?: string;
17
+ stateOrProvinceName?: string;
18
+ countryName?: string;
19
+ }
20
+ /**
21
+ * Order of the X509 subject name attributes (OPC 10000-18 §4.4.3, Table 10).
22
+ *
23
+ * Only the attributes that {@link X509SubjectName} exposes are mappable here
24
+ * (CN, O, OU, L, S, C). DC, dnQualifier and serialNumber are listed for
25
+ * completeness/ordering but are not extracted from certificates.
26
+ */
27
+ export declare const X509_SUBJECT_ORDER: string[];
28
+ /** Build the canonical `Name="Value"/...` string from ordered name/value pairs. */
29
+ export declare function canonicalizeX509Subject(pairs: Array<[string, string]>): string;
30
+ /** Parse a `CN="..."/O="..."` criteria String into ordered name/value pairs. */
31
+ export declare function parseX509SubjectCriteria(criteria: string): Array<[string, string]>;
32
+ /** Build ordered name/value pairs from a certificate subject. */
33
+ export declare function certificateSubjectPairs(subject: X509SubjectName): Array<[string, string]>;
34
+ /**
35
+ * Test whether an `X509Subject` criteria matches a certificate subject.
36
+ *
37
+ * Two criteria formats are accepted:
38
+ * - the full ordered DN format (e.g. `CN="Jane Doe"/O="ACME"`), in which case
39
+ * **every** mappable subject attribute present in the certificate must be
40
+ * present in the criteria and vice-versa;
41
+ * - a plain Common Name string (legacy/simplified), compared against the
42
+ * certificate's `commonName` only.
43
+ */
44
+ export declare function matchX509Subject(criteria: string, subject: X509SubjectName): boolean;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-role-set-common
4
+ *
5
+ * Helpers for matching an `X509Subject` identity mapping rule against a
6
+ * certificate subject, following the ordered Distinguished Name format
7
+ * defined in OPC 10000-18 §4.4.3 (Table 10).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.X509_SUBJECT_ORDER = void 0;
11
+ exports.canonicalizeX509Subject = canonicalizeX509Subject;
12
+ exports.parseX509SubjectCriteria = parseX509SubjectCriteria;
13
+ exports.certificateSubjectPairs = certificateSubjectPairs;
14
+ exports.matchX509Subject = matchX509Subject;
15
+ /**
16
+ * Order of the X509 subject name attributes (OPC 10000-18 §4.4.3, Table 10).
17
+ *
18
+ * Only the attributes that {@link X509SubjectName} exposes are mappable here
19
+ * (CN, O, OU, L, S, C). DC, dnQualifier and serialNumber are listed for
20
+ * completeness/ordering but are not extracted from certificates.
21
+ */
22
+ exports.X509_SUBJECT_ORDER = ["CN", "O", "OU", "DC", "L", "S", "C", "dnQualifier", "serialNumber"];
23
+ /** Build the canonical `Name="Value"/...` string from ordered name/value pairs. */
24
+ function canonicalizeX509Subject(pairs) {
25
+ return pairs
26
+ .map((pair, index) => ({ pair, index }))
27
+ .filter(({ pair }) => exports.X509_SUBJECT_ORDER.includes(pair[0]))
28
+ .sort((a, b) => {
29
+ const d = exports.X509_SUBJECT_ORDER.indexOf(a.pair[0]) - exports.X509_SUBJECT_ORDER.indexOf(b.pair[0]);
30
+ return d !== 0 ? d : a.index - b.index;
31
+ })
32
+ .map(({ pair }) => `${pair[0]}="${pair[1]}"`)
33
+ .join("/");
34
+ }
35
+ /** Parse a `CN="..."/O="..."` criteria String into ordered name/value pairs. */
36
+ function parseX509SubjectCriteria(criteria) {
37
+ const pairs = [];
38
+ const re = /([A-Za-z]+)\s*=\s*"((?:[^"])*)"/g;
39
+ for (const m of criteria.matchAll(re)) {
40
+ pairs.push([m[1], m[2]]);
41
+ }
42
+ return pairs;
43
+ }
44
+ /** Build ordered name/value pairs from a certificate subject. */
45
+ function certificateSubjectPairs(subject) {
46
+ const pairs = [];
47
+ if (subject.commonName)
48
+ pairs.push(["CN", subject.commonName]);
49
+ if (subject.organizationName)
50
+ pairs.push(["O", subject.organizationName]);
51
+ if (subject.organizationUnitName)
52
+ pairs.push(["OU", subject.organizationUnitName]);
53
+ if (subject.localityName)
54
+ pairs.push(["L", subject.localityName]);
55
+ if (subject.stateOrProvinceName)
56
+ pairs.push(["S", subject.stateOrProvinceName]);
57
+ if (subject.countryName)
58
+ pairs.push(["C", subject.countryName]);
59
+ return pairs;
60
+ }
61
+ /**
62
+ * Test whether an `X509Subject` criteria matches a certificate subject.
63
+ *
64
+ * Two criteria formats are accepted:
65
+ * - the full ordered DN format (e.g. `CN="Jane Doe"/O="ACME"`), in which case
66
+ * **every** mappable subject attribute present in the certificate must be
67
+ * present in the criteria and vice-versa;
68
+ * - a plain Common Name string (legacy/simplified), compared against the
69
+ * certificate's `commonName` only.
70
+ */
71
+ function matchX509Subject(criteria, subject) {
72
+ const trimmed = (criteria ?? "").trim();
73
+ if (/[A-Za-z]+\s*=\s*"/.test(trimmed)) {
74
+ return (canonicalizeX509Subject(certificateSubjectPairs(subject)) === canonicalizeX509Subject(parseX509SubjectCriteria(trimmed)));
75
+ }
76
+ return (subject.commonName ?? "") === trimmed;
77
+ }
78
+ //# sourceMappingURL=x509_subject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x509_subject.js","sourceRoot":"","sources":["../source/x509_subject.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAyBH,0DAUC;AAGD,4DAOC;AAGD,0DASC;AAYD,4CAQC;AA9DD;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;AAExG,mFAAmF;A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ED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "node-opcua-role-set-common",
3
+ "version": "2.174.0",
4
+ "description": "pure nodejs OPCUA SDK - role-set common types and identity stores (OPC 10000-18)",
5
+ "scripts": {
6
+ "build": "tsc -b",
7
+ "lint": "eslint source/**/*.ts",
8
+ "clean": "npx rimraf -g node_modules dist *.tsbuildinfo",
9
+ "test": "mocha",
10
+ "test:check": "tsc --noEmit -p test/tsconfig.json"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "devEngines": {
15
+ "node": ">=18.x",
16
+ "npm": ">=10.x"
17
+ },
18
+ "dependencies": {
19
+ "node-opcua-basic-types": "2.174.0",
20
+ "node-opcua-binary-stream": "2.173.0",
21
+ "node-opcua-constants": "2.174.0",
22
+ "node-opcua-crypto": "5.3.6",
23
+ "node-opcua-nodeid": "2.174.0",
24
+ "node-opcua-status-code": "2.173.0",
25
+ "node-opcua-types": "2.174.0",
26
+ "node-opcua-variant": "2.174.0"
27
+ },
28
+ "devDependencies": {
29
+ "node-opcua-leak-detector": "2.172.0"
30
+ },
31
+ "author": "Etienne Rossignon",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git://github.com/node-opcua/node-opcua.git"
36
+ },
37
+ "keywords": [
38
+ "OPCUA",
39
+ "opcua",
40
+ "m2m",
41
+ "iot",
42
+ "opc ua",
43
+ "internet of things"
44
+ ],
45
+ "homepage": "http://node-opcua.github.io/",
46
+ "gitHead": "064029878247adf2fa5d14a8124e1930431e2428",
47
+ "files": [
48
+ "dist",
49
+ "source"
50
+ ]
51
+ }