生成 TLS 证书和密钥

此页面举例说明如何使用 CREATE KEYCREATE CERTIFICATE 生成证书和密钥。要查看密钥和证书,请查询 CRYPTOGRAPHIC_KEYSCERTIFICATES 系统表。

有关创建签名证书的更多详细信息,OpenSSL 建议使用 OpenSSL 手册

有关 x509 扩展的更多详细信息,请参阅 安全套接字层密码库 (OpenSSL) 文档

导入密钥和证书

如果您打算使用其关联的证书来签署某些内容,例如客户端-服务器 TLS 中的消息或其他证书,则仅需导入私钥。即:只有在关联证书为以下之一时,才需要导入密钥:

  • 客户端/服务器证书

  • 在 Vertica 中用于签署其他证书的 CA 证书

如果仅需 CA 证书来验证其他证书,则无需导入其私钥。

导入私钥:

=> CREATE KEY imported_key TYPE 'RSA' AS '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----';

证书

要导入仅验证其他证书(无私钥)的 CA 证书:

=> CREATE CA CERTIFICATE imported_validating_ca AS '-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----';

要导入可以验证和签署其他证书的 CA(需要私钥):

=> CREATE CA CERTIFICATE imported_signing_ca AS '-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----'
KEY ca_key;

要导入客户端/服务器证书,您必须导入并指定其私钥和 CA:

=> CREATE CERTIFICATE imported_cert AS '-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----'
SIGNED BY imported_ca KEY imported_key;

生成私钥和证书

要生成 2048 位 RSA 私钥:

=> CREATE KEY new_key TYPE 'RSA' LENGTH 2048;

自签名 CA 证书

CA 是受信任的实体,它们使用 CA 证书来签署和验证其他证书。以下示例将生成自签名的根 CA:

  1. 生成或导入私钥:

    => CREATE KEY SSCA_key TYPE 'RSA' LENGTH 2048;
    
  2. 使用以下格式生成并使用私钥签署证书:

    => CREATE CA CERTIFICATE certificate_name
    SUBJECT '/C=country_code/ST=state_or_province/L=locality/O=organization/OU=org_unit/CN=Vertica Root CA'
    VALID FOR days_valid
    EXTENSIONS 'authorityKeyIdentifier' = 'keyid:always,issuer', 'nsComment' = 'Vertica generated root CA cert'
    KEY ca_key;
    


    例如:

    => CREATE CA CERTIFICATE SSCA_cert
    SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=Vertica Root CA'
    VALID FOR 3650
    EXTENSIONS 'nsComment' = 'Self-signed root CA cert'
    KEY SSCA_key;
    

中间 CA 证书

除了服务器证书,CA 还可以签署其他 CA 的证书。此过程将生成中间 CA,且在顶级 CA 和中间 CA 之间生成信任链。随后,这些中间 CA 可以签署其他证书。

  1. 生成或导入签署中间 CA 的 CA。以下示例生成并使用自签名根 CA:

    => CREATE KEY SSCA_key TYPE 'RSA' LENGTH 2048;
    
    => CREATE CA CERTIFICATE SSCA_cert
    SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=Vertica Root CA'
    VALID FOR 3650
    EXTENSIONS 'nsComment' = 'Self-signed root CA cert'
    KEY SSCA_key;
    

  2. 生成或导入私钥:

    => CREATE KEY intermediate_key TYPE 'RSA' LENGTH 2048;
    
  3. 生成中间 CA 证书,指定其私钥并使用以下格式签署 CA:

    => CREATE CERTIFICATE intermediate_certificate_name
    SUBJECT '/C=country_code/ST=state_or_province/L=locality/O=organization/OU=org_unit/CN=Vertica intermediate CA'
    SIGNED BY ca_name
    KEY intermediate_key;
    


    例如:

    => CREATE CA CERTIFICATE intermediate_CA
    SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=Vertica Intermediate CA'
    SIGNED BY SSCA_cert
    KEY intermediate_key;
    

客户端/服务器证书

CREATE CERTIFICATE 生成 x509v3 证书,允许您指定扩展来限制证书的使用方式。extendedKeyUsage 扩展的值将根据您的用例而有所不同:

  • 服务器证书:

    'extendedKeyUsage' = 'serverAuth'
    
  • 客户证书:

    'extendedKeyUsage' = 'clientAuth'
    
  • 节点间加密的服务器证书:

    'extendedKeyUsage' = 'serverAuth, clientAuth'
    

由于这些证书用于客户端/服务器 TLS,因此您必须导入或生成其私钥。

以下示例证书均由此自签名 CA 证书签名:

=> CREATE KEY SSCA_key TYPE 'RSA' LENGTH 2048;
=> CREATE CA CERTIFICATE SSCA_cert
SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=Vertica Root CA'
VALID FOR 3650
EXTENSIONS 'nsComment' = 'Self-signed root CA cert'
KEY SSCA_key;

要生成服务器证书:

=> CREATE KEY server_key TYPE 'RSA' LENGTH 2048;
=> CREATE CERTIFICATE server_cert
SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=Vertica server/emailAddress=example@example.com'
SIGNED BY SSCA_cert
EXTENSIONS 'nsComment' = 'Vertica server cert', 'extendedKeyUsage' = 'serverAuth'
KEY server_key;

要生成客户端证书:

=> CREATE KEY client_key TYPE 'RSA' LENGTH 2048;
=> CREATE CERTIFICATE client_cert
SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=Vertica client/emailAddress=clientexample@example.com'
SIGNED BY SSCA_cert
EXTENSIONS 'nsComment' = 'Vertica client cert', 'extendedKeyUsage' = 'clientAuth'
KEY client_key;

要生成 节点间 TLS 证书:

=> CREATE KEY internode_key TYPE 'RSA' LENGTH 2048;
=> CREATE CERTIFICATE internode_cert
SUBJECT '/C=US/ST=Massachusetts/L=Cambridge/O=Micro Focus/OU=Vertica/CN=data channel'
SIGNED BY SSCA_cert
EXTENSIONS 'nsComment' = 'Vertica internode cert', 'extendedKeyUsage' = 'serverAuth, clientAuth'
KEY internode_key;