in src/crypto.ts [43:65]
export async function parseCert(cert: string): Promise<SslCert> {
const {X509Certificate} = await cryptoModule();
try {
const parsed = new X509Certificate(cert);
if (parsed && parsed.validTo) {
return {
cert,
expirationTime: parsed.validTo,
};
}
throw new CloudSQLConnectorError({
message: 'Could not read ephemeral certificate.',
code: 'EPARSESQLADMINEPH',
});
} catch (err: unknown) {
throw new CloudSQLConnectorError({
message: 'Failed to parse as X.509 certificate.',
code: 'EPARSESQLADMINEPH',
errors: [err as Error],
});
}
}