Skip to content

Commit 54312fe

Browse files
committed
Expose certificate expiry from API
1 parent 704d594 commit 54312fe

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/api/api-model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import { getSystemProxy } from 'os-proxy-config';
77
import { SERVER_VERSION } from "../constants";
88
import { delay } from '../util/promise';
99
import { logError, addBreadcrumb } from '../error-tracking';
10+
1011
import { HtkConfig } from "../config";
1112
import { ActivationError, Interceptor } from "../interceptors";
1213
import { getDnsServer } from '../dns-server';
14+
import { getCertExpiry, parseCert } from '../certificates';
15+
1316
import * as Client from '../client/client-types';
1417
import { HttpClient } from '../client/http-client';
1518

@@ -64,6 +67,9 @@ export class ApiModel {
6467
return {
6568
certificatePath: this.config.https.certPath,
6669
certificateContent: this.config.https.certContent,
70+
certificateExpiry: getCertExpiry(
71+
parseCert(this.config.https.certContent)
72+
),
6773

6874
// We could calculate this client side, but it requires node-forge or some
6975
// other heavyweight crypto lib, and we already have that here, so it's

src/certificates.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import * as forge from 'node-forge';
33

44
export const parseCert = forge.pki.certificateFromPem;
55

6+
export function getCertExpiry(cert: forge.pki.Certificate): number {
7+
return cert.validity.notAfter.valueOf();
8+
}
9+
610
export function getTimeToCertExpiry(cert: forge.pki.Certificate): number {
7-
const expiry = cert.validity.notAfter.valueOf();
8-
return expiry - Date.now();
11+
return getCertExpiry(cert) - Date.now();
912
}
1013

1114
// A series of magic incantations that matches the behaviour of openssl's

0 commit comments

Comments
 (0)