1#!/bin/bash 2 3check_result(){ 4 if [ $1 -ne 0 ]; then 5 echo "Failed at \"$2\", Abort" 6 exit 1 7 else 8 echo "Step Succeeded!" 9 fi 10} 11 12openssl pkey -in root-p521-priv.pem -noout >/dev/null 2>&1 13if [ $? -ne 0 ]; then 14 echo "OpenSSL does not support P521" 15 echo "Skipping P521 certificate renewal" 16 exit 0 17fi 18 19############################################################ 20###### update the self-signed root-p521.pem ############### 21############################################################ 22echo "Updating root-p521.pem" 23echo "" 24#pipe the following arguments to openssl req... 25echo -e "US\\nMontana\\nBozeman\\nwolfSSL_P521\\nRoot-P521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n.\\n.\\n" | \ 26openssl req -new -key root-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out root-p521.csr 27check_result $? "Generate request" 28 29openssl x509 -req -in root-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions ca_ecc_cert -signkey root-p521-priv.pem -out root-p521.pem 30check_result $? "Generate certificate" 31rm root-p521.csr 32 33openssl x509 -in root-p521.pem -outform DER > root-p521.der 34check_result $? "Convert to DER" 35openssl x509 -in root-p521.pem -text > tmp.pem 36check_result $? "Add text" 37mv tmp.pem root-p521.pem 38echo "End of section" 39echo "---------------------------------------------------------------------" 40 41############################################################ 42###### update ca-p521.pem signed by root ################## 43############################################################ 44echo "Updating ca-p521.pem" 45echo "" 46#pipe the following arguments to openssl req... 47echo -e "US\\nMontana\\nBozeman\\nwolfSSL_p521\\nCA-p521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n\\n\\n\\n" | openssl req -new -key ca-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out ca-p521.csr 48check_result $? "Generate request" 49 50openssl x509 -req -in ca-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions ca_ecc_cert -CA root-p521.pem -CAkey root-p521-priv.pem -set_serial 01 -out ca-p521.pem 51check_result $? "Generate certificate" 52rm ca-p521.csr 53 54openssl x509 -in ca-p521.pem -outform DER > ca-p521.der 55check_result $? "Convert to DER" 56openssl x509 -in ca-p521.pem -text > tmp.pem 57check_result $? "Add text" 58mv tmp.pem ca-p521.pem 59echo "End of section" 60echo "---------------------------------------------------------------------" 61 62############################################################ 63###### update server-p521.pem signed by ca ################ 64############################################################ 65echo "Updating server-p521.pem" 66echo "" 67#pipe the following arguments to openssl req... 68echo -e "US\\nMontana\\nBozeman\\nwolfSSL_p521\\nServer-p521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n\\n\\n\\n" | openssl req -new -key server-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out server-p521.csr 69check_result $? "Generate request" 70 71openssl x509 -req -in server-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions server_ecc -CA ca-p521.pem -CAkey ca-p521-priv.pem -set_serial 01 -out server-p521-cert.pem 72check_result $? "Generate certificate" 73rm server-p521.csr 74 75openssl x509 -in server-p521-cert.pem -outform DER > server-p521.der 76check_result $? "Convert to DER" 77openssl x509 -in server-p521-cert.pem -text > tmp.pem 78check_result $? "Add text" 79mv tmp.pem server-p521-cert.pem 80cat server-p521-cert.pem ca-p521.pem > server-p521.pem 81check_result $? "Add CA into server cert" 82echo "End of section" 83echo "---------------------------------------------------------------------" 84 85############################################################ 86###### update the self-signed client-p521.pem ############# 87############################################################ 88echo "Updating client-p521.pem" 89echo "" 90#pipe the following arguments to openssl req... 91echo -e "US\\nMontana\\nBozeman\\nwolfSSL_p521\\nClient-p521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n\\n\\n\\n" | openssl req -new -key client-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out client-p521.csr 92check_result $? "Generate request" 93 94openssl x509 -req -in client-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions wolfssl_opts -signkey client-p521-priv.pem -out client-p521.pem 95check_result $? "Generate certificate" 96rm client-p521.csr 97 98openssl x509 -in client-p521.pem -outform DER > client-p521.der 99check_result $? "Convert to DER" 100openssl x509 -in client-p521.pem -text > tmp.pem 101check_result $? "Add text" 102mv tmp.pem client-p521.pem 103echo "End of section" 104echo "---------------------------------------------------------------------" 105 106