Commit 5501f0ea authored by Volker Krause's avatar Volker Krause
Browse files

Add a way to write certificate keys back in ISO 9796-2 format

Allows the certificate downloader to store decoded certificates, and strip
unneeded signatures or other data from the certificates.
parent 05c3dcc8
......@@ -148,6 +148,34 @@ void VdvCertificate::setCaCertificate(const VdvCertificate &caCert)
}
}
static void writeTaggedSize(QIODevice *out, int size)
{
if (size <= 255) {
out->write("\x81");
char size1 = (uint8_t)(size);
out->write(&size1, 1);
} else {
out->write("\x82");
uint16_t size2 = qToBigEndian((uint16_t)(size));
out->write((const char*)&size2, 2);
}
}
void VdvCertificate::writeKey(QIODevice *out) const
{
out->write("\x7F\x21");
if (m_type == Signed) {
writeTaggedSize(out, m_recoveredData.size() + 3);
out->write("\x5F\x4E");
writeTaggedSize(out, m_recoveredData.size());
out->write(m_recoveredData);
} else if (m_type == Raw) {
const auto keyBlock = header()->contentAt<VdvCertificateKeyBlock>(0);
writeTaggedSize(out, keyBlock->size());
out->write((const char*)keyBlock, keyBlock->size());
}
}
bool VdvCertificate::isSelfSigned() const
{
return memcmp(&certKey()->car, certKey()->chr.name, sizeof(VdvCaReference)) == 0;
......
......@@ -21,6 +21,7 @@
#include <QByteArray>
class QDate;
class QIODevice;
namespace KItinerary {
......@@ -60,6 +61,9 @@ public:
/** Sets the CA certificate for decoding ISO 9796-2 signed certificates. */
void setCaCertificate(const VdvCertificate &caCert);
/** Write the key to @p out, in ISO 9796-2 format, without signatures. */
void writeKey(QIODevice *out) const;
/** Returns whether this is a self-signed (== root) certificate. */
bool isSelfSigned() const;
/** Returns the date this certificate expires. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment