fix: refactor serviceKey undefined handling

Check serviceKey directly after parsing instead of checking existing?.serviceKey.
This fixes a bug where key parsing failures would be silently ignored.
This commit is contained in:
Koushik Dutta
2026-04-02 12:45:17 -07:00
parent 65199ecdf7
commit 9cfa6ea58b

View File

@@ -15,7 +15,7 @@ export interface SelfSignedCertificate {
};
export function createSelfSignedCertificate(existing?: SelfSignedCertificate): SelfSignedCertificate {
let serviceKey: ReturnType<typeof pki.privateKeyFromPem>;
let serviceKey: ReturnType<typeof pki.privateKeyFromPem> | undefined;
// check if existing key is usable
if (existing?.certificate && existing?.serviceKey && existing?.version === CURRENT_SELF_SIGNED_CERTIFICATE_VERSION) {
try {
@@ -30,7 +30,7 @@ export function createSelfSignedCertificate(existing?: SelfSignedCertificate): S
const certificate = pki.createCertificate();
if (existing?.serviceKey) {
if (serviceKey) {
certificate.publicKey = pki.rsa.setPublicKey(serviceKey.n, serviceKey.e);
}
else {