Path: blob/master/test/jdk/java/security/cert/CertPathValidator/indirectCRL/generate.sh
41161 views
#1# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#2223#!/bin/ksh24#25# needs ksh to run the script.2627# generate a self-signed root certificate28if [ ! -f root/root_cert.pem ]; then29if [ ! -d root ]; then30mkdir root31fi3233openssl req -x509 -newkey rsa:1024 -keyout root/root_key.pem \34-out root/root_cert.pem -subj "/C=US/O=Example" \35-config openssl.cnf -reqexts cert_issuer -days 7650 \36-passin pass:passphrase -passout pass:passphrase37fi3839# generate a sele-issued root crl issuer certificate40if [ ! -f root/top_crlissuer_cert.pem ]; then41if [ ! -d root ]; then42mkdir root43fi4445openssl req -newkey rsa:1024 -keyout root/top_crlissuer_key.pem \46-out root/top_crlissuer_req.pem -subj "/C=US/O=Example" -days 7650 \47-passin pass:passphrase -passout pass:passphrase4849openssl x509 -req -in root/top_crlissuer_req.pem -extfile openssl.cnf \50-extensions crl_issuer -CA root/root_cert.pem \51-CAkey root/root_key.pem -out root/top_crlissuer_cert.pem \52-CAcreateserial -CAserial root/root_cert.srl -days 7200 \53-passin pass:passphrase54fi5556# generate subca cert issuer and crl iuuser certificates57if [ ! -f subca/subca_cert.pem ]; then58if [ ! -d subca ]; then59mkdir subca60fi6162openssl req -newkey rsa:1024 -keyout subca/subca_key.pem \63-out subca/subca_req.pem -subj "/C=US/O=Example/OU=Class-1" \64-days 7650 -passin pass:passphrase -passout pass:passphrase6566openssl x509 -req -in subca/subca_req.pem -extfile openssl.cnf \67-extensions cert_issuer -CA root/root_cert.pem \68-CAkey root/root_key.pem -out subca/subca_cert.pem -CAcreateserial \69-CAserial root/root_cert.srl -days 7200 -passin pass:passphrase7071openssl req -newkey rsa:1024 -keyout subca/subca_crlissuer_key.pem \72-out subca/subca_crlissuer_req.pem -subj "/C=US/O=Example/OU=Class-1" \73-days 7650 -passin pass:passphrase -passout pass:passphrase7475openssl x509 -req -in subca/subca_crlissuer_req.pem -extfile openssl.cnf \76-extensions crl_issuer -CA root/root_cert.pem \77-CAkey root/root_key.pem -out subca/subca_crlissuer_cert.pem \78-CAcreateserial -CAserial root/root_cert.srl -days 7200 \79-passin pass:passphrase80fi8182# generate dumca cert issuer and crl iuuser certificates83if [ ! -f dumca/dumca_cert.pem ]; then84if [ ! -d sumca ]; then85mkdir dumca86fi8788openssl req -newkey rsa:1024 -keyout dumca/dumca_key.pem \89-out dumca/dumca_req.pem -subj "/C=US/O=Example/OU=Class-D" \90-days 7650 -passin pass:passphrase -passout pass:passphrase9192openssl x509 -req -in dumca/dumca_req.pem -extfile openssl.cnf \93-extensions cert_issuer -CA root/root_cert.pem \94-CAkey root/root_key.pem -out dumca/dumca_cert.pem \95-CAcreateserial -CAserial root/root_cert.srl -days 7200 \96-passin pass:passphrase9798openssl req -newkey rsa:1024 -keyout dumca/dumca_crlissuer_key.pem \99-out dumca/dumca_crlissuer_req.pem -subj "/C=US/O=Example/OU=Class-D" \100-days 7650 -passin pass:passphrase -passout pass:passphrase101102openssl x509 -req -in dumca/dumca_crlissuer_req.pem \103-extfile openssl.cnf -extensions crl_issuer -CA root/root_cert.pem \104-CAkey root/root_key.pem -out dumca/dumca_crlissuer_cert.pem \105-CAcreateserial -CAserial root/root_cert.srl -days 7200 \106-passin pass:passphrase107fi108109# generate certifiacte for Alice110if [ ! -f subca/alice/alice_cert.pem ]; then111if [ ! -d subca/alice ]; then112mkdir -p subca/alice113fi114115openssl req -newkey rsa:1024 -keyout subca/alice/alice_key.pem \116-out subca/alice/alice_req.pem \117-subj "/C=US/O=Example/OU=Class-1/CN=Alice" -days 7650 \118-passin pass:passphrase -passout pass:passphrase119120openssl x509 -req -in subca/alice/alice_req.pem \121-extfile openssl.cnf -extensions ee_of_subca \122-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \123-out subca/alice/alice_cert.pem -CAcreateserial \124-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase125fi126127# generate certifiacte for Bob128if [ ! -f subca/bob/bob_cert.pem ]; then129if [ ! -d subca/bob ]; then130mkdir -p subca/bob131fi132133openssl req -newkey rsa:1024 -keyout subca/bob/bob_key.pem \134-out subca/bob/bob_req.pem \135-subj "/C=US/O=Example/OU=Class-1/CN=Bob" -days 7650 \136-passin pass:passphrase -passout pass:passphrase137138openssl x509 -req -in subca/bob/bob_req.pem \139-extfile openssl.cnf -extensions ee_of_subca \140-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \141-out subca/bob/bob_cert.pem -CAcreateserial \142-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase143fi144145# generate certifiacte for Susan146if [ ! -f subca/susan/susan_cert.pem ]; then147if [ ! -d subca/susan ]; then148mkdir -p subca/susan149fi150151openssl req -newkey rsa:1024 -keyout subca/susan/susan_key.pem \152-out subca/susan/susan_req.pem \153-subj "/C=US/O=Example/OU=Class-1/CN=Susan" -days 7650 \154-passin pass:passphrase -passout pass:passphrase155156openssl x509 -req -in subca/susan/susan_req.pem -extfile openssl.cnf \157-extensions ee_of_subca -CA subca/subca_cert.pem \158-CAkey subca/subca_key.pem -out subca/susan/susan_cert.pem \159-CAcreateserial -CAserial subca/subca_cert.srl -days 7200 \160-passin pass:passphrase161fi162163164# generate the top CRL165if [ ! -f root/top_crl.pem ]; then166if [ ! -d root ]; then167mkdir root168fi169170if [ ! -f root/index.txt ]; then171touch root/index.txt172echo 00 > root/crlnumber173fi174175openssl ca -gencrl -config openssl.cnf -name ca_top -crldays 7000 \176-crl_reason superseded -keyfile root/top_crlissuer_key.pem \177-cert root/top_crlissuer_cert.pem -out root/top_crl.pem \178-passin pass:passphrase179fi180181# revoke dumca182openssl ca -revoke dumca/dumca_cert.pem -config openssl.cnf \183-name ca_top -crl_reason superseded \184-keyfile root/top_crlissuer_key.pem -cert root/top_crlissuer_cert.pem \185-passin pass:passphrase186187openssl ca -gencrl -config openssl.cnf -name ca_top -crldays 7000 \188-crl_reason superseded -keyfile root/top_crlissuer_key.pem \189-cert root/top_crlissuer_cert.pem -out root/top_crl.pem \190-passin pass:passphrase191192# revoke for subca193if [ ! -f subca/subca_crl.pem ]; then194if [ ! -d subca ]; then195mkdir subca196fi197198if [ ! -f subca/index.txt ]; then199touch subca/index.txt200echo 00 > subca/crlnumber201fi202203openssl ca -gencrl -config openssl.cnf -name ca_subca -crldays 7000 \204-crl_reason superseded -keyfile subca/subca_crlissuer_key.pem \205-cert subca/subca_crlissuer_cert.pem -out subca/subca_crl.pem \206-passin pass:passphrase207fi208209# revoke susan210openssl ca -revoke subca/susan/susan_cert.pem -config openssl.cnf \211-name ca_subca -crl_reason superseded \212-keyfile subca/subca_crlissuer_key.pem \213-cert subca/subca_crlissuer_cert.pem -passin pass:passphrase214215openssl ca -gencrl -config openssl.cnf -name ca_subca -crldays 7000 \216-crl_reason superseded -keyfile subca/subca_crlissuer_key.pem \217-cert subca/subca_crlissuer_cert.pem -out subca/subca_crl.pem \218-passin pass:passphrase219220221