Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Mar 9, 2024
1 parent 51a7ce7 commit fb0c716
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from 'node:crypto'
import forge from 'node-forge'
import forge, { pki, tls } from 'node-forge'

interface GenerateCertOptions {
altNameIPs?: string[]
Expand All @@ -17,8 +17,8 @@ export function generateCert(options?: GenerateCertOptions) {
if (!options)
options = def

const keys = forge.pki.rsa.generateKeyPair(2048)
const cert = forge.pki.createCertificate()
const keys = pki.rsa.generateKeyPair(2048)
const cert = pki.createCertificate()
cert.publicKey = keys.publicKey

// NOTE: serialNumber is the hex encoded value of an ASN.1 INTEGER.
Expand Down Expand Up @@ -62,15 +62,17 @@ export function generateCert(options?: GenerateCertOptions) {
cert.sign(keys.privateKey)

// convert a Forge certificate and private key to PEM
const pem = forge.pki.certificateToPem(cert)
const privateKey = forge.pki.privateKeyToPem(keys.privateKey)
const pem = pki.certificateToPem(cert)
const privateKey = pki.privateKeyToPem(keys.privateKey)

return {
cert: pem,
privateKey,
}
}

export { tls, pki, forge }

// export function addCertToSystemTrustStore(cert: string) {
// // TODO
// }

0 comments on commit fb0c716

Please sign in to comment.