mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
Move password verify logic into separate function
... and name it validateDatabasePassword(). It will also be used in the next commit to check if the database password was entered correctly.
This commit is contained in:
parent
d17131d297
commit
e4483bc48d
@ -465,6 +465,13 @@ void pki_evp::fload(const QString &fname)
|
||||
set_EVP_PKEY(pkey, fname);
|
||||
}
|
||||
|
||||
bool pki_evp::validateDatabasePassword(const Passwd &passwd)
|
||||
{
|
||||
return !passHash.isEmpty() &&
|
||||
(sha512passwT(passwd, passHash) == passHash ||
|
||||
sha512passwd(passwd, passHash) == passHash);
|
||||
}
|
||||
|
||||
EVP_PKEY *pki_evp::tryDecryptKey() const
|
||||
{
|
||||
Passwd ownPassBuf;
|
||||
@ -485,10 +492,7 @@ EVP_PKEY *pki_evp::tryDecryptKey() const
|
||||
ownPassBuf = "Bogus";
|
||||
} else {
|
||||
ownPassBuf = passwd;
|
||||
while (passHash.isEmpty() ||
|
||||
(sha512passwT(ownPassBuf, passHash) != passHash &&
|
||||
sha512passwd(ownPassBuf, passHash) != passHash))
|
||||
{
|
||||
while (!validateDatabasePassword(ownPassBuf)) {
|
||||
pass_info p(XCA_TITLE, tr("Please enter the database password for decrypting the key '%1'").arg(getIntName()));
|
||||
ret = PwDialogCore::execute(&p, &ownPassBuf,
|
||||
passHash.isEmpty());
|
||||
@ -627,10 +631,7 @@ void pki_evp::encryptKey(const char *password)
|
||||
int ret = 0;
|
||||
ownPassBuf = passwd;
|
||||
pass_info p(XCA_TITLE, tr("Please enter the database password for encrypting the key"));
|
||||
while (passHash.isEmpty() ||
|
||||
(sha512passwT(ownPassBuf, passHash) != passHash &&
|
||||
sha512passwd(ownPassBuf, passHash) != passHash))
|
||||
{
|
||||
while (!validateDatabasePassword(ownPassBuf)) {
|
||||
ret = PwDialogCore::execute(&p, &ownPassBuf,
|
||||
passHash.isEmpty());
|
||||
if (ret != 1)
|
||||
|
||||
@ -41,6 +41,7 @@ class pki_evp: public pki_key
|
||||
static QString md5passwd(QByteArray pass);
|
||||
static QString sha512passwd(QByteArray pass, QString salt);
|
||||
static QString sha512passwT(QByteArray pass, QString salt);
|
||||
static bool validateDatabasePassword(const Passwd &passwd);
|
||||
|
||||
pki_evp(const QString &n = QString(), int type = EVP_PKEY_RSA);
|
||||
pki_evp(const pki_evp *pkey);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user