feat(ts_node): Add support for HTTPS certificate creation
This commit is contained in:
45
ts_node/classes.tapnodetools.ts
Normal file
45
ts_node/classes.tapnodetools.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
class TapNodeTools {
|
||||
|
||||
private smartshellInstance: plugins.smartshell.Smartshell;
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
public async runCommand(commandArg) {
|
||||
if (!this.smartshellInstance) {
|
||||
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
});
|
||||
}
|
||||
const result = await this.smartshellInstance.exec(commandArg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async createHttpsCert(commonName: string, keyFile: string, certFile: string): Promise<{ key: string, cert: string }> {
|
||||
const key = plugins.crypto.generateKeyPairSync('rsa', {
|
||||
modulusLength: 2048,
|
||||
publicExponent: 65537,
|
||||
});
|
||||
|
||||
const cert = '-----BEGIN CERTIFICATE-----\n' +
|
||||
key.publicKey.export({
|
||||
type: 'spki',
|
||||
format: 'pem'
|
||||
}) +
|
||||
'\n-----END CERTIFICATE-----\n';
|
||||
|
||||
const keyContent = key.privateKey.export({
|
||||
type: 'pkcs8',
|
||||
format: 'pem',
|
||||
});
|
||||
|
||||
return {
|
||||
key: keyContent as string,
|
||||
cert: cert,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const tapNodeTools = new TapNodeTools();
|
@ -1,21 +1 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
class TapNodeTools {
|
||||
|
||||
private smartshellInstance: plugins.smartshell.Smartshell;
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
public async runCommand(commandArg) {
|
||||
if (!this.smartshellInstance) {
|
||||
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
});
|
||||
}
|
||||
const result = await this.smartshellInstance.exec(commandArg);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const tapNodeTools = new TapNodeTools();
|
||||
export * from './classes.tapnodetools.js';
|
||||
|
@ -1,3 +1,10 @@
|
||||
// node native
|
||||
import * as crypto from 'crypto';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export { crypto,fs };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export { smartshell };
|
||||
|
Reference in New Issue
Block a user