Created
July 15, 2024 14:34
-
-
Save samj/66a2e8c601d4ada405080a227935cb0a to your computer and use it in GitHub Desktop.
pinentry program for gpg to access a 1password item via its CLI (op)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set your vault ID and item ID | |
ACCOUNT_ID="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
VAULT_ID="abcdefghijklmnopqrstuvwxyz" | |
ITEM_ID="abcdefghijklmnopqrstuvwxyz" | |
# Authenticate with 1Password (if not already authenticated) | |
# Retrieve the passphrase from 1Password | |
#PASSPHRASE=$(op item get $ITEM_ID --vault $VAULT_ID --fields label=passphrase --format=json | jq -r .value) | |
#PASSPHRASE=$(op item get $ITEM_ID --fields label=password) | |
echo "OK Pleased to meet you" | |
while IFS= read -r cmd; do | |
case "$cmd" in | |
GETPIN) | |
if ! op whoami > /dev/null 2>&1; then | |
eval $(op signin --account $ACCOUNT_ID) | |
fi | |
PASSPHRASE=$(op item get $ITEM_ID --vault $VAULT_ID --fields label=password) | |
echo "D $PASSPHRASE" | |
echo "OK" | |
;; | |
SETDESC*) | |
echo "OK" | |
;; | |
SETPROMPT*) | |
echo "OK" | |
;; | |
SETERROR*) | |
echo "OK" | |
;; | |
SETOK*) | |
echo "OK" | |
;; | |
SETCANCEL*) | |
echo "OK" | |
;; | |
GETINFO*) | |
echo "D none" | |
echo "OK" | |
;; | |
BYE) | |
echo "OK closing connection" | |
exit 0 | |
;; | |
*) | |
echo "OK" | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment