/* * Copyright (C) 2024 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 or (at your option) * version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "AuthenticationFactor.h" #include "AESCBCFactorKeyDerivation.h" #include #include void AuthenticationFactor::setName(const QString& name) { m_name = name; } const QString& AuthenticationFactor::getName() const { return m_name; } void AuthenticationFactor::setKeyType(AuthenticationFactorKeyType type) { m_keyType = type; if (m_keyType == AuthenticationFactorKeyType::AES_CBC) { m_derivation = QSharedPointer::create(); } else { m_derivation = QSharedPointer(nullptr); } } void AuthenticationFactor::setKeySalt(const QByteArray& salt) { m_keySalt = salt; } void AuthenticationFactor::setWrappedKey(const QByteArray& key) { m_wrappedKey = key; } const QByteArray& AuthenticationFactor::getWrappedKey() const { return m_wrappedKey; } const QByteArray& AuthenticationFactor::getKeySalt() const { return m_keySalt; } AuthenticationFactorKeyType AuthenticationFactor::getKeyType() const { return m_keyType; } const QString& AuthenticationFactor::getFactorType() const { return m_factorType; } QSharedPointer AuthenticationFactor::unwrapKey(const QSharedPointer& userData) const { auto unwrappingKey = getUnwrappingKey(userData); auto wrappedKey = getWrappedKey(); if (m_derivation->derive(wrappedKey, unwrappingKey, getKeySalt())) { // "wrappedKey" is now unwrapped! return QSharedPointer::create(wrappedKey); } else { qWarning() << tr("Validation failed when unwrapping factor '%1': %2").arg(getName(), m_derivation->getError()); } return {nullptr}; } QByteArray AuthenticationFactor::getUnwrappingKey(const QSharedPointer& userData) const { Q_UNUSED(userData); // This shouldn't happen - it means we didn't understand the factor type? qWarning() << "Attempted to get unwrapping key from generic AuthenticationFactor"; return QByteArray(); }