Commit 551fe3d3 authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

try verification web version

parent 27c6cb21
package de.upb.asta.verification
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
......@@ -78,7 +78,7 @@ SPEC CHECKSUMS:
qr_code_scanner: bb67d64904c3b9658ada8c402e8b4d406d5d796e
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
shared_preferences_ios: aef470a42dc4675a1cdd50e3158b42e3d1232b32
url_launcher_ios: 02f1989d4e14e998335b02b67a7590fa34f971af
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
......
......@@ -7,6 +7,7 @@ import 'package:connectivity/connectivity.dart';
import 'package:crypto/crypto.dart';
import 'package:digital_3g_common/verification_api.dart';
import 'package:encrypt/encrypt.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter_jailbreak_detection/flutter_jailbreak_detection.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
......@@ -37,16 +38,21 @@ class VerificationBloc extends Bloc<VerificationEvent, VerificationState> {
VerificationBloc(String url) : super(VerificationState.busy) {
_api = VerificationApi(http.Client(), url);
FlutterJailbreakDetection.jailbroken.then((bool jailbroken) {
if (!jailbroken) {
_initVerificationStore()
.then((_) => _initTicketFile().then((_) => _getDeviceId().then((_) => _loadTicket())));
} else {
_log.severe('jailbroken/rooted device detected, VerificationBloc halted');
_error = VerificationErrorType.root;
emit(VerificationState.error);
}
});
if (!kIsWeb) {
FlutterJailbreakDetection.jailbroken.then((bool jailbroken) {
if (!jailbroken) {
_initVerificationStore().then(
(_) => _initTicketFile().then((_) => _getDeviceId().then((_) => _loadTicket())));
} else {
_log.severe('jailbroken/rooted device detected, VerificationBloc halted');
_error = VerificationErrorType.root;
emit(VerificationState.error);
}
});
} else {
_initVerificationStore().then((_) => _initTicketFile()
.then((_) => _getDeviceId().then((_) => add(VerificationEvent.revoke()))));
}
}
VerificationApi? get api => _api;
......@@ -105,7 +111,9 @@ class VerificationBloc extends Bloc<VerificationEvent, VerificationState> {
}
break;
case EventType.revoke:
_ticketStore!.writeAsString('', flush: true);
if (!kIsWeb) {
_ticketStore!.writeAsString('', flush: true);
}
_ticket = null;
_error = null;
yield VerificationState.noTicket;
......@@ -166,16 +174,19 @@ class VerificationBloc extends Bloc<VerificationEvent, VerificationState> {
}
Future<void> _initTicketFile() async {
if (kIsWeb) return;
_ticketStore = File('${(await getApplicationDocumentsDirectory()).path}/ticket');
_log.fine('initialized ticket store in ${_ticketStore?.path}');
}
Future<void> _initVerificationStore() async {
if (kIsWeb) return;
_verificationStore = File('${(await getApplicationDocumentsDirectory()).path}/last');
_log.fine('initialized verification store in ${_verificationStore?.path}');
}
Future<void> _loadTicket() async {
if (kIsWeb) return;
String? ticket;
if (!_ticketStore!.existsSync()) {
_log.fine('no ticket found, creating ticket store');
......
......@@ -228,6 +228,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
......@@ -367,7 +374,7 @@ packages:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
version: "3.5.1"
process:
dependency: transitive
description:
......@@ -395,7 +402,7 @@ packages:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
version: "2.0.13"
shared_preferences_android:
dependency: transitive
description:
......@@ -491,28 +498,28 @@ packages:
name: url_launcher_android
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.14"
version: "6.0.15"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.14"
version: "6.0.15"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
url_launcher_platform_interface:
dependency: transitive
description:
......@@ -533,7 +540,7 @@ packages:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
vector_math:
dependency: transitive
description:
......@@ -547,14 +554,14 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.8"
version: "2.3.11"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
version: "0.2.0+1"
sdks:
dart: ">=2.15.0 <3.0.0"
flutter: ">=2.5.0"
flutter: ">=2.8.0"
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="verification">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>verification</title>
<link rel="manifest" href="manifest.json">
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.3.1/dist/jsQR.min.js"></script>
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}
if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
});
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
</script>
</body>
</html>
{
"name": "verification",
"short_name": "verification",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment