From 6069cf72336147f35b06833c79372bb4f409b8bd Mon Sep 17 00:00:00 2001 From: wanghongenpin Date: Mon, 21 Oct 2024 17:55:48 +0800 Subject: [PATCH] iOS Generate new root certificate --- ios/Runner/pip/PictureInPictureManager.swift | 2 ++ lib/network/util/crts.dart | 11 +++++---- lib/ui/content/panel.dart | 1 + lib/ui/mobile/setting/ssl.dart | 25 ++++++++------------ lib/utils/lang.dart | 4 ++++ 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ios/Runner/pip/PictureInPictureManager.swift b/ios/Runner/pip/PictureInPictureManager.swift index f493ef7..db13018 100644 --- a/ios/Runner/pip/PictureInPictureManager.swift +++ b/ios/Runner/pip/PictureInPictureManager.swift @@ -99,6 +99,8 @@ class PictureInPictureManager: NSObject,AVPictureInPictureControllerDelegate { // 隐藏播放按钮、快进快退按钮 pipController.setValue(1, forKey: "controlsStyle") + //点击回到app + //pipController.setValue(2, forKey: "controlsStyle") } diff --git a/lib/network/util/crts.dart b/lib/network/util/crts.dart index 4edcf1a..9fe1dc8 100644 --- a/lib/network/util/crts.dart +++ b/lib/network/util/crts.dart @@ -25,6 +25,8 @@ import 'package:network_proxy/network/util/logger.dart'; import 'package:network_proxy/network/util/cert/basic_constraints.dart'; import 'package:network_proxy/network/util/cert/pkcs12.dart'; import 'package:network_proxy/network/util/cert/x509.dart'; +import 'package:network_proxy/network/util/random.dart'; +import 'package:network_proxy/utils/lang.dart'; import 'package:path_provider/path_provider.dart'; import 'package:network_proxy/network/util/cert/key_usage.dart' as x509; @@ -135,7 +137,7 @@ class CertificateManager { 'O': 'Proxy', 'OU': 'ProxyPin', }; - x509Subject['CN'] = 'ProxyPin CA (${Platform.localHostname})'; + x509Subject['CN'] = 'ProxyPin CA (${DateTime.now().dateFormat()},${RandomUtil.randomString(6).toUpperCase()})'; var csrPem = X509Generate.generateSelfSignedCertificate( _caCert, @@ -143,10 +145,11 @@ class CertificateManager { serverPriKey, 825, sans: [x509Subject['CN']!], - serialNumber: Random().nextInt(1000000).toString(), + serialNumber: DateTime.now().millisecondsSinceEpoch.toString(), + issuer: x509Subject, subject: x509Subject, - keyUsage: x509.KeyUsage(x509.KeyUsage.keyCertSign | x509.KeyUsage.cRLSign), - extKeyUsage: [ExtendedKeyUsage.SERVER_AUTH, ExtendedKeyUsage.CLIENT_AUTH], + keyUsage: x509.KeyUsage(x509.KeyUsage.keyCertSign), + extKeyUsage: [ExtendedKeyUsage.SERVER_AUTH], basicConstraints: BasicConstraints(isCA: true), ); diff --git a/lib/ui/content/panel.dart b/lib/ui/content/panel.dart index 9b14eb4..19f9fc8 100644 --- a/lib/ui/content/panel.dart +++ b/lib/ui/content/panel.dart @@ -327,6 +327,7 @@ class NetworkTabState extends State with SingleTickerProvi headers.add(Row(children: [ SelectableText(name, contextMenuBuilder: contextMenu, style: nameStyle), const Text(": ", style: nameStyle), + if (Platforms.isDesktop()) SizedBox(width: 5), Expanded( child: SelectableText(v, style: textStyle, contextMenuBuilder: contextMenu, maxLines: 8, minLines: 1)), ])); diff --git a/lib/ui/mobile/setting/ssl.dart b/lib/ui/mobile/setting/ssl.dart index 660ef6b..0f5cad2 100644 --- a/lib/ui/mobile/setting/ssl.dart +++ b/lib/ui/mobile/setting/ssl.dart @@ -80,11 +80,6 @@ class _MobileSslState extends State { ListTile( title: Text(localizations.exportCA), onTap: () async { - if (Platform.isIOS) { - _downloadCert(); - return; - } - var caFile = await CertificateManager.certificateFile(); _exportFile("ProxyPinCA.crt", file: caFile); }), @@ -98,16 +93,15 @@ class _MobileSslState extends State { const Divider(indent: 0.2, height: 1), ListTile(title: Text(localizations.importCaP12), onTap: importPk12), const Divider(indent: 0.2, height: 1), - if (Platform.isAndroid) - ListTile( - title: Text(localizations.generateCA), - onTap: () async { - showConfirmDialog(context, title: localizations.generateCA, content: localizations.generateCADescribe, - onConfirm: () async { - await CertificateManager.generateNewRootCA(); - if (context.mounted) FlutterToastr.show(localizations.success, context); - }); - }), + ListTile( + title: Text(localizations.generateCA), + onTap: () async { + showConfirmDialog(context, title: localizations.generateCA, content: localizations.generateCADescribe, + onConfirm: () async { + await CertificateManager.generateNewRootCA(); + if (context.mounted) FlutterToastr.show(localizations.success, context); + }); + }), const Divider(indent: 0.2, height: 1), ListTile( title: Text(localizations.resetDefaultCA), @@ -224,6 +218,7 @@ class _MobileSslState extends State { void _downloadCert() async { CertificateManager.cleanCache(); + await widget.proxyServer.retryBind(); launchUrl(Uri.parse("http://127.0.0.1:${widget.proxyServer.port}/ssl"), mode: LaunchMode.externalApplication); } diff --git a/lib/utils/lang.dart b/lib/utils/lang.dart index 98c27c1..4a977c5 100644 --- a/lib/utils/lang.dart +++ b/lib/utils/lang.dart @@ -22,6 +22,10 @@ extension DateTimeFormat on DateTime { return formatDate(this, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss, '.', SSS]); } + String dateFormat() { + return formatDate(this, [yyyy, '-', mm, '-', dd]); + } + String timeFormat() { return formatDate(this, [HH, ':', nn, ':', ss]); }