Commit 05c3dcc8 authored by Volker Krause's avatar Volker Krause
Browse files

Add access to certificate expiry date

Needed so the certificate downloader can discard old ones.
parent f69bf931
......@@ -19,6 +19,7 @@
#include "vdvdata_p.h"
#include "iso9796_2decoder_p.h"
#include <QDate>
#include <QDebug>
#include <QFile>
......@@ -147,6 +148,17 @@ void VdvCertificate::setCaCertificate(const VdvCertificate &caCert)
}
}
bool VdvCertificate::isSelfSigned() const
{
return memcmp(&certKey()->car, certKey()->chr.name, sizeof(VdvCaReference)) == 0;
}
QDate KItinerary::VdvCertificate::endOfValidity() const
{
const auto key = certKey();
return QDate(key->date.year(), key->date.month(), key->date.day());
}
const VdvCertificateHeader* VdvCertificate::header() const
{
return reinterpret_cast<const VdvCertificateHeader*>(m_data.constData() + m_offset);
......
......@@ -20,6 +20,8 @@
#include <QByteArray>
class QDate;
namespace KItinerary {
struct VdvCaReference;
......@@ -58,6 +60,11 @@ public:
/** Sets the CA certificate for decoding ISO 9796-2 signed certificates. */
void setCaCertificate(const VdvCertificate &caCert);
/** Returns whether this is a self-signed (== root) certificate. */
bool isSelfSigned() const;
/** Returns the date this certificate expires. */
QDate endOfValidity() const;
private:
const VdvCertificateHeader *header() const;
const VdvCertificateKey *certKey() const;
......
......@@ -130,6 +130,37 @@ struct VdvTaggedSizeDataBlock : public VdvAbstractDataBlock<TagType, TagValue>
}
};
/** Two-digit BCD encoded number. */
struct VdvBcdNumber
{
uint8_t data;
uint8_t value() const
{
return ((data & 0xF0) >> 4) * 10 + (data & 0x0F);
}
};
/** Date encoded as 8 BCD digits. */
struct VdvBcdDate
{
VdvBcdNumber bcdYear[2];
VdvBcdNumber bcdMonth;
VdvBcdNumber bcdDay;
inline uint16_t year() const
{
return bcdYear[0].value() * 100 + bcdYear[1].value();
}
inline uint8_t month() const
{
return bcdMonth.value();
}
inline uint8_t day() const
{
return bcdDay.value();
}
};
/** Signature container for the signed part of the payload data. */
struct VdvSignature : public VdvTaggedSizeDataBlock<uint8_t, TagSignature> {};
......@@ -172,7 +203,7 @@ struct VdvCertificateKey {
VdvCaReference car;
VdvCertificateHolderReference chr;
VdvCertificateHolderAuthorization cha;
uint8_t date[4];
VdvBcdDate date;
uint8_t oidBegin;
inline uint8_t oidSize() const
......
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