-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add a simple test for CSR signing
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |