mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
add option to ignore certificate errors (#46)
add option to ignore certificate errors
This commit is contained in:
@@ -209,7 +209,8 @@
|
|||||||
"Update Comics Info": "更新漫画信息",
|
"Update Comics Info": "更新漫画信息",
|
||||||
"Create Folder": "新建文件夹",
|
"Create Folder": "新建文件夹",
|
||||||
"Select an image on screen": "选择屏幕上的图片",
|
"Select an image on screen": "选择屏幕上的图片",
|
||||||
"Added @count comics to download queue.": "已添加 @count 本漫画到下载队列"
|
"Added @count comics to download queue.": "已添加 @count 本漫画到下载队列",
|
||||||
|
"Ignore Certificate Errors": "忽略证书错误"
|
||||||
},
|
},
|
||||||
"zh_TW": {
|
"zh_TW": {
|
||||||
"Home": "首頁",
|
"Home": "首頁",
|
||||||
@@ -421,6 +422,7 @@
|
|||||||
"Update Comics Info": "更新漫畫信息",
|
"Update Comics Info": "更新漫畫信息",
|
||||||
"Create Folder": "新建文件夾",
|
"Create Folder": "新建文件夾",
|
||||||
"Select an image on screen": "選擇屏幕上的圖片",
|
"Select an image on screen": "選擇屏幕上的圖片",
|
||||||
"Added @count comics to download queue.": "已添加 @count 本漫畫到下載隊列"
|
"Added @count comics to download queue.": "已添加 @count 本漫畫到下載隊列",
|
||||||
|
"Ignore Certificate Errors": "忽略證書錯誤"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -119,6 +119,7 @@ class _Settings with ChangeNotifier {
|
|||||||
'quickFavorite': null,
|
'quickFavorite': null,
|
||||||
'enableTurnPageByVolumeKey': true,
|
'enableTurnPageByVolumeKey': true,
|
||||||
'enableClockAndBatteryInfoInReader': true,
|
'enableClockAndBatteryInfoInReader': true,
|
||||||
|
'ignoreCertificateErrors': false,
|
||||||
};
|
};
|
||||||
|
|
||||||
operator [](String key) {
|
operator [](String key) {
|
||||||
|
@@ -106,6 +106,7 @@ class MyLogInterceptor implements Interceptor {
|
|||||||
|
|
||||||
class AppDio with DioMixin {
|
class AppDio with DioMixin {
|
||||||
String? _proxy = proxy;
|
String? _proxy = proxy;
|
||||||
|
static bool get ignoreCertificateErrors => appdata.settings['ignoreCertificateErrors'] == true;
|
||||||
|
|
||||||
AppDio([BaseOptions? options]) {
|
AppDio([BaseOptions? options]) {
|
||||||
this.options = options ?? BaseOptions();
|
this.options = options ?? BaseOptions();
|
||||||
@@ -123,6 +124,7 @@ class AppDio with DioMixin {
|
|||||||
client.idleTimeout = const Duration(seconds: 100);
|
client.idleTimeout = const Duration(seconds: 100);
|
||||||
client.badCertificateCallback =
|
client.badCertificateCallback =
|
||||||
(X509Certificate cert, String host, int port) {
|
(X509Certificate cert, String host, int port) {
|
||||||
|
if (ignoreCertificateErrors) return true;
|
||||||
if (host.contains("cdn")) return true;
|
if (host.contains("cdn")) return true;
|
||||||
final ipv4RegExp = RegExp(
|
final ipv4RegExp = RegExp(
|
||||||
r'^((25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})$');
|
r'^((25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})$');
|
||||||
@@ -189,8 +191,8 @@ class AppDio with DioMixin {
|
|||||||
ProgressCallback? onSendProgress,
|
ProgressCallback? onSendProgress,
|
||||||
ProgressCallback? onReceiveProgress,
|
ProgressCallback? onReceiveProgress,
|
||||||
}) async {
|
}) async {
|
||||||
if(options?.headers?['prevent-parallel'] == 'true') {
|
if (options?.headers?['prevent-parallel'] == 'true') {
|
||||||
while(_requests.containsKey(path)) {
|
while (_requests.containsKey(path)) {
|
||||||
await Future.delayed(const Duration(milliseconds: 20));
|
await Future.delayed(const Duration(milliseconds: 20));
|
||||||
}
|
}
|
||||||
_requests[path] = true;
|
_requests[path] = true;
|
||||||
@@ -204,6 +206,9 @@ class AppDio with DioMixin {
|
|||||||
proxySettings: proxy == null
|
proxySettings: proxy == null
|
||||||
? const rhttp.ProxySettings.noProxy()
|
? const rhttp.ProxySettings.noProxy()
|
||||||
: rhttp.ProxySettings.proxy(proxy!),
|
: rhttp.ProxySettings.proxy(proxy!),
|
||||||
|
tlsSettings: rhttp.TlsSettings(
|
||||||
|
verifyCertificates: !ignoreCertificateErrors,
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -216,9 +221,8 @@ class AppDio with DioMixin {
|
|||||||
onSendProgress: onSendProgress,
|
onSendProgress: onSendProgress,
|
||||||
onReceiveProgress: onReceiveProgress,
|
onReceiveProgress: onReceiveProgress,
|
||||||
);
|
);
|
||||||
}
|
} finally {
|
||||||
finally {
|
if (_requests.containsKey(path)) {
|
||||||
if(_requests.containsKey(path)) {
|
|
||||||
_requests.remove(path);
|
_requests.remove(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,6 +241,9 @@ class RHttpAdapter implements HttpClientAdapter {
|
|||||||
keepAlivePing: Duration(seconds: 30),
|
keepAlivePing: Duration(seconds: 30),
|
||||||
),
|
),
|
||||||
throwOnStatusCode: false,
|
throwOnStatusCode: false,
|
||||||
|
tlsSettings: rhttp.TlsSettings(
|
||||||
|
verifyCertificates: !AppDio.ignoreCertificateErrors,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +291,7 @@ class RHttpAdapter implements HttpClientAdapter {
|
|||||||
headers[key]!.add(entry.$2);
|
headers[key]!.add(entry.$2);
|
||||||
}
|
}
|
||||||
var data = res.body;
|
var data = res.body;
|
||||||
if(headers['content-encoding']?.contains('gzip') ?? false) {
|
if (headers['content-encoding']?.contains('gzip') ?? false) {
|
||||||
// rhttp does not support gzip decoding
|
// rhttp does not support gzip decoding
|
||||||
data = gzip.decoder.bind(data).map((data) => Uint8List.fromList(data));
|
data = gzip.decoder.bind(data).map((data) => Uint8List.fromList(data));
|
||||||
}
|
}
|
||||||
|
@@ -38,14 +38,11 @@ class _ProxySettingView extends StatefulWidget {
|
|||||||
|
|
||||||
class _ProxySettingViewState extends State<_ProxySettingView> {
|
class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||||
String type = '';
|
String type = '';
|
||||||
|
|
||||||
String host = '';
|
String host = '';
|
||||||
|
|
||||||
String port = '';
|
String port = '';
|
||||||
|
|
||||||
String username = '';
|
String username = '';
|
||||||
|
|
||||||
String password = '';
|
String password = '';
|
||||||
|
bool ignoreCertificateErrors = false;
|
||||||
|
|
||||||
// USERNAME:PASSWORD@HOST:PORT
|
// USERNAME:PASSWORD@HOST:PORT
|
||||||
String toProxyStr() {
|
String toProxyStr() {
|
||||||
@@ -103,6 +100,7 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
var proxy = appdata.settings['proxy'];
|
var proxy = appdata.settings['proxy'];
|
||||||
parseProxyString(proxy);
|
parseProxyString(proxy);
|
||||||
|
ignoreCertificateErrors = appdata.settings['ignoreCertificateErrors'] ?? false;
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +146,17 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (type == 'manual') buildManualProxy(),
|
if (type == 'manual') buildManualProxy(),
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text("Ignore Certificate Errors".tl),
|
||||||
|
value: ignoreCertificateErrors,
|
||||||
|
onChanged: (v) {
|
||||||
|
setState(() {
|
||||||
|
ignoreCertificateErrors = v;
|
||||||
|
});
|
||||||
|
appdata.settings['ignoreCertificateErrors'] = ignoreCertificateErrors;
|
||||||
|
appdata.saveData();
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user