How to pass the .crt content read from the secrets in bash script?

203 Views Asked by At

I have copied the content of the .crt and .key files to the Kubernetes secrets. Then i'm trying to read the same from the bash script when I deploy the application and I can able to read it. It shows the data something as below(sample example)

CLIENT_KEY=absncb asdasdas asdasdasd asdasdasd== asdasddf

when I use the above displayed CLIENT_KEY to generate the .pkc12 file using the below shell script, I'm getting an error such as pkcs12: Use -help for summary.

#!/bin/bash

hdlKey=absncb asdasdas asdasdasd asdasdasd== asdasddf
hdlCert=absncb asdasdas asdasdasd asdasdasd== asdasddf asadasdii

function checkHDLKey(){
  if [ -z "$hdlKey" ] && [ -z "$hdlCert"]; then
    echo "ERROR - HDL values were not properly read"
  else
    echo $hdlKey
    echo $hdlCert
  fi
}

checkHDLKey

PCK12_PATH="/app/pk12/client-keystore.p12"

function generate_password {
  KEY=$(openssl rand -base64 16)
  echo $KEY
}

result=$(generate_password)
echo $result

function generate_pkc12_cert {
    # Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)
    echo "Inside generate_pkc12_cert"
    (openssl pkcs12 -export -inkey $hdlKey -in $hdlCert -out "/app/pk12/client-keystore.p12" -password pass:$result)
    echo "Done generate_pkc12_cert "
}

generate_pkc12_cert

any help would be appreciated. Also is this the write way to read it?

0

There are 0 best solutions below