From b280a74e40d0283541eca58c1b0acf18b52f50c0 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sun, 20 Nov 2022 10:06:44 -0500 Subject: [PATCH] Fix for self signed certs issue (but only partially implemented dev-mode settings) --- .gitignore | 5 +++++ README.md | 5 ++++- lib/friendica_client.dart | 1 + lib/main.dart | 15 ++++++++++++++- lib/screens/sign_in.dart | 4 ++-- pubspec.lock | 7 +++++++ pubspec.yaml | 6 +++++- 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 24476c5..6ad830d 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,8 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + + +# Environment variables +.env +.env* \ No newline at end of file diff --git a/README.md b/README.md index b5667ab..bce62b2 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,7 @@ A Flutter application for interfacing with the Friendica social network. -Licensed with the Mozilla Public License 2.0 copyleft license. \ No newline at end of file +For Linux development be sure that libsecret-1-dev and libjsoncpp-dev are installed on the machine. For running only make sure the non-dev versions are... + + +Licensed with the Mozilla Public License 2.0 copyleft license. diff --git a/lib/friendica_client.dart b/lib/friendica_client.dart index 2f4dfb5..05eec3e 100644 --- a/lib/friendica_client.dart +++ b/lib/friendica_client.dart @@ -168,6 +168,7 @@ class FriendicaClient { FutureResult _getUrl(Uri url) async { try { + //SecurityContext.defaultContext.setTrustedCertificates('/etc/apache2/certificate/apache-certificate.crt'); final response = await http.get( url, headers: { diff --git a/lib/main.dart b/lib/main.dart index 45db895..89680b8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,7 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; import 'package:result_monad/result_monad.dart'; @@ -15,6 +18,16 @@ import 'services/timeline_manager.dart'; import 'utils/app_scrolling_behavior.dart'; void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(fileName: '.env'); + final inDevMode = dotenv.env['USE_DEV_MODE'] == 'true' ? true : false; + if (inDevMode) { + print('In Dev Mode'); + SecurityContext.defaultContext.setTrustedCertificates( + '/etc/apache2/certificate/apache-certificate.crt'); + } else { + print('In Regular Mode'); + } Logger.root.level = Level.ALL; Logger.root.onRecord.listen((event) { final logName = event.loggerName.isEmpty ? 'ROOT' : event.loggerName; @@ -22,7 +35,7 @@ void main() async { '${event.level.name} - $logName @ ${event.time}: ${event.message}'; print(msg); }); - WidgetsFlutterBinding.ensureInitialized(); + final authService = AuthService(); final secretsService = SecretsService(); final entryManagerService = EntryManagerService(); diff --git a/lib/screens/sign_in.dart b/lib/screens/sign_in.dart index f961fd3..156227b 100644 --- a/lib/screens/sign_in.dart +++ b/lib/screens/sign_in.dart @@ -49,7 +49,7 @@ class _SignInScreenState extends State { TextFormField( autovalidateMode: AutovalidateMode.onUserInteraction, controller: usernameController, - validator: (value) => EmailValidator.validate(value ?? '') + validator: (value) => true //EmailValidator.validate(value ?? '') ? null : 'Not a valid Friendica Account Address', decoration: InputDecoration( @@ -99,7 +99,7 @@ class _SignInScreenState extends State { final result = await Credentials.buildFromHandle( usernameController.text, passwordController.text, - ).andThenSuccess((creds) async { + ).andThenAsync((creds) async { return await getIt().signIn(creds); }); diff --git a/pubspec.lock b/pubspec.lock index c515b39..76c74d5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -139,6 +139,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.3.0" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.2" flutter_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 8955175..54e239d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: uuid: ^3.0.6 time_machine: ^0.9.17 url_launcher: ^6.1.6 + flutter_dotenv: ^5.0.2 dev_dependencies: flutter_test: @@ -37,7 +38,9 @@ dev_dependencies: flutter: uses-material-design: true - + assets: + # Add assets from the images directory to the application. + - .env parts: uet-lms: source: . @@ -79,3 +82,4 @@ parts: # # For details regarding fonts from package dependencies, # see https://flutter.dev/custom-fonts/#from-packages +