signon
8.58
|
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of signon 00004 * 00005 * Copyright (C) 2009-2011 Nokia Corporation. 00006 * 00007 * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com> 00008 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public License 00012 * version 2.1 as published by the Free Software Foundation. 00013 * 00014 * This library is distributed in the hope that it will be useful, but 00015 * WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00022 * 02110-1301 USA 00023 */ 00024 00031 #ifndef SIGNON_CRYPTO_MANAGER_H 00032 #define SIGNON_CRYPTO_MANAGER_H 00033 00034 #include <SignOn/AbstractCryptoManager> 00035 00036 #include <QObject> 00037 00038 #define MINUMUM_ENCRYPTED_FILE_SYSTEM_SIZE 4 00039 00045 class CryptoManager: public SignOn::AbstractCryptoManager 00046 { 00047 Q_OBJECT 00048 00049 // DO NOT change the order of the enum values!!! 00050 enum FileSystemMountState { 00051 Unmounted = 0, 00052 LoopSet, 00053 LoopLuksFormatted, 00054 LoopLuksOpened, 00055 Mounted 00056 }; 00057 00058 static const uint signonMinumumDbSize; 00059 static const char signonDefaultFileSystemName[]; 00060 static const char signonDefaultFileSystemType[]; 00061 00062 public: 00063 // reimplemented virtual methods 00064 bool initialize(const QVariantMap &configuration); 00065 00070 enum FileSystemType { 00071 Ext2 = 0, 00072 Ext3, 00073 Ext4 00074 }; 00075 00080 CryptoManager(QObject *parent = 0); 00081 00085 ~CryptoManager(); 00086 00096 bool setupFileSystem(); 00097 00104 bool deleteFileSystem(); 00105 00110 bool mountFileSystem(); 00111 00116 bool unmountFileSystem(); 00117 00121 QString fileSystemMountPath() const; 00122 00126 QStringList backupFiles() const; 00127 00135 bool encryptionKeyInUse(const SignOn::Key &key); 00136 00146 bool addEncryptionKey(const SignOn::Key &key, 00147 const SignOn::Key &existingKey); 00148 00156 bool removeEncryptionKey(const SignOn::Key &key, 00157 const SignOn::Key &remainingKey); 00158 00159 private: 00160 bool setFileSystemType(const QString &type); 00161 bool setFileSystemSize(const quint32 size); 00162 void setFileSystemPath(const QString &path); 00163 00164 void checkFileSystemSetup(); 00165 void clearFileSystemResources(); 00166 bool mountMappedDevice(); 00167 bool unmountMappedDevice(); 00168 void updateMountState(const FileSystemMountState state); 00169 00170 static bool createPartitionFile(const QString &filePath); 00171 static bool formatMapFileSystem(const QString &fileSystemPath); 00172 00173 const QString keychainFilePath() const; 00174 void addKeyToKeychain(const QByteArray &key) const; 00175 void removeKeyFromKeychain(const QByteArray &key) const; 00176 bool keychainContainsKey(const QByteArray &key) const; 00177 00178 private: 00179 //TODO remove this 00180 void serializeData(); 00181 00182 private: 00183 QString m_fileSystemPath; 00184 QString m_fileSystemMapPath; 00185 QString m_fileSystemName; 00186 QString m_fileSystemMountPath; 00187 QString m_loopDeviceName; 00188 00189 FileSystemMountState m_mountState; 00190 FileSystemType m_fileSystemType; 00191 quint32 m_fileSystemSize; 00192 }; 00193 00194 #endif // SIGNON_CRYPTOMANAGER_H