Skip to content

Commit

Permalink
Allows export of certificates, validates import.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikskuh committed Jun 20, 2020
1 parent 4270728 commit 7e0cc55
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
1 change: 0 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ This document contains TODO items for planned Kristall releases as well as some
- [ ] TLS Handling
- [ ] Add management for client certificates
- [ ] Allow merge/delete/merge groups
- [ ] Import/export PEM certificates and keys

## 0.4 - The colorful release
- [ ] Implement dual-colored icon theme
Expand Down
57 changes: 57 additions & 0 deletions src/certificatemanagementdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "newidentitiydialog.hpp"
#include "certificateiodialog.hpp"
#include "ioutil.hpp"

#include <QCryptographicHash>
#include <QMessageBox>
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7e0cc55

Please sign in to comment.