How to use the node-opcua-crypto.convertPEMtoDER function in node-opcua-crypto

To help you get started, we’ve selected a few node-opcua-crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / server / install_push_certitifate_management.ts View on Github external
async function onCertificateChange(server: OPCUAServer) {

    debugLog("on CertificateChanged");

    const _server = server as any as OPCUAServerPartial;

    _server.$$privateKeyPEM = fs.readFileSync(server.serverCertificateManager.privateKey, "utf8");
    const certificateFile = path.join(server.serverCertificateManager.rootDir, "own/certs/certificate.pem");
    const certificatePEM = fs.readFileSync(certificateFile, "utf8");

    const privateKeyFile = server.serverCertificateManager.privateKey;
    const privateKeyPEM = fs.readFileSync(privateKeyFile, "utf8");
    // also reread the private key

    _server.$$certificateChain = convertPEMtoDER(certificatePEM);
    _server.$$privateKeyPEM = privateKeyPEM;
    // note : $$certificate will be reconstructed on demand
    _server.$$certificate = undefined;

    setTimeout(async () => {
        try {
            debugLog(chalk.yellow(" onCertificateChange => shutting down channels"));
            await server.shutdownChannels();
            debugLog(chalk.yellow(" onCertificateChange => channels shut down"));

            debugLog(chalk.yellow(" onCertificateChange => resuming end points"));
            await server.resumeEndPoints();
            debugLog(chalk.yellow(" onCertificateChange => end points resumed"));

            debugLog(chalk.yellow("channels have been closed -> client should reconnect "));
github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / server / install_push_certitifate_management.ts View on Github external
startDate: new Date(),

                validity: 365 * 5, // five year

                /* */
                outputFile: certificateFile

            };

            debugLog("creating self signed certificate", options);
            await this.serverCertificateManager.createSelfSignedCertificate(options);

        }
        const certificatePEM =
            await promisify(fs.readFile)(certificateFile, "utf8");
        this.$$certificateChain = convertPEMtoDER(certificatePEM);

    }
}
github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / server / push_certificate_manager_server_impl.ts View on Github external
}

        // todo : at this time regenerate PrivateKey is not supported
        if (regeneratePrivateKey) {
            debugLog(" regeneratePrivateKey = true not supported yet");
            return {
                statusCode: StatusCodes.BadInvalidArgument
            };
        }

        const options = {
            subject: subjectName
        };
        const csrfile = await certificateManager.createCertificateRequest(options);
        const csrPEM = await promisify(fs.readFile)(csrfile, "utf8");
        const certificateSigningRequest = convertPEMtoDER(csrPEM);
        return {
            certificateSigningRequest,
            statusCode: StatusCodes.Good
        };

    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
public toString(): string {

        const privateKey1 = convertPEMtoDER(this.getPrivateKey());

        const txt =
          " end point" + this._counter +
          " port = " + this.port +
          " l = " + this._endpoints.length +
          " " + makeSHA1Thumbprint(this.getCertificateChain()).toString("hex") +
          " " + makeSHA1Thumbprint(privateKey1).toString("hex");
        return txt;
    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
public toString(): string {

        const privateKey1 = convertPEMtoDER(this.getPrivateKey());

        const txt =
          " end point" + this._counter +
          " port = " + this.port +
          " l = " + this._endpoints.length +
          " " + makeSHA1Thumbprint(this.getCertificateChain()).toString("hex") +
          " " + makeSHA1Thumbprint(privateKey1).toString("hex");
        return txt;
    }
github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / server / install_push_certitifate_management.ts View on Github external
function getCertificateChainEP(this: OPCUAServerEndPoint): Certificate {

    const certificateFile = path.join(this.certificateManager.rootDir, "own/certs/certificate.pem");
    const certificatePEM = fs.readFileSync(certificateFile, "utf8");
    const $$certificateChain = convertPEMtoDER(certificatePEM);
    const thumbprint = makeSHA1Thumbprint($$certificateChain);

    return $$certificateChain;
}