Skip to content

Commit e18f597

Browse files
committed
Improve GPG agent configuration and passphrase presetting
1 parent a1a2edf commit e18f597

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

.github/workflows/main.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,25 @@ jobs:
267267
rm -f ~/.gnupg/gpg.conf
268268
269269
# Configure GPG for non-interactive use
270-
# pinentry-mode is a valid GPG option, but use simpler config
271270
cat > ~/.gnupg/gpg.conf <<EOF
272271
use-agent
272+
pinentry-mode loopback
273273
EOF
274274
275275
# Configure gpg-agent for loopback pinentry
276276
cat > ~/.gnupg/gpg-agent.conf <<EOF
277277
allow-loopback-pinentry
278+
default-cache-ttl 3600
279+
max-cache-ttl 3600
278280
EOF
279281
chmod 600 ~/.gnupg/gpg-agent.conf
280282
281283
# Kill any existing gpg-agent and start fresh with loopback pinentry
282284
gpgconf --kill gpg-agent 2>/dev/null || true
285+
gpgconf --kill dirmngr 2>/dev/null || true
286+
sleep 1
283287
gpg-agent --daemon --allow-loopback-pinentry > /dev/null 2>&1 || true
284-
sleep 1 # Give gpg-agent time to start
288+
sleep 2 # Give gpg-agent time to start
285289
286290
# Import the subkey
287291
# Write key to temp file (key data is okay, but passphrase never touches disk)
@@ -305,13 +309,28 @@ jobs:
305309
306310
# Preset passphrase in gpg-agent for non-interactive signing
307311
# This allows GoReleaser to sign without prompting for passphrase
308-
KEYGRIP=$(gpg --list-secret-keys --with-keygrip --keyid-format LONG "$FINGERPRINT_UPPER" | grep -A1 "^sec" | tail -1 | awk '{print $3}')
309-
if [ -n "$KEYGRIP" ]; then
310-
echo "$GPG_PASSPHRASE" | gpg-preset-passphrase --preset "$KEYGRIP"
311-
echo "✓ Passphrase preset in gpg-agent for keygrip: $KEYGRIP"
312+
# Extract keygrip - try both sec (master key) and ssb (subkey) lines
313+
KEYGRIP=$(gpg --list-secret-keys --with-keygrip --keyid-format LONG "$FINGERPRINT_UPPER" 2>/dev/null | grep -E "^sec|^ssb" | head -1 | awk '{print $NF}')
314+
if [ -z "$KEYGRIP" ]; then
315+
# Try alternative method - get keygrip from the subkey line
316+
KEYGRIP=$(gpg --list-secret-keys --with-keygrip --keyid-format LONG "$FINGERPRINT_UPPER" 2>/dev/null | grep -A5 "^sec" | grep "Keygrip" | head -1 | awk '{print $3}')
317+
fi
318+
319+
if [ -n "$KEYGRIP" ] && [ ${#KEYGRIP} -eq 40 ]; then
320+
echo "$GPG_PASSPHRASE" | gpg-preset-passphrase --preset "$KEYGRIP" 2>&1
321+
if [ $? -eq 0 ]; then
322+
echo "✓ Passphrase preset in gpg-agent for keygrip: $KEYGRIP"
323+
else
324+
echo "⚠ Warning: Failed to preset passphrase for keygrip: $KEYGRIP"
325+
fi
312326
else
313-
echo "⚠ Warning: Could not find keygrip for fingerprint $FINGERPRINT_UPPER"
327+
echo "⚠ Warning: Could not find valid keygrip for fingerprint $FINGERPRINT_UPPER"
328+
echo "Debug: Listing keys with keygrips:"
329+
gpg --list-secret-keys --with-keygrip --keyid-format LONG "$FINGERPRINT_UPPER" 2>&1 || true
314330
fi
331+
332+
# Verify gpg-agent is running and can sign
333+
echo "test" | gpg --batch --pinentry-mode loopback --sign --local-user "$FINGERPRINT_UPPER" -o /dev/null 2>&1 && echo "✓ Test signing successful" || echo "⚠ Test signing failed"
315334
316335
# Test signing capability (GoReleaser will test this anyway, but verify key is importable)
317336
# Note: We skip actual signing test here since --passphrase-fd consumes stdin

0 commit comments

Comments
 (0)