UNPKG

@peculiar/fortify-client-core

Version:

Fortify client core API for quickly connect to Fortify App

67 lines (66 loc) 2.42 kB
"use strict"; /** * @license * Copyright (c) Peculiar Ventures, LLC. * * This source code is licensed under the BSD 3-Clause license found in the * LICENSE file in the root directory of this source tree. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Create = exports.EName = void 0; const x509 = require("@peculiar/x509"); var EName; (function (EName) { EName["CommonName"] = "CN"; EName["Country"] = "C"; EName["Region"] = "L"; EName["State"] = "ST"; EName["Organization"] = "O"; EName["OrganizationUnit"] = "OU"; })(EName = exports.EName || (exports.EName = {})); class Create { static async pkcs10(crypto, algorithm, subjectName) { const keys = await crypto.subtle.generateKey(algorithm, false, Create.keyUsages); const pkcs10 = await x509.Pkcs10CertificateRequestGenerator.create({ name: subjectName, keys, signingAlgorithm: algorithm, extensions: [], attributes: [], }, crypto); return { der: pkcs10.rawData, pem: pkcs10.toString('pem'), privateKey: keys.privateKey, publicKey: keys.publicKey, }; } static async x509(crypto, algorithm, subjectName) { const keys = await crypto.subtle.generateKey(algorithm, false, Create.keyUsages); const now = new Date(); const cert = await x509.X509CertificateGenerator.createSelfSigned({ serialNumber: '01', name: subjectName, notBefore: new Date(now.getFullYear(), now.getMonth(), now.getDate()), notAfter: new Date(now.getFullYear() + 1, now.getMonth(), now.getDate()), signingAlgorithm: algorithm, keys, extensions: [ new x509.BasicConstraintsExtension(false, 0, true), new x509.KeyUsagesExtension(x509.KeyUsageFlags.digitalSignature, true), new x509.ExtendedKeyUsageExtension([ '1.3.6.1.5.5.7.3.2', '1.3.6.1.5.5.7.3.4', // id-kp-emailProtection ], true), ], }, crypto); return { der: cert.rawData, pem: cert.toString('pem'), privateKey: keys.privateKey, publicKey: keys.publicKey, }; } } exports.Create = Create; Create.keyUsages = ['sign', 'verify'];