function checkCn()

in src/socket.ts [99:117]


function checkCn(
  instanceInfo: InstanceConnectionInfo,
  cert: tls.PeerCertificate
) {
  const expectedCN = `${instanceInfo.projectId}:${instanceInfo.instanceId}`;
  if (!cert.subject || !cert.subject.CN) {
    return new CloudSQLConnectorError({
      message: `Certificate missing CN, expected ${expectedCN}`,
      code: 'ENOSQLADMINVERIFYCERT',
    });
  }
  if (cert.subject.CN && cert.subject.CN !== expectedCN) {
    return new CloudSQLConnectorError({
      message: `Certificate had CN ${cert.subject.CN}, expected ${expectedCN}`,
      code: 'EBADSQLADMINVERIFYCERT',
    });
  }
  return undefined;
}