Skip to content

Commit ef2527d

Browse files
committed
Documented test certificate creation
1 parent d110ec2 commit ef2527d

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,57 @@ docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm ./scripts/
163163
We use [PHPUnit](https://phpunit.de/documentation.html) for unit testing.
164164

165165
Testing mostly centers around the conversion and parsing of certificates. For this purpose a bunch of test
166-
certificates has been generated.
166+
certificates has been generated. See [Test certificates](#test-certificates) for how this is done.
167167

168168
Running PHPUnit tests in a standalone Drupal module is a bit tricky, so we use a helper script to run the
169169
analysis:
170170

171171
```shell
172172
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm ./scripts/unit-tests
173173
```
174+
175+
### Test certificates
176+
177+
Certificates have been generated in the follow way
178+
179+
```shell
180+
# p12 with password
181+
openssl req -x509 -newkey rsa:4096 -days 365 -subj "/CN=example.com" -passout pass:test -keyout test.key -out test.crt
182+
openssl pkcs12 -export -out test_with_passphrase.p12 -passin pass:test -passout pass:test -inkey test.key -in test.crt
183+
openssl pkcs12 -in test_with_passphrase.p12 -passin pass:test -noenc
184+
185+
# p12 without password
186+
openssl req -x509 -newkey rsa:4096 -days 365 -subj "/CN=example.com" -passout pass:'' -keyout test_without_passphrase.key -out test_without_passphrase.crt
187+
openssl pkcs12 -export -out test_without_passphrase.p12 -passin pass:'' -passout pass:'' -inkey test_without_passphrase.key -in test_without_passphrase.crt
188+
openssl pkcs12 -in test_without_passphrase.p12 -passin pass:'' -noenc
189+
190+
# PEM with password
191+
openssl req -x509 -newkey rsa:4096 -days 365 -subj "/CN=example.com" -passout pass:test -keyout test.key -out test.crt
192+
cat test.crt test.key > test_with_passphrase.pem
193+
openssl x509 -in test_with_passphrase.pem
194+
195+
# PEM without password
196+
openssl req -x509 -newkey rsa:4096 -days 365 -subj "/CN=example.com" -passout pass:'' -keyout test_without_passphrase.key -out test_without_passphrase.crt -noenc
197+
cat test_without_passphrase.crt test_without_passphrase.key > test_without_passphrase.pem
198+
openssl x509 -in test_without_passphrase.pem
199+
```
200+
201+
Extraction of certificate and private key parts in the following way
202+
203+
```shell
204+
# P12 with passphrase
205+
openssl pkcs12 -in test_with_passphrase.p12 -passin pass:test -clcerts -nokeys | sed -ne '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' > p12_with_passphrase_cert.txt
206+
openssl pkcs12 -in test_with_passphrase.p12 -passin pass:test -nocerts -nodes | sed -ne '/-----BEGIN PRIVATE KEY-----/,/-----END PRIVATE KEY-----/p' > p12_with_passphrase_pkey.txt
207+
208+
# P12 without passphrase
209+
openssl pkcs12 -in test_without_passphrase.p12 -passin pass: -clcerts -nokeys | sed -ne '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' > p12_without_passphrase_cert.txt
210+
openssl pkcs12 -in test_without_passphrase.p12 -passin pass: -nocerts -nodes | sed -ne '/-----BEGIN PRIVATE KEY-----/,/-----END PRIVATE KEY-----/p' > p12_without_passphrase_pkey.txt
211+
212+
# PEM with passphrase
213+
openssl x509 -in test_with_passphrase.pem -passin pass:test -out pem_with_passphrase_cert.txt
214+
openssl pkey -in test_with_passphrase.pem -passin pass:test -out pem_with_passphrase_pkey.txt
215+
216+
# PEM without passphrase
217+
openssl x509 -in test_without_passphrase.pem -passin pass: -out pem_without_passphrase_cert.txt
218+
openssl pkey -in test_without_passphrase.pem -passin pass: -out pem_without_passphrase_pkey.txt
219+
```

0 commit comments

Comments
 (0)