Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable ssl verification on www.stcp.pt #991

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions uni/lib/controller/fetchers/departures_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:convert';
import 'dart:io';

import 'package:html/dom.dart';
import 'package:html/parser.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart' as http;
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/bus.dart';
import 'package:uni/model/entities/bus_stop.dart';
Expand All @@ -13,12 +14,17 @@ class DeparturesFetcher {

final String _stopCode;
final BusStopData _stopData;
static final _client = http.IOClient(
HttpClient(context: SecurityContext())
..badCertificateCallback =
(cert, host, port) => host == 'www.stcp.pt' && port == 443,
);

Future<String> _getCSRFToken() async {
final url =
'https://www.stcp.pt/en/travel/timetables/?paragem=$_stopCode&t=smsbus';

final response = await http.get(url.toUri());
final response = await _client.get(url.toUri());
final htmlResponse = parse(response.body);

final scriptText = htmlResponse
Expand Down Expand Up @@ -50,7 +56,7 @@ class DeparturesFetcher {
final url =
'https://www.stcp.pt/pt/itinerarium/soapclient.php?codigo=$_stopCode&hash123=$csrfToken';

final response = await http.get(url.toUri());
final response = await _client.get(url.toUri());
final htmlResponse = parse(response.body);

final tableEntries =
Expand Down Expand Up @@ -111,7 +117,8 @@ class DeparturesFetcher {
// Search by approximate name
final url =
'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopname=$stopCode';
final response = await http.post(url.toUri());

final response = await _client.post(url.toUri());
final json = jsonDecode(response.body) as List<dynamic>;
for (final busKey in json) {
final bus = busKey as Map<String, dynamic>;
Expand All @@ -134,7 +141,8 @@ class DeparturesFetcher {
static Future<List<Bus>> getBusesStoppingAt(String stop) async {
final url =
'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopcode=$stop';
final response = await http.post(url.toUri());

final response = await _client.post(url.toUri());

final json = jsonDecode(response.body) as List<dynamic>;

Expand Down
Loading