From 4fdf5e9674a7a9ee6d1a710da8f864ef29057fbe Mon Sep 17 00:00:00 2001 From: Aswin V Date: Tue, 1 Mar 2022 00:42:21 +0530 Subject: [PATCH] Get public/private key from env --- .env.example | 2 ++ utils/certificate.ts | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 49022cd..1289164 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ APP_URL=http://localhost:4000 ENTITY_ID=https://saml.example.com/entityid +PUBLIC_KEY= # Base64 encoded value of public key `cat public.crt | base64` +PRIVATE_KEY=# Base64 encoded value of private key `cat key.pem | base64` \ No newline at end of file diff --git a/utils/certificate.ts b/utils/certificate.ts index 25e53e8..8f0135c 100644 --- a/utils/certificate.ts +++ b/utils/certificate.ts @@ -1,13 +1,11 @@ -import { promises as fs } from 'fs'; import { asn1, pki, util } from 'node-forge'; -import path from 'path'; -const fetchPublicKey = async (): Promise => { - return await fs.readFile(path.join('data', 'public.crt'), 'ascii'); +const fetchPublicKey = (): string => { + return Buffer.from(process.env.PUBLIC_KEY!, 'base64').toString('ascii'); }; -const fetchPrivateKey = async (): Promise => { - return await fs.readFile(path.join('data', 'key.pem'), 'ascii'); +const fetchPrivateKey = (): string => { + return Buffer.from(process.env.PRIVATE_KEY!, 'base64').toString('ascii'); }; function getPublicKeyPemFromCertificate(x509Certificate: string) {