1 | import { chmodSync } from 'fs';
|
2 | import { exec, execSync, ExecSyncOptions } from 'child_process';
|
3 | import * as createDebug from 'debug';
|
4 | import * as path from 'path';
|
5 |
|
6 | import {
|
7 | configPath,
|
8 | } from './constants';
|
9 |
|
10 | const debug = createDebug('devcert');
|
11 |
|
12 | export 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 |
|
21 | export function run(cmd: string, options: ExecSyncOptions = {}) {
|
22 | debug(`exec: \`${ cmd }\``);
|
23 | return execSync(cmd, options);
|
24 | }
|
25 |
|
26 | export function waitForUser() {
|
27 | return new Promise((resolve) => {
|
28 | process.stdin.resume();
|
29 | process.stdin.on('data', resolve);
|
30 | });
|
31 | }
|
32 |
|
33 |
|
34 | export function generateKey(filename: string): void {
|
35 | debug(`generateKey: ${ filename }`);
|
36 | openssl(`genrsa -out ${ filename } 2048`);
|
37 | chmodSync(filename, 400);
|
38 | }
|