UNPKG

983 BPlain TextView Raw
1import { chmodSync } from 'fs';
2import { exec, execSync, ExecSyncOptions } from 'child_process';
3import * as createDebug from 'debug';
4import * as path from 'path';
5
6import {
7 configPath,
8} from './constants';
9
10const debug = createDebug('devcert');
11
12export function openssl(cmd: string) {
13 return run(`openssl ${ cmd }`, {
14 stdio: 'ignore',
15 env: Object.assign({
16 RANDFILE: path.join(configPath('.rnd'))
17 }, process.env)
18 });
19}
20
21export function run(cmd: string, options: ExecSyncOptions = {}) {
22 debug(`exec: \`${ cmd }\``);
23 return execSync(cmd, options);
24}
25
26export function waitForUser() {
27 return new Promise((resolve) => {
28 process.stdin.resume();
29 process.stdin.on('data', resolve);
30 });
31}
32
33// Generate a cryptographic key, used to sign certificates or certificate signing requests.
34export function generateKey(filename: string): void {
35 debug(`generateKey: ${ filename }`);
36 openssl(`genrsa -out ${ filename } 2048`);
37 chmodSync(filename, 400);
38}