perf: improve TLS chain fetch way, to make sure can get tls info correct
This commit is contained in:
parent
51675f6129
commit
cc910b7ee6
@ -69,7 +69,19 @@ export const http: MonitorProvider<{
|
|||||||
rejectUnauthorized: !ignoreTLS,
|
rejectUnauthorized: !ignoreTLS,
|
||||||
};
|
};
|
||||||
|
|
||||||
config.httpsAgent = new https.Agent(httpsAgentOptions);
|
const httpsAgent = (config.httpsAgent = new https.Agent(httpsAgentOptions));
|
||||||
|
httpsAgent.once('keylog', (line, tlsSocket) => {
|
||||||
|
tlsSocket.once('secureConnect', async () => {
|
||||||
|
try {
|
||||||
|
const { valid, certInfo } = checkCertificate(tlsSocket);
|
||||||
|
|
||||||
|
await saveMonitorStatus(monitor.id, 'tls', {
|
||||||
|
valid,
|
||||||
|
certInfo,
|
||||||
|
});
|
||||||
|
} catch (err) {}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const startTime = dayjs();
|
const startTime = dayjs();
|
||||||
@ -77,15 +89,8 @@ export const http: MonitorProvider<{
|
|||||||
|
|
||||||
const diff = dayjs().diff(startTime, 'ms');
|
const diff = dayjs().diff(startTime, 'ms');
|
||||||
|
|
||||||
if (url.startsWith('https:')) {
|
if (res.status >= 400) {
|
||||||
try {
|
return -1;
|
||||||
const { valid, certInfo } = checkCertificate(res);
|
|
||||||
|
|
||||||
await saveMonitorStatus(monitor.id, 'tls', {
|
|
||||||
valid,
|
|
||||||
certInfo,
|
|
||||||
});
|
|
||||||
} catch (err) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return diff;
|
return diff;
|
||||||
@ -96,13 +101,13 @@ export const http: MonitorProvider<{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkCertificate(res: AxiosResponse<any, any>) {
|
function checkCertificate(tlsSocket: any) {
|
||||||
if (!res.request.res.socket) {
|
if (!tlsSocket) {
|
||||||
throw new Error('No socket found');
|
throw new Error('No socket found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = res.request.res.socket.getPeerCertificate(true);
|
const info = tlsSocket.getPeerCertificate(true);
|
||||||
const valid = res.request.res.socket.authorized || false;
|
const valid = tlsSocket.authorized || false;
|
||||||
|
|
||||||
logger.debug('cert', 'Parsing Certificate Info', info);
|
logger.debug('cert', 'Parsing Certificate Info', info);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user