Skip to content

Commit

Permalink
displaying gpg output
Browse files Browse the repository at this point in the history
  • Loading branch information
HarithaIBM committed Nov 15, 2024
1 parent 985c609 commit e646c47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions bin/zopen-build
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,15 @@ signPaxFile()

# Import the private key into the specified keyring files
printInfo "Importing private key..."
gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --secret-keyring "$TMP_GPG_DIR/secring.gpg" --batch --yes --import "$PRIVATE_KEY" > /dev/null 2>&1
gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --secret-keyring "$TMP_GPG_DIR/secring.gpg" --batch --yes --import "$PRIVATE_KEY"
if [ $? -ne 0 ]; then
extractPax=false
printError "Importing private key failed. Signing aborted."
fi

# Verify that the key was imported successfully
printInfo "Checking if secret key is imported..."
gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --secret-keyring "$TMP_GPG_DIR/secring.gpg" --list-secret-keys > /dev/null 2>&1
gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --secret-keyring "$TMP_GPG_DIR/secring.gpg" --list-secret-keys
if [ $? -ne 0 ]; then
extractPax=false
printError "No secret key found. Signing aborted."
Expand All @@ -533,7 +533,7 @@ signPaxFile()
# Sign the file
printInfo "Signing the file..."

gpg --armor --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --batch --verbose --pinentry-mode loopback --passphrase-file "$PASSPHRASE_FILE" --output "$OUTPUT_SIGNATURE" --detach-sig "$FILE_TO_SIGN" > /dev/null 2>&1
gpg --armor --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --batch --verbose --pinentry-mode loopback --passphrase-file "$PASSPHRASE_FILE" --output "$OUTPUT_SIGNATURE" --detach-sig "$FILE_TO_SIGN"

if [ $? -ne 0 ]; then
extractPax=false
Expand Down
34 changes: 14 additions & 20 deletions bin/zopen-install
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ checkWritable

startGPGAgent()
{
# Check if gpg-agent is running
if ps -ef | grep -v grep | grep "gpg-agent" ; then #> /dev/null; then
printInfo "gpg-agent is already running."
else
printInfo "gpg-agent is not running. Starting gpg-agent..."
gpg-agent --daemon
# Wait a moment to ensure the gpg-agent has time to start
sleep 2
# Check again to confirm if gpg-agent started successfully
if ps -ef | grep -v grep | grep "gpg-agent" > /dev/null; then
printInfo "gpg-agent started successfully."
else
printError "Failed to start gpg-agent. Install GPG using \"zopen install gpg -y\" command."
fi
fi
printInfo "Starting gpg-agent..."
gpg-agent --daemon
# Wait a moment to ensure the gpg-agent has time to start
sleep 2
# Check again to confirm if gpg-agent started successfully
if ps -ef | grep -v grep | grep "gpg-agent" > /dev/null; then
printInfo "gpg-agent started successfully."
else
printError "Failed to start gpg-agent. Install GPG using \"zopen install gpg -y\" command."
fi
}

verifySignatureOfPax()
Expand Down Expand Up @@ -65,19 +60,17 @@ verifySignatureOfPax()
PUBLIC_KEY_FILE="$zopen_tmp_dir/scriptpubkey.$LOGNAME.$$.asc"
printf "%b" "$SIGNATURE" | tr -d '"' > "$SIGNATURE_FILE"
printf "%b" "$PUBLIC_KEY" | tr -d '"' > "$PUBLIC_KEY_FILE"

startGPGAgent

printVerbose "Importing public key..."
[ -f "$PUBLIC_KEY_FILE" ] && gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --batch --yes --import "$PUBLIC_KEY_FILE" > /dev/null 2>&1
[ -f "$PUBLIC_KEY_FILE" ] && gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --batch --yes --import "$PUBLIC_KEY_FILE"
if [ $? -ne 0 ]; then
[ -e "${TMP_GPG_DIR}" ] && rm -rf "$TMP_GPG_DIR"
printError "Importing public key failed. Verification aborted."
fi

# Verify that the key was imported successfully
printVerbose "Checking if public key is imported..."
gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --list-keys > /dev/null 2>&1
gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --list-keys
if [ $? -ne 0 ]; then
[ -e "${TMP_GPG_DIR}" ] && rm -rf "$TMP_GPG_DIR"
printError "No public key found. Verification aborted."
Expand All @@ -86,7 +79,8 @@ verifySignatureOfPax()
# Verify the signature
printInfo "Verifying the gpg signature..."
if [ -f "$SIGNATURE_FILE" ]; then
if gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --verify "$SIGNATURE_FILE" "$FILE_TO_VERIFY" 2>&1 | grep -q "Good signature from"; then
gpg_output=$(gpg --no-default-keyring --keyring "$TMP_GPG_DIR/pubring.kbx" --verify "$SIGNATURE_FILE" "$FILE_TO_VERIFY" 2>&1)
if echo "$gpg_output" | grep -q "Good signature from"; then
printInfo "${NC}${GREEN}Signature verified successfully: ${name}${NC}"
return 0
else
Expand Down

0 comments on commit e646c47

Please sign in to comment.