Skip to content

Commit c38690d

Browse files
committed
Update documentation of SecureContentServer with new openssl commands
This commit changes the docstring for SecureContentServer to describe how to create a self-signed certificate or a certificate signed by a private CA using OpenSSL 1.1.1. In particular, the -sha256 option is necessary to prevent "ca md too weak" errors with that version of OpenSSL (which is the minimum one required by Python 3.10).
1 parent af1f84a commit c38690d

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

pytest_localserver/https.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ class SecureContentServer (ContentServer):
3333
3434
If you want to create your own server certificate, you need `OpenSSL`_
3535
installed on your machine. A self-signed certificate consists of a
36-
certificate and a private key for your server. It can be created with the
37-
following command::
38-
39-
openssl req -new -x509 -keyout server.pem -out server.pem -nodes
36+
certificate and a private key for your server. It can be created with
37+
a command like this, using OpenSSL 1.1.1::
38+
39+
openssl req \
40+
-x509 \
41+
-newkey rsa:4096 \
42+
-sha256 \
43+
-days 3650 \
44+
-nodes \
45+
-keyout server.pem \
46+
-out server.pem \
47+
-subj "/CN=127.0.0.1/O=pytest-localserver/OU=Testing Dept." \
48+
-addext "subjectAltName=DNS:localhost"
4049
4150
Note that both key and certificate are in a single file now named
4251
``server.pem``.
@@ -47,28 +56,39 @@ class SecureContentServer (ContentServer):
4756
Generate a server key and request for signing (csr). Make sure that the
4857
common name (CN) is your IP address/domain name (e.g. ``localhost``). ::
4958
50-
openssl genrsa -des3 -out server.key 4096
51-
openssl req -new -key server.key -out server.csr
59+
openssl genpkey \
60+
-algorithm RSA \
61+
-pkeyopt rsa_keygen_bits:4096 \
62+
-out server.key
63+
openssl req \
64+
-new \
65+
-addext "subjectAltName=DNS:localhost" \
66+
-key server.key \
67+
-out server.csr
5268
5369
Generate your own CA. Make sure that this time the CN is *not* your IP
5470
address/domain name (e.g. ``localhost CA``). ::
5571
56-
openssl genrsa -des3 -out ca.key 4096
57-
openssl req -new -x509 -key ca.key -out ca.crt
72+
openssl genpkey \
73+
-algorithm RSA \
74+
-pkeyopt rsa_keygen_bits:4096 \
75+
-aes256 \
76+
-out ca.key
77+
openssl req \
78+
-new \
79+
-x509 \
80+
-key ca.key \
81+
-out ca.crt
5882
5983
Sign the certificate signing request (csr) with the self-created CA that
60-
you made earlier. If you issue subsequent certificates and your browser
61-
already knows about previous ones simply increment the serial number. ::
84+
you made earlier. Note that OpenSSL does not copy the subjectAltName field
85+
from the request (csr), so you have to provide it again as a file. If you
86+
issue subsequent certificates and your browser already knows about previous
87+
ones simply increment the serial number. ::
6288
89+
echo "subjectAltName=DNS:localhost" >server-extensions.txt
6390
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
64-
-set_serial 01 -out server.crt
65-
66-
Make a server.key which doesn't cause HTTPSServer to prompt for a
67-
password::
68-
69-
openssl rsa -in server.key -out server.key.insecure
70-
mv server.key server.key.secure
71-
mv server.key.insecure server.key
91+
-set_serial 01 -extfile server-extensions.txt -out server.crt
7292
7393
Create a single file for both key and certificate::
7494

0 commit comments

Comments
 (0)