発行済み証明書を表示

このページでは、Google Cloud コンソール、Google Cloud CLI、Cloud クライアント ライブラリを使用して、発行済みの証明書を表示する方法について説明します。

発行済み証明書を表示

コンソール

  1. Google Cloud コンソールで、[Certificate Authority Service] ページに移動します。

    Certificate Authority Service に移動

  2. [CA マネージャー] タブをクリックします。

  3. [認証局] ページで、CA の名前をクリックします。

  4. [認証局] の詳細ページの一番下にある、[発行済み証明書を表示] をクリックして CA によって発行された証明書のリストを表示します。

    [すべての証明書] ページに証明書のリストが表示されます。表示される詳細には、証明書のステータス、発行 CA、CA を含む CA プール、証明書の有効期限などが含まれます。

gcloud

CA プール内の特定の CA によって発行されたすべての証明書を一覧表示するには、次の gcloud コマンドを使用します。

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

gcloud privateca certificates list コマンドの詳細については、gcloud privateca certificates list をご覧ください。

特定のロケーションにあるすべての CA の証明書をすべて一覧表示するには、次の gcloud コマンドを使用します。

gcloud privateca certificates list --location LOCATION

Go

CA Service への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

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 Service への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。


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 Service への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。


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 つの証明書の詳細を表示する

コンソール

  1. Google Cloud コンソールで、[Certificate Authority Service] ページに移動します。

    Certificate Authority Service に移動

  2. [CA マネージャー] タブでターゲットの CA を選択します。

  3. CA 名をクリックします。

  4. [認証局] の詳細ページの一番下にある、[発行済み証明書を表示] をクリックして発行済み証明書のリストを表示します。

  5. ダウンロードする証明書の [アクション] 列の [] をクリックします。

  6. [ダウンロード] で [証明書] をクリックします。[証明書チェーン] をクリックすると、証明書チェーンをダウンロードできます。

gcloud

証明書の詳細な説明を表示するには、次のコマンドを実行します。

gcloud privateca certificates describe CERT_NAME \
    --issuer-pool POOL_ID

gcloud privateca certificates describe コマンドの詳細については、gcloud privateca certificates describe をご覧ください。

PEM エンコードされた X.509 証明書チェーンをファイルにエクスポートするには、次のコマンドを実行します。

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

gcloud privateca certificates export コマンドの詳細については、gcloud privateca certificates export をご覧ください。

証明書の所持証明

秘密鍵の所持を証明することで、証明書のリクエスト元がその証明書の秘密鍵を保持できるようになります。CA Service は、リクエスト元が RFC 2986 に従って PKCS #10 CSR を提供している場合にのみ、所持の証明を確認します。CertificateConfig によるリクエストなど、他の形式の証明書リクエストの所持証明は適用されません。

証明書の所持者がその証明書の秘密鍵を持っているかどうかを検証する証明書を受け入れるのは、クライアント アプリケーションの責任です。証明書の発行時に所有証明チェックを適用することは、誤動作するクライアントから保護するための多層防御の一つです。このようなクライアントが存在することは、CA が所持証明を確認するかどうかに関係なく、セキュリティの脆弱性を引き起こす可能性があります。

次のステップ