From 722e36e1541e9fdf46284e4915e4a77e1088e1d3 Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 12:21:49 +0100 Subject: Testing initial zx2c4 solution --- localization/localization_ar_MA.ts | 4 ++-- localization/localization_ca.ts | 18 ++++++++++-------- localization/localization_cs_CZ.ts | 4 ++-- localization/localization_de_DE.ts | 4 ++-- localization/localization_de_LU.ts | 4 ++-- localization/localization_el_GR.ts | 4 ++-- localization/localization_en_GB.ts | 4 ++-- localization/localization_en_US.ts | 4 ++-- localization/localization_es_ES.ts | 4 ++-- localization/localization_fr_BE.ts | 4 ++-- localization/localization_fr_FR.ts | 4 ++-- localization/localization_fr_LU.ts | 4 ++-- localization/localization_gl_ES.ts | 4 ++-- localization/localization_he_IL.ts | 4 ++-- localization/localization_hu_HU.ts | 4 ++-- localization/localization_it_IT.ts | 4 ++-- localization/localization_lb_LU.ts | 4 ++-- localization/localization_nl_BE.ts | 4 ++-- localization/localization_nl_NL.ts | 4 ++-- localization/localization_pl_PL.ts | 4 ++-- localization/localization_pt_PT.ts | 4 ++-- localization/localization_ru_RU.ts | 4 ++-- localization/localization_sv_SE.ts | 4 ++-- localization/localization_zh_CN.ts | 4 ++-- src/pass.cpp | 12 ++++-------- src/pass.h | 2 +- src/passworddialog.cpp | 2 +- src/util.cpp | 38 +++++++++++++++++++++++++++----------- src/util.h | 4 ++-- 29 files changed, 91 insertions(+), 77 deletions(-) diff --git a/localization/localization_ar_MA.ts b/localization/localization_ar_MA.ts index 5a7d9aed..c9bedccf 100644 --- a/localization/localization_ar_MA.ts +++ b/localization/localization_ar_MA.ts @@ -792,12 +792,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_ca.ts b/localization/localization_ca.ts index 823dcc04..f6ba394a 100644 --- a/localization/localization_ca.ts +++ b/localization/localization_ca.ts @@ -1,4 +1,6 @@ - + + + ConfigDialog @@ -597,10 +599,10 @@ Expire-Date: 0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; font-weight:600; color:#333333;">QtPass</span><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"> is a GUI for </span><a href="https://www.passwordstore.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;">pass</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;">, the standard unix password manager.</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"><br />Please report any </span><a href="https://github.com/IJHack/qtpass/issues"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4;">issues</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"> you might have with this software.</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://qtpass.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;">Documentation</span></a></p> +</style></head><body style=" font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; font-weight:600; color:#333333;">QtPass</span><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"> is a GUI for </span><a href="https://www.passwordstore.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;">pass</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;">, the standard unix password manager.</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"><br />Please report any </span><a href="https://github.com/IJHack/qtpass/issues"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4;">issues</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"> you might have with this software.</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://qtpass.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;">Documentation</span></a></p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://github.com/IJHack/qtpass"><span style=" font-family:'Noto Sans'; font-size:12pt; text-decoration: underline; color:#4183c4;">SourceCode</span></a></p></body></html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -835,12 +837,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Cap caràcter triat - + Can't generate password, there are no characters to choose from set in the configuration! No es pot generar la contrasenya, no hi ha caràcters per triar a la configuració! @@ -987,4 +989,4 @@ Les entrades vermelles no són vàlides, no podreu xifrar. venç - \ No newline at end of file + diff --git a/localization/localization_cs_CZ.ts b/localization/localization_cs_CZ.ts index 5011aa05..52764be6 100644 --- a/localization/localization_cs_CZ.ts +++ b/localization/localization_cs_CZ.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Znaky nebyly vybrány - + Can't generate password, there are no characters to choose from set in the configuration! Nelze generovat heslo, v nastavení nebyla vybrána skladba znaků pro heslo! diff --git a/localization/localization_de_DE.ts b/localization/localization_de_DE.ts index 3b179241..9ecc6b02 100755 --- a/localization/localization_de_DE.ts +++ b/localization/localization_de_DE.ts @@ -816,12 +816,12 @@ Neues Passwort-Datei: Pass - + No characters chosen Keine Zeichen ausgewählt - + Can't generate password, there are no characters to choose from set in the configuration! Passwortgenerierung nicht möglich: Keine Zeichen zur Generierung ausgewählt! diff --git a/localization/localization_de_LU.ts b/localization/localization_de_LU.ts index 48a17908..b526947c 100755 --- a/localization/localization_de_LU.ts +++ b/localization/localization_de_LU.ts @@ -815,12 +815,12 @@ Neues Passwort-Datei: Pass - + No characters chosen Keine Zeichen ausgewählt - + Can't generate password, there are no characters to choose from set in the configuration! Passwortgenerierung nicht möglich: Keine Zeichen zur Generierung ausgewählt! diff --git a/localization/localization_el_GR.ts b/localization/localization_el_GR.ts index 1bc727bb..436213c2 100644 --- a/localization/localization_el_GR.ts +++ b/localization/localization_el_GR.ts @@ -792,12 +792,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_en_GB.ts b/localization/localization_en_GB.ts index 5c9a9b13..2745415a 100644 --- a/localization/localization_en_GB.ts +++ b/localization/localization_en_GB.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_en_US.ts b/localization/localization_en_US.ts index 00643129..8f839ab1 100644 --- a/localization/localization_en_US.ts +++ b/localization/localization_en_US.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_es_ES.ts b/localization/localization_es_ES.ts index c8e3b283..0740c6ce 100644 --- a/localization/localization_es_ES.ts +++ b/localization/localization_es_ES.ts @@ -805,12 +805,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_fr_BE.ts b/localization/localization_fr_BE.ts index 36651548..0a77d3e6 100644 --- a/localization/localization_fr_BE.ts +++ b/localization/localization_fr_BE.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Pas de caractères choisis - + Can't generate password, there are no characters to choose from set in the configuration! Impossible de générer un mot de passe, il n'y a pas de caractères utilisables définis dans la configuration ! diff --git a/localization/localization_fr_FR.ts b/localization/localization_fr_FR.ts index cbde8821..248cf794 100644 --- a/localization/localization_fr_FR.ts +++ b/localization/localization_fr_FR.ts @@ -837,12 +837,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Aucun caractère sélectionné - + Can't generate password, there are no characters to choose from set in the configuration! Impossible de générer un mot de passe : aucun caractère défini dans la configuration ! diff --git a/localization/localization_fr_LU.ts b/localization/localization_fr_LU.ts index 27857325..92d4b637 100644 --- a/localization/localization_fr_LU.ts +++ b/localization/localization_fr_LU.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Pas de caractères choisis - + Can't generate password, there are no characters to choose from set in the configuration! Impossible de générer un mot de passe, il n'y a pas de caractères utilisables définis dans la configuration ! diff --git a/localization/localization_gl_ES.ts b/localization/localization_gl_ES.ts index 32f8f347..1e7fbab7 100644 --- a/localization/localization_gl_ES.ts +++ b/localization/localization_gl_ES.ts @@ -903,12 +903,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_he_IL.ts b/localization/localization_he_IL.ts index a1ca3fae..09ca569c 100644 --- a/localization/localization_he_IL.ts +++ b/localization/localization_he_IL.ts @@ -792,12 +792,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_hu_HU.ts b/localization/localization_hu_HU.ts index 1523974e..d55171c0 100644 --- a/localization/localization_hu_HU.ts +++ b/localization/localization_hu_HU.ts @@ -792,12 +792,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_it_IT.ts b/localization/localization_it_IT.ts index 3f155c27..199d6778 100644 --- a/localization/localization_it_IT.ts +++ b/localization/localization_it_IT.ts @@ -811,12 +811,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Nessun carattere selezionato - + Can't generate password, there are no characters to choose from set in the configuration! Impossibile generare una password, non ci sono caratteri dai quali scegliere. Cotrolla nella finestra di configurazione! diff --git a/localization/localization_lb_LU.ts b/localization/localization_lb_LU.ts index 452adbc2..400a919a 100644 --- a/localization/localization_lb_LU.ts +++ b/localization/localization_lb_LU.ts @@ -792,12 +792,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_nl_BE.ts b/localization/localization_nl_BE.ts index 3689baad..714491a7 100644 --- a/localization/localization_nl_BE.ts +++ b/localization/localization_nl_BE.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Geen karakters gekozen - + Can't generate password, there are no characters to choose from set in the configuration! Kan wachtwoord niet genereren, er zijn geen karakters gekozen in de configuratie! diff --git a/localization/localization_nl_NL.ts b/localization/localization_nl_NL.ts index dd309e8c..7180c15e 100644 --- a/localization/localization_nl_NL.ts +++ b/localization/localization_nl_NL.ts @@ -830,12 +830,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Geen karakters gekozen - + Can't generate password, there are no characters to choose from set in the configuration! Kan wachtwoord niet genereren, er zijn geen karakters gekozen in de configuratie! diff --git a/localization/localization_pl_PL.ts b/localization/localization_pl_PL.ts index 911cc7c0..4601a88a 100644 --- a/localization/localization_pl_PL.ts +++ b/localization/localization_pl_PL.ts @@ -792,12 +792,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen - + Can't generate password, there are no characters to choose from set in the configuration! diff --git a/localization/localization_pt_PT.ts b/localization/localization_pt_PT.ts index 273b47ff..a782b23c 100644 --- a/localization/localization_pt_PT.ts +++ b/localization/localization_pt_PT.ts @@ -801,12 +801,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Nenhum caracter escolhido - + Can't generate password, there are no characters to choose from set in the configuration! Não foi possível gerar password. Não existe nenhum caracter para escolher do grupo especificado na configuração! diff --git a/localization/localization_ru_RU.ts b/localization/localization_ru_RU.ts index 80a4e9df..74098363 100644 --- a/localization/localization_ru_RU.ts +++ b/localization/localization_ru_RU.ts @@ -829,12 +829,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Ни одного символа не выбрано - + Can't generate password, there are no characters to choose from set in the configuration! Не могу сгенерировать пароль: набор допустимых символов задан пустым в Настройках! diff --git a/localization/localization_sv_SE.ts b/localization/localization_sv_SE.ts index eca8b5a8..36d30334 100644 --- a/localization/localization_sv_SE.ts +++ b/localization/localization_sv_SE.ts @@ -806,12 +806,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen Inga valda tecken - + Can't generate password, there are no characters to choose from set in the configuration! Kan inte skapa lösenord. Konfigurationen saknar tecken att välja från! diff --git a/localization/localization_zh_CN.ts b/localization/localization_zh_CN.ts index d50fe9f1..d9b290b8 100644 --- a/localization/localization_zh_CN.ts +++ b/localization/localization_zh_CN.ts @@ -829,12 +829,12 @@ p, li { white-space: pre-wrap; } Pass - + No characters chosen 未选择任何字符 - + Can't generate password, there are no characters to choose from set in the configuration! 未选择任何字符,无法生成密码! diff --git a/src/pass.cpp b/src/pass.cpp index c6d145ef..8c464ddc 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -62,7 +62,7 @@ void Pass::init() { * @param charset to use for generation * @return the password */ -QString Pass::Generate_b(int length, const QString &charset) { +QString Pass::Generate_b(unsigned int length, const QString &charset) { QString passwd; if (QtPassSettings::isUsePwgen()) { // --secure goes first as it overrides --no-* otherwise @@ -90,11 +90,7 @@ QString Pass::Generate_b(int length, const QString &charset) { } } else { if (charset.length() > 0) { - for (int i = 0; i < length; ++i) { - int index = Util::rand() % charset.length(); - QChar nextChar = charset.at(index); - passwd.append(nextChar); - } + passwd = Util::generateRandomPassword(charset, length); } else { emit critical( tr("No characters chosen"), @@ -223,8 +219,8 @@ void Pass::updateEnv() { } else { // dbg()<< "Update // PASSWORD_STORE_DIR with " + passStore; - env.replaceInStrings( - store.first(), "PASSWORD_STORE_DIR=" + QtPassSettings::getPassStore()); + env.replaceInStrings(store.first(), "PASSWORD_STORE_DIR=" + + QtPassSettings::getPassStore()); } exec.setEnvironment(env); } diff --git a/src/pass.h b/src/pass.h index 6443e4c2..3686dad6 100644 --- a/src/pass.h +++ b/src/pass.h @@ -43,7 +43,7 @@ public: virtual void Copy(const QString srcDir, const QString dest, const bool force = false) = 0; virtual void Init(QString path, const QList &users) = 0; - virtual QString Generate_b(int length, const QString &charset); + virtual QString Generate_b(unsigned int length, const QString &charset); void GenerateGPGKeys(QString batch); QList listKeys(QString keystring = "", bool secret = false); diff --git a/src/passworddialog.cpp b/src/passworddialog.cpp index ac3d63ef..7514b0e2 100644 --- a/src/passworddialog.cpp +++ b/src/passworddialog.cpp @@ -45,7 +45,7 @@ void PasswordDialog::on_checkBoxShow_stateChanged(int arg1) { void PasswordDialog::on_createPasswordButton_clicked() { ui->widget->setEnabled(false); QString newPass = QtPassSettings::getPass()->Generate_b( - ui->spinBox_pwdLength->value(), + static_cast(ui->spinBox_pwdLength->value()), m_passConfig.Characters[(passwordConfiguration::characterSet) ui->passwordTemplateSwitch->currentIndex()]); if (newPass.length() > 0) diff --git a/src/util.cpp b/src/util.cpp index 41df1020..cf334122 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,8 +5,8 @@ #include #include #ifdef Q_OS_WIN -#include #include +#include #else #include #endif @@ -178,14 +178,30 @@ void Util::copyDir(const QString src, const QString dest) { } } -int Util::rand() { -#ifdef Q_OS_WIN - quint32 ret = 0; - if (FAILED(BCryptGenRandom(NULL, (PUCHAR)&ret, sizeof(ret), - BCRYPT_USE_SYSTEM_PREFERRED_RNG))) - return qrand(); - return ret % RAND_MAX; -#else - return qrand(); -#endif +/* Copyright (C) 2017 Jason A. Donenfeld . */ + +#include +#include + +quint32 boundedRandom(quint32 bound) { + if (bound < 2) + return 0; + + quint32 randval; + const quint32 max_mod_bound = (1 + ~bound) % bound; + + do + randval = QRandomGenerator::system()->generate(); + while (randval < max_mod_bound); + + return randval % bound; +} + +static QString generateRandomPassword(const QString &charset, + unsigned int length) { + QString out; + for (unsigned int i = 0; i < length; ++i) + out.append(charset.at(static_cast( + boundedRandom(static_cast(charset.length()))))); + return out; } diff --git a/src/util.h b/src/util.h index 62a10dbc..6fcce29a 100644 --- a/src/util.h +++ b/src/util.h @@ -22,8 +22,8 @@ public: const QFileSystemModel &model, const StoreModel &storeModel); static void copyDir(const QString src, const QString dest); - static int rand(); - + static QString generateRandomPassword(const QString &charset, + unsigned int length); private: static void initialiseEnvironment(); static QProcessEnvironment _env; -- cgit v1.2.3 From f14282412b8a82888b71a3268c985709ba9364d3 Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 13:04:29 +0100 Subject: Generate Password code from #338 placed --- src/pass.cpp | 29 ++++++++++++++++++++++++++--- src/pass.h | 5 +++++ src/util.cpp | 28 ---------------------------- src/util.h | 3 +-- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/pass.cpp b/src/pass.cpp index 8c464ddc..d9600587 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -2,8 +2,6 @@ #include "debughelper.h" #include "qtpasssettings.h" #include "util.h" -#include -#include using namespace std; using namespace Enums; @@ -90,7 +88,7 @@ QString Pass::Generate_b(unsigned int length, const QString &charset) { } } else { if (charset.length() > 0) { - passwd = Util::generateRandomPassword(charset, length); + passwd = generateRandomPassword(charset, length); } else { emit critical( tr("No characters chosen"), @@ -276,3 +274,28 @@ QString Pass::getRecipientString(QString for_file, QString separator, recipients_str += separator + '"' + recipient + '"'; return recipients_str; } + +/* Copyright (C) 2017 Jason A. Donenfeld . All Rights Reserved. + */ + +quint32 Pass::boundedRandom(quint32 bound) { + if (bound < 2) + return 0; + + quint32 randval; + const quint32 max_mod_bound = (1 + ~bound) % bound; + + do + randval = QRandomGenerator::system()->generate(); + while (randval < max_mod_bound); + + return randval % bound; +} + +QString Pass::generateRandomPassword(const QString &charset, + unsigned int length) { + QString out; + for (unsigned int i = 0; i < length; ++i) + out.append(charset.at(boundedRandom(charset.length()))); + return out; +} diff --git a/src/pass.h b/src/pass.h index 3686dad6..4242b422 100644 --- a/src/pass.h +++ b/src/pass.h @@ -9,7 +9,10 @@ #include #include #include +#include #include +#include +#include /*! \class Pass @@ -56,6 +59,8 @@ public: protected: void executeWrapper(PROCESS id, const QString &app, const QStringList &args, bool readStdout = true, bool readStderr = true); + QString generateRandomPassword(const QString &charset, unsigned int length); + quint32 boundedRandom(quint32 bound); virtual void executeWrapper(PROCESS id, const QString &app, const QStringList &args, QString input, diff --git a/src/util.cpp b/src/util.cpp index cf334122..ae65b519 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -177,31 +177,3 @@ void Util::copyDir(const QString src, const QString dest) { dest + QDir::separator() + file); } } - -/* Copyright (C) 2017 Jason A. Donenfeld . */ - -#include -#include - -quint32 boundedRandom(quint32 bound) { - if (bound < 2) - return 0; - - quint32 randval; - const quint32 max_mod_bound = (1 + ~bound) % bound; - - do - randval = QRandomGenerator::system()->generate(); - while (randval < max_mod_bound); - - return randval % bound; -} - -static QString generateRandomPassword(const QString &charset, - unsigned int length) { - QString out; - for (unsigned int i = 0; i < length; ++i) - out.append(charset.at(static_cast( - boundedRandom(static_cast(charset.length()))))); - return out; -} diff --git a/src/util.h b/src/util.h index 6fcce29a..b980edf8 100644 --- a/src/util.h +++ b/src/util.h @@ -22,8 +22,7 @@ public: const QFileSystemModel &model, const StoreModel &storeModel); static void copyDir(const QString src, const QString dest); - static QString generateRandomPassword(const QString &charset, - unsigned int length); + private: static void initialiseEnvironment(); static QProcessEnvironment _env; -- cgit v1.2.3 From 2c72ed4f9809fc781aa97af43767ee0b7c8ca3b0 Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 13:26:25 +0100 Subject: Qt 5.9 fallback (unix) from #338 --- src/pass.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/pass.cpp b/src/pass.cpp index d9600587..3da49ab8 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -279,15 +279,26 @@ QString Pass::getRecipientString(QString for_file, QString separator, */ quint32 Pass::boundedRandom(quint32 bound) { - if (bound < 2) + if (bound < 2) { return 0; + } quint32 randval; const quint32 max_mod_bound = (1 + ~bound) % bound; - do +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + if (fd == -1) { + assert((fd = open("/dev/urandom", O_RDONLY)) >= 0); + } +#endif + + do { +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + assert(read(fd, &randval, sizeof(randval)) == sizeof(randval)); +#else randval = QRandomGenerator::system()->generate(); - while (randval < max_mod_bound); +#endif + } while (randval < max_mod_bound); return randval % bound; } @@ -295,7 +306,9 @@ quint32 Pass::boundedRandom(quint32 bound) { QString Pass::generateRandomPassword(const QString &charset, unsigned int length) { QString out; - for (unsigned int i = 0; i < length; ++i) - out.append(charset.at(boundedRandom(charset.length()))); + for (unsigned int i = 0; i < length; ++i) { + out.append(charset.at(static_cast( + boundedRandom(static_cast(charset.length()))))); + } return out; } -- cgit v1.2.3 From f98648e9845e3bb9328b40b7cb02d3d826847dbb Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 13:32:16 +0100 Subject: QT_VERSION_CHECK in header too --- src/pass.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pass.h b/src/pass.h index 4242b422..44f81a1f 100644 --- a/src/pass.h +++ b/src/pass.h @@ -9,7 +9,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include +#endif #include #include #include -- cgit v1.2.3 From df2fd44d158007174e7c067067be98180574b2fa Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 13:39:18 +0100 Subject: forgot init, now testing on 5.9 --- src/pass.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pass.cpp b/src/pass.cpp index 3da49ab8..d8aaff8d 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -287,6 +287,7 @@ quint32 Pass::boundedRandom(quint32 bound) { const quint32 max_mod_bound = (1 + ~bound) % bound; #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + static int fd = -1; if (fd == -1) { assert((fd = open("/dev/urandom", O_RDONLY)) >= 0); } -- cgit v1.2.3 From 93d5dd841fcd83bef3e85ef75b9e9a40cbd9d42f Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 13:46:00 +0100 Subject: Forgotten includes --- src/pass.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pass.h b/src/pass.h index 44f81a1f..d8fabecc 100644 --- a/src/pass.h +++ b/src/pass.h @@ -11,6 +11,9 @@ #include #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include +#else +#include +#include #endif #include #include -- cgit v1.2.3 From 2bb71d4e6681f9791fe8d69d62ff980b32032d0b Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 2 Jan 2018 13:52:05 +0100 Subject: #include --- src/pass.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pass.h b/src/pass.h index d8fabecc..1292e942 100644 --- a/src/pass.h +++ b/src/pass.h @@ -17,6 +17,7 @@ #endif #include #include +#include #include /*! -- cgit v1.2.3