xca/lib/digest.cpp
Christian Hohnstaedt 827db695b2 Close #368: error while creating CRL with CA using EC key (ed25519)
This fix differs from the proposal in #368 because the signature
of pki_crl::sign() changed after the 2.4.0 release.

However, I was able to increase the bug impact!
Now it crashed instead of only throwing an error! :-)

The signature of the pki_crl::sign() method changed with
commit 61fa66b129, but C++
"outsmarted" me and automatically transformed the EVP_MD == nullptr
into the digest::constructor(EVP_MD) which crashed on the nullptr.
2023-05-25 22:20:27 +02:00

75 lines
1.3 KiB
C++

/* vi: set sw=4 ts=4:
*
* Copyright (C) 2021 Christian Hohnstaedt.
*
* All rights reserved.
*/
#include "func.h"
#include "digest.h"
#include "lib/base.h"
#include <QList>
#include <QDebug>
const QList<int> digest::all_digests(
{ NID_md5, NID_ripemd160, NID_sha1,
NID_sha224, NID_sha256, NID_sha384, NID_sha512
});
int digest::default_md(NID_sha256);
digest::digest(int nid) : md_nid(nid)
{
}
digest::digest(const EVP_MD *md) : md_nid(default_md)
{
if (!md)
return;
if (!OBJ_find_sigid_algs(EVP_MD_type(md), &md_nid, NULL))
md_nid = EVP_MD_type(md);
}
digest::digest(const QString &name) : md_nid(default_md)
{
QString s(name);
// Workaround for Ed25519
if (s.isEmpty()) {
md_nid = NID_undef;
return;
}
md_nid = OBJ_txt2nid(CCHAR(s.remove(QChar(' '))));
ign_openssl_error();
}
bool digest::isInsecure() const
{
switch (md_nid) {
case NID_md5:
case NID_ripemd160:
case NID_sha1:
return true;
}
return false;
}
const EVP_MD *digest::MD() const
{
return md_nid == NID_undef ? NULL : EVP_get_digestbynid(md_nid);
}
QString digest::name() const
{
return QString(md_nid == NID_undef ? "" : OBJ_nid2sn(md_nid));
}
const digest digest::getDefault()
{
return digest(default_md);
}
void digest::setDefault(const QString &def)
{
default_md = digest(def).md_nid;
}