diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-20 21:55:09 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-20 21:55:09 +0200 |
| commit | 7e0cc55346f8d70a1884b457510a8c55ca68f72e (patch) | |
| tree | dde3889f7cc748442e6856954a8b922959f8ef14 /src/certificatemanagementdialog.cpp | |
| parent | 427072815e0156d501d8482290194b16eb38e0c3 (diff) | |
| download | kristall-7e0cc55346f8d70a1884b457510a8c55ca68f72e.tar.gz | |
Allows export of certificates, validates import.
Diffstat (limited to 'src/certificatemanagementdialog.cpp')
| -rw-r--r-- | src/certificatemanagementdialog.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/certificatemanagementdialog.cpp b/src/certificatemanagementdialog.cpp index aeaec4c..3102ac8 100644 --- a/src/certificatemanagementdialog.cpp +++ b/src/certificatemanagementdialog.cpp @@ -5,6 +5,7 @@ #include "newidentitiydialog.hpp" #include "certificateiodialog.hpp" +#include "ioutil.hpp" #include <QCryptographicHash> #include <QMessageBox> @@ -140,6 +141,62 @@ void CertificateManagementDialog::on_export_cert_button_clicked() if(dialog.exec() != QDialog::Accepted) return; + + { + QFile cert_file { dialog.certificateFileName() }; + if(not cert_file.open(QFile::WriteOnly)) { + QMessageBox::warning( + this, + "Kristall", + tr("The file %1 could not be found!").arg(dialog.certificateFileName()) + ); + return; + } + + QByteArray cert_blob; + if(dialog.certificateFileName().endsWith(".der")) { + cert_blob = this->selected_identity->certificate.toDer(); + } else { + cert_blob = this->selected_identity->certificate.toPem(); + } + + if(not IoUtil::writeAll(cert_file, cert_blob)) { + QMessageBox::warning( + this, + "Kristall", + tr("The file %1 could not be created found!").arg(dialog.certificateFileName()) + ); + return; + } + } + + { + QFile key_file { dialog.keyFileName() }; + if(not key_file.open(QFile::WriteOnly)) { + QMessageBox::warning( + this, + "Kristall", + tr("The file %1 could not be found!").arg(dialog.keyFileName()) + ); + return; + } + + QByteArray key_blob; + if(dialog.keyFileName().endsWith(".der")) { + key_blob = this->selected_identity->private_key.toDer(); + } else { + key_blob = this->selected_identity->private_key.toPem(); + } + + if(not IoUtil::writeAll(key_file, key_blob)) { + QMessageBox::warning( + this, + "Kristall", + tr("The file %1 could not be created found!").arg(dialog.keyFileName()) + ); + return; + } + } } void CertificateManagementDialog::on_import_cert_button_clicked() |
