Skip to content

Commit

Permalink
Don't add the ISRG X1 Root on Android (#1434)
Browse files Browse the repository at this point in the history
* Try to trigger the certificate issue

* Only add the certificate on windows

* Add a print statement

* Wait for initial sync twice

* Update changelog
  • Loading branch information
nirinchev authored Nov 29, 2023
1 parent e27a42f commit 2355f74
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* None

### Fixed
* None
* Fixed an issue where connections to Atlas App Services would fail on Android with a certificate expiration error. (Issue [#1430](https://github.com/realm/realm-dart/issues/1430))

### Compatibility
* Realm Studio: 13.0.0 or later.
* Flutter: ^3.13.0
* Dart: ^3.1.0

### Internal
* Using Core x.y.z.
* Using Core 13.23.2.

## 1.6.0 (2023-11-15)

Expand Down Expand Up @@ -90,8 +92,6 @@

### Compatibility
* Realm Studio: 13.0.0 or later.
* Flutter: ^3.13.0
* Dart: ^3.1.0

### Internal
* Using Core 13.17.2.
Expand Down
20 changes: 11 additions & 9 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ he8Y4IWS6wY7bCkjCWDcRQJMEhg76fsO3txE+FiYruq9RUWhiF1myv4Q6W+CyBFC
Dfvp7OOGAN6dEOM4+qR9sdjoSYKEBpsr6GtPAQw4dy753ec5
-----END CERTIFICATE-----''';

try {
final context = SecurityContext.defaultContext;
context.setTrustedCertificatesBytes(const AsciiEncoder().convert(isrgRootX1CertPEM));
return HttpClient(context: context);
} on TlsException catch (e) {
if (e.osError?.message.contains("CERT_ALREADY_IN_HASH_TABLE") == true) {
if (Platform.isWindows) {
try {
final context = SecurityContext(withTrustedRoots: true);
context.setTrustedCertificatesBytes(const AsciiEncoder().convert(isrgRootX1CertPEM));
return HttpClient(context: context);
} on TlsException catch (e) {
// certificate is already trusted. Nothing to do here
return HttpClient();
} else {
rethrow;
if (e.osError?.message.contains("CERT_ALREADY_IN_HASH_TABLE") != true) {
rethrow;
}
}
}

return HttpClient();
}();

/// A class exposing configuration options for an [App]
Expand Down
19 changes: 12 additions & 7 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,18 @@ Future<Object> setupBaas() async {
}

Future<void> _waitForInitialSync() async {
try {
final realm = await getIntegrationRealm();
await realm.syncSession.waitForUpload();
await baasClient!.waitForInitialSync(baasApps[AppNames.flexible.name]!);
} catch (e) {
print(e);
await _waitForInitialSync();
while (true) {
try {
print('Validating initial sync is complete...');
await baasClient!.waitForInitialSync(baasApps[AppNames.flexible.name]!);
final realm = await getIntegrationRealm();
await realm.syncSession.waitForUpload();
await baasClient!.waitForInitialSync(baasApps[AppNames.flexible.name]!);
return;
} catch (e) {
print(e);
await _waitForInitialSync();
}
}
}

Expand Down

0 comments on commit 2355f74

Please sign in to comment.