Skip to content

Commit

Permalink
Merge pull request #19 from dchristl/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dchristl authored Jul 3, 2023
2 parents f277812 + 0f8dfc9 commit 2c61861
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
mkdir -p ./headless_haystack/build/webapplication
cp ./webserver/FindMy_proxy.py ./headless_haystack/build/webapplication
cp ./webserver/rename_me.pem ./headless_haystack/build/webapplication
cp ./webserver/apple_cryptography.py ./headless_haystack/build/webapplication
cp -R ./headless_haystack/build/web ./headless_haystack/build/webapplication
cd ./headless_haystack/build/webapplication
Expand Down
17 changes: 16 additions & 1 deletion OSX-KVM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ nano apple_cryptography.py
```
> You have now two options. You can use the application directly at [my GitHub-Page](https://dchristl.github.io/headless-haystack/) or you can host your own application on your Mac.
If you want to use the Github-Pages, you just have to brows to the page and import your JSON-file. All inputs are local only, so no data will be transferred outside your client.
If you want to use the Github-Pages, you just have to browse to the page and import your JSON-file. All inputs are local only, so no data will be transferred outside your client.

For self hosting you can run a simple HTTP-Server in the 'web'- folder on port 6443
```
Expand All @@ -121,3 +121,18 @@ python -m http.server 6443
```

You should now able to browse to [http://localhost:56443/](http://localhost:56443/) on your host and use headless haystack

> **Note**
> If you want to use Headless Haystack not on the same machine your MacOs is running or you want to use SSL, some extra steps are needed. You need a valid certificate, called certificate.pem in the server's folder (i.e. created with [Let's Encrypt](https://letsencrypt.org/) ) or you can rename the file rename_me.pem to certificate.pem and use my self signed one. After that restart the service:
```
mv rename_me.pem certificate.pem
./FindMy_proxy.py
```
Go to your client where you want to run Headless Haystack and point your browser to your FindMyProxy-Server (i.e. https://myserver:56176). You should see something like that:
![Certificate error](firefox_cert.png)

Go to 'Advanced' and 'Accept the Risk and continue'. You should see a directory listing now. Use Headless Haystack now normally, but change the Fetch location server setting, according to your needs. Use now https instead!

![changed_setting](firefox_ok.png)

This have to be repeated for every other client once!
Binary file added OSX-KVM/firefox_cert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added OSX-KVM/firefox_ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 18 additions & 10 deletions headless_haystack/lib/findMy/reports_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:logger/logger.dart';
Expand All @@ -17,18 +18,25 @@ class ReportsFetcher {
[String? url]) async {
var keys = hashedAdvertisementKeys.toList(growable: false);
logger.i('Using ${keys.length} key(s) to ask webservice');
final response = await http.post(Uri.parse(url as String),
headers: <String, String>{
"Content-Type": "application/json",
},
body: jsonEncode(<String, dynamic>{
"ids": keys,
"days": daysToFetch,
}));
var httpClient = HttpClient();
/*Ignore certificate errors*/
httpClient.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;

final request = await httpClient.postUrl(Uri.parse(url as String));
var body = jsonEncode(<String, dynamic>{
"ids": keys,
"days": daysToFetch,
});
request.headers.set(HttpHeaders.contentTypeHeader, "application/json");
request.headers
.set(HttpHeaders.contentLengthHeader, utf8.encode(body).length);
request.write(body);
final response = await request.close();

if (response.statusCode == 200) {
var out = await jsonDecode(response.body)["results"];
logger.i('Found ${out.length} reports');
String body = await response.transform(utf8.decoder).join();
var out = await jsonDecode(body)["results"];
return out;
} else {
throw Exception(
Expand Down
2 changes: 1 addition & 1 deletion headless_haystack/lib/preferences/preferences_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _PreferencesPageState extends State<PreferencesPage> {
return TextInputSettingsTile(
initialValue: 'http://localhost:56176',
settingKey: haystackurl,
title: 'Url to Headless Haystack server',
title: 'Url to Fetch location server',
validator: (String? url) {
if (url != null &&
url.startsWith(RegExp('http[s]?://', caseSensitive: false))) {
Expand Down
9 changes: 8 additions & 1 deletion webserver/FindMy_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ def do_POST(self):
Handler = ServerHandler

httpd = six.moves.socketserver.TCPServer(("", PORT), Handler)
cert = 'certificate.pem'
if os.path.isfile(cert):
print("Certificate file "+ cert + " exists, so using SSL")
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=cert, server_side=True)
print("serving at port " + str(PORT) + " over HTTPS")
else:
print("Certificate file "+ cert + " not found, so not using SSL")
print("serving at port " + str(PORT) + " over HTTP")

print("serving at port " + str(PORT))

try:
httpd.serve_forever()
Expand Down
47 changes: 47 additions & 0 deletions webserver/rename_me.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-----BEGIN CERTIFICATE-----
MIIDGTCCAgGgAwIBAgIUMoCTzYoASTKRvlYk8R6StkETVJ8wDQYJKoZIhvcNAQEL
BQAwHDEaMBgGA1UEAwwRaGVhZGxlc3NfaGF5c3RhY2swHhcNMjMwNzAzMTEwMjI3
WhcNMzMwNjMwMTEwMjI3WjAcMRowGAYDVQQDDBFoZWFkbGVzc19oYXlzdGFjazCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALPAPB1uf9RdgAjsmRNGe4nh
oNDTiGj7/V9Sn3p2NtG2YV8uD+V8zOeFrv1hEh3LqgCkaXA+8xu8y+CcA1stvlC3
6PfGHCEGTqZj3NQ96BBkRDuPepKHecwsWJrUDcFGrjEot9jImgMPTqocQHDQdiEe
VN/0Ndh5ZOSf3gVJAitkrVbTiAKq6n3fmxh+vW28hQDVu/MKpSIQtk75d4nxq3SN
gAvIRSXtg7q+weIYivnFGD2R6+DuB1Y+OXqBHhMXWZHt3DXkJHNDKzeQoyWpV/VR
Rn9iw4iWVC1aMyjEXt0EL87tv5Y9A8AzQrU+5bUk1w//Vx54hh1lQQLn6rxTYLMC
AwE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