fix peer cert
This commit is contained in:
1 parent
df95ee7687
commit
d8007a9a5f
2 files changed
+25
-9
No files matched your search
@@ -129,7 +129,6 @@ const UptimeDetailsPage = () => {
|
|||||||
stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"
|
stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{/**
|
|
||||||
<StatBox
|
<StatBox
|
||||||
title={t("monitors.common.stats.certificate")}
|
title={t("monitors.common.stats.certificate")}
|
||||||
subtitle={
|
subtitle={
|
||||||
@@ -138,7 +137,6 @@ const UptimeDetailsPage = () => {
|
|||||||
: "N/A"
|
: "N/A"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
*/}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
<HeaderRange loading={loading} range={range} setRange={setRange} />
|
<HeaderRange loading={loading} range={range} setRange={setRange} />
|
||||||
<Stack direction={isSmall ? "column" : "row"} gap={theme.spacing(8)}>
|
<Stack direction={isSmall ? "column" : "row"} gap={theme.spacing(8)}>
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import type {
|
|||||||
ICaptureInfo,
|
ICaptureInfo,
|
||||||
ILighthouseResult,
|
ILighthouseResult,
|
||||||
} from "@/db/models/index.js";
|
} from "@/db/models/index.js";
|
||||||
import type { TLSSocket, DetailedPeerCertificate } from "node:tls";
|
import type { TLSSocket } from "node:tls";
|
||||||
import type { ClientRequest } from "node:http";
|
|
||||||
import { MonitorType, MonitorStatus } from "@/db/models/monitors/Monitor.js";
|
import { MonitorType, MonitorStatus } from "@/db/models/monitors/Monitor.js";
|
||||||
import ApiError from "@/utils/ApiError.js";
|
import ApiError from "@/utils/ApiError.js";
|
||||||
import { config } from "@/config/index.js";
|
import { config } from "@/config/index.js";
|
||||||
@@ -69,15 +68,28 @@ class NetworkService implements INetworkService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getCertificateExpiryFromSocket(
|
||||||
|
socket?: TLSSocket | null
|
||||||
|
): Date | null {
|
||||||
|
if (!socket || typeof socket.getPeerCertificate !== "function") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const cert = socket.getPeerCertificate(true);
|
||||||
|
if (!cert?.valid_to) return null;
|
||||||
|
const parsed = new Date(cert.valid_to);
|
||||||
|
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private buildStatusResponse = <T>(
|
private buildStatusResponse = <T>(
|
||||||
monitor: IMonitor,
|
monitor: IMonitor,
|
||||||
response: Response<T> | null,
|
response: Response<T> | null,
|
||||||
certificateExpiryOrError?: Date | null | any,
|
certificateExpiryOrError?: Date | null | any,
|
||||||
maybeError?: any | null
|
maybeError?: any | null
|
||||||
): StatusResponse<T> => {
|
): StatusResponse<T> => {
|
||||||
// Support both call styles:
|
|
||||||
// - buildStatusResponse(monitor, response, error)
|
|
||||||
// - buildStatusResponse(monitor, response, certificateExpiry, error)
|
|
||||||
let certificateExpiry: Date | null = null;
|
let certificateExpiry: Date | null = null;
|
||||||
let error: any | null = null;
|
let error: any | null = null;
|
||||||
if (
|
if (
|
||||||
@@ -137,15 +149,21 @@ class NetworkService implements INetworkService {
|
|||||||
const isHttps = url.startsWith("https://");
|
const isHttps = url.startsWith("https://");
|
||||||
const haveRejectFlag =
|
const haveRejectFlag =
|
||||||
isHttps && typeof (monitor as any).rejectUnauthorized !== "undefined";
|
isHttps && typeof (monitor as any).rejectUnauthorized !== "undefined";
|
||||||
const req: any = haveRejectFlag
|
const req = haveRejectFlag
|
||||||
? this.client(url, {
|
? this.client(url, {
|
||||||
https: {
|
https: {
|
||||||
rejectUnauthorized: (monitor as any).rejectUnauthorized,
|
rejectUnauthorized: (monitor as any).rejectUnauthorized,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: this.client(url);
|
: this.client(url, {});
|
||||||
|
|
||||||
const response: Response = await req;
|
const response: Response = await req;
|
||||||
|
|
||||||
|
// Attempt to get SSL certificate expiry date
|
||||||
|
certificateExpiry = this.getCertificateExpiryFromSocket(
|
||||||
|
(response.request?.socket as TLSSocket | undefined) ?? null
|
||||||
|
);
|
||||||
|
|
||||||
return this.buildStatusResponse(
|
return this.buildStatusResponse(
|
||||||
monitor,
|
monitor,
|
||||||
response,
|
response,
|
||||||
|
|||||||
Reference in new issue
Block a user