node-opcua-server-configuration 2.163.0 → 2.164.2
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.
- package/dist/clientTools/certificate_types.d.ts +17 -0
- package/dist/clientTools/certificate_types.js +20 -0
- package/dist/clientTools/certificate_types.js.map +1 -0
- package/dist/clientTools/get_certificate_key_type.d.ts +6 -0
- package/dist/clientTools/get_certificate_key_type.js +55 -0
- package/dist/clientTools/get_certificate_key_type.js.map +1 -0
- package/dist/clientTools/index.d.ts +2 -1
- package/dist/clientTools/index.js +2 -17
- package/dist/clientTools/index.js.map +1 -1
- package/dist/clientTools/push_certificate_management_client.d.ts +10 -10
- package/dist/clientTools/push_certificate_management_client.js +85 -89
- package/dist/clientTools/push_certificate_management_client.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +9 -23
- package/dist/index.js.map +1 -1
- package/dist/push_certificate_manager.d.ts +4 -4
- package/dist/push_certificate_manager.js +1 -2
- package/dist/server/certificate_validation.d.ts +15 -0
- package/dist/server/certificate_validation.js +76 -0
- package/dist/server/certificate_validation.js.map +1 -0
- package/dist/server/file_transaction_manager.d.ts +30 -0
- package/dist/server/file_transaction_manager.js +223 -0
- package/dist/server/file_transaction_manager.js.map +1 -0
- package/dist/server/install_certificate_file_watcher.d.ts +1 -1
- package/dist/server/install_certificate_file_watcher.js +8 -14
- package/dist/server/install_certificate_file_watcher.js.map +1 -1
- package/dist/server/install_push_certitifate_management.d.ts +6 -6
- package/dist/server/install_push_certitifate_management.js +61 -65
- package/dist/server/install_push_certitifate_management.js.map +1 -1
- package/dist/server/promote_trust_list.d.ts +1 -1
- package/dist/server/promote_trust_list.js +323 -82
- package/dist/server/promote_trust_list.js.map +1 -1
- package/dist/server/push_certificate_manager/apply_changes.d.ts +3 -0
- package/dist/server/push_certificate_manager/apply_changes.js +59 -0
- package/dist/server/push_certificate_manager/apply_changes.js.map +1 -0
- package/dist/server/push_certificate_manager/create_signing_request.d.ts +5 -0
- package/dist/server/push_certificate_manager/create_signing_request.js +108 -0
- package/dist/server/push_certificate_manager/create_signing_request.js.map +1 -0
- package/dist/server/push_certificate_manager/get_rejected_list.d.ts +3 -0
- package/dist/server/push_certificate_manager/get_rejected_list.js +46 -0
- package/dist/server/push_certificate_manager/get_rejected_list.js.map +1 -0
- package/dist/server/push_certificate_manager/internal_context.d.ts +35 -0
- package/dist/server/push_certificate_manager/internal_context.js +45 -0
- package/dist/server/push_certificate_manager/internal_context.js.map +1 -0
- package/dist/server/push_certificate_manager/subject_to_string.d.ts +3 -0
- package/dist/server/push_certificate_manager/subject_to_string.js +27 -0
- package/dist/server/push_certificate_manager/subject_to_string.js.map +1 -0
- package/dist/server/push_certificate_manager/update_certificate.d.ts +5 -0
- package/dist/server/push_certificate_manager/update_certificate.js +132 -0
- package/dist/server/push_certificate_manager/update_certificate.js.map +1 -0
- package/dist/server/push_certificate_manager/util.d.ts +29 -0
- package/dist/server/push_certificate_manager/util.js +117 -0
- package/dist/server/push_certificate_manager/util.js.map +1 -0
- package/dist/server/push_certificate_manager_helpers.d.ts +5 -2
- package/dist/server/push_certificate_manager_helpers.js +109 -112
- package/dist/server/push_certificate_manager_helpers.js.map +1 -1
- package/dist/server/push_certificate_manager_server_impl.d.ts +16 -29
- package/dist/server/push_certificate_manager_server_impl.js +49 -437
- package/dist/server/push_certificate_manager_server_impl.js.map +1 -1
- package/dist/server/roles_and_permissions.d.ts +1 -1
- package/dist/server/roles_and_permissions.js +24 -27
- package/dist/server/roles_and_permissions.js.map +1 -1
- package/dist/server/tools.d.ts +1 -1
- package/dist/server/tools.js +7 -13
- package/dist/server/tools.js.map +1 -1
- package/dist/server/trust_list_server.d.ts +2 -2
- package/dist/server/trust_list_server.js +40 -29
- package/dist/server/trust_list_server.js.map +1 -1
- package/dist/standard_certificate_types.js +6 -9
- package/dist/standard_certificate_types.js.map +1 -1
- package/dist/trust_list.d.ts +2 -2
- package/dist/trust_list.js +1 -2
- package/dist/trust_list_impl.js +1 -2
- package/dist/trust_list_impl.js.map +1 -1
- package/package.json +29 -30
- package/source/clientTools/certificate_types.ts +21 -0
- package/source/clientTools/get_certificate_key_type.ts +73 -0
- package/source/clientTools/index.ts +2 -1
- package/source/clientTools/push_certificate_management_client.ts +49 -44
- package/source/index.ts +9 -7
- package/source/push_certificate_manager.ts +15 -17
- package/source/server/certificate_validation.ts +103 -0
- package/source/server/file_transaction_manager.ts +253 -0
- package/source/server/install_certificate_file_watcher.ts +15 -11
- package/source/server/install_push_certitifate_management.ts +52 -51
- package/source/server/promote_trust_list.ts +362 -73
- package/source/server/push_certificate_manager/apply_changes.ts +63 -0
- package/source/server/push_certificate_manager/create_signing_request.ts +137 -0
- package/source/server/push_certificate_manager/get_rejected_list.ts +63 -0
- package/source/server/push_certificate_manager/internal_context.ts +63 -0
- package/source/server/push_certificate_manager/subject_to_string.ts +25 -0
- package/source/server/push_certificate_manager/update_certificate.ts +201 -0
- package/source/server/push_certificate_manager/util.ts +145 -0
- package/source/server/push_certificate_manager_helpers.ts +61 -51
- package/source/server/push_certificate_manager_server_impl.ts +94 -553
- package/source/server/roles_and_permissions.ts +7 -8
- package/source/server/tools.ts +2 -5
- package/source/server/trust_list_server.ts +24 -9
- package/source/standard_certificate_types.ts +2 -3
- package/source/trust_list.ts +26 -33
package/dist/index.js
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
1
|
/**
|
|
18
2
|
* @module node-opcua-server-configuration
|
|
19
3
|
*/
|
|
20
4
|
// export * from "./trust_list_impl";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
export * from "./clientTools/certificate_types.js";
|
|
6
|
+
export * from "./clientTools/push_certificate_management_client.js";
|
|
7
|
+
export * from "./push_certificate_manager.js";
|
|
8
|
+
export * from "./server/install_push_certitifate_management.js";
|
|
9
|
+
export * from "./server/promote_trust_list.js";
|
|
10
|
+
export * from "./server/push_certificate_manager/subject_to_string.js";
|
|
11
|
+
export * from "./server/push_certificate_manager_helpers.js";
|
|
12
|
+
export * from "./server/push_certificate_manager_server_impl.js";
|
|
13
|
+
export * from "./standard_certificate_types.js";
|
|
28
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qCAAqC;AAErC,cAAc,oCAAoC,CAAC;AACnD,cAAc,qDAAqD,CAAC;AACpE,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iDAAiD,CAAC;AAChE,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wDAAwD,CAAC;AACvE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,kDAAkD,CAAC;AACjE,cAAc,iCAAiC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module node-opcua-server-configuration
|
|
3
3
|
*/
|
|
4
|
-
import { ByteString, UAString } from "node-opcua-basic-types";
|
|
5
|
-
import { NodeId } from "node-opcua-nodeid";
|
|
6
|
-
import { StatusCode } from "node-opcua-status-code";
|
|
4
|
+
import type { ByteString, UAString } from "node-opcua-basic-types";
|
|
5
|
+
import type { NodeId } from "node-opcua-nodeid";
|
|
6
|
+
import type { StatusCode } from "node-opcua-status-code";
|
|
7
7
|
export interface CreateSigningRequestResult {
|
|
8
8
|
statusCode: StatusCode;
|
|
9
9
|
certificateSigningRequest?: Buffer;
|
|
@@ -58,7 +58,7 @@ export interface PushCertificateManager {
|
|
|
58
58
|
* BadSecurityChecksFailed Some failure occurred verifying the integrity of the Certificate.
|
|
59
59
|
*
|
|
60
60
|
*/
|
|
61
|
-
updateCertificate(certificateGroupId: NodeId | string, certificateTypeId: NodeId | string, certificate: ByteString, issuerCertificates: ByteString[], privateKeyFormat
|
|
61
|
+
updateCertificate(certificateGroupId: NodeId | string, certificateTypeId: NodeId | string, certificate: ByteString, issuerCertificates: ByteString[], privateKeyFormat?: UAString, privateKey?: ByteString): Promise<UpdateCertificateResult>;
|
|
62
62
|
/**
|
|
63
63
|
* The ApplyChanges Method is used to apply any security related changes if the Server sets
|
|
64
64
|
* the applyChangesRequired flag when another Method is called. Servers should minimize the
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-server-configuration-server
|
|
3
|
+
*/
|
|
4
|
+
import type { ByteString } from "node-opcua-basic-types";
|
|
5
|
+
import type { OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
6
|
+
import { type StatusCode } from "node-opcua-status-code";
|
|
7
|
+
/**
|
|
8
|
+
* Validates the certificate and its issuer chain, including parsing, date validity,
|
|
9
|
+
* chain verification, and trust verification.
|
|
10
|
+
* @returns Object with statusCode. If Good, also contains the concatenated certificateChain.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateCertificateAndChain(certificateManager: OPCUACertificateManager, isApplicationGroup: boolean, certificate: Buffer, issuerCertificates: ByteString[] | null | undefined): Promise<{
|
|
13
|
+
statusCode: StatusCode;
|
|
14
|
+
certificateChain?: Buffer;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { exploreCertificate, verifyCertificateChain } from "node-opcua-crypto/web";
|
|
2
|
+
import { make_errorLog, make_warningLog } from "node-opcua-debug";
|
|
3
|
+
import { StatusCodes } from "node-opcua-status-code";
|
|
4
|
+
const warningLog = make_warningLog("ServerConfiguration");
|
|
5
|
+
const errorLog = make_errorLog("ServerConfiguration");
|
|
6
|
+
/**
|
|
7
|
+
* Validates the certificate and its issuer chain, including parsing, date validity,
|
|
8
|
+
* chain verification, and trust verification.
|
|
9
|
+
* @returns Object with statusCode. If Good, also contains the concatenated certificateChain.
|
|
10
|
+
*/
|
|
11
|
+
export async function validateCertificateAndChain(certificateManager, isApplicationGroup, certificate, issuerCertificates) {
|
|
12
|
+
let certInfo;
|
|
13
|
+
try {
|
|
14
|
+
certInfo = exploreCertificate(certificate);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
errorLog("Cannot parse certificate:", err.message);
|
|
18
|
+
return { statusCode: StatusCodes.BadCertificateInvalid };
|
|
19
|
+
}
|
|
20
|
+
const issuerCertBuffers = (issuerCertificates || []).filter((cert) => {
|
|
21
|
+
return Buffer.isBuffer(cert) && cert.length > 0;
|
|
22
|
+
});
|
|
23
|
+
if ((issuerCertificates || []).length !== issuerCertBuffers.length) {
|
|
24
|
+
warningLog("issuerCertificates contains invalid entries");
|
|
25
|
+
return { statusCode: StatusCodes.BadCertificateInvalid };
|
|
26
|
+
}
|
|
27
|
+
for (const issuerCert of issuerCertBuffers) {
|
|
28
|
+
try {
|
|
29
|
+
const issuerInfo = exploreCertificate(issuerCert);
|
|
30
|
+
const nowIssuer = new Date();
|
|
31
|
+
if (issuerInfo.tbsCertificate.validity.notBefore.getTime() > nowIssuer.getTime()) {
|
|
32
|
+
warningLog("Issuer certificate is not yet valid");
|
|
33
|
+
return { statusCode: StatusCodes.BadSecurityChecksFailed };
|
|
34
|
+
}
|
|
35
|
+
if (issuerInfo.tbsCertificate.validity.notAfter.getTime() < nowIssuer.getTime()) {
|
|
36
|
+
warningLog("Issuer certificate is out of date");
|
|
37
|
+
return { statusCode: StatusCodes.BadSecurityChecksFailed };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
errorLog("Cannot parse issuer certificate:", err.message);
|
|
42
|
+
return { statusCode: StatusCodes.BadCertificateInvalid };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (issuerCertBuffers.length > 0) {
|
|
46
|
+
const chainCheck = await verifyCertificateChain([certificate, ...issuerCertBuffers]);
|
|
47
|
+
if (chainCheck.status !== "Good") {
|
|
48
|
+
warningLog("Issuer chain validation failed:", chainCheck.status, chainCheck.reason);
|
|
49
|
+
return { statusCode: StatusCodes.BadSecurityChecksFailed };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const certificateChain = Buffer.concat([certificate, ...issuerCertBuffers]);
|
|
53
|
+
// Trust validation is only relevant for client certificates, not the server's own certificate
|
|
54
|
+
if (!isApplicationGroup) {
|
|
55
|
+
if (certificateManager.verifyCertificate) {
|
|
56
|
+
const status = await certificateManager.verifyCertificate(certificateChain, {
|
|
57
|
+
acceptCertificateWithValidIssuerChain: true
|
|
58
|
+
});
|
|
59
|
+
if (status !== "Good") {
|
|
60
|
+
warningLog("Certificate trust validation failed:", status);
|
|
61
|
+
return { statusCode: StatusCodes.BadSecurityChecksFailed };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const now = new Date();
|
|
66
|
+
if (certInfo.tbsCertificate.validity.notBefore.getTime() > now.getTime()) {
|
|
67
|
+
warningLog("Certificate is not yet valid : not before ", certInfo.tbsCertificate.validity.notBefore.toISOString(), "now = ", now.toISOString());
|
|
68
|
+
return { statusCode: StatusCodes.BadSecurityChecksFailed };
|
|
69
|
+
}
|
|
70
|
+
if (certInfo.tbsCertificate.validity.notAfter.getTime() < now.getTime()) {
|
|
71
|
+
warningLog("Certificate is already out of date : not after ", certInfo.tbsCertificate.validity.notAfter.toISOString(), "now = ", now.toISOString());
|
|
72
|
+
return { statusCode: StatusCodes.BadSecurityChecksFailed };
|
|
73
|
+
}
|
|
74
|
+
return { statusCode: StatusCodes.Good, certificateChain };
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=certificate_validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certificate_validation.js","sourceRoot":"","sources":["../../source/server/certificate_validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAmB,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEtE,MAAM,UAAU,GAAG,eAAe,CAAC,qBAAqB,CAAC,CAAC;AAC1D,MAAM,QAAQ,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC7C,kBAA2C,EAC3C,kBAA2B,EAC3B,WAAmB,EACnB,kBAAmD;IAEnD,IAAI,QAA8B,CAAC;IACnC,IAAI,CAAC;QACD,QAAQ,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,QAAQ,CAAC,2BAA2B,EAAG,GAAa,CAAC,OAAO,CAAC,CAAC;QAC9D,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,qBAAqB,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,iBAAiB,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAA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IAC/D,CAAC;IACD,IAAI,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;QACtE,UAAU,CACN,iDAAiD,EACjD,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,EACvD,QAAQ,EACR,GAAG,CAAC,WAAW,EAAE,CACpB,CAAC;QACF,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,uBAAuB,EAAE,CAAC;IAC/D,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,IAAI,EAAE,gBAAgB,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-server-configuration-server
|
|
3
|
+
*/
|
|
4
|
+
type Functor = () => Promise<void>;
|
|
5
|
+
export declare class FileTransactionManager {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Gets or initializes the underlying temporary directory for the transaction.
|
|
9
|
+
*/
|
|
10
|
+
getTmpDir(): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Stages a file for writing during the transaction.
|
|
13
|
+
* Writes the content to a temporary location and registers
|
|
14
|
+
* a move operation to atomically place it at destinationPath upon applyFileOps().
|
|
15
|
+
*/
|
|
16
|
+
stageFile(destinationPath: string, content: Buffer | string, encoding?: BufferEncoding): Promise<void>;
|
|
17
|
+
addFileOp(functor: Functor): void;
|
|
18
|
+
addCleanupTask(functor: Functor): void;
|
|
19
|
+
get pendingTasksCount(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Abort the current transaction by clearing pending file operations
|
|
22
|
+
* and deleting the temporary staging folder.
|
|
23
|
+
*/
|
|
24
|
+
abortTransaction(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Commit the transaction by executing all pending file operations.
|
|
27
|
+
*/
|
|
28
|
+
applyFileOps(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-server-configuration-server
|
|
3
|
+
*/
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
|
|
9
|
+
const debugLog = make_debugLog("ServerConfiguration");
|
|
10
|
+
const errorLog = make_errorLog("ServerConfiguration");
|
|
11
|
+
const warningLog = make_warningLog("ServerConfiguration");
|
|
12
|
+
async function _copyFile(source, dest) {
|
|
13
|
+
try {
|
|
14
|
+
debugLog("copying file \n source ", source, "\n =>\n dest ", dest);
|
|
15
|
+
const sourceExist = fs.existsSync(source);
|
|
16
|
+
if (sourceExist) {
|
|
17
|
+
await fs.promises.copyFile(source, dest);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
errorLog(err);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function _deleteFile(file) {
|
|
25
|
+
try {
|
|
26
|
+
const exists = fs.existsSync(file);
|
|
27
|
+
if (exists) {
|
|
28
|
+
debugLog("deleting file ", file);
|
|
29
|
+
await fs.promises.unlink(file);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
errorLog(err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function _moveFile(source, dest) {
|
|
37
|
+
debugLog("moving file file \n source ", source, "\n =>\n dest ", dest);
|
|
38
|
+
try {
|
|
39
|
+
await _copyFile(source, dest);
|
|
40
|
+
await _deleteFile(source);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
errorLog(err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function _moveFileWithBackup(source, dest, backupPath) {
|
|
47
|
+
// let make a copy of the destination file
|
|
48
|
+
debugLog("moveFileWithBackup file \n source ", source, "\n =>\n dest ", dest);
|
|
49
|
+
await _copyFile(dest, backupPath);
|
|
50
|
+
await _moveFile(source, dest);
|
|
51
|
+
}
|
|
52
|
+
export class FileTransactionManager {
|
|
53
|
+
#pendingFileOps = [];
|
|
54
|
+
#cleanupTasks = [];
|
|
55
|
+
#backupFiles = new Map();
|
|
56
|
+
#tmpdir;
|
|
57
|
+
/**
|
|
58
|
+
* Gets or initializes the underlying temporary directory for the transaction.
|
|
59
|
+
*/
|
|
60
|
+
async getTmpDir() {
|
|
61
|
+
if (!this.#tmpdir) {
|
|
62
|
+
const tempBase = path.join(os.tmpdir(), "node-opcua-tx-");
|
|
63
|
+
this.#tmpdir = await fs.promises.mkdtemp(tempBase);
|
|
64
|
+
}
|
|
65
|
+
return this.#tmpdir;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Stages a file for writing during the transaction.
|
|
69
|
+
* Writes the content to a temporary location and registers
|
|
70
|
+
* a move operation to atomically place it at destinationPath upon applyFileOps().
|
|
71
|
+
*/
|
|
72
|
+
async stageFile(destinationPath, content, encoding) {
|
|
73
|
+
// ensure tmpdir exists
|
|
74
|
+
const tmpDir = await this.getTmpDir();
|
|
75
|
+
const uniqueFileName = `${crypto.randomBytes(16).toString("hex")}.tmp`;
|
|
76
|
+
const tempFilePath = path.join(tmpDir, uniqueFileName);
|
|
77
|
+
if (encoding) {
|
|
78
|
+
await fs.promises.writeFile(tempFilePath, content, encoding);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
await fs.promises.writeFile(tempFilePath, content);
|
|
82
|
+
}
|
|
83
|
+
this.addFileOp(() => this.#moveFileWithBackupTracked(tempFilePath, destinationPath));
|
|
84
|
+
}
|
|
85
|
+
addFileOp(functor) {
|
|
86
|
+
this.#pendingFileOps.push(functor);
|
|
87
|
+
}
|
|
88
|
+
addCleanupTask(functor) {
|
|
89
|
+
this.#cleanupTasks.push(functor);
|
|
90
|
+
}
|
|
91
|
+
get pendingTasksCount() {
|
|
92
|
+
return this.#pendingFileOps.length;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Abort the current transaction by clearing pending file operations
|
|
96
|
+
* and deleting the temporary staging folder.
|
|
97
|
+
*/
|
|
98
|
+
async abortTransaction() {
|
|
99
|
+
this.#pendingFileOps.length = 0;
|
|
100
|
+
await this.#executeCleanupTasks();
|
|
101
|
+
await this.#cleanupTempFolder();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Move file with backup and track the backup for potential rollback.
|
|
105
|
+
* This method creates a backup of the destination file and tracks it
|
|
106
|
+
* so it can be restored if the transaction fails.
|
|
107
|
+
*/
|
|
108
|
+
async #moveFileWithBackupTracked(source, dest) {
|
|
109
|
+
const tmpDir = await this.getTmpDir();
|
|
110
|
+
const uniqueFileName = `${crypto.randomBytes(16).toString("hex")}_backup.tmp`;
|
|
111
|
+
const backupPath = path.join(tmpDir, uniqueFileName);
|
|
112
|
+
// Track the backup before creating it
|
|
113
|
+
this.#backupFiles.set(dest, backupPath);
|
|
114
|
+
// Perform the actual move with backup
|
|
115
|
+
await _moveFileWithBackup(source, dest, backupPath);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Commit the transaction by executing all pending file operations.
|
|
119
|
+
*/
|
|
120
|
+
async applyFileOps() {
|
|
121
|
+
debugLog("start applyFileOps");
|
|
122
|
+
const fileOperation = this.#pendingFileOps.splice(0);
|
|
123
|
+
try {
|
|
124
|
+
while (fileOperation.length) {
|
|
125
|
+
const op = fileOperation.shift();
|
|
126
|
+
await op?.();
|
|
127
|
+
}
|
|
128
|
+
debugLog("end applyFileOps");
|
|
129
|
+
// Transaction successful - clean up backup files
|
|
130
|
+
await this.#cleanupBackupFiles();
|
|
131
|
+
await this.#executeCleanupTasks();
|
|
132
|
+
await this.#cleanupTempFolder();
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
errorLog("Error during applyFileOps:", err.message);
|
|
136
|
+
errorLog("Rolling back transaction to restore previous certificate state");
|
|
137
|
+
// Rollback: restore all backup files to their original locations
|
|
138
|
+
try {
|
|
139
|
+
await this.#rollbackTransaction();
|
|
140
|
+
debugLog("Transaction rollback successful");
|
|
141
|
+
}
|
|
142
|
+
catch (rollbackErr) {
|
|
143
|
+
errorLog("Critical: Rollback failed:", rollbackErr.message);
|
|
144
|
+
errorLog("Certificate state may be inconsistent - manual intervention required");
|
|
145
|
+
}
|
|
146
|
+
// Clear backup tracking after rollback
|
|
147
|
+
this.#backupFiles.clear();
|
|
148
|
+
await this.#executeCleanupTasks();
|
|
149
|
+
await this.#cleanupTempFolder();
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Rollback the transaction by restoring all backup files.
|
|
155
|
+
* This restores files from their *_old backups to recover the previous state.
|
|
156
|
+
*/
|
|
157
|
+
async #rollbackTransaction() {
|
|
158
|
+
debugLog("Rolling back transaction, restoring", this.#backupFiles.size, "backup files");
|
|
159
|
+
const rollbackPromises = [];
|
|
160
|
+
for (const [dest, backupPath] of this.#backupFiles.entries()) {
|
|
161
|
+
rollbackPromises.push((async () => {
|
|
162
|
+
try {
|
|
163
|
+
// Check if backup exists before trying to restore
|
|
164
|
+
if (fs.existsSync(backupPath)) {
|
|
165
|
+
debugLog("Restoring backup:", backupPath, "to", dest);
|
|
166
|
+
await _copyFile(backupPath, dest);
|
|
167
|
+
// Delete backup immediately after restoration
|
|
168
|
+
await _deleteFile(backupPath);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
errorLog("Error restoring backup file", backupPath, "to", dest, ":", err.message);
|
|
173
|
+
}
|
|
174
|
+
})());
|
|
175
|
+
}
|
|
176
|
+
await Promise.all(rollbackPromises);
|
|
177
|
+
debugLog("Transaction rollback completed");
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Clean up backup files after successful transaction.
|
|
181
|
+
* Removes all *_old backup files that were created during the transaction.
|
|
182
|
+
*/
|
|
183
|
+
async #cleanupBackupFiles() {
|
|
184
|
+
debugLog("Cleaning up", this.#backupFiles.size, "backup files");
|
|
185
|
+
const cleanupPromises = [];
|
|
186
|
+
for (const backupPath of this.#backupFiles.values()) {
|
|
187
|
+
cleanupPromises.push(_deleteFile(backupPath).catch((err) => {
|
|
188
|
+
warningLog("Failed to delete backup file", backupPath, ":", err);
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
await Promise.all(cleanupPromises);
|
|
192
|
+
this.#backupFiles.clear();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Clean up the temporary transaction folder.
|
|
196
|
+
*/
|
|
197
|
+
async #cleanupTempFolder() {
|
|
198
|
+
if (this.#tmpdir) {
|
|
199
|
+
try {
|
|
200
|
+
await fs.promises.rm(this.#tmpdir, { recursive: true, force: true });
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
warningLog("Failed to delete temporary transaction folder", this.#tmpdir, ":", err);
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
this.#tmpdir = undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async #executeCleanupTasks() {
|
|
211
|
+
debugLog("Executing cleanup tasks");
|
|
212
|
+
const tasks = this.#cleanupTasks.splice(0);
|
|
213
|
+
for (const task of tasks) {
|
|
214
|
+
try {
|
|
215
|
+
await task();
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
errorLog("Error during cleanup task:", err.message);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=file_transaction_manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file_transaction_manager.js","sourceRoot":"","sources":["../../source/server/file_transaction_manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAA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AG,GAAa,CAAC,OAAO,CAAC,CAAC;YACnE,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
10
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)("ServerConfiguration");
|
|
11
|
-
function installCertificateFileWatcher(node, certificateFile) {
|
|
12
|
-
const fileToWatch = path_1.default.basename(certificateFile);
|
|
13
|
-
const fsWatcher = fs_1.default.watch(path_1.default.dirname(certificateFile), { persistent: false }, (eventType, filename) => {
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { make_debugLog } from "node-opcua-debug";
|
|
4
|
+
const debugLog = make_debugLog("ServerConfiguration");
|
|
5
|
+
export function installCertificateFileWatcher(node, certificateFile) {
|
|
6
|
+
const fileToWatch = path.basename(certificateFile);
|
|
7
|
+
const fsWatcher = fs.watch(path.dirname(certificateFile), { persistent: false }, (_eventType, filename) => {
|
|
14
8
|
/** */
|
|
15
9
|
if (filename === fileToWatch) {
|
|
16
10
|
debugLog("filename changed = ", filename, fileToWatch);
|
|
@@ -18,7 +12,7 @@ function installCertificateFileWatcher(node, certificateFile) {
|
|
|
18
12
|
}
|
|
19
13
|
});
|
|
20
14
|
const addressSpace = node.addressSpace;
|
|
21
|
-
addressSpace
|
|
15
|
+
addressSpace?.registerShutdownTask(() => {
|
|
22
16
|
fsWatcher.close();
|
|
23
17
|
});
|
|
24
18
|
return node;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install_certificate_file_watcher.js","sourceRoot":"","sources":["../../source/server/install_certificate_file_watcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"install_certificate_file_watcher.js","sourceRoot":"","sources":["../../source/server/install_certificate_file_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,QAAQ,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;AAKtD,MAAM,UAAU,6BAA6B,CAAC,IAAc,EAAE,eAAuB;IACjF,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IACnD,MAAM,SAAS,GAAG,EAAE,CAAC,KAAK,CACtB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAC7B,EAAE,UAAU,EAAE,KAAK,EAAE,EACrB,CAAC,UAA+B,EAAE,QAAQ,EAAE,EAAE;QAC1C,MAAM;QACN,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;YAC3B,QAAQ,CAAC,qBAAqB,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;YACvD,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACnC,CAAC;IACL,CAAC,CACJ,CAAC;IACF,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;IACvC,YAAY,EAAE,oBAAoB,CAAC,GAAG,EAAE;QACpC,SAAS,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,OAAO,IAAiC,CAAC;AAC7C,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AddressSpace } from "node-opcua-address-space";
|
|
2
|
-
import { OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { OPCUAServer } from "node-opcua-server";
|
|
6
|
-
import { ApplicationDescriptionOptions } from "node-opcua-types";
|
|
1
|
+
import type { AddressSpace } from "node-opcua-address-space";
|
|
2
|
+
import type { OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
3
|
+
import type { ICertificateKeyPairProviderPriv } from "node-opcua-common";
|
|
4
|
+
import { type Certificate, type PrivateKey } from "node-opcua-crypto/web";
|
|
5
|
+
import type { OPCUAServer } from "node-opcua-server";
|
|
6
|
+
import type { ApplicationDescriptionOptions } from "node-opcua-types";
|
|
7
7
|
export interface OPCUAServerPartial extends ICertificateKeyPairProviderPriv {
|
|
8
8
|
serverInfo?: ApplicationDescriptionOptions;
|
|
9
9
|
serverCertificateManager: OPCUACertificateManager;
|