mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
CertificateSettings: Add export functionality
This commit is contained in:
parent
8b881eaf02
commit
dfce65a0ab
2 changed files with 37 additions and 0 deletions
|
@ -106,6 +106,28 @@ ErrorOr<void> CertificateStoreWidget::import_pem()
|
|||
return {};
|
||||
}
|
||||
|
||||
Certificate CertificateStoreModel::get(int index)
|
||||
{
|
||||
return m_certificates.at(index);
|
||||
}
|
||||
|
||||
ErrorOr<void> CertificateStoreWidget::export_pem()
|
||||
{
|
||||
auto index = m_root_ca_tableview->selection().first().row();
|
||||
auto cert = m_root_ca_model->get(index);
|
||||
|
||||
auto filename = cert.subject.subject.is_empty() ? cert.subject.unit : cert.subject.subject;
|
||||
auto file = FileSystemAccessClient::Client::the().save_file(window(), filename.replace(" "sv, "_"sv), "pem"sv);
|
||||
if (file.is_error())
|
||||
return {};
|
||||
|
||||
auto data = TRY(Crypto::encode_pem(cert.original_asn1));
|
||||
|
||||
TRY(file.release_value().release_stream()->write_until_depleted(data));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<CertificateStoreWidget>> CertificateStoreWidget::try_create()
|
||||
{
|
||||
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) CertificateStoreWidget()));
|
||||
|
@ -127,6 +149,10 @@ ErrorOr<void> CertificateStoreWidget::initialize()
|
|||
m_root_ca_tableview->set_column_width(CertificateStoreModel::Column::IssuedTo, 150);
|
||||
m_root_ca_tableview->set_column_width(CertificateStoreModel::Column::IssuedBy, 150);
|
||||
|
||||
m_root_ca_tableview->on_selection_change = [&]() {
|
||||
m_export_ca_button->set_enabled(m_root_ca_tableview->selection().size() == 1);
|
||||
};
|
||||
|
||||
m_import_ca_button = find_descendant_of_type_named<GUI::Button>("import_button");
|
||||
m_import_ca_button->on_click = [&](auto) {
|
||||
auto import_result = import_pem();
|
||||
|
@ -135,6 +161,14 @@ ErrorOr<void> CertificateStoreWidget::initialize()
|
|||
}
|
||||
};
|
||||
|
||||
m_export_ca_button = find_descendant_of_type_named<GUI::Button>("export_button");
|
||||
m_export_ca_button->on_click = [&](auto) {
|
||||
auto export_result = export_pem();
|
||||
if (export_result.is_error()) {
|
||||
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("{}", export_result.release_error()));
|
||||
}
|
||||
};
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
|
||||
virtual ErrorOr<void> load();
|
||||
virtual ErrorOr<size_t> add(Vector<Certificate> const&);
|
||||
virtual Certificate get(int index);
|
||||
|
||||
private:
|
||||
Vector<Certificate> m_certificates;
|
||||
|
@ -47,9 +48,11 @@ private:
|
|||
CertificateStoreWidget() = default;
|
||||
ErrorOr<void> initialize();
|
||||
ErrorOr<void> import_pem();
|
||||
ErrorOr<void> export_pem();
|
||||
|
||||
RefPtr<CertificateStoreModel> m_root_ca_model;
|
||||
RefPtr<GUI::TableView> m_root_ca_tableview;
|
||||
RefPtr<GUI::Button> m_import_ca_button;
|
||||
RefPtr<GUI::Button> m_export_ca_button;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue