Skip to content

Commit

Permalink
test: improve https_renew_cert.sh script
Browse files Browse the repository at this point in the history
- To avoid unnecessarily large diffs, only generate a new private key
  if necessary. Otherwise, reuse the existing private key and only
  issue a new certificate.
- Remove an unnecessary conversion step using openssl rsa.
- Extend the certificate validity from 1 year to 10 years.
- Show a text representation of the issued certificate upon completion
  such that the user can verify the validity.
- Make the script executable.
- Use "#!/usr/bin/env bash" instead of "#!/bin/bash".
- Allow the script to be called from any directory.

Refs: nodejs#42342
Refs: nodejs#37990
  • Loading branch information
tniessen committed Mar 15, 2022
1 parent a01302b commit 509afd4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions test/fixtures/keys/selfsigned-no-keycertsign/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
csr.pem
33 changes: 17 additions & 16 deletions test/fixtures/keys/selfsigned-no-keycertsign/cert.pem
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIC9jCCAd6gAwIBAgIJANHflGRpZM1IMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV
BAMMCWxvY2FsaG9zdDAeFw0yMTAzMTUwOTEzMjdaFw0yMjAzMTUwOTEzMjdaMBQx
EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBANMt6TLw9gIxucRgZBn8owavEIMAddxMTjkHiR7jGfaBrvvVTB8ymsIizw/Q
KTANmu2r3EOqeR9Ht25KZFKxOKCDMd3aKHht38HInXIF6CQe8c5P0xsVKZAWkell
8ohL05EsFpcrJODIdHfaovODrtX8w1WexqDsUoPQdEk7pISJ2HhmXzpf7QmV00Ux
8J+64v2pTg8/C9VgpSgxE4oXlfJEqdSIAzGDT+VX96GWXTh7QqLjiQ9T96QHUJEn
Bx0Sr4rO9mY2lOQG408QuCLR/ng2J+lYx+03SC8Lq7lrtt4M06Ffr8TQRgpDAjkU
0YitbuysD5Xg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AQABo0swSTALBgNVHQ8E
BAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwJQYDVR0RBB4wHIIJMTI3LjAuMC4x
gglsb2NhbGhvc3SHBH8AAAEwDQYJKoZIhvcNAQELBQADggEBAEhs8bBvvUmnwb04
U814MSZO1zU9Bj0+iGqgpLIcaG8V+UxhK2m+QSh2HrBN2ROKpziU2VlmoPLrrVuA
CPvFWwWuA3+OJlcQzkKxbje4S3cZ6tEzloYFvE9aXbiGnxMhzgA94F6JbJzIEX9g
ibxG6HueDTxV6LjsjQUQZApEp1yPDObdLYjOPzgRTWHJHhyaEDucT5IBdWAxA0f7
kqEQQFuHIXoH9d4Sl1GSnUEural5lHKBrVgVywLDdayrCDhSDJAlchG7gtbYDCne
BNw+Z51nBu+3SJtGpwK0QyLCuqRouIC1c+urUFnXooRfpjcnmoW9XumqKV0PBi8e
uhHh3CM=
-----END CERTIFICATE-----
16 changes: 11 additions & 5 deletions test/fixtures/keys/selfsigned-no-keycertsign/https_renew_cert.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash
openssl genrsa -out rsa.pem 2048
openssl rsa -in rsa.pem -out key.pem
openssl req -sha256 -new -key key.pem -out csr.pem -subj "/CN=localhost"
openssl x509 -req -extfile cert.conf -extensions v3_req -days 365 -in csr.pem -signkey key.pem -out cert.pem
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

cd -- "$(dirname -- "${BASH_SOURCE[0]}")"

if [ ! -f key.pem ]; then
openssl genrsa -out key.pem 2048
fi
openssl req -sha256 -new -key key.pem -out csr.pem -subj "/CN=localhost"
openssl x509 -req -extfile cert.conf -extensions v3_req -days 3650 -in csr.pem -signkey key.pem -out cert.pem
openssl x509 -in cert.pem -noout -text

0 comments on commit 509afd4

Please sign in to comment.