added bash script for encryption

This commit is contained in:
henne 2022-01-21 14:07:20 +01:00
parent 523cb0c08b
commit 1c4b1f667a
5 changed files with 106 additions and 9 deletions

14
create_json.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript" src="https://cdn.rawgit.com/ricmoo/aes-js/e27b99df/index.js"></script>
</head>
<body>
Input: <input type="text" id="input"><br />
Output: <input type="text" id="output">
</body>
</html>

32
encryptKey Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
KEY=$1
KEYLENGTH=${#KEY}
TOKEN=$3
if ! [[ $KEY =~ ^[0-9]+$ ]];
then
echo "Invalid key"
exit 1
fi
if [ $KEYLENGTH -gt 32 ]; then
echo "Key is to long"
exit 1
fi
while [ $KEYLENGTH -lt 32 ]
do
KEY="0${KEY}"
KEYLENGTH=${#KEY}
done
echo -n $TOKEN >/tmp/apitoken_snipe
K=$(echo -n $KEY | xxd -p -c 100)
ENC=$(openssl enc -aes-256-ecb -e -in /tmp/apitoken_snipe -K $K -base64 -A)
echo ""
echo ""
echo "Insert the following (only inbetween the ---) into the scanner_users.json file:"
echo "---"
echo "{\"name\":\"${2}\", \"token\": \"${ENC}\"},"
echo "---"
rm /tmp/apitoken_snipe

View File

@ -18,12 +18,14 @@ class HttpException implements Exception {
}
Future<List<LoginUser>> getLoginUsers() async {
final response = await http.get(
Uri.parse(Preferences.getHostUrl() + "/scanner_users.json"),
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.acceptHeader: 'application/json',
});
var url = Preferences.getHostUrl() + "/scanner_users.json";
if (Preferences.getCustomUserUrl() != "") {
url = Preferences.getCustomUserUrl();
}
final response = await http.get(Uri.parse(url), headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
HttpHeaders.acceptHeader: 'application/json',
});
if (response.statusCode != 200) {
throw HttpException(response.statusCode, response.body);
}

View File

@ -4,6 +4,7 @@ class Preferences {
static SharedPreferences? _preferences;
static const String _keyHost = 'host';
static const String _keyCustomUserJsonUrl = 'custom_user_url';
static Future init() async =>
_preferences = await SharedPreferences.getInstance();
@ -12,4 +13,10 @@ class Preferences {
await _preferences?.setString(_keyHost, host);
static String getHostUrl() => _preferences?.getString(_keyHost) ?? '';
static Future setCustomUserUrl(String url) async =>
await _preferences?.setString(_keyCustomUserJsonUrl, url);
static String getCustomUserUrl() =>
_preferences?.getString(_keyCustomUserJsonUrl) ?? '';
}

View File

@ -10,13 +10,20 @@ class PreferencesWidget extends StatefulWidget {
class PreferencesWidgetState extends State<PreferencesWidget> {
late TextEditingController _hostController;
late TextEditingController _userJsonController;
int counter = 0;
bool _hostSaved = false;
Widget? hostIcon;
bool _customUserJsonSaved = false;
bool _useCustomUserJson = false;
@override
void initState() {
_hostController = TextEditingController(text: Preferences.getHostUrl());
_userJsonController =
TextEditingController(text: Preferences.getCustomUserUrl());
if (Preferences.getCustomUserUrl() != "") {
_useCustomUserJson = true;
}
super.initState();
}
@ -29,21 +36,29 @@ class PreferencesWidgetState extends State<PreferencesWidget> {
void _save() {
counter++;
Preferences.setHostUrl(_hostController.text);
Preferences.setCustomUserUrl(_userJsonController.text);
setState(() {
_hostSaved = true;
_customUserJsonSaved = true;
});
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
Widget? hostIcon;
if (_hostSaved) {
hostIcon = const Icon(
Icons.check,
color: Colors.green,
);
} else {
hostIcon = null;
}
Widget? customUrlIcon;
if (_customUserJsonSaved) {
customUrlIcon = const Icon(
Icons.check,
color: Colors.green,
);
}
return Scaffold(
appBar: AppBar(title: const Text('Settings')),
@ -63,6 +78,33 @@ class PreferencesWidgetState extends State<PreferencesWidget> {
}),
),
),
Container(
child: Row(
children: [
Checkbox(
value: _useCustomUserJson,
onChanged: (value) =>
setState(() => _useCustomUserJson = value!)),
const Text("Use custom URL for the user JSON")
],
),
padding: const EdgeInsets.symmetric(horizontal: 40),
),
if (_useCustomUserJson)
Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(horizontal: 40),
child: TextField(
decoration: InputDecoration(
suffixIcon: customUrlIcon,
labelText: "Custom user JSON url"),
controller: _userJsonController,
keyboardType: TextInputType.url,
onChanged: (_) => setState(() {
_customUserJsonSaved = false;
}),
),
),
SizedBox(height: size.height * 0.04),
Container(
alignment: Alignment.center,