4

I am new to Unix and ksh script writing. I wrote a script that decrypts a gpg message. I get this error that I do not know how to resolve. I was hoping someone could look at my script and help me figure out what is going on. Thank you for any assistance you can provide. Here is the error:

gpg: processing message failed: eof

Here is my script:

#!/bin/ksh
####################################################################       
#   1. Decrypt Inbound File                                        #
#                                                                  #
#   Two parms are required:   output file                          #
#                             encrypted file(to be decrypted)      #
#                                                                  #
####################################################################
# Variable declaration                                             #
####################################################################
outputF=$1 
encryptedF=$2
id=$$
####################################################################
# print_message                                                    #
#    prints messages to log file                                   #
####################################################################
print_message()
{
   message="$1"
   echo "`date '+%m-%d-%y %T'`  $message" 

}
#####################################################################
# Validate input parameters and existence of encrypted file         #
#####################################################################

if [ $1 -eq ""] ||  [ $2 -eq ""]
    then 
    print_message "Parameters not satisfied"

    exit 1 
fi 

if [ ! -f $encryptedF ]
then
   print_message "$id ERROR: $encryptedF File does not exist"
   exit 1
fi

#####################################################
#               Decrypt encryptedF                  #
#####################################################

gpg --output "$outputF" --decrypt "$encryptedF"

echo "PASSPHRASE" | gpg --passphrase-fd 0 

print_message "$id INFO: File Decrypted Successfully"
3
  • You wrote: I get this error that I do not know how to resolve... Please edit your message to include the exact text of the error message. As you have discovered, use the {} edit tool to keep the format of the message. Good luck. Commented Aug 5, 2013 at 22:12
  • @shellter updated, do you think you can help? Commented Aug 5, 2013 at 23:43
  • please edit your question to show which line with gpg you are executing. All the other code looks fine, I would delete that, and post only the simpliest test case for gpg. ..... I'm not sure how I can help, given what I know about unix processes in general, I would have expected your 2 commands to be merged into one, AND for the output of gpg to be sent somewhere: a redirect file like gpg ... > unecryptedFile OR assigned to shell variable like myUnecryptedOutput=$(gpg .... ). Can you update to include expected output of using some simple phrase of input? Good luck. Commented Aug 6, 2013 at 0:58

1 Answer 1

3

This is not a gpg problem :-) Your script tries to run the gpg binary twice. The first call tries to decode the file:

gpg --output "$outputF" --decrypt "$encryptedF"

Since no means of passphrase input is given, gpg tries to read the passphrase from the console. What now happens, depends on your gpg configuration, ksh behaviour, etc., but I suspect interaction with STDIN is somehow crippled, resulting in the EOF error.

The solution of your problem: You have to add the passphrase source to the decryption call:

echo "PASSPHRASE" | gpg --passphrase-fd 0 --output "$outputF" --decrypt "$encryptedF"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.