Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
u-minor committed Dec 22, 2017
0 parents commit 645d725
Show file tree
Hide file tree
Showing 7 changed files with 1,061 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/mfa.crt
/mfa.key
/mfalist.dat
/services.txt
13 changes: 13 additions & 0 deletions confirmInit.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var app = Application.currentApplication();
app.includeStandardAdditions = true;

try {
app.displayDialog('Do you want to initialize settings?');
var ret = app.displayDialog('Enter new pass phrase:', {
defaultAnswer: '',
hiddenAnswer: true
});
ret.textReturned;
} catch (e) {
'';
}
137 changes: 137 additions & 0 deletions ctrl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash
cmd=$1
service=$2
key=$3

getPass() {
osascript -l JavaScript getPass.scpt
}

initData() {
pass=$(osascript -l JavaScript confirmInit.scpt)
if [ -z "$pass" ]; then
echo 'Init canceled.'
exit 1
fi

rm -f mfa.key mfa.crt mfalist.dat services.txt
openssl req -x509 -sha256 -days 3650 -subj '/' -newkey rsa:2048 -passout pass:"$pass" -keyout mfa.key -out mfa.crt > /dev/null 2>&1
touch services.txt

echo "Initialized!"
}

addService() {
pass=$(getPass)
if [ -z "$pass" ]; then
echo 'Add canceled.'
exit 1
fi

ret=$(echo $pass | ./mfacodegen -a $service,$key)
if [ $? -ne 0 ]; then
echo "$ret" | head -n 1
exit 1
fi
echo "$ret"

echo $pass | ./mfacodegen -l > services.txt
}

generateServiceList() {
pass=$(getPass)
if [ -z "$pass" ]; then
echo 'List canceled.'
exit 1
fi

ret=$(echo $pass | ./mfacodegen -l 2>&1)
if [ $? -ne 0 ]; then
echo "$ret" | head -n 1
exit 1
fi
echo "$ret" > services.txt

echo "list generated."
}

generateToken() {
pass=$(getPass)
if [ -z "$pass" ]; then
echo 'Generate canceled.'
exit 1
fi

ret=$(echo $pass | ./mfacodegen -s $service 2>&1)
if [ $? -ne 0 ]; then
echo "$ret" | head -n 1
exit 1
fi

data=''
if [ -f ./services.txt ]; then
data=$(egrep -v "^${service}\$" ./services.txt)
fi
(echo "$service"; echo "$data") > services.txt

echo -n $ret
}

removeService() {
pass=$(getPass)
if [ -z "$pass" ]; then
echo 'Remove canceled.'
exit 1
fi

ret=$(echo $pass | ./mfacodegen -d $service)
if [ $? -ne 0 ]; then
echo "$ret" | head -n 1
exit 1
fi
echo "$ret"

echo $pass | ./mfacodegen -l > services.txt
}

filter() {
services=($(grep "$service" "./services.txt"))

arr=()
for s in ${services[@]}; do
arr+=("$(cat << EOI
{
"arg": "$s",
"title": "$s",
"subtitle": "generate MFA token for $s",
"autocomplete": "$s"
}
EOI
)")
done

echo '{"items": ['
(IFS=','; echo "${arr[*]}")
echo ']}'
}

case "$cmd" in
'init' )
initData
;;
'listgen' )
generateServiceList
;;
'add' )
addService
;;
'rm' )
removeService
;;
'filter' )
filter
;;
'token' )
generateToken
;;
esac
12 changes: 12 additions & 0 deletions getPass.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var app = Application.currentApplication();
app.includeStandardAdditions = true;

try {
var ret = app.displayDialog('Enter pass phrase:', {
defaultAnswer: '',
hiddenAnswer: true
});
ret.textReturned;
} catch (e) {
'';
}
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 645d725

Please sign in to comment.