@@ -33,10 +33,19 @@ class SecureContentServer (ContentServer):
33
33
34
34
If you want to create your own server certificate, you need `OpenSSL`_
35
35
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"
40
49
41
50
Note that both key and certificate are in a single file now named
42
51
``server.pem``.
@@ -47,28 +56,39 @@ class SecureContentServer (ContentServer):
47
56
Generate a server key and request for signing (csr). Make sure that the
48
57
common name (CN) is your IP address/domain name (e.g. ``localhost``). ::
49
58
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
52
68
53
69
Generate your own CA. Make sure that this time the CN is *not* your IP
54
70
address/domain name (e.g. ``localhost CA``). ::
55
71
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
58
82
59
83
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. ::
62
88
89
+ echo "subjectAltName=DNS:localhost" >server-extensions.txt
63
90
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
72
92
73
93
Create a single file for both key and certificate::
74
94
0 commit comments