aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_gpg
diff options
context:
space:
mode:
Diffstat (limited to 'lib/_ak_gpg')
-rwxr-xr-xlib/_ak_gpg106
1 files changed, 69 insertions, 37 deletions
diff --git a/lib/_ak_gpg b/lib/_ak_gpg
index b381067..7832ca1 100755
--- a/lib/_ak_gpg
+++ b/lib/_ak_gpg
@@ -1,24 +1,45 @@
-#!/bin/bash
-source $AK_LIBDIR/_ak_log
-source $AK_LIBDIR/_ak_ipfs
-source $AK_LIBDIR/_ak_config
-source $AK_LIBDIR/_ak_settings
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+_ak_lib_load _ak_ipfs
+_ak_lib_load _ak_config
+_ak_lib_load _ak_settings
-_ak_gpg(){
+export AK_FINGERPRINT="$(_ak_settings_get gpg.fingerprint)"
+
+function _ak_gpg(){
gpg2 --homedir $AK_GPGHOME $*
}
-_ak_gpg_check_or_create(){
+function _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
+ FINGERPRINT="$(_ak_gpg --list-keys | grep kaos@kaos.kaos -B 1 | head -n 1 | awk '{print $1}')"
+ _ak_gpg --batch --passphrase '' --quick-add-key $FINGERPRINT rsa3072 encrypt 0
fi
}
-_ak_gpg_create_key(){
+function _ak_gpg_create_key(){
_ak_log_debug "Key name: $1"
if [ -z $1 ] || [ ! -n "$1" ]
then
@@ -36,7 +57,7 @@ _ak_gpg_create_key(){
_ak_gpg --batch --passphrase '' --quick-add-key $FINGERPRINT rsa4096 encrypt 0
}
-_ak_gpg_key_import_from_file(){
+function _ak_gpg_key_import_from_file(){
if [ -z $1 ]
then
_ak_log_error "No argument given"
@@ -55,11 +76,11 @@ _ak_gpg_key_import_from_file(){
_ak_gpg --import $AK_IPFS_ARTIFACTS/$1 > /dev/null 2>&1
}
-_ak_gpg_key_self_get_fingerprint_from_config(){
+function _ak_gpg_key_self_get_fingerprint_from_config(){
_ak_config_show | jq -r '.gpg'
}
-_ak_gpg_key_self_get_fingerprint(){
+function _ak_gpg_key_self_get_fingerprint(){
if [ -z $1 ]
then
_ak_ipfs_cat "$(_ak_gpg_key_self_get_fingerprint_from_config)" | \
@@ -72,7 +93,7 @@ _ak_gpg_key_self_get_fingerprint(){
fi
}
-_ak_gpg_key_get_fingerprint_from_ipfs(){
+function _ak_gpg_key_get_fingerprint_from_ipfs(){
if [ -n "$1" ]
then
_ak_ipfs_cat "$1" | \
@@ -85,7 +106,7 @@ _ak_gpg_key_get_fingerprint_from_ipfs(){
fi
}
-_ak_gpg_sign(){
+function _ak_gpg_sign(){
if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ]
then
_ak_gpg --sign --sign-with $AK_FINGERPRINT --armor --output $1 $2
@@ -94,7 +115,7 @@ _ak_gpg_sign(){
fi
}
-_ak_gpg_sign_detached(){
+function _ak_gpg_sign_detached(){
if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ]
then
_ak_gpg --detach-sign --sign-with $AK_FINGERPRINT --armor --output $1 $2
@@ -104,7 +125,7 @@ _ak_gpg_sign_detached(){
fi
}
-_ak_gpg_sign_clear(){
+function _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
@@ -113,43 +134,52 @@ _ak_gpg_sign_clear(){
fi
}
-_ak_gpg_encrypt_sign(){
+function _ak_gpg_sign_clear_with_key(){
if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ ! -z $3 ] && [ -n "$3" ]
then
- _ak_gpg --sign-with $AK_FINGERPRINT --encypt -r $3 --armor --output $1 $2
+ _ak_gpg --clear-sign --sign-with $3 --armor --output $1 $2
else
exit 1
fi
}
-_ak_gpg_encrypt_sign_for_self(){
+function _ak_gpg_encrypt_sign(){
+ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ ! -z $3 ] && [ -n "$3" ]
+ then
+ _ak_gpg --sign-with $AK_FINGERPRINT --encrypt -r $3 --armor --output $1 $2
+ else
+ exit 1
+ fi
+}
+
+function _ak_gpg_encrypt_sign_for_self(){
if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ]
then
- _ak_gpg --sign-with $AK_FINGERPRINT --encypt -r $AK_FINGERPRINT --armor --output $1 $2
+ _ak_gpg --sign-with $AK_FINGERPRINT --encrypt -r $AK_FINGERPRINT --armor --output $1 $2
else
exit 1
fi
}
-_ak_gpg_encrypt(){
+function _ak_gpg_encrypt(){
if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ ! -z $3 ] && [ -n "$3" ]
then
- _ak_gpg --encypt -r $3 --armor --output $1 $2
+ _ak_gpg --encrypt -r $3 --armor --output $1 $2
else
exit 1
fi
}
-_ak_gpg_encrypt_for_self(){
+function _ak_gpg_encrypt_for_self(){
if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ]
then
- _ak_gpg --encypt -r $AK_FINGERPRINT --armor --output $1 $2
+ _ak_gpg --encrypt -r $AK_FINGERPRINT --armor --output $1 $2
else
exit 1
fi
}
-_ak_gpg_verify_clear_signature(){
+function _ak_gpg_verify_clear_signature(){
if [ ! -z $1 ] && [ -n "$1" ] && [ -f "$1" ]
then
fingerprint="$(cat $1 | _ak_gpg 2>&1 | grep RSA | awk '{print $5}')"
@@ -166,7 +196,7 @@ _ak_gpg_verify_clear_signature(){
fi
}
-_ak_gpg_verify_signature(){
+function _ak_gpg_verify_signature(){
if [ ! -z $1 ] && [ -n "$1" ] && [ -f "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ -f "$2" ]
then
_ak_gpg --verify $1 $2 > /dev/null 2>&1
@@ -176,7 +206,7 @@ _ak_gpg_verify_signature(){
fi
}
-_ak_gpg_key_self_export(){
+function _ak_gpg_key_self_export(){
if [ ! -z $1 ] && [ -n "$1" ]
then
_ak_gpg --armour --output $1 --export $AK_FINGERPRINT
@@ -185,15 +215,15 @@ _ak_gpg_key_self_export(){
fi
}
-_ak_gpg_list_keys_plain(){
+function _ak_gpg_list_keys_plain(){
_ak_gpg --list-keys
}
-_ak_gpg_list_keys(){
+function _ak_gpg_list_keys(){
_ak_gpg --list-keys | grep '^ ' | awk '{print $1}'
}
-_ak_gpg_list_keys_long(){
+function _ak_gpg_list_keys_long(){
_ak_gpg --list-keys | \
grep -A 1 '^ \{6\}' | \
tr $'\n' ' ' | \
@@ -204,15 +234,15 @@ _ak_gpg_list_keys_long(){
uniq
}
-_ak_gpg_list_secret_keys_plain(){
+function _ak_gpg_list_secret_keys_plain(){
_ak_gpg --list-secret-keys
}
-_ak_gpg_list_secret_keys(){
+function _ak_gpg_list_secret_keys(){
_ak_gpg --list-secret-keys | grep '^ ' | awk '{print $1}'
}
-_ak_gpg_list_secret_keys_long(){
+function _ak_gpg_list_secret_keys_long(){
_ak_gpg --list-secret-keys | \
grep -A 1 '^ \{6\}' | \
tr $'\n' ' ' | \
@@ -223,7 +253,7 @@ _ak_gpg_list_secret_keys_long(){
uniq
}
-_ak_gpg_select_key(){
+function _ak_gpg_select_key(){
select x in $(_ak_gpg_list_secret_keys | tr '\n' ' ')
do
if [ -n "$x" ]
@@ -237,7 +267,7 @@ _ak_gpg_select_key(){
done
}
-_ak_gpg_delete_key(){
+function _ak_gpg_delete_key(){
select x in $(_ak_gpg_list_keys | tr '\n' ' ')
do
if [ -n "$x" ]
@@ -257,7 +287,7 @@ _ak_gpg_delete_key(){
done
}
-_ak_gpg_delete_secret_key(){
+function _ak_gpg_delete_secret_key(){
if [ ! -z $1 ]
then
x="$1"
@@ -279,3 +309,5 @@ _ak_gpg_delete_secret_key(){
fi
fi
}
+
+_ak_log_debug "_ak_gpg loaded $(caller)"