mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Fix keepassxc-browser password entropy display (#3107)
* Pass correct entropy amount to keepassxc-browser instead of amount of bits for both password and passphrase. * Rename json key from "login" to "entropy" (keeping "login" key for backwards compatibility). * Also make some changes to entropy calculation methods: - Rename PassphraseGenerator::calculateEntropy to estimateEntropy - Rename PasswordGenerator::calculateEntropy to estimateEntropy
This commit is contained in:
parent
7ceca8ff3c
commit
e40f10657d
@ -278,18 +278,18 @@ QJsonObject BrowserAction::handleGetLogins(const QJsonObject& json, const QStrin
|
|||||||
|
|
||||||
QJsonObject BrowserAction::handleGeneratePassword(const QJsonObject& json, const QString& action)
|
QJsonObject BrowserAction::handleGeneratePassword(const QJsonObject& json, const QString& action)
|
||||||
{
|
{
|
||||||
const QString nonce = json.value("nonce").toString();
|
auto nonce = json.value("nonce").toString();
|
||||||
const QString password = browserSettings()->generatePassword();
|
auto password = browserSettings()->generatePassword();
|
||||||
|
|
||||||
if (nonce.isEmpty() || password.isEmpty()) {
|
if (nonce.isEmpty() || password.isEmpty()) {
|
||||||
return QJsonObject();
|
return QJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For backwards compatibility
|
||||||
|
password["login"] = password["entropy"];
|
||||||
|
|
||||||
QJsonArray arr;
|
QJsonArray arr;
|
||||||
QJsonObject passwd;
|
arr.append(password);
|
||||||
passwd["login"] = QString::number(password.length() * 8); // bits;
|
|
||||||
passwd["password"] = password;
|
|
||||||
arr.append(passwd);
|
|
||||||
|
|
||||||
const QString newNonce = incrementNonce(nonce);
|
const QString newNonce = incrementNonce(nonce);
|
||||||
|
|
||||||
|
@ -512,18 +512,23 @@ PasswordGenerator::GeneratorFlags BrowserSettings::passwordGeneratorFlags()
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BrowserSettings::generatePassword()
|
QJsonObject BrowserSettings::generatePassword()
|
||||||
{
|
{
|
||||||
|
QJsonObject password;
|
||||||
if (generatorType() == 0) {
|
if (generatorType() == 0) {
|
||||||
m_passwordGenerator.setLength(passwordLength());
|
m_passwordGenerator.setLength(passwordLength());
|
||||||
m_passwordGenerator.setCharClasses(passwordCharClasses());
|
m_passwordGenerator.setCharClasses(passwordCharClasses());
|
||||||
m_passwordGenerator.setFlags(passwordGeneratorFlags());
|
m_passwordGenerator.setFlags(passwordGeneratorFlags());
|
||||||
return m_passwordGenerator.generatePassword();
|
const QString pw = m_passwordGenerator.generatePassword();
|
||||||
|
password["entropy"] = m_passwordGenerator.estimateEntropy(pw);
|
||||||
|
password["password"] = pw;
|
||||||
} else {
|
} else {
|
||||||
m_passPhraseGenerator.setWordCount(passPhraseWordCount());
|
m_passPhraseGenerator.setWordCount(passPhraseWordCount());
|
||||||
m_passPhraseGenerator.setWordSeparator(passPhraseWordSeparator());
|
m_passPhraseGenerator.setWordSeparator(passPhraseWordSeparator());
|
||||||
return m_passPhraseGenerator.generatePassphrase();
|
password["entropy"] = m_passPhraseGenerator.estimateEntropy();
|
||||||
|
password["password"] = m_passPhraseGenerator.generatePassphrase();
|
||||||
}
|
}
|
||||||
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserSettings::updateBinaryPaths(const QString& customProxyLocation)
|
void BrowserSettings::updateBinaryPaths(const QString& customProxyLocation)
|
||||||
|
@ -119,7 +119,7 @@ public:
|
|||||||
void setPasswordLength(int length);
|
void setPasswordLength(int length);
|
||||||
PasswordGenerator::CharClasses passwordCharClasses();
|
PasswordGenerator::CharClasses passwordCharClasses();
|
||||||
PasswordGenerator::GeneratorFlags passwordGeneratorFlags();
|
PasswordGenerator::GeneratorFlags passwordGeneratorFlags();
|
||||||
QString generatePassword();
|
QJsonObject generatePassword();
|
||||||
void updateBinaryPaths(const QString& customProxyLocation = QString());
|
void updateBinaryPaths(const QString& customProxyLocation = QString());
|
||||||
bool checkIfProxyExists(QString& path);
|
bool checkIfProxyExists(QString& path);
|
||||||
|
|
||||||
|
@ -35,15 +35,16 @@ PassphraseGenerator::PassphraseGenerator()
|
|||||||
setDefaultWordList();
|
setDefaultWordList();
|
||||||
}
|
}
|
||||||
|
|
||||||
double PassphraseGenerator::calculateEntropy(const QString& passphrase)
|
double PassphraseGenerator::estimateEntropy(int wordCount)
|
||||||
{
|
{
|
||||||
Q_UNUSED(passphrase);
|
|
||||||
|
|
||||||
if (m_wordlist.isEmpty()) {
|
if (m_wordlist.isEmpty()) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
if (wordCount < 1) {
|
||||||
|
wordCount = m_wordCount;
|
||||||
|
}
|
||||||
|
|
||||||
return std::log2(m_wordlist.size()) * m_wordCount;
|
return std::log2(m_wordlist.size()) * wordCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassphraseGenerator::setWordCount(int wordCount)
|
void PassphraseGenerator::setWordCount(int wordCount)
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
TITLECASE
|
TITLECASE
|
||||||
};
|
};
|
||||||
|
|
||||||
double calculateEntropy(const QString& passphrase);
|
double estimateEntropy(int wordCount = 0);
|
||||||
void setWordCount(int wordCount);
|
void setWordCount(int wordCount);
|
||||||
void setWordList(const QString& path);
|
void setWordList(const QString& path);
|
||||||
void setWordCase(PassphraseWordCase wordCase);
|
void setWordCase(PassphraseWordCase wordCase);
|
||||||
|
@ -31,7 +31,7 @@ PasswordGenerator::PasswordGenerator()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
double PasswordGenerator::calculateEntropy(const QString& password)
|
double PasswordGenerator::estimateEntropy(const QString& password)
|
||||||
{
|
{
|
||||||
return ZxcvbnMatch(password.toLatin1(), nullptr, nullptr);
|
return ZxcvbnMatch(password.toLatin1(), nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
PasswordGenerator();
|
PasswordGenerator();
|
||||||
|
|
||||||
double calculateEntropy(const QString& password);
|
double estimateEntropy(const QString& password);
|
||||||
void setLength(int length);
|
void setLength(int length);
|
||||||
void setCharClasses(const CharClasses& classes);
|
void setCharClasses(const CharClasses& classes);
|
||||||
void setFlags(const GeneratorFlags& flags);
|
void setFlags(const GeneratorFlags& flags);
|
||||||
|
@ -254,9 +254,9 @@ void PasswordGeneratorWidget::updatePasswordStrength(const QString& password)
|
|||||||
{
|
{
|
||||||
double entropy = 0.0;
|
double entropy = 0.0;
|
||||||
if (m_ui->tabWidget->currentIndex() == Password) {
|
if (m_ui->tabWidget->currentIndex() == Password) {
|
||||||
entropy = m_passwordGenerator->calculateEntropy(password);
|
entropy = m_passwordGenerator->estimateEntropy(password);
|
||||||
} else {
|
} else {
|
||||||
entropy = m_dicewareGenerator->calculateEntropy(password);
|
entropy = m_dicewareGenerator->estimateEntropy();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui->entropyLabel->setText(tr("Entropy: %1 bit").arg(QString::number(entropy, 'f', 2)));
|
m_ui->entropyLabel->setText(tr("Entropy: %1 bit").arg(QString::number(entropy, 'f', 2)));
|
||||||
|
Loading…
Reference in New Issue
Block a user