Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
024f16b
python script for signing
diveshuttam May 30, 2018
d108baf
Reorganize python scripts in a separate directory. (closes #25)
dashohoxha May 31, 2018
d22229f
add verify script (#53)
diveshuttam Jun 6, 2018
52bb20a
Fix seal problem (#50)
dashohoxha Jun 7, 2018
c009d11
key/rev.py added (closes #50)
diveshuttam Jun 14, 2018
b94a9f2
Add key delete (#58)
diveshuttam Jun 16, 2018
f181139
setup debug log (#62)
diveshuttam Jun 21, 2018
113093a
Make tests pass (#64)
diveshuttam Jun 23, 2018
e7f9cbc
Add seal.py (#60)
diveshuttam Jun 23, 2018
455f341
Add open.py (#61)
diveshuttam Jun 23, 2018
ee04183
Add contact import (#69)
diveshuttam Jun 27, 2018
c922b43
Issue38 (#70)
diveshuttam Jun 27, 2018
5b0edf0
Add print_key.py (#66)
diveshuttam Jun 28, 2018
49c5b5a
key gen added (#67)
diveshuttam Jun 29, 2018
cde2b80
update a few tests (#71)
diveshuttam Jun 30, 2018
5b99753
add key pass functionality (#68)
diveshuttam Jul 2, 2018
8516640
contact fetch added, contact export added (#77)
diveshuttam Jul 2, 2018
a3a74de
contact delete and list added (#78)
diveshuttam Jul 5, 2018
b06a724
add contact trust (#80)
diveshuttam Jul 6, 2018
cb23f39
Add contact renew
diveshuttam Jul 7, 2018
e3cc0f5
move commands functionality to python script
diveshuttam Jul 9, 2018
c2ef8f8
Use lists instead of string.split
diveshuttam Jul 9, 2018
8492078
Improve code
diveshuttam Jul 11, 2018
922f4ea
Merge pull request #81 from EasyGnuPG/issue49
diveshuttam Jul 11, 2018
4bd6c99
Merge branch 'gnupg-2.2' into code_improvements
diveshuttam Jul 11, 2018
2560681
Use decorators and other functions to simplify code
diveshuttam Jul 11, 2018
cb952dc
s/auxilary/auxiliary
diveshuttam Jul 12, 2018
d202a79
Add note about handle exception decorator
diveshuttam Jul 12, 2018
114bb3d
Merge pull request #85 from EasyGnuPG/code_improvements
diveshuttam Jul 12, 2018
19f0a5f
[WIP] hkp demo added
diveshuttam Jul 13, 2018
8d02d9b
add search
diveshuttam Aug 7, 2018
9dc4c9c
add receive
diveshuttam Aug 7, 2018
5773262
add gpg version from python
diveshuttam Aug 7, 2018
90b343f
added regex for receive keys
diveshuttam Aug 7, 2018
6c5a096
resolve flake issues
diveshuttam Aug 7, 2018
e573244
add pycache to gitignore
diveshuttam Aug 7, 2018
03541da
Merge pull request #86 from EasyGnuPG/hkp
diveshuttam Aug 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ tests/gnupg/pubring.kbx
tests/gnupg/trustdb.gpg
tests/gnupg/tofu.db
tests/gnupg/pubring.kbx~
__pycache__/
*.pyc
5 changes: 4 additions & 1 deletion src/auxiliary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ is_false() {
}

gpg_version() {
gpg --version | head -n 1 | cut -d" " -f3
python3 <<EndOfPythonCode
import gpg
print(gpg.Context().engine_info.version)
EndOfPythonCode
}

# Return the ids of the keys that are not revoked and not expired.
Expand Down
6 changes: 1 addition & 5 deletions src/cmd/contact/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ cmd_contact_delete() {
[[ $err != 0 ]] && fail "Usage:\n$(cmd_contact_delete_help)"
[[ -z $1 ]] && fail "Usage:\n$(cmd_contact_delete_help)"

if [[ $force == 0 ]]; then
gpg --delete-keys "$@"
else
gpg --batch --no-tty --yes --delete-keys "$@"
fi
call_gpg contact/delete.py $force "$@"
}

#
Expand Down
11 changes: 9 additions & 2 deletions src/cmd/contact/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _EOF
}

cmd_contact_export() {
local opts output="-"
local opts output
opts="$(getopt -o o: -l output: -n "$PROGRAM" -- "$@")"
local err=$?
eval set -- "$opts"
Expand All @@ -21,8 +21,15 @@ cmd_contact_export() {
done
[[ $err == 0 ]] || fail "Usage:\n$(cmd_contact_export_help)"

if [[ -f "$output" ]]; then
yesno "File '$output' exists. Overwrite?" || return 1
fi

# set output to stdout if empty
[[ -z "$output" ]] && output="-"

# export
gpg --armor --export --output $output $@
call_gpg contact/export.py "$GNUPGHOME" "$output" "$@"
}

#
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/contact/fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ cmd_contact_fetch() {
# export to tmp file
workdir_make
local file="$WORKDIR/contacts.asc"
gpg --homedir="$homedir" --armor --export "$@" > "$file"
call_gpg contact/export.py "$homedir" "$file" "$@"

# import from the tmp file
gpg --import "$file"
call_gpg contact/import.py "$file"
workdir_clear
}

Expand Down
3 changes: 1 addition & 2 deletions src/cmd/contact/fetchuri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ _EOF

cmd_contact_fetchuri() {
[[ -z $1 ]] && fail "Usage:\n$(cmd_contact_fetchuri_help)"
#gpg --fetch-keys "$@"
workdir_make
cd "$WORKDIR"
wget -q $@
gpg --import *
call_gpg contact/import.py *
workdir_clear
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/contact/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cmd_contact_import() {

# import
echo "Importing contacts from file: $file"
gpg --import "$file"
call_gpg contact/import.py "$file"
}

#
Expand Down
9 changes: 1 addition & 8 deletions src/cmd/contact/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ cmd_contact_list() {
return

# display the details of each key
local ids
ids=$(gpg --list-keys --with-colons "$@" | grep '^pub' | cut -d: -f5)
source "$LIBDIR/fn/print_key.sh"
for id in $ids; do
echo
print_key $id
echo
done
call_gpg contact/list.py "$@"
}

#
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/contact/receive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cmd_contact_receive() {
[[ $err != 0 ]] && fail "Usage:\n$(cmd_contact_receive_help)"
[[ -z $1 ]] && fail "Usage:\n$(cmd_contact_receive_help)"

gpg --keyserver "$keyserver" --recv-keys "$@"
call_gpg contact/receive.py "$keyserver" "$@"
}

#
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/contact/search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cmd_contact_search() {
[[ $err != 0 ]] && fail "Usage:\n$(cmd_contact_search_help)"
[[ -z $1 ]] && fail "Usage:\n$(cmd_contact_search_help)"

gpg --keyserver="$keyserver" --search-keys "$@"
call_gpg contact/search.py "$keyserver" "$@"
}

#
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/contact/trust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ cmd_contact_trust() {
*) fail "Unknown trust level: $level" ;;
esac

local commands=$(echo "$level|quit" | tr '|' "\n")
echo -e "$commands" | gpg --no-tty --command-fd=0 --edit-key "$contact" trust 2>/dev/null
call_gpg contact/trust.py "$contact" "$level" || fail ""
call cmd_contact_list "$contact" | grep -e "^uid:" -e "^trust:" -e "^\$"
}

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/key/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ cmd_key_delete() {
for grip in $(get_keygrips $key_id); do
rm -f "$GNUPGHOME"/private-keys-v1.d/$grip.key
done

# delete public keys
gpg --delete-keys --batch --yes "$fingerprint"
call_gpg key/delete.py "$fingerprint"

# remove any partials
rm -f "$GNUPGHOME"/$key_id.key.[0-9][0-9][0-9]
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/key/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cmd_key_gen() {

# generate the key
haveged_start
echo -e "$PARAMETERS" | gpg --batch --gen-key 2>/dev/null
call_gpg key/gen.py "$PARAMETERS" || fail ""
haveged_stop

# restrict expiration time to 1 month from now
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/key/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ cmd_key_list() {
return

# display the details of each key
source "$LIBDIR/fn/print_key.sh"
for gpg_key in $secret_keys; do
echo
print_key $gpg_key
call_gpg fn/print_key.py $gpg_key
echo
done
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/key/pass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Try first: $(basename $0) key join
and: $(basename $0) key split
"

gpg --batch --no-tty --passwd $GPG_KEY
call_gpg key/pass.py $GPG_KEY
}

#
Expand Down
4 changes: 1 addition & 3 deletions src/cmd/key/renew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ Try first: $(basename $0) key join
local today=$(date -d $(date +%F) +%s)
time=$(( ( $expday - $today ) / 86400 ))

local commands=";expire;$time;y;key 1;expire;$time;y;key 1;save"
commands=$(echo "$commands" | tr ';' "\n")
echo -e "$commands" | gpg --no-tty --command-fd=0 --key-edit $GPG_KEY 2>/dev/null
call_gpg key/renew.py "$GPG_KEY" "$time" || fail ""
call_fn gpg_send_keys $GPG_KEY

call cmd_key_list
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/key/rev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Are you sure about this?" || return 1

# import the revocation certificate
sed -i "$revcert" -e "s/^:---/---/"
gpg --import "$revcert"
call_gpg key/rev.py "$revcert" || fail ""

call_fn gpg_send_keys $GPG_KEY
}

Expand Down
8 changes: 5 additions & 3 deletions src/cmd/open.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ cmd_open() {
local output=${file%.sealed}
[[ "$output" != "$file" ]] || fail "The given file does not end in '.sealed'."

if [[ -f "$output" ]]; then
yesno "File '$output' exists. Overwrite?" || return 1
fi

# decrypt and verify
gnupghome_setup
gpg --keyserver "$KEYSERVER" \
--keyserver-options auto-key-retrieve,honor-keyserver-url \
--decrypt --output "$output" "$file"
call_gpg open.py "$file" "$output" # $output will be overwritten if exists
gnupghome_reset
}

Expand Down
18 changes: 7 additions & 11 deletions src/cmd/seal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@ cmd_seal() {
rm -f "$file.sealed"
fi

# get recipients
get_gpg_key
local recipients="--recipient $GPG_KEY"
while [[ -n "$1" ]]; do
recipients="$recipients --recipient $1"
shift
done

local recipients=("$GPG_KEY" "$@")

# sign and encrypt
gnupghome_setup
gpg --no-tty --auto-key-locate=local,cert,keyserver,pka \
--keyserver "$KEYSERVER" $recipients \
--sign --encrypt --armor \
--output "$file.sealed" "$file"
call_gpg seal.py "$file" "$recipients"
local err=$?
gnupghome_reset

[[ $err == 0 ]] || fail ""

[[ -s "$file.sealed" ]] || rm -f "$file.sealed"
[[ -f "$file.sealed" ]] && shred "$file"
}

Expand Down
3 changes: 1 addition & 2 deletions src/cmd/sign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ cmd_sign() {

# sign
gnupghome_setup
gpg --local-user $GPG_KEY \
--detach-sign --armor --output "$file.signature" "$file"
call_gpg sign.py $GPG_KEY "$file"
gnupghome_reset
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cmd_verify() {
[[ -f "$file" ]] || fail "Cannot find file '$file'"

# verify
gpg --verify "$signature" "$file"
call_gpg verify.py "$signature" "$file"
}

#
Expand Down
13 changes: 13 additions & 0 deletions src/egpg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ call_fn() {
$fn "$@"
}

call_gpg() {
local file=$1; shift
local pyfile="$LIBDIR/gpg/$file"
[[ -f "$pyfile" ]] || fail "Cannot find python file: $pyfile"
if is_true $DEBUG; then
# User can override level by exporting GPGME_DEBUG
[[ -z "$GPGME_DEBUG" ]] && export GPGME_DEBUG=2
fi
export PYTHONPATH=$PYTHONPATH:"$LIBDIR/gpg/"
python3 "$pyfile" "$@"
}

call_ext() {
local cmd=$1; shift

Expand Down Expand Up @@ -185,6 +197,7 @@ config() {

export GNUPGHOME
export GPG_TTY=$(tty)
export DEBUG

# create the config file, if it does not exist
local gpghome="$GNUPGHOME"
Expand Down
54 changes: 0 additions & 54 deletions src/fn/print_key.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/fn/restore_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ restore_key() {

# restore public keys
local pub_key=$(ls "$WORKDIR"/*/*.pub)
gpg --import "$pub_key" || fail "Failed to import public key."
call_gpg contact/import.py "$pub_key" || fail "Failed to import public key."

# set trust to 'ultimate'
local key_id=$(basename "${pub_key%.pub}")
Expand Down
Empty file added src/gpg/__init__.py
Empty file.
Empty file added src/gpg/contact/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions src/gpg/contact/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

import gpg

from fn.auxiliary import handle_exception
from fn.print_key import print_key


@handle_exception(gpg.errors.GpgError)
def delete(contacts, force):
c = gpg.Context()
for contact in contacts:
keys = list(c.keylist(contact))
ans = "n"
for key in keys:
if not force:
print_key(key.fpr, end="\n")
try:
ans = input("Delete this contact? (y/N)")
except EOFError:
exit(0)

if ans.lower() == 'y' or force:
c.op_delete(key, False)


if __name__ == "__main__":
force = int(sys.argv[1])
contacts = sys.argv[2:]
delete(contacts, force)
Loading