From 2523282a890b4925bf9ca4f4e11d286f659eb832 Mon Sep 17 00:00:00 2001 From: Ricky Date: Tue, 12 Nov 2024 10:30:21 +0800 Subject: [PATCH] feat(http): add option to skip SSL certificate verification (#801) --- internal/protocol/http/fetcher.go | 4 +++ pkg/base/model.go | 2 ++ ui/flutter/lib/api/model/request.dart | 2 ++ ui/flutter/lib/api/model/request.g.dart | 2 ++ .../app/modules/create/views/create_view.dart | 25 ++++++++++++++++++- ui/flutter/lib/i18n/langs/en_us.dart | 1 + ui/flutter/lib/i18n/langs/es_es.dart | 1 + ui/flutter/lib/i18n/langs/fa_ir.dart | 1 + ui/flutter/lib/i18n/langs/fr_fr.dart | 1 + ui/flutter/lib/i18n/langs/id_id.dart | 1 + ui/flutter/lib/i18n/langs/it_it.dart | 1 + ui/flutter/lib/i18n/langs/ja_jp.dart | 1 + ui/flutter/lib/i18n/langs/pl_pl.dart | 1 + ui/flutter/lib/i18n/langs/ru_ru.dart | 1 + ui/flutter/lib/i18n/langs/ta_ta.dart | 1 + ui/flutter/lib/i18n/langs/tr_tr.dart | 1 + ui/flutter/lib/i18n/langs/vi_vn.dart | 1 + ui/flutter/lib/i18n/langs/zh_cn.dart | 1 + ui/flutter/lib/i18n/langs/zh_tw.dart | 1 + 19 files changed, 48 insertions(+), 1 deletion(-) diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 75ada8408..82e65aa71 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -3,6 +3,7 @@ package http import ( "bytes" "context" + "crypto/tls" "errors" "fmt" "io" @@ -449,6 +450,9 @@ func (f *Fetcher) splitChunk() (chunks []*chunk) { func (f *Fetcher) buildClient() *http.Client { transport := &http.Transport{ Proxy: f.ctl.GetProxy(f.meta.Req.Proxy), + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: f.meta.Req.SkipVerifyCert, + }, } // Cookie handle jar, _ := cookiejar.New(nil) diff --git a/pkg/base/model.go b/pkg/base/model.go index 8f79f4a7c..1a90b67ea 100644 --- a/pkg/base/model.go +++ b/pkg/base/model.go @@ -18,6 +18,8 @@ type Request struct { Labels map[string]string `json:"labels"` // Proxy is special proxy config for request Proxy *RequestProxy `json:"proxy"` + // SkipVerifyCert is the flag that skip verify cert + SkipVerifyCert bool `json:"skipVerifyCert"` } func (r *Request) Validate() error { diff --git a/ui/flutter/lib/api/model/request.dart b/ui/flutter/lib/api/model/request.dart index 96dfdd2dc..fd9a7e063 100644 --- a/ui/flutter/lib/api/model/request.dart +++ b/ui/flutter/lib/api/model/request.dart @@ -8,12 +8,14 @@ class Request { Object? extra; Map? labels = {}; RequestProxy? proxy; + bool skipVerifyCert = false; Request({ required this.url, this.extra, this.labels, this.proxy, + this.skipVerifyCert = false, }); factory Request.fromJson(Map json) => diff --git a/ui/flutter/lib/api/model/request.g.dart b/ui/flutter/lib/api/model/request.g.dart index 20a383f00..5acbda52a 100644 --- a/ui/flutter/lib/api/model/request.g.dart +++ b/ui/flutter/lib/api/model/request.g.dart @@ -15,6 +15,7 @@ Request _$RequestFromJson(Map json) => Request( proxy: json['proxy'] == null ? null : RequestProxy.fromJson(json['proxy'] as Map), + skipVerifyCert: json['skipVerifyCert'] as bool? ?? false, ); Map _$RequestToJson(Request instance) { @@ -31,6 +32,7 @@ Map _$RequestToJson(Request instance) { writeNotNull('extra', instance.extra); writeNotNull('labels', instance.labels); writeNotNull('proxy', instance.proxy?.toJson()); + val['skipVerifyCert'] = instance.skipVerifyCert; return val; } diff --git a/ui/flutter/lib/app/modules/create/views/create_view.dart b/ui/flutter/lib/app/modules/create/views/create_view.dart index 5e1b29595..cf4e16a24 100644 --- a/ui/flutter/lib/app/modules/create/views/create_view.dart +++ b/ui/flutter/lib/app/modules/create/views/create_view.dart @@ -43,6 +43,8 @@ class CreateView extends GetView { final _availableSchemes = ["http:", "https:", "magnet:"]; + final _skipVerifyCertController = false.obs; + CreateView({Key? key}) : super(key: key); @override @@ -454,6 +456,22 @@ class CreateView extends GetView { decoration: const InputDecoration( labelText: 'Referer', )), + Padding( + padding: + const EdgeInsets.only(top: 10), + child: CompactCheckbox( + label: 'skipVerifyCert'.tr, + value: + _skipVerifyCertController.value, + onChanged: (bool? value) { + _skipVerifyCertController.value = + value ?? false; + }, + textStyle: const TextStyle( + color: Colors.grey, + ), + ), + ), ], ), Column( @@ -578,7 +596,11 @@ class CreateView extends GetView { await Future.wait(urls.map((url) { return createTask(CreateTask( req: Request( - url: url, extra: parseReqExtra(url), proxy: parseProxy()), + url: url, + extra: parseReqExtra(url), + proxy: parseProxy(), + skipVerifyCert: _skipVerifyCertController.value, + ), opt: Options( name: isMultiLine ? "" : _renameController.text, path: _pathController.text, @@ -592,6 +614,7 @@ class CreateView extends GetView { url: submitUrl, extra: parseReqExtra(_urlController.text), proxy: parseProxy(), + skipVerifyCert: _skipVerifyCertController.value, )); await _showResolveDialog(rr); } diff --git a/ui/flutter/lib/i18n/langs/en_us.dart b/ui/flutter/lib/i18n/langs/en_us.dart index c1dfad697..6af60fa4a 100644 --- a/ui/flutter/lib/i18n/langs/en_us.dart +++ b/ui/flutter/lib/i18n/langs/en_us.dart @@ -107,5 +107,6 @@ const enUS = { 'taskName': 'Task Name', 'taskUrl': 'Task URL', 'downloadPath': 'Download Path', + 'skipVerifyCert': 'Skip Certificate Verification', }, }; diff --git a/ui/flutter/lib/i18n/langs/es_es.dart b/ui/flutter/lib/i18n/langs/es_es.dart index 298366dd1..22219bc77 100644 --- a/ui/flutter/lib/i18n/langs/es_es.dart +++ b/ui/flutter/lib/i18n/langs/es_es.dart @@ -103,5 +103,6 @@ const esES = { 'taskName': 'Nombre de la Tarea', 'taskUrl': 'URL de la Tarea', 'downloadPath': 'Ruta de Descarga', + 'skipVerifyCert': 'Omitir Verificación de Certificado', }, }; \ No newline at end of file diff --git a/ui/flutter/lib/i18n/langs/fa_ir.dart b/ui/flutter/lib/i18n/langs/fa_ir.dart index e8591e928..b9825baaa 100644 --- a/ui/flutter/lib/i18n/langs/fa_ir.dart +++ b/ui/flutter/lib/i18n/langs/fa_ir.dart @@ -61,5 +61,6 @@ const faIR = { 'thanksDesc': 'از تمامی افرادی که در ساخت و توسعه‌ی جامعه‌ی Gopeed مشارکت کرده‌اند، سپاسگزاری می‌کنیم!', 'browserExtension': 'فایل های دانلود شده را نگه دارد', + 'skipVerifyCert': 'رد کردن تأیید گواهینامه', } }; diff --git a/ui/flutter/lib/i18n/langs/fr_fr.dart b/ui/flutter/lib/i18n/langs/fr_fr.dart index 05469c3c0..e5e94c3da 100644 --- a/ui/flutter/lib/i18n/langs/fr_fr.dart +++ b/ui/flutter/lib/i18n/langs/fr_fr.dart @@ -92,5 +92,6 @@ const frFR = { 'thanksDesc': 'Merci à tous les contributeurs qui ont aidé à construire et développer la communauté Gopeed !', 'browserExtension': 'Extension du navigateur', 'launchAtStartup': 'Lancer au démarrage', + 'skipVerifyCert': 'Bypass Verifikasi Sertifikat', }, }; diff --git a/ui/flutter/lib/i18n/langs/id_id.dart b/ui/flutter/lib/i18n/langs/id_id.dart index dd46f80cd..c58a4ed19 100644 --- a/ui/flutter/lib/i18n/langs/id_id.dart +++ b/ui/flutter/lib/i18n/langs/id_id.dart @@ -107,5 +107,6 @@ const idID = { 'taskName': 'Nama Tugas', 'taskUrl': 'URL Tugas', 'downloadPath': 'Direktori Unduhan', + 'skipVerifyCert': 'Lupakan verifikasi sertifikat', }, }; diff --git a/ui/flutter/lib/i18n/langs/it_it.dart b/ui/flutter/lib/i18n/langs/it_it.dart index 5e5753339..3c53c31d6 100644 --- a/ui/flutter/lib/i18n/langs/it_it.dart +++ b/ui/flutter/lib/i18n/langs/it_it.dart @@ -96,5 +96,6 @@ const itIT = { 'Grazie a tutti i contributori che hanno contribuito a costruire e sviluppare la comunità Gopeed!', 'browserExtension': 'Estensione del browser', 'launchAtStartup': "Lancia all'avvio", + 'skipVerifyCert': 'Salta la verifica del certificato', }, }; diff --git a/ui/flutter/lib/i18n/langs/ja_jp.dart b/ui/flutter/lib/i18n/langs/ja_jp.dart index 48b03bc43..26bc3111a 100644 --- a/ui/flutter/lib/i18n/langs/ja_jp.dart +++ b/ui/flutter/lib/i18n/langs/ja_jp.dart @@ -62,5 +62,6 @@ const jaJP = { 'thanks': '感謝', 'thanksDesc': 'Gopeedコミュニティの建設に協力してくださったすべての貢献者の方々に感謝します!', 'browserExtension': 'ブラウザ拡張機能', + 'skipVerifyCert': '証明書の検証をスキップ', } }; diff --git a/ui/flutter/lib/i18n/langs/pl_pl.dart b/ui/flutter/lib/i18n/langs/pl_pl.dart index 85317e8e9..6327da1c4 100644 --- a/ui/flutter/lib/i18n/langs/pl_pl.dart +++ b/ui/flutter/lib/i18n/langs/pl_pl.dart @@ -94,5 +94,6 @@ const plPL = { 'Dziękuję wszystkim za pomoc przy powstawaniu aplikacji Gopeed!', 'browserExtension': 'Wtyczka dla przeglądarki', 'launchAtStartup': 'Uruchom na starcie', + 'skipVerifyCert': 'Pomiń weryfikację certyfikatu', }, }; diff --git a/ui/flutter/lib/i18n/langs/ru_ru.dart b/ui/flutter/lib/i18n/langs/ru_ru.dart index 949ee8869..e5a6f3650 100644 --- a/ui/flutter/lib/i18n/langs/ru_ru.dart +++ b/ui/flutter/lib/i18n/langs/ru_ru.dart @@ -77,5 +77,6 @@ const ruRU = { 'thanksDesc': 'Благодарим всех участников за их вклад в строительство и развитие сообщества Gopeed!', 'browserExtension': 'Расширение браузера', + 'skipVerifyCert': 'Пропустить проверку сертификата', } }; diff --git a/ui/flutter/lib/i18n/langs/ta_ta.dart b/ui/flutter/lib/i18n/langs/ta_ta.dart index ee96ec298..e9e78338a 100644 --- a/ui/flutter/lib/i18n/langs/ta_ta.dart +++ b/ui/flutter/lib/i18n/langs/ta_ta.dart @@ -95,5 +95,6 @@ const taTA = { 'Gopeed சமூகத்தை உருவாக்கவும் மற்றும் மேம்படுத்த உதவிய அனைத்து பங்களிப்பாளர்களுக்கும் நன்றி!', 'browserExtension': 'உலாவி நீட்டிப்பு', 'launchAtStartup': 'தொடக்கத்தின் போது இயங்கு', + 'skipVerifyCert': 'திருத்தி சான்று சரிபார்க்கவும்', }, }; diff --git a/ui/flutter/lib/i18n/langs/tr_tr.dart b/ui/flutter/lib/i18n/langs/tr_tr.dart index 7946d8b98..5c7912164 100644 --- a/ui/flutter/lib/i18n/langs/tr_tr.dart +++ b/ui/flutter/lib/i18n/langs/tr_tr.dart @@ -104,5 +104,6 @@ const trTR = { 'taskName': 'Görev adı', 'taskUrl': 'Görev URL', 'downloadPath': 'İndirme yolu', + 'skipVerifyCert': 'Sertifika doğrulamasını atla', }, }; diff --git a/ui/flutter/lib/i18n/langs/vi_vn.dart b/ui/flutter/lib/i18n/langs/vi_vn.dart index ea12dba52..de182fa85 100644 --- a/ui/flutter/lib/i18n/langs/vi_vn.dart +++ b/ui/flutter/lib/i18n/langs/vi_vn.dart @@ -89,5 +89,6 @@ const viVN = { 'thanksDesc': 'Cảm ơn tất cả những người đóng góp đã giúp xây dựng và phát triển cộng đồng Gopeed!', 'browserExtension': 'Tiện ích mở rộng trình duyệt', + 'skipVerifyCert': 'Bỏ qua xác thực chứng chỉ', }, }; diff --git a/ui/flutter/lib/i18n/langs/zh_cn.dart b/ui/flutter/lib/i18n/langs/zh_cn.dart index b65e2c44a..a84dee909 100644 --- a/ui/flutter/lib/i18n/langs/zh_cn.dart +++ b/ui/flutter/lib/i18n/langs/zh_cn.dart @@ -104,5 +104,6 @@ const zhCN = { 'taskName': '任务名称', 'taskUrl': '任务链接', 'downloadPath': '下载路径', + 'skipVerifyCert': '跳过证书验证', } }; diff --git a/ui/flutter/lib/i18n/langs/zh_tw.dart b/ui/flutter/lib/i18n/langs/zh_tw.dart index c48aa4582..0a4ce12a0 100644 --- a/ui/flutter/lib/i18n/langs/zh_tw.dart +++ b/ui/flutter/lib/i18n/langs/zh_tw.dart @@ -104,5 +104,6 @@ const zhTW = { 'taskName': '任務名稱', 'taskUrl': '任務連結', 'downloadPath': '下載路徑', + 'skipVerifyCert': '跳過憑證驗證', } };