summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs97
1 files changed, 43 insertions, 54 deletions
diff --git a/docs b/docs
index 68ced06..6cd4500 100644
--- a/docs
+++ b/docs
@@ -1,31 +1,10 @@
1 1
2nginx handles mtls, and allows connection to local gunicorn instance. If mTLS fails, connection fails and event is logged 2
3 3
4
5 ubuntu
6sudo pip install Flask gunicorn # to install for all users, especially www-data so that the service runs
7 nginx
8install nginx
9sudo systemctl enable --now nginx
10 # cat /var/log/nginx/access.log
11 # /etc/nginx/nginx.conf
12 gunicorn
13gunicorn --bind localhost:5000 app:app # for testing
14sudo nano /etc/systemd/system/gunicorn1.service # as a service
15sudo systemctl enable --now gunicorn1 # as a service
16 python
17app1.py
18sudo mkdir /var/www
19sudo chown -R www-data:www-data /var/www
20sudo cp app1.py /var/www
21
22
23 test
24# private key 4# private key
25openssl genrsa -out ca.key 2048 5openssl genrsa -out ca.key 2048
26# public certificate 6# public certificate
27openssl req -x509 -new -nodes -key ca.key -sha256 -days 1024 -out ca.pem -subj "/C=US/ST=YourState/L=YourCity/O=YourOrg/CN=YourCA" 7openssl req -x509 -new -nodes -key ca.key -sha256 -days 1024 -out ca.pem -subj "/C=US/ST=YourState/L=YourCity/O=YourOrg/CN=YourCA"
28
29# server private key 8# server private key
30openssl genrsa -out server.key 2048 9openssl genrsa -out server.key 2048
31# generate certificate signing request 10# generate certificate signing request
@@ -39,46 +18,56 @@ openssl x509 -req -in client.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out c
39 18
40openssl genrsa -out wrong_client.key 2048 19openssl genrsa -out wrong_client.key 2048
41openssl req -new -x509 -key wrong_client.key -out wrong_client.crt -days 365 -subj "/C=US/ST=State/L=City/O=Organization/CN=incorrectclient" 20openssl req -new -x509 -key wrong_client.key -out wrong_client.crt -days 365 -subj "/C=US/ST=State/L=City/O=Organization/CN=incorrectclient"
42
43curl https://127.0.0.1 --cacert ca.pem --cert wrong_client.crt --key wrong_client.key -k 21curl https://127.0.0.1 --cacert ca.pem --cert wrong_client.crt --key wrong_client.key -k
44curl https://127.0.0.1 --cacert ca.pem --cert client.crt --key client.key -k 22curl https://127.0.0.1 --cacert ca.pem --cert client.crt --key client.key -k
45 23
46 24
47 untested 25# Allow nginx to connect to any network port for nginx to go through selinux
48sudo cp /path/to/ca.pem /usr/local/share/ca-certificates/your-ca.crt 26also turn off selinux permanently
49sudo update-ca-certificates 27sudo setsebool -P httpd_can_network_connect 1
50 nginx configuration 28sudo mkdir -p /etc/nginx/certs
51 ocsp server to check that the server is valid 29sudo cp /flask/v1/keys/* /etc/nginx/certs/
52 crl to check if a client is revoked 30sudo chown -R nginx:nginx /etc/nginx/certs
53server { 31
54 listen 443 ssl; 32# no yubikey verification
55 server_name yourdomain.com; 33curl https://127.0.0.1/v/0ty2 --cacert ca.pem --cert client.crt --key client.key -k
34
35# to activate hsm, move these over
36cat server.crt ../intermediate/certs/intermediate.crt ../certs/root.crt > fullchain.crt
37cp fullchain.crt /etc/nginx/certs/hsm_chain.crt
38cp server.crt /etc/nginx/certs/hsm_server.crt
39sudo pkcs11-tool -L # for denk serial number
40
41
42openssl version -d
43
44edit the openssl.conf file
45/etc/nginx/nginx.conf
46
47then edit the nginx service file
48Environment="OPENSSL_CONF=/etc/pki/tls/openssl.pkcs11.cnf"
49
50add under service
51 systemctl daemon-reload
52 sudo systemctl restart nginx
53
54
55 openssl s_client -connect localhost:443 -cert client.crt -key client.key -CAfile /etc/nginx/certs/hsm_chain.crt
56
57 curl --cert client.crt --key client.key --cacert /etc/nginx/certs/hsm_chain.crt https://localhost:443/ -k
58
56 59
57 ssl_certificate /path/to/your/server.crt; 60 sudo -u nginx pkcs11-tool --module /usr/lib64/opensc-pkcs11.so --list-objects --login
58 ssl_certificate_key /path/to/your/server.key;
59 61
60 # Client certificate verification 62tail -f /var/log/nginx/error.log # to see ssl errors
61 ssl_client_certificate /path/to/your/ca.pem;
62 ssl_verify_client on;
63 63
64 # Enable OCSP stapling and strict verification 64/usr/share/polkit-1/actions/org.debian.pcsc-lite.policy
65 ssl_stapling on; 65change all to yes then restart systemctl pcscd
66 ssl_stapling_verify on; 66if nginx cannot access pcscd(can also prove this by doing a pkcs11-tool list), systemctl pcscd will have error logs)
67 ssl_trusted_certificate /path/to/your/ca.pem;
68 67
69 # Specify resolver for OCSP stapling
70 resolver 8.8.8.8 8.8.4.4 valid=300s;
71 resolver_timeout 10s;
72 68
73 # Enforce OCSP response checking strictly
74 ssl_ocsp on;
75 ssl_ocsp_fail closed;
76 69
77 # Specify CRL file for client certificate revocation checking 70 https://www.redhat.com/en/blog/controlling-access-smart-cards
78 ssl_crl /etc/nginx/ssl/crl.pem;
79 71
80 location / {
81 try_files $uri $uri/ =404;
82 }
83}
84 72
73sudo curl -vvv -E 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=00000000;token=user2;pin-value=123456' --cacert fullchain2.crt https://p.0nom.ch/c