Skip to content

Commit

Permalink
tests: add a simple test for CSR signing
Browse files Browse the repository at this point in the history
  • Loading branch information
gotthardp committed Nov 11, 2023
1 parent a1dd78d commit b696679
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ TESTS_SHELL = test/list.sh \
test/rsa_genpkey_x509_cert.sh \
test/rsa_genpkey_x509_cmp.sh \
test/rsa_genpkey_x509_cms.sh \
test/rsa_genpkey_x509_csr.sh \
test/rsa_genpkey_tls_server.sh \
test/rsa_createak_x509_csr.sh \
test/rsapss_genpkey_sign_rawin.sh \
Expand Down
25 changes: 25 additions & 0 deletions test/rsa_genpkey_x509_csr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
set -eufx

# create a TPM based private key
openssl genpkey -provider tpm2 -algorithm RSA -pkeyopt bits:2048 -out rootca.key

# create a self-signed CA certificate
openssl req -provider tpm2 -provider default -propquery '?provider=tpm2' \
-x509 -new -key rootca.key -subj '/CN=My CA/C=TH/ST=Phuket/L=Phuket/O=Example' -out rootca.crt
# check the certificate
openssl x509 -in rootca.crt -text -noout

# create a (non TPM) key and certificate request
openssl req -new -newkey rsa:2048 -subj '/CN=My Server/C=TH/ST=Phuket/L=Phuket/O=Example' -noenc -keyout server.key -out server.csr
# check the CSR
openssl req -verify -in server.csr -text -noout

# issue the certificate by the TPM-based CA
openssl x509 -provider tpm2 -provider default -propquery '?provider=tpm2' \
-req -in server.csr -CAkey rootca.key -CA rootca.crt -CAcreateserial -out server.crt
# check the certificate
openssl x509 -in server.crt -text -noout

rm rootca.key rootca.crt server.key server.csr server.crt

0 comments on commit b696679

Please sign in to comment.