# helloworld-ssl: JBoss EAP Server Side SSL Configuration Example

Giriraj Sharma, Stefan Guilhen

> The `helloworld-ssl` quickstart is a basic example that demonstrates server side SSL configuration in JBoss EAP.

## What is it?

This `helloworld-ssl` quickstart demonstrates the configuration of SSL in JBoss Enterprise Application Platform Server.

This quickstart shows how to configure JBoss EAP to enable TLS/SSL configuration for the new `undertow` web subsystem.

Before you run this example, you must create certificates and configure the server to use SSL.

## System Requirements

The application this project produces is designed to be run on JBoss Enterprise Application Platform Server 7.2 or later.

All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.3.1 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.

To run these quickstarts with the provided build scripts, you need the JBoss EAP distribution ZIP. For information on how to install and run the JBoss EAP server, see the Getting Started Guide.

## Use of EAP_HOME

In the following instructions, replace `EAP_HOME` with the actual path to your JBoss EAP installation. The installation path is described in detail here: Use of EAP_HOME and JBOSS_HOME Variables.

## Generate a Keystore and Self-signed Certificate

1. Open a terminal and navigate to the JBoss EAP server `configuration` directory:

       $ cd EAP_HOME/standalone/configuration/

2. Create a certificate for your server using the following command:

       $>keytool -genkey -alias mycert -keyalg RSA -sigalg MD5withRSA -keystore server.keystore -storepass secret -keypass secret -validity 9999

       What is your first and last name?
          [Unknown]:  localhost
       What is the name of your organizational unit?
          [Unknown]:  wildfly
       What is the name of your organization?
          [Unknown]:  jboss
       What is the name of your City or Locality?
          [Unknown]:  Raleigh
       What is the name of your State or Province?
          [Unknown]:  Carolina
       What is the two-letter country code for this unit?
          [Unknown]:  US
       Is CN=localhost, OU=wildfly, O=jboss, L=Raleigh, ST=Carolina, C=US correct?
          [no]:  yes

   Make sure you enter your desired "hostname" for the `first and last name` field, otherwise you might run into issues while permanently accepting this certificate as an exception in some browsers. Chrome does not currently exhibit this issue.

## Back Up the JBoss EAP Standalone Server Configuration

Before you begin, back up your server configuration file.

1. If it is running, stop the JBoss EAP server.

2. Back up the `EAP_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.

## Start the JBoss EAP Standalone Server

1. Open a terminal and navigate to the root of the JBoss EAP directory.

2. Start the JBoss EAP server with the default profile by typing the following command.

       $ EAP_HOME/bin/standalone.sh

   Note | For Windows, use the `EAP_HOME\bin\standalone.bat` script.

## Configure the Server

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.

1. Before you begin, make sure you do the following:

   - Back up the JBoss EAP standalone server configuration as described above.

   - Start the JBoss EAP server with the standalone default profile as described above.

2. 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.

3. Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing `EAP_HOME` with the path to your server:

       $ EAP_HOME/bin/jboss-cli.sh --connect --file=configure-ssl.cli

   Note | For Windows, use the `EAP_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

## Test the Server SSL Configuration

To test the connection to the SSL port of your your server instance by opening a browser and navigation to https://localhost:8443/. Note, that you get the privacy error because the server certificate is self-signed. If you need to use a fully signed certificate, you must get a PEM file from the Certificate Authority and then import the PEM into the keystore. . Stop the JBoss EAP server.

## Review the Modified Server Configuration

1. Stop the server and open the `EAP_HOME/standalone/configuration/standalone.xml` file and review the changes.

2. The following `key-store` was added to the `elytron` subsystem:

       <key-stores>
           <key-store name="qsKeyStore">
               <credential-reference clear-text="secret"/>
               <implementation type="JKS"/>
               <file path="server.keystore" relative-to="jboss.server.config.dir"/>
           </key-store>
       </key-stores>

3. The following `key-manager` was added to the `elytron` subsystem:

       <key-managers>
           <key-manager name="qsKeyManager" key-store="qsKeyStore">
               <credential-reference clear-text="secret"/>
           </key-manager>
       </key-managers>

4. The following `ssl-context` was added to the `elytron` subsystem:

       <server-ssl-contexts>
           <server-ssl-context name="qsSSLContext" protocols="TLSv1.2" key-manager="qsKeyManager"/>
       </server-ssl-contexts>

5. The `https-listener` in the `undertow` subsystem was changed to reference the `qsSSLContext` `ssl-context`:

       <https-listener name="https" socket-binding="https" ssl-context="qsSSLContext" enable-http2="true"/>

## Build and Deploy the Quickstart

1. Make sure you start the JBoss EAP server as described above.

2. Open a terminal and navigate to the root directory of this quickstart.

3. Type the following command to build the artifacts.

       $ mvn clean package wildfly:deploy

This deploys the `helloworld-ssl/target/helloworld-ssl.war` to the running instance of the server.

You should see a message in the server log indicating that the archive deployed successfully.

## Access the Application

The application will be running at the following URL: https://localhost:8443/helloworld-ssl/.

## Undeploy the Quickstart

When you are finished testing the quickstart, follow these steps to undeploy the archive.

1. Make sure you start the JBoss EAP server as described above.

2. Open a terminal and navigate to the root directory of this quickstart.

3. Type this command to undeploy the archive:

       $ mvn wildfly:undeploy

## Restore the JBoss EAP Standalone Server Configuration

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.

### Restore the JBoss EAP Standalone Server Configuration by Running the JBoss CLI Script

1. Start the JBoss EAP server as described above.

2. Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing `EAP_HOME` with the path to your server:

       $ EAP_HOME/bin/jboss-cli.sh --connect --file=restore-configuration.cli

   Note | For Windows, use the `EAP_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`, and `key-store` from the `elytron` subsystem. You should see the following result when you run the script.

    The batch executed successfully
    process-state: reload-required

### Restore the JBoss EAP Standalone Server Configuration Manually

When you have completed testing the quickstart, you can restore the original server configuration by manually restoring the backup copy the configuration file.

1. If it is running, stop the JBoss EAP server.

2. Replace the `EAP_HOME/standalone/configuration/standalone.xml` file with the backup copy of the file.

## Remove the keystore created for this quickstart

1. Open a terminal and navigate to the JBoss EAP server `configuration` directory.

       $ cd EAP_HOME/standalone/configuration/

2. Remove the keystore generated for this quickstart.

## Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse

You can also start the server and deploy the quickstarts or run the Arquillian tests in Red Hat JBoss Developer Studio or from Eclipse using JBoss tools. For general information about how to import a quickstart, add a JBoss EAP server, and build and deploy a quickstart, see Use JBoss Developer Studio or Eclipse to Run the Quickstarts.

- Make sure you configure the server by running the JBoss CLI commands as described above under Configure the Server. Stop the server at the end of that step.

- Make sure you restore the server configuration when you have completed testing this quickstart.

## Debug the Application

If you want to debug the source code of any library in the project, run the following command to pull the source into your local repository. The IDE should then detect it.

    $ mvn dependency:sources