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 
149 #if 0
150 
157  bool removeEncryptionKey(const SignOn::Key &key,
158  const SignOn::Key &remainingKey);
159 #endif
160 
161 private:
162  bool setFileSystemType(const QString &type);
163  bool setFileSystemSize(const quint32 size);
164  void setFileSystemPath(const QString &path);
165 
166  void checkFileSystemSetup();
167  void clearFileSystemResources();
168  bool mountMappedDevice();
169  bool unmountMappedDevice();
170  void updateMountState(const FileSystemMountState state);
171 
172  static bool createPartitionFile(const QString &filePath);
173  static bool formatMapFileSystem(const QString &fileSystemPath);
174 
175  const QString keychainFilePath() const;
176  void addKeyToKeychain(const QByteArray &key) const;
177  void removeKeyFromKeychain(const QByteArray &key) const;
178  bool keychainContainsKey(const QByteArray &key) const;
179 
180 private:
181  //TODO remove this
182  void serializeData();
183 
184 private:
185  QString m_fileSystemPath;
186  QString m_fileSystemMapPath;
187  QString m_fileSystemName;
188  QString m_fileSystemMountPath;
189  QString m_loopDeviceName;
190 
191  FileSystemMountState m_mountState;
192  FileSystemType m_fileSystemType;
193  quint32 m_fileSystemSize;
194 };
195 
196 #endif // SIGNON_CRYPTOMANAGER_H
bool deleteFileSystem()
Deletes the encrypted file system.
~CryptoManager()
Destroys a CryptoManager object.
bool mountFileSystem()
Mounts the encrypted file system.
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's header.
bool unmountFileSystem()
Unmounts the encrypted file system.
bool setupFileSystem()
Sets up an encrypted file system.