#!/bin/bash -ex # Copyright The Ratify Authors. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This file include the script to generate testing certificates for CRL testing. # The generated files are: # - certchain_with_crl.pem: the fullchain file that includes the leaf # certificate with CRL, intermediate certificate with invalid OCSP and valid # CRL, and the root certificate. # - leaf.crl: the CRL file that includes the leaf certificate. # - leaf.key: the private key of the leaf certificate. # - leaf_revoked.crl: the CRL file that includes the revoked leaf certificate. # - intermediate.crl: the CRL file that includes the intermediate certificate. # - intermediate_revoked.crl: the CRL file that includes the revoked intermediate # - root.crt: the root certificate. # set -o errexit set -o nounset set -o pipefail CERT_DIR=$1 generate() { # Create root CA configuration file cat > root.cnf < demoCA/serial echo '1002' > demoCA/crlnumber # Generate root private key openssl genrsa -out root.key 2048 # Generate self-signed root certificate with extensions openssl req -x509 -new -key root.key -sha256 -days 36500 -out root.crt \ -config root.cnf -extensions v3_ca # Update intermediate.cnf to include [ca] and [CA_default] sections cat > intermediate.cnf < intermediateCA/serial echo '1000' > intermediateCA/crlnumber # Generate intermediate private key openssl genrsa -out intermediate.key 2048 # Generate intermediate CSR openssl req -new -key intermediate.key -out intermediate.csr -config intermediate.cnf # Sign intermediate certificate with root CA openssl ca -config root.cnf -in intermediate.csr -out intermediate.crt -batch -extensions v3_intermediate_ca -extfile intermediate.cnf -notext # Update leaf.cnf to remove OCSP server cat > leaf.cnf < certchain_with_crl.pem } rm -r ${CERT_DIR} || true mkdir -p ${CERT_DIR} pushd "${CERT_DIR}" generate popd