mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-01-19 03:37:02 +00:00
991837676a
This pulls out a component that we can use for "dangerous" operations like deleting, and styles it in one place. It also starts to move us slowly towards Material 3, with the rounded corners on these buttons in Android. Android: |Before Light|Before Dark|After Light|After Dark| |---|---|---|---| |<img width="425" alt="Android Studio 2025-01-15 14 16 36" src="https://github.com/user-attachments/assets/4823e551-6a40-48dd-9bc1-3004699b90ea" />|<img width="417" alt="Android Studio 2025-01-15 14 16 47" src="https://github.com/user-attachments/assets/df5461fd-586e-47bb-99b9-0212e63f0454" />|<img width="413" alt="Android Studio 2025-01-15 14 15 59" src="https://github.com/user-attachments/assets/d88a6225-b71a-4886-8387-e35811a3a6ec" />|<img width="418" alt="Android Studio 2025-01-15 14 16 15" src="https://github.com/user-attachments/assets/d4f23b1c-7003-4a00-b865-4a123d8fe3e9" />| iOS: |Before Light|Before Dark|After Light|After Dark| |---|---|---|---| |<img width="437" alt="Simulator 2025-01-15 15 56 26" src="https://github.com/user-attachments/assets/87c4eed3-6d07-4858-8ad8-d8c011538154" />|<img width="445" alt="Simulator 2025-01-15 15 56 36" src="https://github.com/user-attachments/assets/9dc5b174-7bc7-48ec-a3c0-61633168c31a" />|<img width="439" alt="Simulator 2025-01-15 16 05 23" src="https://github.com/user-attachments/assets/31dc9ab6-8a3c-49c7-892d-627f16e2a8cd" />|<img width="444" alt="Simulator 2025-01-15 16 05 37" src="https://github.com/user-attachments/assets/979280d6-e1f4-4d57-a86a-10bb4def729a" />|
209 lines
7 KiB
Dart
209 lines
7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
|
import 'package:mobile_nebula/components/DangerButton.dart';
|
|
import 'package:mobile_nebula/components/FormPage.dart';
|
|
import 'package:mobile_nebula/components/config/ConfigItem.dart';
|
|
import 'package:mobile_nebula/components/config/ConfigSection.dart';
|
|
import 'package:mobile_nebula/models/Certificate.dart';
|
|
import 'package:mobile_nebula/screens/siteConfig/AddCertificateScreen.dart';
|
|
import 'package:mobile_nebula/services/utils.dart';
|
|
|
|
/// Displays the details of a CertificateInfo object. Respects incomplete objects (missing validity or rawCert)
|
|
class CertificateDetailsScreen extends StatefulWidget {
|
|
const CertificateDetailsScreen({
|
|
Key? key,
|
|
required this.certInfo,
|
|
this.onDelete,
|
|
this.onSave,
|
|
this.onReplace,
|
|
this.pubKey,
|
|
this.privKey,
|
|
required this.supportsQRScanning,
|
|
}) : super(key: key);
|
|
|
|
final CertificateInfo certInfo;
|
|
|
|
// onDelete is used to remove a CA cert
|
|
final Function? onDelete;
|
|
|
|
// onSave is used to install a new certificate
|
|
final Function? onSave;
|
|
|
|
// onReplace is used to install a new certificate over top of the old one
|
|
final ValueChanged<CertificateResult>? onReplace;
|
|
|
|
// pubKey and privKey should be set if onReplace is not null.
|
|
final String? pubKey;
|
|
final String? privKey;
|
|
|
|
final bool supportsQRScanning;
|
|
|
|
@override
|
|
_CertificateDetailsScreenState createState() => _CertificateDetailsScreenState();
|
|
}
|
|
|
|
class _CertificateDetailsScreenState extends State<CertificateDetailsScreen> {
|
|
bool changed = false;
|
|
CertificateResult? certResult;
|
|
late CertificateInfo certInfo;
|
|
ScrollController controller = ScrollController();
|
|
|
|
@override
|
|
void initState() {
|
|
certInfo = widget.certInfo;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FormPage(
|
|
title: 'Certificate Details',
|
|
scrollController: controller,
|
|
changed: widget.onSave != null || changed,
|
|
onSave: () {
|
|
if (widget.onSave != null) {
|
|
Navigator.pop(context);
|
|
widget.onSave!();
|
|
} else if (widget.onReplace != null) {
|
|
Navigator.pop(context);
|
|
widget.onReplace!(certResult!);
|
|
}
|
|
},
|
|
hideSave: widget.onSave == null && widget.onReplace == null,
|
|
child: Column(children: [
|
|
_buildID(),
|
|
_buildFilters(),
|
|
_buildValid(),
|
|
_buildAdvanced(),
|
|
_buildReplace(),
|
|
_buildDelete(),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildID() {
|
|
return ConfigSection(children: <Widget>[
|
|
ConfigItem(label: Text('Name'), content: SelectableText(certInfo.cert.details.name)),
|
|
ConfigItem(
|
|
label: Text('Type'), content: Text(certInfo.cert.details.isCa ? 'CA certificate' : 'Client certificate')),
|
|
]);
|
|
}
|
|
|
|
Widget _buildValid() {
|
|
var valid = Text('yes');
|
|
if (certInfo.validity != null && !certInfo.validity!.valid) {
|
|
valid = Text(certInfo.validity!.valid ? 'yes' : certInfo.validity!.reason,
|
|
style: TextStyle(color: CupertinoColors.systemRed.resolveFrom(context)));
|
|
}
|
|
return ConfigSection(
|
|
label: 'VALIDITY',
|
|
children: <Widget>[
|
|
ConfigItem(label: Text('Valid?'), content: valid),
|
|
ConfigItem(
|
|
label: Text('Created'), content: SelectableText(certInfo.cert.details.notBefore.toLocal().toString())),
|
|
ConfigItem(
|
|
label: Text('Expires'), content: SelectableText(certInfo.cert.details.notAfter.toLocal().toString())),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildFilters() {
|
|
List<Widget> items = [];
|
|
if (certInfo.cert.details.groups.length > 0) {
|
|
items.add(ConfigItem(label: Text('Groups'), content: SelectableText(certInfo.cert.details.groups.join(', '))));
|
|
}
|
|
|
|
if (certInfo.cert.details.ips.length > 0) {
|
|
items.add(ConfigItem(label: Text('IPs'), content: SelectableText(certInfo.cert.details.ips.join(', '))));
|
|
}
|
|
|
|
if (certInfo.cert.details.subnets.length > 0) {
|
|
items.add(ConfigItem(label: Text('Subnets'), content: SelectableText(certInfo.cert.details.subnets.join(', '))));
|
|
}
|
|
|
|
return items.length > 0
|
|
? ConfigSection(label: certInfo.cert.details.isCa ? 'FILTERS' : 'DETAILS', children: items)
|
|
: Container();
|
|
}
|
|
|
|
Widget _buildAdvanced() {
|
|
return ConfigSection(
|
|
children: <Widget>[
|
|
ConfigItem(
|
|
label: Text('Fingerprint'),
|
|
content:
|
|
SelectableText(certInfo.cert.fingerprint, style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14)),
|
|
crossAxisAlignment: CrossAxisAlignment.start),
|
|
ConfigItem(
|
|
label: Text('Public Key'),
|
|
content: SelectableText(certInfo.cert.details.publicKey,
|
|
style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14)),
|
|
crossAxisAlignment: CrossAxisAlignment.start),
|
|
certInfo.rawCert != null
|
|
? ConfigItem(
|
|
label: Text('PEM Format'),
|
|
content: SelectableText(certInfo.rawCert!, style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14)),
|
|
crossAxisAlignment: CrossAxisAlignment.start)
|
|
: Container(),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildReplace() {
|
|
if (widget.onReplace == null || widget.pubKey == null || widget.privKey == null) {
|
|
return Container();
|
|
}
|
|
|
|
return Padding(
|
|
padding: EdgeInsets.only(top: 50, bottom: 10, left: 10, right: 10),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: DangerButton(
|
|
child: Text('Replace certificate'),
|
|
onPressed: () {
|
|
Utils.openPage(context, (context) {
|
|
return AddCertificateScreen(
|
|
onReplace: (result) {
|
|
setState(() {
|
|
changed = true;
|
|
certResult = result;
|
|
certInfo = result.certInfo;
|
|
});
|
|
// Slam the page back to the top
|
|
controller.animateTo(0,
|
|
duration: const Duration(milliseconds: 10), curve: Curves.linearToEaseOut);
|
|
},
|
|
pubKey: widget.pubKey!,
|
|
privKey: widget.privKey!,
|
|
supportsQRScanning: widget.supportsQRScanning,
|
|
);
|
|
});
|
|
})));
|
|
}
|
|
|
|
Widget _buildDelete() {
|
|
if (widget.onDelete == null) {
|
|
return Container();
|
|
}
|
|
|
|
var title = certInfo.cert.details.isCa ? 'Delete CA?' : 'Delete cert?';
|
|
|
|
return Padding(
|
|
padding: EdgeInsets.only(top: 50, bottom: 10, left: 10, right: 10),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: DangerButton(
|
|
child: Text('Delete'),
|
|
onPressed: () => Utils.confirmDelete(context, title, () async {
|
|
Navigator.pop(context);
|
|
widget.onDelete!();
|
|
}))));
|
|
}
|
|
}
|