f5 Nginx Server Nshield Ig
f5 Nginx Server Nshield Ig
The benefits of using an nShield HSM with the NGINX Server include:
Product Version
NGINX nginx-1:1.14.1-9
OpenSSL openssl-libs-1:1.1.1k-7
Feature Support
Softcards Yes
nSaaS Yes
1.1.2.1. Connect XC
1.1.2.2. nShield 5c
1.2. Requirements
Ensure that you have supported versions of the Entrust, NGINX, and third-party
products.
Consult the security team in your organization for a suitable setting of the following:
• The SE Linux policy to allow the web server read access to the files in /opt/nfast.
• The firewall.
• The number and quorum of Administrator cards in the Administrator Card Set (ACS)
and the policy for managing these cards.
• Whether the application keys are protected by the module, an Operator Card Set
(OCS) or a Softcard with or without a pass phrase.
• The number and quorum of Operator cards in the OCS and the policy for managing
these cards.
• Whether the Security World should be compliant with FIPS 140-2 Level 3.
For more information, refer to the User Guide and Installation Guide for the HSM.
2. Switch off SE Linux. If SE Linux is active, this might prevent NGINX from loading.
% sudo setenforce 0
Entrust recommends that you install the HSM before configuring the Security World
software with your NGINX Server.
Entrust recommends that you uninstall any existing nShield software before installing
2. Create the Security World as described in the User Guide, creating the ACS and OCS
that you require.
3. Install the TAC-955 hot fix. This hotfix contains an updated version of the PKCS11
library and utilities.
You can confirm that the right binary is being run with the following command:
% which openssl
/usr/bin/openssl
If this command returns output inside /opt/nfast, check your $PATH variable.
% openssl version -d
OPENSSLDIR: "/etc/pki/tls"
# Note that you can include other files from the main configuration
# file using the .include directive.
#.include filename
# This definition stops the following lines generating an error if HOME isn't
# defined.
HOME = .
RANDFILE = $ENV::HOME/.rnd
# nShield PKCS11
openssl_conf = openssl_def
[openssl_def]
engines = engine_section
[engine_section]
pkcs11 = pkcs11_section
[pkcs11_section]
engine_id = pkcs11
dynamic_path = /usr/lib64/engines-1.1/pkcs11.so
MODULE_PATH = /opt/nfast/toolkits/pkcs11/libcknfast.so
init = 0
#!
2. If you see this message when creating certificates, you need to update your
OpenSSL configuration:
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = FL
L = Sunrise
O = Entrust
OU = nShield
CN = www.entrust.com
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = www.entrust.com
DNS.2 = entrust.com
% sudo vi /etc/pki/tls/openssl.pkcs11.cnf
CKNFAST_DEBUG=10
CKNFAST_DEBUGFILE=/path/to/debug/file
CKNFAST_FAKE_ACCELERATOR_LOGIN=1
CKNFAST_LOADSHARING=1
% export OPENSSL_CONF=/etc/pki/tls/openssl.pkcs11.cnf
2. Debug variables:
CKNFAST_DEBUG=10
CKNFAST_DEBUGFILE=/path
If you don’t see the PKCS11 engine in the output, check the dynamic_path line in the
openssl.pkcs11.cnf configuration file. It may be different on other platforms and other
operating system versions.
dynamic_path = /usr/lib64/engines-1.1/pkcs11.so
[Service]
Environment=LANG=C
Environment="OPENSSL_CONF=/etc/pki/tls/openssl.pkcs11.cnf"
Environment="NFAST_NFKM_TOKENSFILE=/opt/nfast/kmdata/local/preload"
2. With Softcard and OCS protection, the usual arrangement of spawning worker
processes requires preloading the Softcard or the OCS card. You must specify a
preload file and define its location in the environment to give the other processes
access to the key. No pin value is used in the configuration file, but you can include a
fake one to avoid typing one in on start-up. For the master process you must ensure
the variable is set in the system or session from which the master process is
launched. For worker processes, you must specify the variable in the NGINX config
file.
3. Restart the daemon units:
env NFAST_NFKM_TOKENSFILE=/opt/nfast/kmdata/local/preload;
ssl_engine pkcs11;
c. If it is not in the http section, before the end of the section, add the following
line:
include /etc/nginx/conf.d/*.conf;
user nginx;
worker_processes auto;
events {
worker_connections 1024;
}
ssl_engine pkcs11;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
5. Create a https.conf file in /etc/nginx/conf.d folder. Include the following content with
all lines commented out:
7. Set the environment variable so that OpenSSL commands use the PKCS11 engine:
% export OPENSSL_CONF=/etc/pki/tls/openssl.pkcs11.cnf
2.8. Test the PKCS #11 integration with the NGINX Server
and the HSM
Your organization can use the following scenarios, according to the security guidelines
that you follow:
% sudo rm -f /opt/nfast/kmdata/local/preload
% openssl req -engine pkcs11 -new -x509 -days 365 -key pkcs11localhost.key -out pkcs11localhost.crt
b. Edit /etc/httpd/conf.d/https.conf and change the following lines to use the new
.key and .crt files:
ssl_certificate /etc/pki/tls/certs/pkcs11localhost.crt;
ssl_certificate_key /etc/pki/tls/private/pkcs11localhost.key;
CONNECTED(00000003)
Can't use SSL_get_servername
depth=0 C = US, ST = FL, L = Sunrise, O = Entrust, OU = nShield, CN = www.entrust.com
verify return:1
---
Certificate chain
0 s:C = US, ST = FL, L = Sunrise, O = Entrust, OU = nShield, CN = www.entrust.com
i:C = US, ST = FL, L = Sunrise, O = Entrust, OU = nShield, CN = www.entrust.com
---
Server certificate
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 1504 bytes and written 394 bytes
Verification: OK
---
New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID: CA7B4725395C94DFCF51AC312E39713F313920AA9E3DA278B321F71AFA60F792
Session-ID-ctx:
Master-Key: 1ABCCCB5A64FC49C84D7DF3EBF0FAF94EBB807F2DC4EA7606C8713A5CC907FB82F3A086D0D3BB45AE0F4490A38ED2398
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 300 (seconds)
TLS session ticket:
0000 - 90 a4 24 fc db f8 f3 63-b4 55 47 d1 1c ea e8 34 ..$....c.UG....4
0010 - c8 0d 7e ae 19 9e 9d 50-78 05 b2 1b a4 7d ec d6 ..~....Px....}..
0020 - a4 c4 e5 35 86 f3 c6 7c-a1 bb 5f 0c e9 d9 e7 1d ...5...|.._.....
0030 - 83 52 13 d5 5c 2a 53 01-a3 b8 03 23 6e b2 61 4d .R..\*S....#n.aM
0040 - d1 5c 2d b6 d7 f4 51 69-b6 3d db 2f 4c 39 4d a8 .\-...Qi.=./L9M.
0050 - b3 69 eb 80 0e 24 85 37-14 24 3c 15 1f 2b 86 1b .i...$.7.$<..+..
0060 - f5 47 f6 51 00 e4 ff 5d-a9 65 7f a3 d8 ef 91 e9 .G.Q...].e......
0070 - de 81 e2 fe 66 9c fe 1d-6f ca 8f c9 ec c9 06 f5 ....f...o.......
0080 - 74 6f 84 5d 7f 59 1e 24-d7 ab 4e 4f 9b 03 df e6 to.].Y.$..NO....
0090 - 92 c7 ee 85 c8 20 8c ad-dd 7b 04 44 0f 60 53 7e ..... ...{.D.`S~
00a0 - 49 d0 28 27 48 52 7b f2-ee 38 93 5a 1f fc 66 d5 I.('HR{..8.Z..f.
% sudo rm -f /opt/nfast/kmdata/local/preload
2. To allow module protection, set the cknfast library to allow access to the module
(CKNFAST_FAKE_ACCELERATOR_LOGIN).
Edit the /opt/nfast/cknfastrc file and add the following information before
proceeding to set up module protection:
CKNFAST_FAKE_ACCELERATOR_LOGIN=1
3. Create a key:
% openssl req -engine pkcs11 -x509 -out modulersa.pem -days 365 -key "pkcs11:token=accelerator;object=modulersa"
-keyform engine -subj "/CN=modulersa"
b. Edit /etc/httpd/conf.d/https.conf and change the following lines to use the new
.key and .pem files.
ssl_certificate /etc/pki/tls/certs/modulersa.pem;
ssl_certificate_key "engine:pkcs11:pkcs11:object=modulersa;token=accelerator";
% sudo rm -f /opt/nfast/kmdata/local/preload
Edit the /opt/nfast/cknfastrc file and add the following information before
proceeding to set up Softcard protection:
CKNFAST_LOADSHARING=1
3. Create a Softcard:
% ppmk -n softcardhsm_1
4. Create a key:
Please wait........
Key successfully generated.
Path to key: /opt/nfast/kmdata/local/key_pkcs11_uc415a6f3e010e0a4a9a7f8869eb2ac70210a54f2b-
25143883fd360f7aa24bc7a750f7fab0ebb38160
Make sure you expose the Softcards as described in this section and run the
command again.
b. Edit /etc/httpd/conf.d/https.conf and change the following lines to use the new
.key and pem files.
ssl_certificate /etc/pki/tls/certs/softcardhsm1_170047.pem;
ssl_certificate_key "engine:pkcs11:pkcs11:object=softcardhsm1_170047;token=softcardhsm_1;pin-value=123456";
If you don’t restart NGINX by executing ppm --preload first, you get an error like
this and the certificate doesn’t load:
CONNECTED(00000003)
Can't use SSL_get_servername
...
No client certificate CA names sent
...
7. With Softcard and OCS protection, the usual arrangement of spawning worker
processes requires preloading the Softcard or the OCS card. Specify a preload file
and define its location in the environment to give the other processes access to the
Environment="NFAST_NFKM_TOKENSFILE=/opt/nfast/kmdata/local/preload"
env NFAST_NFKM_TOKENSFILE=/opt/nfast/kmdata/local/preload;
ssl_certificate_key "engine:pkcs11:pkcs11:object=softcardhsm1_170047;token=softcardhsm_1;pin-value=123456";
% sudo rm -f /opt/nfast/kmdata/local/preload
2. Create an OCS:
Creating Cardset:
Module 1: 0 cards of 1 written
Module 1 slot 0: Admin Card #2
Module 1 slot 3: inappropriate Operator Card (TokenAuthFailed)
Module 1 slot 2: unknown card
Module 1 slot 2:- passphrase specified - overwriting card
Card writing complete.
3. Create a key:
Loading `ocscard':
Module 1: 0 cards of 1 read
Module 1 slot 2: `ocscard' #1
Module 1 slot 0: Admin Card #2
Module 1 slot 3: inappropriate Operator Card (TokenAuthFailed)
Module 1 slot 2:- passphrase supplied - reading card
Card reading complete.
% openssl req -engine pkcs11 -x509 -out ocskey.pem -days 365 -key
"pkcs11:token=ocscard;object=ocskey;type=private?pin-value=123456" -keyform engine -subj "/CN=ocskey"
b. Edit /etc/httpd/conf.d/https.conf and change the following lines to use the new
ssl_certificate /etc/pki/tls/certs/ocskey.pem;
ssl_certificate_key "engine:pkcs11:pkcs11:object=ocskey;token=ocscard;pin-value=123456";
Loading `ocscard':
Module 1 slot 2: `ocscard' #1
Module 1 slot 0: Admin Card #2
Module 1 slot 3: inappropriate Operator Card (TokenAuthFailed)
Module 1 slot 2:- passphrase supplied - reading card
Card reading complete.
2022-09-21 10:13:01: [160923]: INFO: Stored Admin key: kfips (5ab6...) in module #1
2022-09-21 10:13:01: [160923]: INFO: Loading cardset: Cardset: ocscard (454e...) in module: 1
2022-09-21 10:13:01: [160923]: INFO: Stored Cardset: ocscard (454e...) in module #1
2022-09-21 10:13:01: [160923]: INFO: Maintaining the cardset ocscard protected
key(s)=['pkcs11:uc454e988e226b33fa94087c0ee6112e0975c1557f-bf7b5f0412619a354f86f58c77d796f27bd3ee12'].
2022-09-21 10:13:01: [160923]: INFO: The private/symmetric key
pkcs11/uc454e988e226b33fa94087c0ee6112e0975c1557f-bf7b5f0412619a354f86f58c77d796f27bd3ee12 is loaded in
module(s): [1].
2022-09-21 10:13:01: [160923]: INFO: Loading complete. Executing subprocess sudo systemctl restart nginx
6. With Softcard and OCS protection, the usual arrangement of spawning worker
processes requires preloading the Softcard or the OCS card. Specify a preload file
and define its location in the environment to give the other processes access to the
key. No pin value is used in the configuration file, but you can include a fake one to
avoid typing one in on start-up. For the master process you must ensure the variable
is set in the system or session from which the master process is launched. For worker
processes, specify the variable in the NGINX config file.
Environment="NFAST_NFKM_TOKENSFILE=/opt/nfast/kmdata/local/preload"
env NFAST_NFKM_TOKENSFILE=/opt/nfast/kmdata/local/preload;
ssl_certificate_key "engine:pkcs11:pkcs11:object=ocskey;token=ocscard;pin-value=123456";