aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_gpg
blob: b74d4112e420df63d8c2b68ba712544610604be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_ipfs

_ak_gpg(){
    gpg2 --homedir $AK_GPGHOME $*
}

_ak_gpg_key_import_from_file(){
    if [ -z $1 ]
    then
        logit "[ERROR]" "No argument given"
        exit 1
    fi
    if [ ! -n "$1" ]
    then
        logit "[ERROR]" "Empty argument given"
        exit 1
    fi
    if [ ! -f "$1" ]
    then
        logit "[ERROR]" "File not found"
        exit 1
    fi
    _ak_gpg --import $1 > /dev/null 2>&1
}

_ak_gpg_key_self_get_fingerprint_from_config(){
    ak-config --show | jq -r '.gpg'
}

_ak_gpg_key_self_get_fingerprint(){
    if [ -z $1 ]
    then
        _ak_ipfs_cat "$(_ak_gpg_key_self_get_fingerprint_from_config)" | \
            _ak_gpg --show-keys 2>&1 | \
            head -n 2 | \
            tail -n 1 | \
            sed 's/ //g'
    else
        exit 1
    fi
}

_ak_gpg_key_get_fingerprint_from_ipfs(){
    if [ -n "$1" ]
    then
        _ak_ipfs_cat "$1" | \
            _ak_gpg --show-keys 2>&1 | \
            head -n 2 | \
            tail -n 1 | \
            sed 's/ //g'
    else
        exit 1
    fi
}

_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
    else
        exit 1
    fi
}

_ak_gpg_encrypt_sign(){
    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
    else
        exit 1
    fi
}

_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
    else
        exit 1
    fi
}

_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
    else
        exit 1
    fi
}

_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
    else
        exit 1
    fi
}

_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
    else
        exit 1
    fi
}

_ak_gpg_key_self_export(){
    if [ ! -z $1 ] && [ -n "$1" ]
    then
        _ak_gpg --armour --output $1 --export $AK_FINGERPRINT
    else
        exit 1
    fi
}

_ak_gpg_list_keys(){
    _ak_gpg --list-keys | grep '^ ' | awk '{print $1}' | tr '\n' ' '
}

_ak_gpg_select_key(){
    select x in $(_ak_gpg_list_keys)
    do
        echo $x
        if [ -n "$x" ]
        then
            break
        fi
    done
}