Skip to content

Commit

Permalink
return ca
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Dec 7, 2017
1 parent 09f98ee commit e2a52e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export default async function generateDevCert (commonName: string) {
const opensslConfPath = generateOpensslConf(commonName);
const { rootKeyPath, rootCertPath } = await generateRootCertificate(commonName, opensslConfPath);
await installAuthority(commonName, rootCertPath);
const { keyPath, certPath } = generateSignedCertificate(commonName, opensslConfPath, rootKeyPath, rootCertPath);
const { keyPath, certPath, caPath } = generateSignedCertificate(commonName, opensslConfPath, rootKeyPath, rootCertPath);
const key = fs.readFileSync(keyPath).toString();
const cert = fs.readFileSync(certPath).toString();
return { key, cert };
const ca = fs.readFileSync(caPath).toString();
return { key, cert, ca };
}
finally {
// clear all tmp files (including root cert!)
Expand Down
6 changes: 3 additions & 3 deletions src/openssl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function generateRootCertificate (commonName: string, opensslConfPath: st
return { rootKeyPath, rootCertPath };
}

export function generateSignedCertificate (commonName: string, opensslConfPath: string, rootKeyPath: string, rootCertPath: string) {
export function generateSignedCertificate (commonName: string, opensslConfPath: string, rootKeyPath: string, caPath: string) {
const keyPath = generateKey();
process.env.SAN = commonName;
const csrFile = tmpFile(`${commonName}.csr`);
Expand All @@ -154,9 +154,9 @@ export function generateSignedCertificate (commonName: string, opensslConfPath:
const caCertsDir = path.join(os.tmpdir(), Math.round(Math.random() * 36 ** 10).toString(36));
mkdirp.sync(caCertsDir);

openssl(`ca -config ${opensslConfPath} -in ${csrFile} -out ${certPath} -outdir ${caCertsDir} -keyfile ${rootKeyPath} -cert ${rootCertPath} -notext -md sha256 -days 7000 -batch -extensions server_cert`)
openssl(`ca -config ${opensslConfPath} -in ${csrFile} -out ${certPath} -outdir ${caCertsDir} -keyfile ${rootKeyPath} -cert ${caPath} -notext -md sha256 -days 7000 -batch -extensions server_cert`)

rimraf.sync(caCertsDir);

return { keyPath, certPath };
return { keyPath, certPath, caPath };
}

0 comments on commit e2a52e5

Please sign in to comment.