diff options
-rwxr-xr-x | bin/ak-gpg | 32 | ||||
-rwxr-xr-x | config.sh | 2 | ||||
-rwxr-xr-x | init.sh | 1 | ||||
-rwxr-xr-x | lib/_ak_gpg | 103 |
4 files changed, 134 insertions, 4 deletions
@@ -12,7 +12,27 @@ ## ## --get-key-fingerprint-from-ipfs Returns the fingerprint of a given key ## -## --list-keys Returns a list of known GPG keys +## -l, --list-keys Returns a list of known GPG keys +## +## -lp, --list-keys-plain Returns a list of known GPG keys as +## plain GPG output +## +## -ll, --list-keys-long Returns a list of known GPG keys with +## their 1st uid +## +## -ls, --list-secret-keys Returns a list of secret GPG keys +## +## -lsp, --list-secret-keys-plain Returns a list of secret GPG keys as +## plain GPG output +## +## -lsl, --list-secret-keys-long Returns a list of secret GPG keys with +## their 1st uid +## +## -c, --create-key <email> Creates a GPG key with a label <email> +## +## -s, --select-key Selects the GPG key you want to use +## +## -d, --delete-key Delete GPG keys from your keyring ## fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) @@ -33,7 +53,15 @@ if [ ! -z $1 ]; then --get-key-self-as-ipfs) _ak_gpg_key_self_get_fingerprint_from_config; exit;; --get-key-self-as-fingerprint) _ak_gpg_key_self_get_fingerprint; exit;; --get-key-fingerprint-from-ipfs) _ak_gpg_key_get_fingerprint_from_ipfs $1; exit;; - --list-keys) _ak_gpg_list_keys; exit;; + --list-keys | -l) _ak_gpg_list_keys; exit;; + --list-keys-long | -ll) _ak_gpg_list_keys_long; exit;; + --list-keys-plain | -lp) _ak_gpg_list_keys_plain; exit;; + --list-secret-keys | -ls) _ak_gpg_list_secret_keys; exit;; + --list-secret-keys-long | -lsl) _ak_gpg_list_secret_keys_long; exit;; + --list-secret-keys-plain | -lsp) _ak_gpg_list_secret_keys_plain; exit;; + --create-key | -c) _ak_gpg_create_key $2; exit;; + --select-key | -s) _ak_gpg_select_key; exit;; + --delete-key | -d) _ak_gpg_delete_key; exit;; * ) _ak_usage;; esac else _ak_usage @@ -22,7 +22,7 @@ export AK_ZLIST="$AK_WORKDIR/zlist" export AK_ZLATEST="$AK_WORKDIR/zlatest" export AK_LOGSFILE="$AK_WORKDIR/logs" export AK_GPGHOME="$AK_WORKDIR/keyring" -export AK_FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -B 1 | head -n 1 | awk '{print $1}')" +export AK_FINGERPRINT="$(cat $AK_WORKDIR/selected_key)" export AK_MINEDBLOCKSDIR="$AK_WORKDIR/mined_blocks" export AK_ZBLOCKSFILE="$AK_WORKDIR/zBlocksFile" export AK_ZPAIRSFILE="$AK_WORKDIR/pairsFile" @@ -12,6 +12,7 @@ ak_gpg_check_or_create(){ then gpg2 --homedir $AK_GPGHOME --batch --passphrase '' --quick-gen-key kaos@kaos.kaos rsa3072 sign 0 AK_FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -B 1 | head -n 1 | awk '{print $1}')" + printf '%s' "$AK_FINGERPRINT" > $AK_WORKDIR/current_key gpg2 --homedir $AK_GPGHOME --batch --passphrase '' --quick-add-key $AK_FINGERPRINT rsa3072 encrypt 0 fi } diff --git a/lib/_ak_gpg b/lib/_ak_gpg index b0036ca..a2cca7a 100755 --- a/lib/_ak_gpg +++ b/lib/_ak_gpg @@ -7,6 +7,34 @@ _ak_gpg(){ gpg2 --homedir $AK_GPGHOME $* } +_ak_gpg_check_or_create(){ + _ak_gpg --list-keys | grep kaos@kaos.kaos -B 1 + if [ $? -ne 0 ] + then + _ak_gpg --batch --passphrase '' --quick-gen-key kaos@kaos.kaos rsa3072 sign 0 + AK_FINGERPRINT="$(_ak_gpg --list-keys | grep kaos@kaos.kaos -B 1 | head -n 1 | awk '{print $1}')" + _ak_gpg --batch --passphrase '' --quick-add-key $AK_FINGERPRINT rsa3072 encrypt 0 + fi +} + +_ak_gpg_create_key(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + _ak_log_error "No email label was given" + exit 1 + fi + _ak_gpg --list-secret-keys | grep -F $1 >/dev/null 2>&1 + if [ $? -eq 0 ] + then + _ak_log_error "Key exists with the same email label" + exit 1 + fi + exit 3 + _ak_gpg --batch --passphrase '' --quick-gen-key $1 rsa3072 sign 0 + AK_FINGERPRINT="$(_ak_gpg --list-keys | grep $1 -B 1 | head -n 1 | awk '{print $1}')" + _ak_gpg --batch --passphrase '' --quick-add-key $AK_FINGERPRINT rsa3072 encrypt 0 +} + _ak_gpg_key_import_from_file(){ if [ -z $1 ] then @@ -56,6 +84,15 @@ _ak_gpg_key_get_fingerprint_from_ipfs(){ fi } +_ak_gpg_sign(){ + if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] + then + _ak_gpg --sign --sign-with $AK_FINGERPRINT --armor --output $1 $2 + else + exit 1 + fi +} + _ak_gpg_sign_detached(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] then @@ -65,6 +102,15 @@ _ak_gpg_sign_detached(){ fi } +_ak_gpg_sign_clear(){ + if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] + then + _ak_gpg --clear-sign --sign-with $AK_FINGERPRINT --armor --output $1 $2 + else + exit 1 + fi +} + _ak_gpg_encrypt_sign(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ ! -z $3 ] && [ -n "$3" ] then @@ -120,17 +166,72 @@ _ak_gpg_key_self_export(){ fi } +_ak_gpg_list_keys_plain(){ + _ak_gpg --list-keys +} + _ak_gpg_list_keys(){ _ak_gpg --list-keys | grep '^ ' | awk '{print $1}' } +_ak_gpg_list_keys_long(){ + _ak_gpg --list-keys | \ + grep -A 1 '^ \{6\}' | \ + tr $'\n' ' ' | \ + tr '\-\-' $'\n' | \ + awk '{print $1 " " $5}' | \ + sort | \ + uniq +} + +_ak_gpg_list_secret_keys_plain(){ + _ak_gpg --list-secret-keys +} + +_ak_gpg_list_secret_keys(){ + _ak_gpg --list-secret-keys | grep '^ ' | awk '{print $1}' +} + +_ak_gpg_list_secret_keys_long(){ + _ak_gpg --list-secret-keys | \ + grep -A 1 '^ \{6\}' | \ + tr $'\n' ' ' | \ + tr '\-\-' $'\n' | \ + awk '{print $1 " " $5}' | \ + sort | \ + uniq +} + _ak_gpg_select_key(){ + select x in $(_ak_gpg_list_secret_keys | tr '\n' ' ') + do + if [ -n "$x" ] + then + _ak_log_info "$x was selected" + printf '%s' "$x" > $AK_WORKDIR/selected_key + break + else + _ak_log_warning "You didn't select a key" + fi + done +} + +_ak_gpg_delete_key(){ select x in $(_ak_gpg_list_keys | tr '\n' ' ') do - echo $x if [ -n "$x" ] then + _ak_log_info "$x was selected" + _ak_gpg --delete-keys $x + if [ $? -ne 0 ] + then + _ak_log_error "Some error occured while removing $x" + else + _ak_log_info "Key $x was deleted" + fi break + else + _ak_log_warning "You didn't select a key" fi done } |