Add raw key generation and rework help display
This commit is contained in:
parent
05fbe26959
commit
cfb2da563e
@ -2,8 +2,12 @@
|
||||
|
||||
#### Slouží pro automatičtější přidávání zařízení na IOTT síť
|
||||
|
||||
## Použití
|
||||
## Usage
|
||||
|
||||
iottadd.sh < -l | -r > < id > < pass >
|
||||
- -l for usage on local machine
|
||||
- -r for usage on server (remote)
|
||||
|
||||
## Dependencies
|
||||
|
||||
- python library `passlib`
|
||||
|
37
iottadd.sh
37
iottadd.sh
@ -1,9 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN="\033[1;32m"
|
||||
RED="\033[1;31m"
|
||||
PURPLE="\033[1;35m"
|
||||
PURPLE="\033[0;35m"
|
||||
BLUE="\033[1;34m"
|
||||
RESET="\033[0m"
|
||||
|
||||
usage() {
|
||||
echo -e $GREEN"Usage: iottadd.sh < -l | -r > < id > < pass >
|
||||
|
||||
-l for usage on local machine
|
||||
-r for usage on server (remote)"$RESET
|
||||
}
|
||||
|
||||
|
||||
if [ -z $3 ]; then
|
||||
echo -e $RED"Not enough arguments!\n"$RESET
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
#############################################################################
|
||||
|
||||
if [[ $1 == "-l" ]]; then
|
||||
# Used on local machine
|
||||
echo -e $RED"Not implemented"$RESET
|
||||
@ -12,20 +31,26 @@ elif [[ $1 == "-r" ]]; then
|
||||
# Used on server
|
||||
echo -en $GREEN"Running with: ID="$BLUE$2$GREEN" and PASS="$BLUE$3"\nIs that ok? ["$GREEN"Y"$BLUE"/"$RED"n"$BLUE"]"$PURPLE
|
||||
read -p " " confirmation
|
||||
printf $RESET
|
||||
|
||||
if [[ $confirmation == "n" ]]; then
|
||||
exit 666
|
||||
fi
|
||||
|
||||
if [ ! -w ./rawkey-generator.py ]; then
|
||||
echo -e $RED"You don't have rawkey-generator.py in the same folder or don't have execute permitions"$CLEAR
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elif [[ $1 == "-h" ]]; then
|
||||
echo "iottadd.sh < -l | -r > < id > < pass >
|
||||
RAWKEY=$(python ./rawkey-generator.py $3 "Sincoolka IoTT")
|
||||
|
||||
-l for usage on local machine
|
||||
-r for usage on server (remote)"
|
||||
echo -e $GREEN"Generated raw key: "$BLUE$RAWKEY$CLEAR
|
||||
|
||||
|
||||
############################################################################
|
||||
|
||||
else
|
||||
echo -e $RED"Expected \"-l\" or \"-r\""$RESET
|
||||
usage
|
||||
|
||||
fi
|
||||
|
||||
|
14
rawkey-generator.py
Normal file
14
rawkey-generator.py
Normal file
@ -0,0 +1,14 @@
|
||||
from passlib.utils import pbkdf2
|
||||
import binascii, sys
|
||||
|
||||
arguments_counter = len(sys.argv) - 1
|
||||
|
||||
if arguments_counter != 2:
|
||||
raise TypeError("The function takes exactly 2 arguments (%d passed)" % arguments_counter)
|
||||
|
||||
password = sys.argv[1]
|
||||
ssid = sys.argv[2]
|
||||
|
||||
var = pbkdf2.pbkdf2(str.encode(password), str.encode(ssid), 4096, 32)
|
||||
|
||||
print(binascii.hexlify(var).decode("utf-8"))
|
Loading…
Reference in New Issue
Block a user