1515# limitations under the License.
1616
1717# [START privateca_create_certificate]
18- from google .cloud import kms
1918import google .cloud .security .privateca_v1 as privateca_v1
2019from google .protobuf import duration_pb2
2120
@@ -26,13 +25,10 @@ def create_certificate(
2625 ca_pool_name : str ,
2726 ca_name : str ,
2827 certificate_name : str ,
29- kms_location : str ,
30- key_ring_id : str ,
31- key_id : str ,
32- key_version_id : str ,
3328 common_name : str ,
3429 domain_name : str ,
3530 certificate_lifetime : int ,
31+ public_key_bytes : bytes ,
3632) -> None :
3733 """
3834 Create a Certificate which is issued by the Certificate Authority present in the CA Pool.
@@ -44,30 +40,21 @@ def create_certificate(
4440 ca_pool_name: set a unique name for the CA pool.
4541 ca_name: the name of the certificate authority which issues the certificate.
4642 certificate_name: set a unique name for the certificate.
47- kms_location: Cloud KMS location.
48- key_ring_id: ID of the Cloud KMS key ring.
49- key_id: ID of the key to use.
50- key_version_id: verstion ID of the key to use.
5143 common_name: a title for your certificate.
5244 domain_name: fully qualified domain name for your certificate.
5345 certificate_lifetime: the validity of the certificate in seconds.
46+ public_key_bytes: public key used in signing the certificates.
5447 """
5548
56- kmsClient = kms .KeyManagementServiceClient ()
5749 caServiceClient = privateca_v1 .CertificateAuthorityServiceClient ()
5850
59- # To sign and issue a certificate, a public key is essential. Here, we are making use
60- # of Cloud KMS to retrieve an already created public key. For more info, see: https://cloud.google.com/kms/docs/retrieve-public- key.
61- # Generating keys locally is also possible .
51+ # The public key used to sign the certificate can be generated using any crypto library/framework.
52+ # Also you can use Cloud KMS to retrieve an already created public key.
53+ # For more info, see: https://cloud.google.com/kms/docs/retrieve-public-key .
6254
63- key_version_name = kmsClient .crypto_key_version_path (
64- project_id , kms_location , key_ring_id , key_id , key_version_id
65- )
66- kms_public_key = kmsClient .get_public_key (name = key_version_name )
67-
68- # Set the Public Key and its format as obtained from the Cloud KMS.
55+ # Set the Public Key and its format.
6956 public_key = privateca_v1 .PublicKey (
70- key = str . encode ( kms_public_key . pem ) ,
57+ key = public_key_bytes ,
7158 format_ = privateca_v1 .PublicKey .KeyFormat .PEM ,
7259 )
7360
0 commit comments