feat(server-api): Implement bad certificates fallback for staging environment

Without it client application won't accept staging certificates from server
pull/140/head
NaiJi ✨ 2022-11-18 10:59:47 +04:00
parent 0c4da8eb9f
commit da394e22ac
7 changed files with 44 additions and 22 deletions

View File

@ -1,10 +1,25 @@
import 'dart:io';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:http/io_client.dart';
import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
abstract class ApiMap {
Future<GraphQLClient> getClient() async {
final HttpClient httpClient = HttpClient();
if (StagingOptions.stagingAcme) {
httpClient.badCertificateCallback = (
final cert,
final host,
final port,
) =>
true;
}
final httpLink = HttpLink(
'https://api.$rootAddress/graphql',
httpClient: IOClient(httpClient),
);
final String token = _getApiToken();

View File

@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_provider.dart';
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider.dart';
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
import 'package:selfprivacy/logic/models/disk_size.dart';
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
import 'package:selfprivacy/logic/models/hive/server_details.dart';
@ -320,6 +321,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
final String formattedHostname = getHostnameFromDomain(domainName);
const String infectBranch = 'providers/digital-ocean';
final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false';
final String userdataString =
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$infectBranch/nixos-infect | PROVIDER=$infectProviderName STAGING_ACME='$stagingAcme' DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$formattedHostname bash 2>&1 | tee /tmp/infect.log";

View File

@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_provider.dart';
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider.dart';
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
import 'package:selfprivacy/logic/models/disk_size.dart';
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
@ -355,7 +356,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
final String apiToken = StringGenerators.apiToken();
final String hostname = getHostnameFromDomain(domainName);
const String infectBranch = 'providers/hetzner';
final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false';
final String base64Password =
base64.encode(utf8.encode(rootUser.password ?? 'PASS'));

View File

@ -55,9 +55,4 @@ abstract class ServerProviderApi extends ApiMap {
/// Actual provider name to render on information page for user,
/// for example 'Digital Ocean' for Digital Ocean
String get appearanceProviderName;
/// Whether we request for staging temprorary certificates.
/// Hardcode to 'true' in the middle of testing to not
/// get your domain banned but constant certificate renewal
String get stagingAcme => 'true';
}

View File

@ -0,0 +1,8 @@
/// Controls staging environment for network, is used during manual
/// integration testing and such
class StagingOptions {
/// Whether we request for staging temprorary certificates.
/// Hardcode to 'true' in the middle of testing to not
/// get your domain banned but constant certificate renewal
static bool get stagingAcme => true;
}

View File

@ -35,7 +35,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
auto_size_text:
dependency: "direct main"
description:
@ -126,7 +126,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
@ -147,7 +147,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
code_builder:
dependency: transitive
description:
@ -350,7 +350,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
ffi:
dependency: transitive
description:
@ -631,12 +631,12 @@ packages:
source: hosted
version: "1.1.3"
http:
dependency: transitive
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.4"
version: "0.13.5"
http_multi_server:
dependency: transitive
description:
@ -762,21 +762,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
mime:
dependency: transitive
description:
@ -846,7 +846,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
path_drawing:
dependency: transitive
description:
@ -1159,7 +1159,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
@ -1187,7 +1187,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
system_theme:
dependency: "direct main"
description:
@ -1208,28 +1208,28 @@ packages:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test:
dependency: transitive
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.21.1"
version: "1.21.4"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.13"
version: "0.4.16"
timezone:
dependency: "direct main"
description:

View File

@ -33,6 +33,7 @@ dependencies:
gtk_theme_fl: ^0.0.1
hive: ^2.2.3
hive_flutter: ^1.1.0
http: ^0.13.5
intl: ^0.17.0
ionicons: ^0.1.2
json_annotation: ^4.6.0