Skip to content

Commit 7a28b84

Browse files
committed
Sync documentation of main branch
1 parent 5a7b7a6 commit 7a28b84

File tree

1 file changed

+190
-0
lines changed

1 file changed

+190
-0
lines changed

_versions/main/guides/tls-registry-reference.adoc

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,193 @@ To handle the renewal, you can use the periodic reloading mechanism:
693693
%prod.quarkus.http.insecure-requests=disabled
694694
----
695695

696+
== Quarkus CLI commands and development CA (Certificate Authority)
697+
698+
The TLS registry provides CLI commands to generate a development CA and trusted certificates.
699+
This avoids having to use self-signed certificates locally.
700+
701+
[source, shell]
702+
----
703+
> quarkus tls
704+
Install and Manage TLS development certificates
705+
Usage: tls [COMMAND]
706+
Commands:
707+
generate-quarkus-ca Generate Quarkus Dev CA certificate and private key.
708+
generate-certificate Generate a TLS certificate with the Quarkus Dev CA if
709+
available.
710+
----
711+
712+
In most cases, you generate the Quarkus Development CA once, and then generate certificates signed by this CA.
713+
The Quarkus Development CA is a Certificate Authority that can be used to sign certificates locally.
714+
It is only valid for development purposes and only trusted on the local machine.
715+
The generated CA is located in `$HOME/.quarkus/quarkus-dev-root-ca.pem`, and installed in the system trust store.
716+
717+
=== CA, signed vs. self-signed certificates
718+
719+
When developing with TLS, you can use two types of certificates:
720+
721+
- a self-signed certificate: the certificate is signed by the same entity that uses it. It is not trusted by default. It's generally what we use when we don't have a CA, or don't want to dig too much into TLS. This is not a production setup, and may be used only for development.
722+
- a signed certificate: the certificate is signed by a Certificate Authority (CA). The CA is a trusted entity that signs the certificate. The certificate is trusted by default. This is what we use in production.
723+
724+
We could use self-signed certificate when running application locally, but it's not always convenient.
725+
Typically, browsers will not trust the certificate, and you will have to import it manually.
726+
`curl`, `wget`, `httpie` and other tools will also not trust the certificate.
727+
728+
To avoid this, we can use a development CA to sign the certificates, and install it into the system trust store.
729+
Thus, every certificate signed by this CA will be trusted by the system.
730+
731+
Quarkus makes it easy to generate a development CA and certificates signed by this CA.
732+
733+
=== Generate a development CA
734+
735+
The development CA is a Certificate Authority that can be used to sign certificates locally.
736+
Note that the generated CA is only valid for development purposes, and only trusted on the local machine.
737+
738+
To generate a development CA, use the following command:
739+
740+
[source, shell]
741+
----
742+
quarkus tls generate-ca-certificate --install --renew --truststore
743+
----
744+
745+
`--install` installs the CA in the system trust store.
746+
Windows, Mac and Linux (Fedora and Ubuntu) are supported.
747+
However, depending on your browser, you may need to import the generated CA manually.
748+
Refer to the browser documentation for more information.
749+
The generated CA is located in `$HOME/.quarkus/quarkus-dev-root-ca.pem`.
750+
751+
WARNING: When installing the certificate, your system may ask for your password to install the certificate in the system trust store, or ask for confirmation in a dialog (on Windows).
752+
753+
IMPORTANT: On Windows, makes sure you run from an elevated terminal (run as administrator) to install the CA in the system trust store.
754+
755+
`--renew` renews the CA if it already exists.
756+
When this option is used, you need to re-generate the certificates that were signed by the CA, as the private key is changed.
757+
Note that if the CA expires, it will automatically be renewed (without passing `--renew`).
758+
759+
`--truststore` also generates a PKCS12 trust store containing the CA certificate.
760+
761+
=== Generate a trusted (signed) certificate
762+
763+
Once you have installed the Quarkus Development CA, you can generate a trusted certificate.
764+
It will be signed by the Quarkus Development CA, and so trusted by your system.
765+
766+
[source, shell]
767+
----
768+
quarkus tls generate-certificate --name my-cert
769+
----
770+
771+
This generates a certificate signed by the Quarkus Development CA, and so if properly installed / imported, will be trusted by your system.
772+
773+
The certificate is stored in `./.certs/`.
774+
Two files are generated:
775+
776+
- `$NAME-keystore.p12` - contains the private key and the certificate. It's password protected.
777+
- `$NAME-truststore.p12` - contains the CA certificate, that you can used as trust store (for test, for instance).
778+
779+
More options are available:
780+
781+
[source, shell]
782+
----
783+
Usage: tls generate-certificate [-hrV] [-c=<cn>] [-d=<directory>]
784+
-n=<name> [-p=<password>]
785+
Generate a TLS certificate with the Quarkus Dev CA if available.
786+
-c, --cn=<cn> The common name of the certificate. Default is 'localhost'
787+
-d, --directory=<directory>
788+
The directory in which the certificates will be created.
789+
Default is `.certs`
790+
-n, --name=<name> Name of the certificate. It will be used as file name and
791+
alias in the keystore
792+
-p, --password=<password>
793+
The password of the keystore. Default is 'password'
794+
-r, --renew Whether existing certificates will need to be replaced
795+
----
796+
797+
When generating the certificate, a `.env` file is also generated making the Quarkus dev mode aware of these certificates.
798+
So, then, if you run your application in dev mode, it will use these certificates:
799+
800+
[source, shell]
801+
----
802+
./mvnw quarkus:dev
803+
...
804+
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
805+
----
806+
807+
Now, you can open the Dev UI using HTTPS: `https://localhost:8443/q/dev`, or issue a request using `curl`:
808+
809+
[source, shell]
810+
----
811+
curl https://localhost:8443/hello
812+
Hello from Quarkus REST%
813+
----
814+
815+
IMPORTANT: If the Quarkus Development CA is not installed, a self-signed certificate is generated.
816+
817+
818+
=== Generating a self-signed certificate
819+
820+
Even if the Quarkus Development CA is installed, you can generate a self-signed certificate:
821+
822+
[source, shell]
823+
----
824+
quarkus tls generate-certificate --name my-cert --self-signed
825+
----
826+
827+
This generates a self-signed certificate, not signed by the Quarkus Development CA.
828+
829+
=== Uninstalling the Quarkus Development CA
830+
831+
Uninstalling the Quarkus Development CA from your system depends on your OS.
832+
833+
==== Deleting the CA certificate on Windows
834+
835+
To delete the CA certificate on Windows, use the following commands from a Powershell terminal with administrator rights:
836+
837+
[source, shell]
838+
----
839+
# First, we need to identify the serial number of the CA certificate
840+
> certutil -store -user Root
841+
root "Trusted Root Certification Authorities"
842+
================ Certificate 0 ================
843+
Serial Number: 019036d564c8
844+
Issuer: O=Quarkus, CN=quarkus-dev-root-ca # <-That's the CA, copy the Serial Number (the line above)
845+
NotBefore: 6/19/2024 11:07 AM
846+
NotAfter: 6/20/2025 11:07 AM
847+
Subject: C=Cloud, S=world, L=home, OU=Quarkus Dev, O=Quarkus Dev, CN=quarkus-dev-root-ca
848+
Signature matches Public Key
849+
Non-root Certificate uses same Public Key as Issuer
850+
Cert Hash(sha1): 3679bc95b613a2112a3d3256fe8321b6eccce720
851+
No key provider information
852+
Cannot find the certificate and private key for decryption.
853+
CertUtil: -store command completed successfully.
854+
855+
> certutil -delstore -user -v Root $Serial_Number
856+
----
857+
858+
Replace `$Serial_Number` with the serial number of the CA certificate.
859+
860+
==== Deleting the CA certificate on Linux
861+
862+
On Fedora, you can use the following command:
863+
864+
[source, shell]
865+
----
866+
sudo rm /etc/pki/ca-trust/source/anchors/quarkus-dev-root-ca.pem
867+
sudo update-ca-trust
868+
----
869+
870+
On Ubuntu, you can use the following command:
871+
872+
[source, shell]
873+
----
874+
sudo rm /usr/local/share/ca-certificates/quarkus-dev-root-ca.pem
875+
sudo update-ca-certificates
876+
----
877+
878+
==== Deleting the CA certificate on Mac
879+
880+
On Mac, you can use the following command:
881+
882+
[source, shell]
883+
----
884+
sudo security -v remove-trusted-cert -d /Users/clement/.quarkus/quarkus-dev-root-ca.pem
885+
----

0 commit comments

Comments
 (0)