0

Analyze Certificate

by
Published Nov 16, 2023

Returns the set of hostnames, the signature algorithm, and the expiration date of the certificate.

Script cloudflare Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Analyze Certificate
8
 * Returns the set of hostnames, the signature algorithm, and the expiration date of the certificate.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  body: {
14
    bundle_method?: "ubiquitous" | "optimal" | "force";
15
    certificate?: string;
16
    [k: string]: unknown;
17
  }
18
) {
19
  const url = new URL(
20
    `https://api.cloudflare.com/client/v4/zones/${identifier}/ssl/analyze`
21
  );
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "X-AUTH-EMAIL": auth.email,
27
      "X-AUTH-KEY": auth.key,
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39