fix(exports): stabilize published types and compatibility with updated dependencies
This commit is contained in:
+23
-22
@@ -2,6 +2,7 @@ import * as plugins from './plugins.js';
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import * as https from 'https';
|
||||
import * as nodeForge from 'node-forge';
|
||||
|
||||
export interface ISigningOptions {
|
||||
certificatePem?: string;
|
||||
@@ -57,19 +58,19 @@ export class SecurityManager {
|
||||
|
||||
try {
|
||||
// Parse certificate and key
|
||||
const certificate = plugins.nodeForge.pki.certificateFromPem(cert);
|
||||
const certificate = nodeForge.pki.certificateFromPem(cert);
|
||||
const privateKey = this.options.privateKeyPassphrase
|
||||
? plugins.nodeForge.pki.decryptRsaPrivateKey(key, this.options.privateKeyPassphrase)
|
||||
: plugins.nodeForge.pki.privateKeyFromPem(key);
|
||||
? nodeForge.pki.decryptRsaPrivateKey(key, this.options.privateKeyPassphrase)
|
||||
: nodeForge.pki.privateKeyFromPem(key);
|
||||
|
||||
// Create PKCS#7 signed data (CMS)
|
||||
const p7 = plugins.nodeForge.pkcs7.createSignedData();
|
||||
const p7 = nodeForge.pkcs7.createSignedData();
|
||||
|
||||
// Add content
|
||||
if (typeof data === 'string') {
|
||||
p7.content = plugins.nodeForge.util.createBuffer(data, 'utf8');
|
||||
p7.content = nodeForge.util.createBuffer(data, 'utf8');
|
||||
} else {
|
||||
p7.content = plugins.nodeForge.util.createBuffer(data.toString('latin1'));
|
||||
p7.content = nodeForge.util.createBuffer(data.toString('latin1'));
|
||||
}
|
||||
|
||||
// Add certificate
|
||||
@@ -79,17 +80,17 @@ export class SecurityManager {
|
||||
p7.addSigner({
|
||||
key: privateKey,
|
||||
certificate: certificate,
|
||||
digestAlgorithm: plugins.nodeForge.pki.oids.sha256,
|
||||
digestAlgorithm: nodeForge.pki.oids.sha256,
|
||||
authenticatedAttributes: [
|
||||
{
|
||||
type: plugins.nodeForge.pki.oids.contentType,
|
||||
value: plugins.nodeForge.pki.oids.data
|
||||
type: nodeForge.pki.oids.contentType,
|
||||
value: nodeForge.pki.oids.data
|
||||
},
|
||||
{
|
||||
type: plugins.nodeForge.pki.oids.messageDigest
|
||||
type: nodeForge.pki.oids.messageDigest
|
||||
},
|
||||
{
|
||||
type: plugins.nodeForge.pki.oids.signingTime,
|
||||
type: nodeForge.pki.oids.signingTime,
|
||||
value: new Date().toISOString()
|
||||
}
|
||||
]
|
||||
@@ -99,7 +100,7 @@ export class SecurityManager {
|
||||
p7.sign({ detached: true });
|
||||
|
||||
// Convert to PEM
|
||||
const pem = plugins.nodeForge.pkcs7.messageToPem(p7);
|
||||
const pem = nodeForge.pkcs7.messageToPem(p7);
|
||||
|
||||
// Extract base64 signature
|
||||
const signature = pem
|
||||
@@ -237,14 +238,14 @@ export class SecurityManager {
|
||||
}
|
||||
|
||||
// Parse the PKCS#7 message
|
||||
const p7 = plugins.nodeForge.pkcs7.messageFromPem(pemSignature);
|
||||
const p7 = nodeForge.pkcs7.messageFromPem(pemSignature);
|
||||
|
||||
// Prepare content for verification
|
||||
let content: plugins.nodeForge.util.ByteStringBuffer;
|
||||
let content: nodeForge.util.ByteStringBuffer;
|
||||
if (typeof data === 'string') {
|
||||
content = plugins.nodeForge.util.createBuffer(data, 'utf8');
|
||||
content = nodeForge.util.createBuffer(data, 'utf8');
|
||||
} else {
|
||||
content = plugins.nodeForge.util.createBuffer(data.toString('latin1'));
|
||||
content = nodeForge.util.createBuffer(data.toString('latin1'));
|
||||
}
|
||||
|
||||
// Verify the signature
|
||||
@@ -267,8 +268,8 @@ export class SecurityManager {
|
||||
commonName: string = 'SKR Export System',
|
||||
validDays: number = 365
|
||||
): Promise<{ certificate: string; privateKey: string }> {
|
||||
const keys = plugins.nodeForge.pki.rsa.generateKeyPair(2048);
|
||||
const cert = plugins.nodeForge.pki.createCertificate();
|
||||
const keys = nodeForge.pki.rsa.generateKeyPair(2048);
|
||||
const cert = nodeForge.pki.createCertificate();
|
||||
|
||||
cert.publicKey = keys.publicKey;
|
||||
cert.serialNumber = '01';
|
||||
@@ -326,11 +327,11 @@ export class SecurityManager {
|
||||
]);
|
||||
|
||||
// Self-sign certificate
|
||||
cert.sign(keys.privateKey, plugins.nodeForge.md.sha256.create());
|
||||
cert.sign(keys.privateKey, nodeForge.md.sha256.create());
|
||||
|
||||
// Convert to PEM
|
||||
const certificatePem = plugins.nodeForge.pki.certificateToPem(cert);
|
||||
const privateKeyPem = plugins.nodeForge.pki.privateKeyToPem(keys.privateKey);
|
||||
const certificatePem = nodeForge.pki.certificateToPem(cert);
|
||||
const privateKeyPem = nodeForge.pki.privateKeyToPem(keys.privateKey);
|
||||
|
||||
return {
|
||||
certificate: certificatePem,
|
||||
@@ -402,4 +403,4 @@ export class SecurityManager {
|
||||
|
||||
return ltv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user