bringing in testkit tools
[feisty_meow.git] / testkit / library / generate_csr_from_existing_key.sh
1 #!/bin/bash
2
3 privkey="$1"; shift
4 subject="$1"; shift
5 csrfile="$1"; shift
6
7 function print_instructions()
8 {
9   echo -e "\n\
10 This script creates a new CSR (certificate signing request) file for you from\n\
11 an existing private key.  Getting a new certificate using this CSR ensures\n\
12 that previously signed resources can still be considered properly signed, even\n\
13 after the original certificate has expired, by using the new certificate for\n\
14 validation.  After the new CSR file is generated, it must be sent to the\n\
15 certificate authority and they can generate a new certificate for you.\n\
16 \n\
17 The script takes three parameters.  The first is the file in which the\n\
18 private key is stored in PEM format.  The second parameter is the subject\n\
19 to use in the certificate (who the certificate is issued to).  The third\n\
20 parameter is the output file for the generated CSR (certificate signing\n\
21 request).\n\
22 \n\
23 For example:\n\
24   $(basename $0) my-private.key \"Julius Orange\" orange-new-cert-request.csr\n\
25 "
26 }
27
28 if [ -z "$privkey" -o -z "$subject" -o -z "$csrfile" -o ! -f "$privkey" ]; then
29   print_instructions
30   echo -e "\nThere was a missing parameter or the private key file did not exist."
31   exit 1
32 fi
33
34 openssl req -new -key "$privkey" -nodes -subj "$subject" -out "$csrfile"
35
36