From 10473454f295cf7edbc9363681987bd7b9b79e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lima?= Date: Mon, 2 Oct 2023 20:25:57 +0100 Subject: [PATCH] fix: disable ssl verification for www.stcp.pt --- uni/assets/certificates/www.stcp.pt.crt | 35 ------------------- .../fetchers/departures_fetcher.dart | 32 +++++------------ uni/pubspec.yaml | 1 - 3 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 uni/assets/certificates/www.stcp.pt.crt diff --git a/uni/assets/certificates/www.stcp.pt.crt b/uni/assets/certificates/www.stcp.pt.crt deleted file mode 100644 index 41a19edb5..000000000 --- a/uni/assets/certificates/www.stcp.pt.crt +++ /dev/null @@ -1,35 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIGFDCCBPygAwIBAgIQAe6h3RyHx1fCpxVViJmEjzANBgkqhkiG9w0BAQsFADBe -MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 -d3cuZGlnaWNlcnQuY29tMR0wGwYDVQQDExRUaGF3dGUgVExTIFJTQSBDQSBHMTAe -Fw0yMzA5MjEwMDAwMDBaFw0yNDA5MzAyMzU5NTlaMBYxFDASBgNVBAMTC3d3dy5z -dGNwLnB0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlVSRpvVSkBHk -AsDlP2iPOT3/tgHY2lWdzhMjkOPtNmRKLDooMPXwxm+SkDrXp6QB9TgwfraRCbA4 -+ChodbOs42J//DMAPm6l3MduB0gFbnT+v1R7h9wShjscXW/+Ort/UNAJrBWQzuGN -33T3ToPZAsK8k9UvwkCT0XvdXYT0WQNHY7R1iy9vz4hlbsCB3Ctx00upoulN7rBD -sje915+6prwZGLepvRMMGjRRexdy+YnrzTEmiUS3y236AReIMbCZTpde3+sLySZM -GAAMQt7WFgU5LwWllSixeHUloDRTqIk6NHI47rY0PX/xaWKqI8i80DdGV6WgrWIm -F4D0AensQwIDA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rZF2nSOQ+lPwnTsFMA0GCSqGSIb3DQEB -CwUAA4IBAQBlveKOAeFEV21Fd+/DqvNHjIPZdWp651t+cr1i8fxosAFXUJjfLHrh -mpHQrjMUdYnI1SgP6aWxWco7T99/orS4NUmtzb6gVc6MhE1gHLQyQDIY0Z5KJ1/R -D3hldNtiDegMzSir5YPJKQXe8kSp5uHFWmfKqBeB8++V1pCdfOG+yLWKrsAeRFGa -t1qg0++V4AZl91MdfnWGX5DC6dD/1H9c+zxTQqIBA+Ht9a9xk137xgRWJwFdq4Xh -o8cvIhsqqD+M+PY7sijGFLEY2G3MwtYtRBuYAfjQP65rZ1sJcZyip+4Ez4iePwE1 -146k97CUzEYZCHYiBkQaJSYC5FECqnDl ------END CERTIFICATE----- diff --git a/uni/lib/controller/fetchers/departures_fetcher.dart b/uni/lib/controller/fetchers/departures_fetcher.dart index 1ea490b34..64e2d3585 100644 --- a/uni/lib/controller/fetchers/departures_fetcher.dart +++ b/uni/lib/controller/fetchers/departures_fetcher.dart @@ -1,6 +1,5 @@ import 'dart:convert'; import 'dart:io'; -import 'package:flutter/services.dart' show rootBundle; import 'package:html/dom.dart'; import 'package:html/parser.dart'; @@ -15,27 +14,17 @@ class DeparturesFetcher { final String _stopCode; final BusStopData _stopData; - static final _client = Future.microtask(() async { - // FIXME(limwa): replace `rootBundle` with `DefaultAssetBundle.of(context)` - final certificateBytes = - await rootBundle.load('assets/certificates/www.stcp.pt.crt'); - - final securityContext = SecurityContext(withTrustedRoots: true) - ..setTrustedCertificatesBytes(certificateBytes.buffer.asUint8List()); - - return http.IOClient( - HttpClient( - context: securityContext, - ), - ); - }); + static final _client = http.IOClient( + HttpClient(context: SecurityContext()) + ..badCertificateCallback = + (cert, host, port) => host == 'www.stcp.pt' && port == 443, + ); Future _getCSRFToken() async { final url = 'https://www.stcp.pt/en/travel/timetables/?paragem=$_stopCode&t=smsbus'; - final client = await _client; - final response = await client.get(url.toUri()); + final response = await _client.get(url.toUri()); final htmlResponse = parse(response.body); final scriptText = htmlResponse @@ -67,8 +56,7 @@ class DeparturesFetcher { final url = 'https://www.stcp.pt/pt/itinerarium/soapclient.php?codigo=$_stopCode&hash123=$csrfToken'; - final client = await _client; - final response = await client.get(url.toUri()); + final response = await _client.get(url.toUri()); final htmlResponse = parse(response.body); final tableEntries = @@ -130,8 +118,7 @@ class DeparturesFetcher { final url = 'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopname=$stopCode'; - final client = await _client; - final response = await client.post(url.toUri()); + final response = await _client.post(url.toUri()); final json = jsonDecode(response.body) as List; for (final busKey in json) { final bus = busKey as Map; @@ -155,8 +142,7 @@ class DeparturesFetcher { final url = 'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopcode=$stop'; - final client = await _client; - final response = await client.post(url.toUri()); + final response = await _client.post(url.toUri()); final json = jsonDecode(response.body) as List; diff --git a/uni/pubspec.yaml b/uni/pubspec.yaml index 2b5b3253b..3491c6fe4 100644 --- a/uni/pubspec.yaml +++ b/uni/pubspec.yaml @@ -79,7 +79,6 @@ flutter: - assets/text/ - assets/text/locations/ - assets/meal-icons/ - - assets/certificates/ fonts: - family: Raleway fonts: