From 28717aded7df4ac4842fa308e67c1c15e1de4ffa Mon Sep 17 00:00:00 2001 From: kaotisk Date: Wed, 27 Mar 2024 03:49:27 +0200 Subject: Introduced and applied _ak_gpg library --- bin/ak-articles | 3 ++- bin/ak-categories | 3 ++- bin/ak-comments | 3 ++- bin/ak-data-expand | 5 +++-- bin/ak-enter | 5 +++-- bin/ak-files | 3 ++- bin/ak-get-gpg | 3 ++- bin/ak-get-gpg-fingerprint | 7 ++++--- bin/ak-mixtapes | 3 ++- bin/ak-news | 5 +++-- bin/ak-profile | 3 ++- bin/ak-reference | 3 ++- bin/ak-sm-files | 3 ++- bin/ak-todos | 3 ++- bin/ak-transactions | 3 ++- bin/ak-zblock-manipulator | 7 ++++--- bin/ak-zblock-pack | 7 ++++--- 17 files changed, 43 insertions(+), 26 deletions(-) diff --git a/bin/ak-articles b/bin/ak-articles index 363aa7f..9a9f462 100755 --- a/bin/ak-articles +++ b/bin/ak-articles @@ -5,6 +5,7 @@ descriptionString="Articles module for Arching Kaos" source $AK_LIBDIR/_ak_logit source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_gpg ZARTICLESDIR="$AK_WORKDIR/articles" TEMP="/tmp/aktmp" @@ -91,7 +92,7 @@ _ak_modules_articles_add(){ TITLE=$(head -n 1 $FILE) FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$FILE".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE + _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < data < data else diff --git a/bin/ak-data-expand b/bin/ak-data-expand index 0c79741..0a82e63 100755 --- a/bin/ak-data-expand +++ b/bin/ak-data-expand @@ -1,6 +1,7 @@ #!/bin/bash PROGRAM="$(basename $0)" source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_gpg if [ ! -d $AK_WORKDIR/ipfs ] then @@ -64,7 +65,7 @@ then logit "ERROR" "Could not get GPG key: $gpg" exit 1 fi - gpg2 --homedir $AK_GPGHOME --import $gpg > /dev/null 2>&1 + _ak_gpg_key_import_from_file $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then logit "ERROR" "Could not import GPG key: $gpg" @@ -85,7 +86,7 @@ then exit 1 fi logit "INFO" "Data downloaded: $DATA" - gpg2 --homedir $AK_GPGHOME --verify $DATA.asc $DATA > /dev/null 2>&1 + _ak_gpg_verify_signature $DATA.asc $DATA > /dev/null 2>&1 if [ "$?" -ne 0 ] then logit "ERROR" "Error while verifying signature for $DATA" diff --git a/bin/ak-enter b/bin/ak-enter index fd96231..01a93f9 100755 --- a/bin/ak-enter +++ b/bin/ak-enter @@ -21,6 +21,7 @@ PROGRAM="$(basename $0)" descriptionString="Crawl an arching kaos chain" source $AK_LIBDIR/_ak_logit source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_gpg _ak_enter_title(){ description @@ -236,7 +237,7 @@ do logit "ERROR" "Could not get GPG key: $gpg ." exit 1 fi - gpg2 --homedir $AK_GPGHOME --import $gpg > /dev/null 2>&1 + _ak_gpg_key_import_from_file $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then logit "ERROR" "Could not import GPG key: $gpg ." @@ -259,7 +260,7 @@ do fi logit "INFO" "Downloaded block $block." - gpg2 --homedir $AK_GPGHOME --verify $block.asc > /dev/null 2>&1 + _ak_gpg_verify_signature $block.asc $block > /dev/null 2>&1 if [ "$?" -ne 0 ] then logit "ERROR" "Could not verify $block with GPG key $gpg." diff --git a/bin/ak-files b/bin/ak-files index 2280cce..c4d6f2c 100755 --- a/bin/ak-files +++ b/bin/ak-files @@ -4,6 +4,7 @@ ZFILESDIR="$AK_WORKDIR/files" TEMP="/tmp/aktmp" PROGRAM="$(basename $0)" source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_gpg if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR @@ -62,7 +63,7 @@ main(){ fi logit "INFO" "Signing..." SIGN_FILE=$FILENAME".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $SIGN_FILE $FILE + _ak_gpg_sign_detached $SIGN_FILE $FILE if [ $? == 0 ]; then logit "INFO" "Signed" else diff --git a/bin/ak-get-gpg b/bin/ak-get-gpg index ca718dc..e441f87 100755 --- a/bin/ak-get-gpg +++ b/bin/ak-get-gpg @@ -1,2 +1,3 @@ #!/bin/bash -ak-config show | jq -r '.gpg' +source $AK_LIBDIR/_ak_gpg +_ak_gpg_key_self_get_fingerprint_from_config diff --git a/bin/ak-get-gpg-fingerprint b/bin/ak-get-gpg-fingerprint index 34bc4e8..84025e5 100755 --- a/bin/ak-get-gpg-fingerprint +++ b/bin/ak-get-gpg-fingerprint @@ -1,10 +1,11 @@ #!/bin/bash +source $AK_LIBDIR/_ak_gpg + if [ -z $1 ] then - gpg2 --fingerprint $(ak-ipfs-cat $(ak-get-gpg) | gpg2 --import 2>&1 | head -n 1 | cut -d ' ' -f 3 | sed 's/://') | head -n 2 | tail -n 1 | sed 's/ //g' + _ak_gpg_key_self_get_fingerprint elif [ -n "$1" ] then - gpg2 --fingerprint $(ak-ipfs-cat "$1" | gpg2 --import 2>&1 | head -n 1 | cut -d ' ' -f 3 | sed 's/://') | head -n 2 | tail -n 1 | sed 's/ //g' - + _ak_gpg_key_get_fingerprint_from_ipfs $1 fi diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes index 2004ccb..242211d 100755 --- a/bin/ak-mixtapes +++ b/bin/ak-mixtapes @@ -5,6 +5,7 @@ PROGRAM="$(basename $0)" descriptionString="AK mixtape block creator" source $AK_LIBDIR/_ak_logit source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_gpg _ak_modules_mixtapes_usage(){ _ak_modules_mixtapes_title @@ -35,7 +36,7 @@ _ak_modules_mixtapes_main(){ MIXTAPE_IPFS_HASH=$(ak-ipfs-add $MIXTAPE_FILE) MIXTAPE_SIGN_FILE=$MIXTAPE_FILE".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $MIXTAPE_SIGN_FILE $MIXTAPE_FILE + _ak_gpg_sign_detached $MIXTAPE_SIGN_FILE $MIXTAPE_FILE MIXTAPE_SIGNATURE=$(ak-ipfs-add $MIXTAPE_SIGN_FILE) diff --git a/bin/ak-news b/bin/ak-news index 5dbc847..84458c8 100755 --- a/bin/ak-news +++ b/bin/ak-news @@ -7,6 +7,7 @@ TEMP="/tmp/aktmp" source $AK_LIBDIR/_ak_logit source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_gpg if [ ! -d $ZNEWSDIR ]; then mkdir $ZNEWSDIR @@ -103,7 +104,7 @@ _ak_modules_news_add_from_file(){ TITLE=$(head -n 1 $FILE) FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$FILE".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE + _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < data < data < data < data <