The helloworld-mutual-ssl
quickstart is a basic example that demonstrates mutual TLS configuration in WildFly
Mutual TLS provides the same security as TLS, with the addition of authentication and non-repudiation of the client authentication, using digital signatures. When mutual authentication is used, the server requests the client to provide a certificate in addition to the server certificate issued to the client. Mutual authentication requires an extra round trip each time for client certificate exchange. In addition, the client must obtain and maintain a digital certificate.
The out of the box configuration for WildFly has one-way TLS enabled by default. This quickstart shows how to configure WildFly with mutual (two-way) TLS authentication.
Before you run this example, you must create the client certificate and configure the server to use two-way TLS.
The application this project produces is designed to be run on WildFly Application Server 34 or later.
All you need to build this project is Java SE 17.0 or later, and Maven 3.6.0 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.
In the following instructions, replace WILDFLY_HOME
with the actual path to your WildFly installation. The installation path is described in detail here: Use of WILDFLY_HOME and JBOSS_HOME Variables.
When you see the replaceable variable QUICKSTART_HOME, replace it with the path to the root directory of all of the quickstarts.
Before you begin, back up your server configuration file.
-
If it is running, stop the WildFly server.
-
Back up the
WILDFLY_HOME/standalone/configuration/standalone.xml
file.
After you have completed testing this quickstart, you can replace this file to restore the server to its original configuration.
-
Open a terminal and navigate to the root of the WildFly directory.
-
Start the WildFly server with the default profile by typing the following command.
$ WILDFLY_HOME/bin/standalone.sh
NoteFor Windows, use the WILDFLY_HOME\bin\standalone.bat
script.
-
Create the client certificate, which is used to authenticate against the server when accessing a resource through TLS.
$ WILDFLY_HOME/bin/jboss-cli.sh --connect --file=configure-client-cert.cli
-
The certificate and keystore are now properly configured.
You configure the SSL context by running JBoss CLI commands. For your convenience, this quickstart batches the commands into a configure-ssl.cli
script provided in the root directory of this quickstart.
-
Before you begin, make sure you do the following:
-
Back up the WildFly standalone server configuration as described above.
-
Start the WildFly server with the standalone default profile as described above.
-
-
Review the
configure-ssl.cli
file in the root of this quickstart directory. Comments in the script describe the purpose of each block of commands. -
Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing WILDFLY_HOME with the path to your server:
$ WILDFLY_HOME/bin/jboss-cli.sh --connect --file=configure-ssl.cli
NoteFor Windows, use the WILDFLY_HOME\bin\jboss-cli.bat
script.You should see the following result when you run the script:
The batch executed successfully process-state: reload-required
-
Stop the WildFly server.
After stopping the server, open the WILDFLY_HOME/standalone/configuration/standalone.xml
file and review the changes.
-
The following
keystore
element was added to theelytron
subsystem:<key-store name="qsTrustStore"> <credential-reference clear-text="secret"/> <implementation type="JKS"/> <file path="client.truststore" relative-to="jboss.server.config.dir"/> </key-store>
-
The following
trust-manager
was added to theelytron
subsystem:<trust-managers> <trust-manager name="qsTrustManager" key-store="qsTrustStore"/> </trust-managers>
-
The default
ssl-context
was updated to reference thetrust-manager
to enable two-way TLS:<server-ssl-contexts> <server-ssl-context name="applicationSSC" need-client-auth="true" key-manager="applicationKM" trust-manager="qsTrustManager"/> </server-ssl-contexts>
Note that the
https-listener
in theundertow
subsystem references theapplicationSSC
server-ssl-context
by default.
To test the TLS configuration, access: https://localhost:8443
If it is configured correctly, you should be asked to trust the server certificate.
Before you access the application, you must import the client.keystore.P12, which holds the client certificate, into your browser.
-
Click the Chrome menu icon (3 dots) in the upper right on the browser toolbar and choose Settings. This takes you to
link:`chrome://settings/
. -
Click on Privacy and security and then on Security.
-
Scroll down to the Advanced section and on the Manage certificates screen, select the Your Certificates tab and click on the Import button.
-
Select the client.keystore.P12 file. You will be prompted to enter the password:
secret
. -
The client certificate is now installed in the Google Chrome browser.
-
Click the Edit menu item on the browser menu and choose Settings.
-
A new window will open. Click on Privacy & Security and scroll down to the Certificates section.
-
Click the View Certificates button.
-
A new window will open. Select the Your Certificates tab and click the Import button.
-
Select the client.keystore.P12 file. You will be prompted to enter the password:
secret
. -
The certificate is now installed in the Mozilla Firefox browser.
-
Make sure WildFly server is started.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type the following command to build the quickstart.
$ mvn clean package
-
Type the following command to deploy the quickstart.
$ mvn wildfly:deploy
This deploys the helloworld-mutual-ssl/target/helloworld-mutual-ssl.war
to the running instance of the server.
You should see a message in the server log indicating that the archive deployed successfully.
The application will be running at the following URL: https://localhost:8443/helloworld-mutual-ssl/HelloWorld.
A page displaying the client certificate should be visible:
Hello World ! WildFly mutual TLS is configured and client certificate is verified !!
Client Certificate Pem: MIIDhTCCAm2gAwIBAgIEf9lc5DANBgkqhkiG9w0BAQsFADBzMQswCQYDVQQGEwJCUjESMBAGA1UECBMJU2FvIFBhd
WxvMRIwEAYDVQQHEwlTYW8gUGF1bG8xEzARBgNVBAoTCk15IENvbXBhbnkxDjAMBgNVBAsTBVNhbGVzMRcwFQYDVQQDEw5xdWlja3N0YXJ0VXNlcj
AeFw0xNzA3MjQxOTE0MDNaFw0xODA3MjQxOTE0MDNaMHMxCzAJBgNVBAYTAkJSMRIwEAYDVQQIEwlTYW8gUGF1bG8xEjAQBgNVBAcTCVNhbyBQYXV
sbzETMBEGA1UEChMKTXkgQ29tcGFueTEOMAwGA1UECxMFU2FsZXMxFzAVBgNVBAMTDnF1aWNrc3RhcnRVc2VyMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAnHwflE8K/ArTPbTeZZEFK+1jtpg9grPSD62GIz/awoIDr6Rf9vCBTpAg4lom62A0BNZDEJKdab/ExNOOBRY+/pOnYlXZTYlDp
dQQap0E7UP5EfHNZsafgpfILCop2LdTuUbcV7tLKBsthJLJ0ZCoG5QJFble+OPxEbissOvIqHfvUJZi34k9ULteLJc330g0uTuDrLgtoFQ0cbHa4F
CQ86o85EuRPpFeW6EBA3iYE/tKHSYsK7QSajefX6jZjXoZiUflw97SAGL43ZtvNbrKRywEfsVqDpDurjBg2HI+YahuDz5R1QWTSyTHWMZzcyJYqxj
XiSf0oK1cUahn6m5t1wIDAQABoyEwHzAdBgNVHQ4EFgQUlYS+xjK7KxNMf13UxMgiEssJOQkwDQYJKoZIhvcNAQELBQADggEBADkp+R6kSNXJNfih
qbDRp3uFtNMG6OgaYsfC7RtNLMdrhvoLlU7uWzxVCFuifvNlWVRiADBHDCRQU2uNRFW35GQSfHQyok4KoBuKlfBtQ+Xu7c8R0JzxN/rPJPXoCbShz
DHo1uoz5/dzXZz0EjjWCPJk+LVEhEvH0GcWAp3x3irpNU4hRZLd0XomY0Z4NnUt7VMBNYDOxVxgT9qcLnEaEpIfYULubLLCFHwAga2YgsKzZYLuwM
aEWK4zhPVFynfnMaOxI67FC2QzhfzERyKqHj47WuwN0xWbS/1gBypS2nUwvItyxaEQG2X5uQY8j8QoY9wcMzIIkP2Mk14gJGHUnA8=
This quickstart includes integration tests, which are located under the src/test/
directory. The integration tests verify that the quickstart runs correctly when deployed on the server.
Follow these steps to run the integration tests.
-
Make sure WildFly server is started.
-
Make sure the quickstart is deployed.
-
Type the following command to run the
verify
goal with theintegration-testing
profile activated.$ mvn verify -Pintegration-testing -Dserver.dir=__WILDFLY_HOME__
When you are finished testing the quickstart, follow these steps to undeploy the archive.
-
Make sure WildFly server is started.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type this command to undeploy the archive:
$ mvn wildfly:undeploy
You can restore the original server configuration using either of the following methods.
-
You can run the
restore-configuration.cli
script provided in the root directory of this quickstart. -
You can manually restore the configuration using the backup copy of the configuration file.
-
Start the WildFly server as described above.
-
Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing
WILDFLY_HOME
with the path to your server:$ WILDFLY_HOME/bin/jboss-cli.sh --connect --file=restore-configuration.cli
NoteFor Windows, use the WILDFLY_HOME\bin\jboss-cli.bat
script.
This script reverts the changes made to the undertow
subsystem and it also removes the ssl-context
, key-manager
, trust-manager
and key-store`s
from the `elytron
subsystem. You should see the following result when you run the script:
The batch executed successfully
process-state: reload-required
When you have completed testing the quickstart, you can restore the original server configuration by manually restoring the backup copy the configuration file.
-
If it is running, stop the WildFly server.
-
Replace the
WILDFLY_HOME/standalone/configuration/standalone.xml
file with the backup copy of the file.
-
Run the CLI script for restoring client cert configuration:
$ WILDFLY_HOME/bin/jboss-cli.sh --connect --file=restore-client-cert.cli
NoteFor Windows, use the WILDFLY_HOME\bin\jboss-cli.bat
script. -
Remove the
client.keystore.P12
,clientCert.crt
,client.keystore
, andclient.truststore
files that were generated for this quickstart.
After you are done with this quickstart, remember to remove the certificate that was imported into your browser.
-
Click the Chrome menu icon (3 dots) in the upper right on the browser toolbar and choose Settings. This takes you to chrome://settings/.
-
Click on Privacy and security and then on Security.
-
Scroll down to the Advanced section and on the Manage certificates screen, select the Your Certificates tab and click on the arrow to the right of the certificate to be removed.
-
The certificate is expanded, displaying the
quickstartUser
entry. Click on the icon (3 dots) to the right of it and then select Delete. -
Confirm the deletion in the dialog box. The certificate has now been removed from the Google Chrome browser.
-
Click the Edit menu item on the browser menu and choose Preferences.
-
A new window will open. Click on Privacy & Security and scroll down to the Certificates section.
-
Click the View Certificates button.
-
A new window will open. Select the Your Certificates tab.
-
Select the
quickstartUser
certificate and click theDelete
button. -
The certificate has now been removed from the Mozilla Firefox browser.
Instead of using a standard WildFly server distribution, you can alternatively provision a WildFly server to deploy and run the quickstart. The functionality is provided by the WildFly Maven Plugin, and you may find its configuration in the quickstart pom.xml
:
<profile>
<id>provisioned-server</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<discover-provisioning-info>
<version>${version.server}</version>
</discover-provisioning-info>
<add-ons>...</add-ons>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
</profile>
When built, the provisioned WildFly server can be found in the target/server
directory, and its usage is similar to a standard server distribution, with the simplification that there is never the need to specify the server configuration to be started.
Follow these steps to run the quickstart using the provisioned server.
-
Make sure the server is provisioned.
$ mvn clean package
-
Start the WildFly provisioned server, using the WildFly Maven Plugin
start
goal.$ mvn wildfly:start
-
Type the following command to run the integration tests.
$ mvn verify -Pintegration-testing
-
Shut down the WildFly provisioned server.
$ mvn wildfly:shutdown