signon  8.58
crypto-manager.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of signon
4  *
5  * Copyright (C) 2009-2011 Nokia Corporation.
6  *
7  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
8  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * version 2.1 as published by the Free Software Foundation.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  */
24 
31 #ifndef SIGNON_CRYPTO_MANAGER_H
32 #define SIGNON_CRYPTO_MANAGER_H
33 
34 #include <SignOn/AbstractCryptoManager>
35 
36 #include <QObject>
37 
38 #define MINUMUM_ENCRYPTED_FILE_SYSTEM_SIZE 4
39 
45 class CryptoManager: public SignOn::AbstractCryptoManager
46 {
47  Q_OBJECT
48 
49  // DO NOT change the order of the enum values!!!
50  enum FileSystemMountState {
51  Unmounted = 0,
52  LoopSet,
53  LoopLuksFormatted,
54  LoopLuksOpened,
55  Mounted
56  };
57 
58  static const uint signonMinumumDbSize;
59  static const char signonDefaultFileSystemName[];
60  static const char signonDefaultFileSystemType[];
61 
62 public:
63  // reimplemented virtual methods
64  bool initialize(const QVariantMap &configuration);
65 
71  Ext2 = 0,
74  };
75 
80  CryptoManager(QObject *parent = 0);
81 
86 
96  bool setupFileSystem();
97 
104  bool deleteFileSystem();
105 
110  bool mountFileSystem();
111 
116  bool unmountFileSystem();
117 
121  QString fileSystemMountPath() const;
122 
126  QStringList backupFiles() const;
127 
135  bool encryptionKeyInUse(const SignOn::Key &key);
136 
146  bool addEncryptionKey(const SignOn::Key &key,
147  const SignOn::Key &existingKey);
148 
156  bool removeEncryptionKey(const SignOn::Key &key,
157  const SignOn::Key &remainingKey);
158 
159 private:
160  bool setFileSystemType(const QString &type);
161  bool setFileSystemSize(const quint32 size);
162  void setFileSystemPath(const QString &path);
163 
164  void checkFileSystemSetup();
165  void clearFileSystemResources();
166  bool mountMappedDevice();
167  bool unmountMappedDevice();
168  void updateMountState(const FileSystemMountState state);
169 
170  static bool createPartitionFile(const QString &filePath);
171  static bool formatMapFileSystem(const QString &fileSystemPath);
172 
173  const QString keychainFilePath() const;
174  void addKeyToKeychain(const QByteArray &key) const;
175  void removeKeyFromKeychain(const QByteArray &key) const;
176  bool keychainContainsKey(const QByteArray &key) const;
177 
178 private:
179  //TODO remove this
180  void serializeData();
181 
182 private:
183  QString m_fileSystemPath;
184  QString m_fileSystemMapPath;
185  QString m_fileSystemName;
186  QString m_fileSystemMountPath;
187  QString m_loopDeviceName;
188 
189  FileSystemMountState m_mountState;
190  FileSystemType m_fileSystemType;
191  quint32 m_fileSystemSize;
192 };
193 
194 #endif // SIGNON_CRYPTOMANAGER_H
bool deleteFileSystem()
Deletes the encrypted file system.
~CryptoManager()
Destroys a CryptoManager object.
bool mountFileSystem()
Mounts the encrypted file system.
bool removeEncryptionKey(const SignOn::Key &key, const SignOn::Key &remainingKey)
Releases an existing used keyslot in the LUKS partition&#39;s header.
Encrypted file system manager.
bool initialize(const QVariantMap &configuration)
QStringList backupFiles() const
CryptoManager(QObject *parent=0)
Constructs a CryptoManager object with the given parent.
bool encryptionKeyInUse(const SignOn::Key &key)
QString fileSystemMountPath() const
FileSystemType
Supported encrypted partion filesystem type.
bool addEncryptionKey(const SignOn::Key &key, const SignOn::Key &existingKey)
Adds an encryption key to one of the available keyslots of the LUKS partition&#39;s header.
bool unmountFileSystem()
Unmounts the encrypted file system.
bool setupFileSystem()
Sets up an encrypted file system.