|
1 | | -This project shows how to create an SSLContext to support deploying modules when 2-way SSL is configured for an app server. |
| 1 | +**Note** - if you are using ml-gradle 4.7.0 or higher, you can now configure 2-way SSL via properties instead of having |
| 2 | +to construct an `SSLContext` yourself. Please see [the SSL guide](https://github.com/marklogic/ml-gradle/wiki/SSL-guide) |
| 3 | +for more information. |
2 | 4 |
|
3 | | -2-way SSL requires a certificate template to be configured on the MarkLogic app server, "ssl require client certificate" set to true and one or more "ssl client certificate authorities" selected indicating which CAs the client certificates must be signed by. |
| 5 | +This project shows how to create an SSLContext to support deploying modules when 2-way SSL is configured for an app |
| 6 | +server. |
4 | 7 |
|
5 | | -Follow instructions here <https://docs.marklogic.com/guide/security/SSL> to setup SSL for the MarkLogic app server. |
| 8 | +2-way SSL requires a certificate template to be configured on the MarkLogic app server, "ssl require client certificate" |
| 9 | +set to true and one or more "ssl client certificate authorities" selected indicating which CAs the client certificates |
| 10 | +must be signed by. |
6 | 11 |
|
7 | | -To make this work, you will need a certificate authority (CA) that can sign certificates for you. You can either use a known 3rd party or setup your own CA for testing. The rest of the instructions assume that the same CA is used to sign both the client and the server certificates. |
| 12 | +Follow instructions here <https://docs.marklogic.com/guide/security/SSL> to setup SSL for the MarkLogic app server. |
| 13 | + |
| 14 | +To make this work, you will need a certificate authority (CA) that can sign certificates for you. You can either use a |
| 15 | +known 3rd party or setup your own CA for testing. The rest of the instructions assume that the same CA is used to sign |
| 16 | +both the client and the server certificates. |
8 | 17 |
|
9 | 18 | ### Create a server certificate |
10 | | -If the server does not yet have a certificate signed by your CA, you will need to get one and imort it to the server. If you already have server certificated signed by the CA, you can skip this step. |
| 19 | + |
| 20 | +If the server does not yet have a certificate signed by your CA, you will need to get one and imort it to the server. If |
| 21 | +you already have server certificated signed by the CA, you can skip this step. |
11 | 22 |
|
12 | 23 | #### Generate and download a certificate request (CSR) |
13 | 24 |
|
14 | | -Using the certificate template created above, generate and download a certificate request (CSR). Use that CSR to request a certificate from the CA (or generate one yourself if you have your own CA). |
| 25 | +Using the certificate template created above, generate and download a certificate request (CSR). Use that CSR to request |
| 26 | +a certificate from the CA (or generate one yourself if you have your own CA). |
15 | 27 |
|
16 | | -_Important: Your CSR will have the values for country, state/province, city/town, organization, organizational unit and email address from the certificate template. Your CA will have requirements for what must be in each of those fields. If using your own CA to sign certificates, you will need to configure openssl to be able to process CSRs with the values from the template or set the template values to the values needed for your openssl CA configuration before generating the server CSR._ |
| 28 | +_Important: Your CSR will have the values for country, state/province, city/town, organization, organizational unit and |
| 29 | +email address from the certificate template. Your CA will have requirements for what must be in each of those fields. If |
| 30 | +using your own CA to sign certificates, you will need to configure openssl to be able to process CSRs with the values |
| 31 | +from the template or set the template values to the values needed for your openssl CA configuration before generating |
| 32 | +the server CSR._ |
17 | 33 |
|
18 | 34 | The following are helpful resources if considering setting up your own CA for testing: |
| 35 | + |
19 | 36 | * <https://www.area536.com/projects/be-your-own-certificate-authority-with-openssl/> |
20 | 37 | * <https://jamielinux.com/docs/openssl-certificate-authority/create-the-root-pair.html> |
21 | 38 |
|
22 | 39 | #### Import the signed server certificate |
23 | | -Once you have the signed server certificate, import it into the server using the "Import" tab of the certificate template used to generate the CSR. |
24 | 40 |
|
25 | | -_Important: The CN in the server cert will be the hostname of the MarkLogic host as seen from the "Hosts" list in the admin UI. This will need to be the hostname you use to connect to MarkLogic if hostname verification is being used._ |
| 41 | +Once you have the signed server certificate, import it into the server using the "Import" tab of the certificate |
| 42 | +template used to generate the CSR. |
| 43 | + |
| 44 | +_Important: The CN in the server cert will be the hostname of the MarkLogic host as seen from the "Hosts" list in the |
| 45 | +admin UI. This will need to be the hostname you use to connect to MarkLogic if hostname verification is being used._ |
26 | 46 |
|
27 | 47 | ### Create a client certificate |
28 | | -Since we are using ml-gradle which uses the MarkLogic Java Client under the covers, we need to use the Java SSL libraries to setup the client SSL configuration. Java uses a "keystore" to manage client and CA certificates. We will use the Java _keytool_ commandline tool to setup a keystore for the client. |
| 48 | + |
| 49 | +Since we are using ml-gradle which uses the MarkLogic Java Client under the covers, we need to use the Java SSL |
| 50 | +libraries to setup the client SSL configuration. Java uses a "keystore" to manage client and CA certificates. We will |
| 51 | +use the Java _keytool_ commandline tool to setup a keystore for the client. |
29 | 52 |
|
30 | 53 | The follow instructions were guided by the following helpful resources: |
| 54 | + |
31 | 55 | * <https://docs.oracle.com/cd/E19509-01/820-3503/ggfen/index.html> |
32 | 56 | * <https://www.digitalocean.com/community/tutorials/java-keytool-essentials-working-with-java-keystores> |
33 | 57 |
|
34 | 58 | #### Create a keystore |
| 59 | + |
35 | 60 | ``` |
36 | 61 | keytool -keystore clientkeystore -genkey -alias client |
37 | 62 | ``` |
38 | 63 |
|
39 | | -You will be prompted for a password for the keystore. Remember this and use it as the `mlKeystorePassword` in the `gradle.properties` file. |
| 64 | +You will be prompted for a password for the keystore. Remember this and use it as the `mlKeystorePassword` in |
| 65 | +the `gradle.properties` file. |
40 | 66 |
|
41 | | -You will be propted to enter values for your name (CN), country, state/province, city/town, organization and organizational unit. Enter values as required by your CA but make sure to use the MarkLogic username that will be using the certificate when propted for "your first and last name". This is the CN stored in the certificate. |
| 67 | +You will be propted to enter values for your name (CN), country, state/province, city/town, organization and |
| 68 | +organizational unit. Enter values as required by your CA but make sure to use the MarkLogic username that will be using |
| 69 | +the certificate when propted for "your first and last name". This is the CN stored in the certificate. |
42 | 70 |
|
43 | | -_Important: The CN in client certificate needs to match the user name that you will use to connect to MarkLogic or authentication will fail._ |
| 71 | +_Important: The CN in client certificate needs to match the user name that you will use to connect to MarkLogic or |
| 72 | +authentication will fail._ |
44 | 73 |
|
45 | | -If you want a different password on the client certificate, enter one when prompted and use this as the `mlKeystoreCertPassword` in the `gradle.properties` file. Otherwise, hit enter to use the same password as the keystore. |
| 74 | +If you want a different password on the client certificate, enter one when prompted and use this as |
| 75 | +the `mlKeystoreCertPassword` in the `gradle.properties` file. Otherwise, hit enter to use the same password as the |
| 76 | +keystore. |
46 | 77 |
|
47 | | -When complete, this will create a file called `clientkeystore` (you can name this file whatever you want though). Use this as the value for `mlKeystore` in the `gradle.properties` file. |
| 78 | +When complete, this will create a file called `clientkeystore` (you can name this file whatever you want though). Use |
| 79 | +this as the value for `mlKeystore` in the `gradle.properties` file. |
48 | 80 |
|
49 | 81 | #### Create a client CSR |
| 82 | + |
50 | 83 | ``` |
51 | 84 | keytool -keystore clientkeystore -certreq -alias client -keyalg rsa -file client.csr |
52 | 85 | ``` |
53 | 86 |
|
54 | 87 | #### Generate a signed client certificate |
| 88 | + |
55 | 89 | Use the CSR to have a CA generate a signed client certificate (or generate one using your own CA) |
56 | 90 |
|
57 | 91 | #### Import the CA certificate |
| 92 | + |
58 | 93 | ``` |
59 | 94 | keytool -import -keystore clientkeystore -file ca.crt -alias theCARoot |
60 | 95 | ``` |
61 | 96 |
|
62 | 97 | #### Import the signed client certificate |
| 98 | + |
63 | 99 | ``` |
64 | 100 | keytool -import -keystore clientkeystore -file client.crt -alias client |
65 | 101 | ``` |
|
0 commit comments