signon  8.42
credentialsaccessmanager.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-2010 Nokia Corporation.
6  *
7  * Contact: Aurel Popirtac <mailto: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 CREDENTIALS_ACCESS_MANAGER_H
32 #define CREDENTIALS_ACCESS_MANAGER_H
33 
35 #include "credentialsdb.h"
36 #include "signonui_interface.h"
37 
38 #include <QObject>
39 #include <QPointer>
40 #include <QFlags>
41 #include <QStringList>
42 #include <QVariantMap>
43 
44 #include "SignOn/AbstractAccessControlManager"
45 #include "SignOn/AbstractCryptoManager"
46 #include "SignOn/AbstractKeyAuthorizer"
47 #include "SignOn/AbstractKeyManager"
48 #include "SignOn/AbstractSecretsStorage"
49 #include "SignOn/KeyHandler"
50 
58 #define SIGNON_SECURE_STORAGE_NOT_AVAILABLE (QEvent::User + 1001)
59 
66 #define SIGNON_SECURE_STORAGE_AVAILABLE (QEvent::User + 1002)
67 
72 namespace SignonDaemonNS {
73 
77 typedef QPointer<QObject> EventSender;
78 
91 class SecureStorageEvent: public QEvent
92 {
93 public:
94  SecureStorageEvent(QEvent::Type type): QEvent(type), m_sender(0) {}
95 
97 };
98 
105 {
111 
116  void serialize(QIODevice *device);
117 
121  QString metadataDBPath() const;
122 
126  QString cryptoManagerName() const;
127 
131  QString accessControlManagerName() const;
132 
133  bool useEncryption() const;
134 
138  QString secretsStorageName() const;
139 
140  void setStoragePath(const QString &storagePath);
141 
142  void addSetting(const QString &key, const QVariant &value) {
143  m_settings.insert(key, value);
144  }
145 
146  QString m_storagePath;
147  QString m_dbName;
148  QString m_secretsDbName;
152  QVariantMap m_settings;
153 };
154 
159  NoError = 0,
177 };
178 
193 class CredentialsAccessManager: public QObject
194 {
195  Q_OBJECT
196 
214  enum KeySwapAuthorizingMech {
215  Disabled = 0,
216  AuthorizedKeyRemovedFirst,
217  UnauthorizedKeyRemovedFirst
218  };
219 
225  enum StorageUiCleanupFlag {
226  NoFlags = 0,
227  DisableCoreKeyAuthorization
231  };
232  Q_DECLARE_FLAGS(StorageUiCleanupFlags, StorageUiCleanupFlag)
233 
234 public:
241  QObject *parent = 0);
242 
250 
255 
262  bool init();
263 
269  void finalize();
270 
275  void addKeyManager(SignOn::AbstractKeyManager *keyManager);
276 
283  bool initExtension(QObject *object);
284 
285  QStringList backupFiles() const;
286 
297  bool openCredentialsSystem();
298 
308  bool closeCredentialsSystem();
309 
321 
326  bool credentialsSystemOpened() const { return m_systemOpened; }
327 
336  bool isCredentialsSystemReady() const;
337 
341  CredentialsDB *credentialsDB() const;
342 
346  const CAMConfiguration &configuration() const { return m_CAMConfiguration; }
347 
352  CredentialsAccessError lastError() const { return m_error; }
353 
358  bool keysAvailable() const;
359 
360 Q_SIGNALS:
364  void credentialsSystemReady();
365 
366 private Q_SLOTS:
367  void onKeyInserted(const SignOn::Key key);
368  void onLastAuthorizedKeyRemoved(const SignOn::Key key);
369  void onKeyRemoved(const SignOn::Key key);
370  void onKeyAuthorizationQueried(const SignOn::Key, int);
371  void onEncryptedFSMounted();
372  void onEncryptedFSUnmounting();
373 
374 protected:
375  void customEvent(QEvent *event);
376 
377 private:
378  bool createStorageDir();
379  bool openSecretsDB();
380  bool isSecretsDBOpen();
381  bool closeSecretsDB();
382  bool openMetaDataDB();
383  void closeMetaDataDB();
384  void replyToSecureStorageEventNotifiers();
385 
386 private:
387  static CredentialsAccessManager *m_pInstance;
388 
389  bool m_isInitialized;
390  bool m_systemOpened;
391  /* Flag indicating whether the system is ready or not.
392  * Currently the system is ready when all of the key managers have
393  * successfully reported all of the inserted keys.
394  */
395  mutable CredentialsAccessError m_error;
396  QList<SignOn::AbstractKeyManager *> keyManagers;
397 
398  CredentialsDB *m_pCredentialsDB;
399  SignOn::AbstractCryptoManager *m_cryptoManager;
400  SignOn::KeyHandler *m_keyHandler;
401  SignOn::AbstractKeyAuthorizer *m_keyAuthorizer;
402  SignOn::AbstractSecretsStorage *m_secretsStorage;
403  CAMConfiguration m_CAMConfiguration;
404  SignOn::AbstractAccessControlManager *m_acManager;
405  AccessControlManagerHelper *m_acManagerHelper;
406 
407  /* List of all the senders of a SecureStorageEvent. */
408  QList<EventSender> m_secureStorageEventNotifiers;
409 };
410 
411 } //namespace SignonDaemonNS
412 
413 #endif // CREDENTIALS_ACCESS_MANAGER_H