FFDHE: add NamedGroups method for getting a list of supported named groups.

Also updates TestFFDHE to exercise the new method (and, in doing so,
refactors the tests a bit).

The core check logic from exercise() is moved into a tryFFDHELookupByName
function, which is now used by both the exercise() test, as well as the
namedGroupsMethod() test that is added by this commit.
This commit is contained in:
Mikkel Krautz 2017-08-06 22:13:01 +02:00
parent 1178f64509
commit 7d83448d09
3 changed files with 29 additions and 5 deletions

View File

@ -8,6 +8,16 @@
#include "FFDHE.h"
#include "FFDHETable.h"
QStringList FFDHE::NamedGroups() {
QStringList ng;
ng << QLatin1String("ffdhe2048");
ng << QLatin1String("ffdhe3072");
ng << QLatin1String("ffdhe4096");
ng << QLatin1String("ffdhe6144");
ng << QLatin1String("ffdhe8192");
return ng;
}
QByteArray FFDHE::PEMForNamedGroup(QString name) {
name = name.toLower();

View File

@ -9,6 +9,10 @@
/// FFDHE provides access to the Diffie-Hellman parameters from RFC 7919.
class FFDHE {
public:
/// NamedGroups returns a list of the supported named
/// groups for PEMForNamedGroup.
static QStringList NamedGroups();
/// PEMForNamedGroup returns the PEM-encoded
/// Diffie-Hellman parameters for the RFC 7919
/// group with the given name, such as "ffdhe2048",

View File

@ -22,6 +22,7 @@ class TestFFDHE : public QObject {
#if defined(USE_QSSLDIFFIEHELLMANPARAMETERS)
void exercise_data();
void exercise();
void namedGroupsMethod();
#endif
};
@ -51,10 +52,7 @@ void TestFFDHE::exercise_data() {
QTest::newRow("trailingspace") << QString(QLatin1String("ffdhe2048 ")) << false;
}
void TestFFDHE::exercise() {
QFETCH(QString, name);
QFETCH(bool, expectedToWork);
static bool tryFFDHELookupByName(QString name) {
bool ok = true;
QByteArray pem = FFDHE::PEMForNamedGroup(name);
@ -69,7 +67,19 @@ void TestFFDHE::exercise() {
}
}
QCOMPARE(ok, expectedToWork);
return ok;
}
void TestFFDHE::exercise() {
QFETCH(QString, name);
QFETCH(bool, expectedToWork);
QCOMPARE(tryFFDHELookupByName(name), expectedToWork);
}
void TestFFDHE::namedGroupsMethod() {
foreach (QString name, FFDHE::NamedGroups()) {
QCOMPARE(tryFFDHELookupByName(name), true);
}
}
#endif