fix cerrificate bundle issue. (#1266)

LGTM
This commit is contained in:
Wenkai Yin 2016-12-26 15:49:53 +08:00 committed by yhua123
parent 6088d45686
commit ad4da5f043

View File

@ -42,15 +42,18 @@ flag=$base_dir/cert_gen_type
#The location of harbor.cfg
cfg=$base_dir/harbor/harbor.cfg
#Format cert and key files
function format {
file=$1
head=$(sed -rn 's/(-+[A-Za-z ]*-+)([^-]*)(-+[A-Za-z ]*-+)/\1/p' $file)
body=$(sed -rn 's/(-+[A-Za-z ]*-+)([^-]*)(-+[A-Za-z ]*-+)/\2/p' $file)
tail=$(sed -rn 's/(-+[A-Za-z ]*-+)([^-]*)(-+[A-Za-z ]*-+)/\3/p' $file)
echo $head > $file
echo $body | sed 's/\s\+/\n/g' >> $file
echo $tail >> $file
#Format cert file
function formatCert {
content=$1
file=$2
echo $content | sed -r "s/ /\n/g" | sed -r "/-+$/d" | sed -r "s/^(-+).*/& CERTIFICATE\1/g" > $file
}
#Format key file
function formatKey {
content=$1
file=$2
echo $content | sed -r "s/ /\n/g" | sed -r "/^PRIVATE$/d"| sed -r "/-+$/d" | sed -r "s/^(-+).*/& PRIVATE KEY\1/g" > $file
}
function genCert {
@ -81,10 +84,8 @@ function secure {
if [ -n "$ssl_cert" ] && [ -n "$ssl_cert_key" ]
then
echo "ssl_cert and ssl_cert_key are both set, using customized certificate"
echo $ssl_cert > $cert
format $cert
echo $ssl_cert_key > $key
format $key
formatCert "$ssl_cert" $cert
formatKey "$ssl_cert_key" $key
echo "customized" > $flag
return
fi