2022-02-10 20:06:39 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022-2022 QuasarApp.
|
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ecdsaauthtest.h"
|
|
|
|
#include "authecdsa.h"
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* test class
|
|
|
|
*/
|
|
|
|
class ECDSA: public QH::AuthECDSA {
|
|
|
|
|
|
|
|
public:
|
|
|
|
ECDSA(const QByteArray &publicKey, const QByteArray &privKey) {
|
|
|
|
setPublicKey(publicKey);
|
|
|
|
_priv = privKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AsyncKeysAuth interface
|
|
|
|
protected:
|
|
|
|
QByteArray getPrivateKey() const override {
|
|
|
|
return _priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray _priv;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ECDSAAuthTest::ECDSAAuthTest() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ECDSAAuthTest::~ECDSAAuthTest() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ECDSAAuthTest::test() {
|
2022-02-13 19:04:06 +03:00
|
|
|
// create a publick and private keys array.
|
2022-02-10 20:06:39 +03:00
|
|
|
QByteArray pub, priv;
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// make public and private keys.
|
2022-02-10 20:06:39 +03:00
|
|
|
QVERIFY(QH::AuthECDSA::makeKeys(pub, priv));
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// check createed keys. should be larget then 0.
|
2022-02-10 20:06:39 +03:00
|
|
|
QVERIFY(pub.length() && priv.length());
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// create test auth object using ecdsa algorithm
|
2022-02-10 20:06:39 +03:00
|
|
|
ECDSA edsa(pub, priv);
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// The terst object should be invalid because it is not prepared.
|
2022-02-10 20:06:39 +03:00
|
|
|
QVERIFY(!edsa.isValid());
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// the authetication should be failed bacause ecdsa class is invalid.
|
2022-02-13 18:45:11 +03:00
|
|
|
QVERIFY(!edsa.auth(600));
|
2022-02-10 20:06:39 +03:00
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// prepare an authentication object.
|
2022-02-10 20:06:39 +03:00
|
|
|
QVERIFY(edsa.prepare());
|
2022-02-13 19:04:06 +03:00
|
|
|
// the prepared object should be valid.
|
2022-02-10 20:06:39 +03:00
|
|
|
QVERIFY(edsa.isValid());
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
// authentication should be finished successful because auth object contains prepared valid signature.
|
2022-02-13 18:45:11 +03:00
|
|
|
QVERIFY(edsa.auth(600));
|
2022-02-13 19:04:06 +03:00
|
|
|
// authentication should be failed because the time range is depricated.
|
2022-02-10 20:06:39 +03:00
|
|
|
QVERIFY(!edsa.auth(0));
|
|
|
|
|
|
|
|
|
2022-02-13 19:04:06 +03:00
|
|
|
|
|
|
|
|
2022-02-10 20:06:39 +03:00
|
|
|
}
|