Debian Codegraph @

src/security/core/tests/common/etc/create_p7s

raw
1 #!/usr/bin/env bash
2
3 # Argument
4 if [ -z "$1" ]
5 then
6 echo "This script can be used for signing Permissions and Governance file list. Can be called from any directory"
7 echo "Expected a filename list with or without the .xml extension"
8 echo "PERMISSION_CA_CERT and PERMISSION_CA_KEY environment variables are used for signing if they are set"
9 exit
10 fi
11
12 # Location of the pem files is the same as this script location.
13 PEM_LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
14 if [ -v PERMISSION_CA_CERT ] && [ -v PERMISSION_CA_KEY ] ; then
15 echo "Using custom permission key and certificate"
16 echo "PERMISSION_CA_CERT: $PERMISSION_CA_CERT"
17 echo "PERMISSION_CA_KEY: $PERMISSION_CA_KEY"
18 else
19 PERMISSION_CA_CERT=${PEM_LOCATION}/default_permissions_ca.pem
20 PERMISSION_CA_KEY=${PEM_LOCATION}/default_permissions_ca_key.pem
21 fi
22
23 # Do all given files.
24 for filename in "$@"
25 do
26 if [ ${filename:${#filename}-4:4} == ".xml" ] ; then
27 BASE_FILE_NAME=${filename:0:-4}
28 echo $BASE_FILE_NAME
29 else
30 BASE_FILE_NAME=$filename
31 fi
32
33 # Create the p7s file(s)
34 openssl smime -sign -in "${BASE_FILE_NAME}.xml" -text -out "${BASE_FILE_NAME}.p7s" -signer "$PERMISSION_CA_CERT" -inkey "$PERMISSION_CA_KEY"
35 done
36