Skip to content
Snippets Groups Projects
Commit a88e6a4c authored by Adrien Béraud's avatar Adrien Béraud
Browse files

crypto: make CRL default expiration same as certificate

parent c776dad9
No related branches found
No related tags found
No related merge requests found
...@@ -333,6 +333,7 @@ class OPENDHT_PUBLIC RevocationList ...@@ -333,6 +333,7 @@ class OPENDHT_PUBLIC RevocationList
{ {
using clock = std::chrono::system_clock; using clock = std::chrono::system_clock;
using time_point = clock::time_point; using time_point = clock::time_point;
using duration = clock::duration;
public: public:
RevocationList(); RevocationList();
RevocationList(const Blob& b); RevocationList(const Blob& b);
...@@ -365,8 +366,9 @@ public: ...@@ -365,8 +366,9 @@ public:
/** /**
* Sign this revocation list using provided key and certificate. * Sign this revocation list using provided key and certificate.
* Validity_period sets the duration until expiration (default to certificate expiration).
*/ */
void sign(const PrivateKey&, const Certificate&); void sign(const PrivateKey&, const Certificate&, duration validity_period = {});
void sign(const Identity& id) { sign(*id.first, *id.second); } void sign(const Identity& id) { sign(*id.first, *id.second); }
bool isSignedBy(const Certificate& issuer) const; bool isSignedBy(const Certificate& issuer) const;
......
...@@ -976,12 +976,12 @@ T endian(T w, Endian endian = Endian::BIG) ...@@ -976,12 +976,12 @@ T endian(T w, Endian endian = Endian::BIG)
} }
void void
RevocationList::sign(const PrivateKey& key, const Certificate& ca) RevocationList::sign(const PrivateKey& key, const Certificate& ca, duration validity)
{ {
if (auto err = gnutls_x509_crl_set_version(crl, 2)) if (auto err = gnutls_x509_crl_set_version(crl, 2))
throw CryptoException(std::string("Can't set CRL version: ") + gnutls_strerror(err)); throw CryptoException(std::string("Can't set CRL version: ") + gnutls_strerror(err));
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto next_update = now + std::chrono::hours(24*7); auto next_update = (validity == duration{}) ? ca.getExpiration() : now + validity;
if (auto err = gnutls_x509_crl_set_this_update(crl, std::chrono::system_clock::to_time_t(now))) if (auto err = gnutls_x509_crl_set_this_update(crl, std::chrono::system_clock::to_time_t(now)))
throw CryptoException(std::string("Can't set CRL update time: ") + gnutls_strerror(err)); throw CryptoException(std::string("Can't set CRL update time: ") + gnutls_strerror(err));
if (auto err = gnutls_x509_crl_set_next_update(crl, std::chrono::system_clock::to_time_t(next_update))) if (auto err = gnutls_x509_crl_set_next_update(crl, std::chrono::system_clock::to_time_t(next_update)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment