1.9. Quarkus CLI 命令和开发证书颁发机构


TLS registry 提供 Quarkus CLI 命令来生成开发证书颁发机构(CA)和可信证书。这可避免在本地使用自签名证书。

以下片段显示了 quarkus tls 命令的描述,它包含两个子命令:

> quarkus tls
Install and Manage TLS development certificates
Usage: tls [COMMAND]
Commands:
  generate-quarkus-ca   Generate Quarkus Dev CA certificate and private key. 
1

  generate-certificate  Generate a TLS certificate with the Quarkus Dev CA if
                        available. 
2
Copy to Clipboard Toggle word wrap
1
这对本地开发很有用,因为它允许 Quarkus 作为自己的证书颁发机构(可用于为其他证书签名)。
2
这在为应用和外部服务或客户端在开发过程中安全通信而创建证书时很有用。

在大多数情况下,您要生成 Quarkus Development CA 一次,然后生成由此 CA 签名的证书。Quarkus Development CA 是一个证书颁发机构,可用于在本地签名证书。它仅对开发目的有效,且仅在本地计算机上信任。生成的 CA 位于 $HOME/.quarkus/quarkus-dev-root-ca.pem 中,并安装到系统信任存储中。

1.9.1. 了解自签名与 CA 签名证书

使用 TLS 进行开发时,您可以使用两种类型的证书:

  • 自签名证书 :证书 由使用它的同一实体签名。默认情况下不信任它。当证书颁发机构(CA)不可用或需要简单设置时,通常使用此类证书。它不适用于生产环境,仅适用于开发。
  • CA 签名证书 :证书 由证书 CA (可信实体)签名。此证书默认是可信的,是生产环境的标准选择。

虽然您可以使用自签名证书进行本地开发,但存在限制。浏览器和工具 curlwgethttpie 通常不信任自签名证书,需要在操作系统中手动导入 CA。

要避免这个问题,请使用开发 CA 为证书签名并在系统信任存储中安装 CA。这样可确保系统信任 CA 签名的证书。Quarkus 简化了开发 CA 和此 CA 签名的证书的生成。

1.9.2. 生成开发 CA

开发 CA 是一个证书颁发机构,可用于在本地签名证书。请注意,生成的 CA 仅适用于开发目的,只能在本地机器上信任。

生成开发 CA:

quarkus tls generate-quarkus-ca --install \   
1

     --renew \     
2

     --truststore  
3
Copy to Clipboard Toggle word wrap
1
--install 会在系统信任存储中安装 CA。支持 Windows、Mac 和 Linux (Fedora 和 Ubuntu)。但是,根据您的浏览器,您可能需要手动导入生成的 CA。如需更多信息,请参阅浏览器的文档。生成的 CA 位于 $HOME/.quarkus/quarkus-dev-root-ca.pem 中。
2
-- 续订 CA (如果已存在)。使用此选项时,会更改私钥,因此您需要重新生成 CA 签名的证书。如果 CA 过期,它将自动更新,而无需-- renew 选项。
3
--truststore 还会生成包含 CA 证书的 PKCS12 信任存储。
警告

安装证书时,您的系统可能会要求您的密码在系统信任存储中安装证书,或者要求在 Windows 上的对话框中进行确认。

重要

在 Windows 上,以管理员身份从提升的终端运行,以在系统信任存储中安装 CA。

1.9.3. 生成可信(签名)证书

先决条件

  • 生成开发 CA

    1. 安装 Quarkus Development CA 后,生成可信证书。此证书由 Quarkus Development CA 签名,并被您的系统信任。

      quarkus tls generate-certificate --name my-cert
      Copy to Clipboard Toggle word wrap

      此命令生成由 Quarkus Development CA 签名的证书,如果正确安装或导入,您的系统将会信任。

      证书存储在 ./.certs/ 中。生成两个文件:

  • $name-keystore.p12 :包含私钥和证书。它受密码保护。
  • $NAME-truststore.p12 :包含 CA 证书,您可以将其用作信任存储,例如用于测试。

    其它选项可用:

    Usage: tls generate-certificate [-hrV] [-c=<cn>] [-d=<directory>]
           -n=<name> [-p=<password>]
    Generate a TLS certificate with the Quarkus Dev CA if available.
      -c, --cn=<cn>       The common name of the certificate. Default is 'localhost'
      -d, --directory=<directory>
                          The directory in which the certificates will be created.
                            Default is `.certs`
      -n, --name=<name>   Name of the certificate. It will be used as file name and
                            alias in the keystore
      -p, --password=<password>
                          The password of the keystore. Default is 'password'
      -r, --renew         Whether existing certificates will need to be replaced
    Copy to Clipboard Toggle word wrap

    生成证书时也会生成 .env 文件,使 Quarkus dev 模式了解这些证书。

    1. 以 dev 模式运行应用程序以使用这些证书:

      ./mvnw quarkus:dev
      ...
      INFO  [io.quarkus] (Quarkus Main Thread) demo 1.0.0-SNAPSHOT on JVM (powered by Quarkus 999-SNAPSHOT) started in 1.286s. Listening on: http://localhost:8080 and https://localhost:8443
      Copy to Clipboard Toggle word wrap
    2. 使用 HTTPS: https://localhost:8443/q/dev 或发出 curl 请求来打开 Dev UI:

      curl https://localhost:8443/hello
      Hello from Quarkus REST%
      Copy to Clipboard Toggle word wrap
      重要

      如果没有安装 Quarkus Development CA,quarkus 会生成自签名证书。

1.9.4. 生成自签名证书

即使安装了 Quarkus Development CA,也可以生成自签名证书:

quarkus tls generate-certificate --name my-cert --self-signed
Copy to Clipboard Toggle word wrap

这会生成 Quarkus 开发 CA 不签名的自签名证书。

1.9.5. 卸载 Quarkus 开发 CA

从您的系统卸载 Quarkus 开发 CA 取决于您的操作系统。

1.9.5.1. 删除 Windows 上的 CA 证书

  1. 使用带有管理员权限的 Powershell 终端列出 Windows 上的 CA 证书:

    # First, we need to identify the serial number of the CA certificate
    > certutil -store -user Root
    root "Trusted Root Certification Authorities"
    ================ Certificate 0 ================
    Serial Number: 019036d564c8
    Issuer: O=Quarkus, CN=quarkus-dev-root-ca # <-That's the CA, copy the Serial Number (the line above)
    NotBefore: 6/19/2024 11:07 AM
    NotAfter: 6/20/2025 11:07 AM
    Subject: C=Cloud, S=world, L=home, OU=Quarkus Dev, O=Quarkus Dev, CN=quarkus-dev-root-ca
    Signature matches Public Key
    Non-root Certificate uses same Public Key as Issuer
    Cert Hash(sha1): 3679bc95b613a2112a3d3256fe8321b6eccce720
    No key provider information
    Cannot find the certificate and private key for decryption.
    CertUtil: -store command completed successfully.
    Copy to Clipboard Toggle word wrap
  2. 删除存储的 CA 证书,并将 $Serial_Number 替换为 CA 证书的序列号:

    > certutil -delstore -user -v Root $Serial_Number
    Copy to Clipboard Toggle word wrap

1.9.5.2. 删除 Linux 中的 CA 证书

  • 对于 Fedora:

    sudo rm /etc/pki/ca-trust/source/anchors/quarkus-dev-root-ca.pem
    sudo update-ca-trust
    Copy to Clipboard Toggle word wrap
  • 在 Ubuntu 中:

    sudo rm /usr/local/share/ca-certificates/quarkus-dev-root-ca.pem
    sudo update-ca-certificates
    Copy to Clipboard Toggle word wrap

1.9.5.3. 删除 Mac 上的 CA 证书

  • 在 Mac 上:

    sudo security -v remove-trusted-cert -d /Users/clement/.quarkus/quarkus-dev-root-ca.pem
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat