@@ -73,16 +73,21 @@ realpath() {
7373
7474_openssl_encrypt () {
7575 # In 3.x openssl disabled output of the salt prefix, which we need for determinism.
76- # We take control over outputting the the prefix 'Salted__' with the salt
76+ # For 3.x we take control over outputting the the prefix 'Salted__' with the salt
7777 # to ensure it is always included regardless of the OpenSSL version. #133
78- (
79- # Always prepend encrypted ciphertext with "Salted__" prefix and binary salt value
80- printf " Salted__" && printf " %s" " $final_salt " | xxd -r -p &&
81- # Encrypt file to binary ciphertext
82- ENC_PASS=$password " $openssl_path " enc -e " -${cipher} " -md " ${digest} " -pass env:ENC_PASS -S " $final_salt " " ${pbkdf2_args[@]} " -in " $tempfile " |
83- # Strip "Salted__" prefix and salt value if also added by OpenSSL (version < 3)
84- LC_ALL=C sed -e " s/^\(Salted__.\{8\}\)\(.*\)/\2/"
85- ) | base64
78+ openssl_major_version=$( $openssl_path version | cut -d' ' -f2 | cut -d' .' -f1)
79+ if [ " $openssl_major_version " -ge " 3" ]; then
80+ # Encrypt the file to base64, ensuring it includes the prefix 'Salted__' with the salt. #133
81+ (
82+ printf " Salted__" && printf " %s" " $final_salt " | xxd -r -p &&
83+ # Encrypt file to binary ciphertext
84+ ENC_PASS=$password " $openssl_path " enc -e " -${cipher} " -md " ${digest} " -pass env:ENC_PASS -S " $final_salt " " ${pbkdf2_args[@]} " -in " $tempfile "
85+ ) |
86+ base64
87+ else
88+ # Encrypt file to base64 ciphertext
89+ ENC_PASS=$password " $openssl_path " enc -e -a " -${cipher} " -md " ${digest} " -pass env:ENC_PASS -S " $final_salt " " ${pbkdf2_args[@]} " -in " $tempfile "
90+ fi
8691}
8792
8893_openssl_decrypt () {
@@ -295,7 +300,7 @@ gather_repo_metadata() {
295300
296301 # the current git repository's gitattributes file
297302 local CORE_ATTRIBUTES
298- CORE_ATTRIBUTES=$( git config --get --local --path core.attributesFile 2> /dev/null || printf ' ' )
303+ CORE_ATTRIBUTES=$( git config --get --local --path core.attributesFile 2> /dev/null || git config --get --path core.attributesFile 2> /dev/null || printf ' ' )
299304 if [[ $CORE_ATTRIBUTES ]]; then
300305 readonly GIT_ATTRIBUTES=$CORE_ATTRIBUTES
301306 elif [[ $IS_BARE == ' true' ]] || [[ $IS_VCSH == ' true' ]]; then
@@ -530,6 +535,12 @@ run_safety_checks() {
530535 for cmd in {column,grep,mktemp," ${openssl_path} " ,sed,tee}; do
531536 command -v " $cmd " > /dev/null || die ' required command "%s" was not found' " $cmd "
532537 done
538+ # check for extra `xxd` dependency when running against OpenSSL version 3+
539+ openssl_major_version=$( $openssl_path version | cut -d' ' -f2 | cut -d' .' -f1)
540+ if [ " $openssl_major_version " -ge " 3" ]; then
541+ cmd=" xxd"
542+ command -v " $cmd " > /dev/null || die ' required command "%s" was not found' " $cmd "
543+ fi
533544
534545 # ensure the repository is clean (if it has a HEAD revision) so we can force
535546 # checkout files without the destruction of uncommitted changes
0 commit comments