Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/sshagent/OpenSSHKey.cpp')
-rw-r--r--src/sshagent/OpenSSHKey.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/sshagent/OpenSSHKey.cpp b/src/sshagent/OpenSSHKey.cpp
index ccc7606f0..cfff5a400 100644
--- a/src/sshagent/OpenSSHKey.cpp
+++ b/src/sshagent/OpenSSHKey.cpp
@@ -319,9 +319,9 @@ bool OpenSSHKey::openPrivateKey(const QString& passphrase)
if (m_cipherName.compare("aes-128-cbc", Qt::CaseInsensitive) == 0) {
cipher.reset(new SymmetricCipher(SymmetricCipher::Aes128, SymmetricCipher::Cbc, SymmetricCipher::Decrypt));
- } else if (m_cipherName == "aes256-cbc") {
+ } else if (m_cipherName == "aes256-cbc" || m_cipherName.compare("aes-256-cbc", Qt::CaseInsensitive) == 0) {
cipher.reset(new SymmetricCipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt));
- } else if (m_cipherName == "aes256-ctr") {
+ } else if (m_cipherName == "aes256-ctr" || m_cipherName.compare("aes-256-ctr", Qt::CaseInsensitive) == 0) {
cipher.reset(new SymmetricCipher(SymmetricCipher::Aes256, SymmetricCipher::Ctr, SymmetricCipher::Decrypt));
} else if (m_cipherName != "none") {
m_error = tr("Unknown cipher: %1").arg(m_cipherName);
@@ -372,10 +372,22 @@ bool OpenSSHKey::openPrivateKey(const QString& passphrase)
return false;
}
- QCryptographicHash hash(QCryptographicHash::Md5);
- hash.addData(passphrase.toUtf8());
- hash.addData(m_cipherIV.data(), 8);
- QByteArray keyData = hash.result();
+ QByteArray keyData;
+ QByteArray mdBuf;
+ do {
+ QCryptographicHash hash(QCryptographicHash::Md5);
+ hash.addData(mdBuf);
+ hash.addData(passphrase.toUtf8());
+ hash.addData(m_cipherIV.data(), 8);
+ mdBuf = hash.result();
+ keyData.append(mdBuf);
+ } while(keyData.size() < cipher->keySize());
+
+ if (keyData.size() > cipher->keySize()) {
+ // If our key size isn't a multiple of 16 (e.g. AES-192 or something),
+ // then we will need to truncate it.
+ keyData.resize(cipher->keySize());
+ }
if (!cipher->init(keyData, m_cipherIV)) {
m_error = cipher->errorString();