-
Notifications
You must be signed in to change notification settings - Fork 3
/
source.sh
executable file
·125 lines (107 loc) · 3.79 KB
/
source.sh
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
#!/bin/bash
##################################################################
## ##
## Initialization script for a QAR ##
## ##
##################################################################
case $1 in
--insecure | --kc | --op)
;;
*)
echo 1>&2 "$0: secret storage option required"
exit 2
;;
esac
# Change to the name you want to use for your local database environment.
export QAR_NAME="QAR"
# Change to the name you want for the alias for your local QAR AID
export QAR_ALIAS="John Doe"
# Change to the name you want for the alias for your group multisig AID
export QAR_AID_ALIAS="QVI AID"
# Change to the name you want for the registry for your QVI
export QAR_REG_NAME="QVI Registry"
# Set current working directory for all scripts that must access files
QAR_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export QAR_SCRIPT_DIR="${QAR_DIR}/scripts"
export QAR_DATA_DIR="${QAR_DIR}/data"
set_passcode() {
if [ "$1" = "--insecure" ]; then
head -n 1 passcode >/dev/null 2>&1
ret=$?
if [ $ret -eq 1 ]; then
echo "Generating passcode"
kli passcode generate > passcode
fi
elif [ "$1" = "--op" ]; then
op vault get QVI >/dev/null 2>&1
ret=$?
if [ $ret -eq 1 ]; then
echo "Generating QVI Vault"
op vault create QVI >/dev/null 2>&1
fi
op item get passcode --vault QVI --fields label=value >/dev/null 2>&1
ret=$?
if [ $ret -eq 1 ]; then
echo "Generating random passcode and storing in 1Password"
op item create --category password --title "passcode" --vault QVI value="$(kli passcode generate)" >/dev/null 2>&1
fi
elif [ "$1" = "--kc" ]; then
passcode="$(security find-generic-password -w -a "${LOGNAME}" -s qar-passcode 2> /dev/null)"
if [ -z "${passcode}" ]; then
echo "Generating random passcode and storing in Keychain"
security add-generic-password -a "${LOGNAME}" -s qar-passcode -w "$(kli passcode generate)"
fi
fi
}
export -f set_passcode >/dev/null 2>&1
get_passcode() {
if [ "$1" = "--insecure" ]; then
echo $(head -n 1 passcode)
elif [ "$1" = "--op" ]; then
echo $(op item get passcode --vault QVI --fields label=value)
elif [ "$1" = "--kc" ]; then
echo $(security find-generic-password -w -a "${LOGNAME}" -s qar-passcode)
fi
}
export -f get_passcode >/dev/null 2>&1
set_salt() {
if [ "$1" = "--insecure" ]; then
head -n 1 salt >/dev/null 2>&1
ret=$?
if [ $ret -eq 1 ]; then
echo "Generating salt"
kli salt > salt
fi
elif [ "$1" = "--op" ]; then
op vault get QVI >/dev/null 2>&1
ret=$?
if [ $ret -eq 1 ]; then
echo "Generating QVI Vault"
op vault create QVI >/dev/null 2>&1
fi
op item get salt --vault QVI --fields label=value >/dev/null 2>&1
ret=$?
if [ $ret -eq 1 ]; then
echo "Generating random salt and storing in 1Password"
op item create --category password --title "salt" --vault QVI value="$(kli salt)" >/dev/null 2>&1
fi
elif [ "$1" = "--kc" ]; then
salt="$(security find-generic-password -w -a "${LOGNAME}" -s qar-salt 2> /dev/null)"
if [ -z "${salt}" ]; then
echo "Generating random salt and storing in Keychain"
security add-generic-password -a "${LOGNAME}" -s qar-salt -w "$(kli salt)"
fi
fi
}
get_salt() {
if [ "$1" = "--insecure" ]; then
echo $(head -n 1 salt)
elif [ "$1" = "--op" ]; then
echo $(op item get salt --vault QVI --fields label=value)
elif [ "$1" = "--kc" ]; then
echo $(security find-generic-password -w -a "${LOGNAME}" -s qar-salt)
fi
}
export -f get_salt >/dev/null 2>&1
set_passcode $1
set_salt $1