Skip to content

Commit

Permalink
update certGen.sh (#670)
Browse files Browse the repository at this point in the history
* update certGen.sh

fix the openssl -subj parameter to make the script successfully run on windows and linux os

* make the CN subject by tracking the OSTYPE value

* function makeCNsubject check only pure windows OSTYPE
  • Loading branch information
nnmer authored and jspaith committed Feb 20, 2019
1 parent 31c09d4 commit 609482a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/CACertificates/certGen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ intermediate_ca_password="1234"
root_ca_prefix="azure-iot-test-only.root.ca"
intermediate_ca_prefix="azure-iot-test-only.intermediate"

function makeCNsubject()
{
local result="/CN=${1}"
case $OSTYPE in
msys|win32) result="/${result}"
esac
echo "$result"
}

function warn_certs_not_for_production()
{
tput smso
Expand Down Expand Up @@ -64,7 +73,7 @@ function generate_root_ca()
-config ${openssl_root_config_file} \
${password_cmd} \
-key ${root_ca_dir}/private/${root_ca_prefix}.key.pem \
-subj "/CN=${common_name}" \
-subj "$(makeCNsubject "${common_name}")" \
-days ${days_till_expire} \
-sha256 \
-extensions v3_ca \
Expand Down Expand Up @@ -115,7 +124,7 @@ function generate_intermediate_ca()
openssl req -new -sha256 \
${password_cmd} \
-config ${openssl_intermediate_config_file} \
-subj "/CN=${common_name}" \
-subj "$(makeCNsubject "${common_name}")" \
-key ${intermediate_ca_dir}/private/${intermediate_ca_prefix}.key.pem \
-out ${intermediate_ca_dir}/csr/${intermediate_ca_prefix}.csr.pem
[ $? -eq 0 ] || exit $?
Expand Down Expand Up @@ -197,7 +206,7 @@ function generate_device_certificate_common()
echo "----------------------------------------"
openssl req -config ${openssl_config_file} \
-key ${certificate_dir}/private/${device_prefix}.key.pem \
-subj "/CN=${common_name}" \
-subj "$(makeCNsubject "${common_name}")" \
-new -sha256 -out ${certificate_dir}/csr/${device_prefix}.csr.pem
[ $? -eq 0 ] || exit $?

Expand Down

0 comments on commit 609482a

Please sign in to comment.