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

crypto: avoid generating 0 or negative certificate serial numbers

parent 8aa24f12
No related branches found
No related tags found
No related merge requests found
...@@ -80,6 +80,8 @@ struct OPENDHT_PUBLIC PublicKey ...@@ -80,6 +80,8 @@ struct OPENDHT_PUBLIC PublicKey
* Takes ownership of an existing gnutls_pubkey. * Takes ownership of an existing gnutls_pubkey.
*/ */
PublicKey(gnutls_pubkey_t k) : pk(k) {} PublicKey(gnutls_pubkey_t k) : pk(k) {}
/** Import public key from serialized data */
PublicKey(const uint8_t* dat, size_t dat_size); PublicKey(const uint8_t* dat, size_t dat_size);
PublicKey(const Blob& pk) : PublicKey(pk.data(), pk.size()) {} PublicKey(const Blob& pk) : PublicKey(pk.data(), pk.size()) {}
PublicKey(PublicKey&& o) noexcept : pk(o.pk) { o.pk = nullptr; }; PublicKey(PublicKey&& o) noexcept : pk(o.pk) { o.pk = nullptr; };
......
...@@ -1147,8 +1147,8 @@ void ...@@ -1147,8 +1147,8 @@ void
setRandomSerial(gnutls_x509_crt_t cert) setRandomSerial(gnutls_x509_crt_t cert)
{ {
random_device rdev; random_device rdev;
std::uniform_int_distribution<uint64_t> dist{}; std::uniform_int_distribution<int64_t> dist{1};
uint64_t cert_serial = dist(rdev); int64_t cert_serial = dist(rdev);
gnutls_x509_crt_set_serial(cert, &cert_serial, sizeof(cert_serial)); gnutls_x509_crt_set_serial(cert, &cert_serial, sizeof(cert_serial));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment