查看已核發的憑證

本頁說明如何使用Google Cloud 控制台、Google Cloud CLI 和 Cloud 用戶端程式庫,查看已核發的憑證。

您只能查看企業版 CA 核發的憑證。

查看已核發的憑證

控制台

  1. 在 Google Cloud 控制台中,前往「Certificate Authority Service」(憑證授權單位服務) 頁面。

    前往憑證授權單位服務

  2. 按一下「CA 管理員」分頁標籤。

  3. 在「憑證授權單位」頁面上,按一下 CA 的名稱。

  4. 在「憑證授權單位」詳細資料頁面底部,按一下「查看核發的憑證」,即可查看 CA 核發的憑證清單。

    「所有憑證」頁面會顯示憑證清單。顯示的詳細資料包括憑證狀態、核發 CA、包含 CA 的 CA 集區、憑證到期日等。

gcloud

如要列出 CA 集區中特定 CA 核發的所有憑證,請使用下列 gcloud 指令:

gcloud privateca certificates list --issuer-pool ISSUER_POOL --issuer-location ISSUER_LOCATION --ca CA_NAME

如要進一步瞭解 gcloud privateca certificates list 指令,請參閱 gcloud privateca certificates list

如要列出特定位置中所有憑證授權單位的憑證,請使用下列 gcloud 指令:

gcloud privateca certificates list --location LOCATION

Go

如要向 CA 服務進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import (
	"context"
	"fmt"
	"io"

	privateca "cloud.google.com/go/security/privateca/apiv1"
	"cloud.google.com/go/security/privateca/apiv1/privatecapb"
	"google.golang.org/api/iterator"
)

// List Certificates present in the given CA pool.
func listCertificates(
	w io.Writer,
	projectId string,
	location string,
	caPoolId string) error {
	// projectId := "your_project_id"
	// location := "us-central1"		// For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
	// caPoolId := "ca-pool-id"			// The CA Pool id in which the certificate exists.

	ctx := context.Background()
	caClient, err := privateca.NewCertificateAuthorityClient(ctx)
	if err != nil {
		return fmt.Errorf("NewCertificateAuthorityClient creation failed: %w", err)
	}
	defer caClient.Close()

	fullCaName := fmt.Sprintf("projects/%s/locations/%s/caPools/%s", projectId, location, caPoolId)

	// Create the ListCertificatesRequest.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#ListCertificatesRequest.
	req := &privatecapb.ListCertificatesRequest{Parent: fullCaName}

	it := caClient.ListCertificates(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("unable to get the list of cerficates: %w", err)
		}

		fmt.Fprintf(w, " - %s (common name: %s)", resp.Name,
			resp.CertificateDescription.SubjectDescription.Subject.CommonName)
	}

	return nil
}

Java

如要向 CA 服務進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.security.privateca.v1.CaPoolName;
import com.google.cloud.security.privateca.v1.Certificate;
import com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient;
import java.io.IOException;

public class ListCertificates {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // location: For a list of locations, see:
    // https://cloud.google.com/certificate-authority-service/docs/locations
    // poolId: Id of the CA pool which contains the certificates to be listed.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    listCertificates(project, location, poolId);
  }

  // List Certificates present in the given CA pool.
  public static void listCertificates(String project, String location, String poolId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `certificateAuthorityServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient =
        CertificateAuthorityServiceClient.create()) {

      CaPoolName caPool =
          CaPoolName.newBuilder()
              .setProject(project)
              .setLocation(location)
              .setCaPool(poolId)
              .build();

      // Retrieve and print the certificate names.
      System.out.println("Available certificates: ");
      for (Certificate certificate :
          certificateAuthorityServiceClient.listCertificates(caPool).iterateAll()) {
        System.out.println(certificate.getName());
      }
    }
  }
}

Python

如要向 CA 服務進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import google.cloud.security.privateca_v1 as privateca_v1


def list_certificates(
    project_id: str,
    location: str,
    ca_pool_name: str,
) -> None:
    """
    List Certificates present in the given CA pool.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        location: location you want to use. For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
        ca_pool_name: name of the CA pool which contains the certificates to be listed.
    """

    caServiceClient = privateca_v1.CertificateAuthorityServiceClient()

    ca_pool_path = caServiceClient.ca_pool_path(project_id, location, ca_pool_name)

    # Retrieve and print the certificate names.
    print(f"Available certificates in CA pool {ca_pool_name}:")
    for certificate in caServiceClient.list_certificates(parent=ca_pool_path):
        print(certificate.name)

查看專案中核發的所有憑證

控制台

  1. 在 Google Cloud 控制台中,前往「Certificate Authority Service」(憑證授權單位服務) 頁面。

    前往憑證授權單位服務

  2. 按一下「私人憑證管理員」分頁標籤。

    「所有憑證」頁面會顯示憑證清單。

    顯示的詳細資料包括憑證狀態、核發 CA、包含 CA 的 CA 集區、憑證到期日等。您可以使用任何參數篩選憑證。

查看單一憑證的詳細資料

控制台

  1. 前往 Google Cloud 控制台的「Certificate Authority Service」(憑證授權單位服務) 頁面。

    前往憑證授權單位服務

  2. 在「CA Manager」(CA 管理員) 分頁標籤下方,挑選目標 CA。

  3. 按一下 CA 名稱。

  4. 在「憑證授權單位」詳細資料頁面底部,按一下「查看核發的憑證」,即可查看核發的憑證清單。

  5. 找到要下載的憑證,然後按一下「動作」欄中的

  6. 按一下「下載」下方的「認證」。按一下「憑證鏈結」即可下載憑證鏈結

gcloud

如要查看憑證的完整說明,請執行下列指令:

gcloud privateca certificates describe CERT_NAME --issuer-pool POOL_ID --issuer-location ISSUER_LOCATION

如要進一步瞭解 gcloud privateca certificates describe 指令,請參閱 gcloud privateca certificates describe

如要匯出 PEM 編碼的 X.509 憑證鏈結至檔案,請執行下列指令:

gcloud privateca certificates export CERT_NAME \
    --issuer-pool POOL_ID \
    --issuer-location ISSUER_LOCATION \
    --include-chain \
    --output-file certificate-file

如要進一步瞭解 gcloud privateca certificates export 指令,請參閱 gcloud privateca certificates export

憑證擁有權證明

私密金鑰擁有權證明可確保憑證要求者持有該憑證的私密金鑰。只有在要求者根據 RFC 2986 提供 PKCS #10 CSR 時,CA 服務才會檢查擁有權證明。 對於其他形式的憑證要求 (例如透過 CertificateConfig 提出的要求),系統不會強制執行擁有權驗證。

接受憑證的用戶端應用程式有責任驗證憑證持有人是否擁有該憑證的私密金鑰。在核發憑證期間強制執行擁有權驗證,是深層防禦的一種形式,可防範行為不當的用戶端。無論 CA 是否檢查擁有權證明,這類用戶端的存在都可能構成安全漏洞。

後續步驟