Qt Cryptographic Architecture
qca_keystore.h
Go to the documentation of this file.
1 /*
2  * qca_keystore.h - Qt Cryptographic Architecture
3  * Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
4  * Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22 
33 #ifndef QCA_KEYSTORE_H
34 #define QCA_KEYSTORE_H
35 
36 #include "qca_cert.h"
37 #include "qca_core.h"
38 
39 namespace QCA {
40 
41 class KeyStoreTracker;
42 class KeyStoreManagerPrivate;
43 class KeyStorePrivate;
44 
140 class QCA_EXPORT KeyStoreEntry : public Algorithm
141 {
142 public:
146  enum Type
147  {
148  TypeKeyBundle,
149  TypeCertificate,
150  TypeCRL,
151  TypePGPSecretKey,
152  TypePGPPublicKey
153  };
154 
159 
168  KeyStoreEntry(const QString &serialized);
169 
176 
177  ~KeyStoreEntry() override;
178 
185 
189  bool isNull() const;
190 
200  bool isAvailable() const;
201 
217  bool isAccessible() const;
218 
222  Type type() const;
223 
227  QString name() const;
228 
232  QString id() const;
233 
237  QString storeName() const;
238 
244  QString storeId() const;
245 
249  QString toString() const;
250 
259  static KeyStoreEntry fromString(const QString &serialized);
260 
266 
272 
277  CRL crl() const;
278 
284 
291 
311 
322  bool ensureAccess();
323 
324 private:
325  class Private;
326  Private *d;
327 
328  friend class KeyStoreTracker;
329 };
330 
350 class QCA_EXPORT KeyStoreEntryWatcher : public QObject
351 {
352  Q_OBJECT
353 public:
364  explicit KeyStoreEntryWatcher(const KeyStoreEntry &e, QObject *parent = nullptr);
365 
366  ~KeyStoreEntryWatcher() override;
367 
372 
373 Q_SIGNALS:
378  void available();
379 
384  void unavailable();
385 
386 private:
387  Q_DISABLE_COPY(KeyStoreEntryWatcher)
388 
389  class Private;
390  friend class Private;
391  Private *d;
392 };
393 
416 class QCA_EXPORT KeyStore : public QObject, public Algorithm
417 {
418  Q_OBJECT
419 public:
423  enum Type
424  {
429  PGPKeyring
430  };
431 
438  KeyStore(const QString &id, KeyStoreManager *keyStoreManager);
439 
440  ~KeyStore() override;
441 
447  bool isValid() const;
448 
452  Type type() const;
453 
457  QString name() const;
458 
462  QString id() const;
463 
469  bool isReadOnly() const;
470 
485 
496 
501 
505  bool holdsIdentities() const;
506 
510  bool holdsPGPPublicKeys() const;
511 
526  QString writeEntry(const KeyBundle &kb);
527 
533  QString writeEntry(const Certificate &cert);
534 
540  QString writeEntry(const CRL &crl);
541 
549  QString writeEntry(const PGPKey &key);
550 
562  bool removeEntry(const QString &id);
563 
564 Q_SIGNALS:
571  void updated();
572 
576  void unavailable();
577 
585  void entryWritten(const QString &entryId);
586 
593  void entryRemoved(bool success);
594 
595 private:
596  Q_DISABLE_COPY(KeyStore)
597 
598  friend class KeyStorePrivate;
599  KeyStorePrivate *d;
600 
601  friend class KeyStoreManagerPrivate;
602 };
603 
623 class QCA_EXPORT KeyStoreInfo
624 {
625 public:
634 
645  KeyStoreInfo(KeyStore::Type type, const QString &id, const QString &name);
646 
653 
654  ~KeyStoreInfo();
655 
662 
668  bool isNull() const;
669 
675 
680  QString id() const;
681 
686  QString name() const;
687 
688 private:
689  class Private;
690  QSharedDataPointer<Private> d;
691 };
692 
709 class QCA_EXPORT KeyStoreManager : public QObject
710 {
711  Q_OBJECT
712 public:
718  KeyStoreManager(QObject *parent = nullptr);
719  ~KeyStoreManager() override;
720 
724  static void start();
725 
731  static void start(const QString &provider);
732 
736  bool isBusy() const;
737 
742 
746  QStringList keyStores() const;
747 
752  static QString diagnosticText();
753 
757  static void clearDiagnosticText();
758 
763  void sync();
764 
765 Q_SIGNALS:
769  void busyStarted();
770 
774  void busyFinished();
775 
781  void keyStoreAvailable(const QString &id);
782 
783 private:
784  Q_DISABLE_COPY(KeyStoreManager)
785 
786  friend class KeyStoreManagerPrivate;
787  KeyStoreManagerPrivate *d;
788 
789  friend class Global;
790  friend class KeyStorePrivate;
791 
792  static void scan();
793  static void shutdown();
794 };
795 
796 }
797 
798 #endif
General superclass for an algorithm.
Definition: qca_core.h:1164
Certificate Revocation List
Definition: qca_cert.h:1740
Public Key (X.509) certificate.
Definition: qca_cert.h:857
Certificate chain and private key pair.
Definition: qca_cert.h:2176
Class to monitor the availability of a KeyStoreEntry.
Definition: qca_keystore.h:351
KeyStoreEntryWatcher(const KeyStoreEntry &e, QObject *parent=nullptr)
Standard constructor.
void unavailable()
This signal is emitted when the entry that is being monitored becomes unavailble.
KeyStoreEntry entry() const
The KeyStoreEntry that is being monitored.
void available()
This signal is emitted when the entry that is being monitored becomes available.
Single entry in a KeyStore.
Definition: qca_keystore.h:141
KeyStoreEntry(const KeyStoreEntry &from)
Standard copy constructor.
KeyStoreEntry()
Create an empty KeyStoreEntry.
bool ensureAvailable()
Returns true if the entry is available, otherwise false.
KeyStoreEntry & operator=(const KeyStoreEntry &from)
Standard assignment operator.
Type
The type of entry in the KeyStore.
Definition: qca_keystore.h:147
QString toString() const
Serialize into a string for use as a passive entry.
CRL crl() const
If a CRL is stored in this object, return the value of the CRL.
bool isAccessible() const
Test if the key is currently accessible.
Type type() const
Determine the type of key stored in this object.
bool isAvailable() const
Test if the key is available for use.
KeyBundle keyBundle() const
If a KeyBundle is stored in this object, return that bundle.
Certificate certificate() const
If a Certificate is stored in this object, return that certificate.
static KeyStoreEntry fromString(const QString &serialized)
Load a passive entry by using a serialized string as input.
QString name() const
The name associated with the key stored in this object.
QString storeName() const
The name of the KeyStore for this key object.
KeyStoreEntry(const QString &serialized)
Create a passive KeyStoreEntry based on a serialized string.
bool ensureAccess()
Like ensureAvailable, but will also ensure that the PIN is provided if needed.
QString id() const
The ID associated with the key stored in this object.
PGPKey pgpPublicKey() const
If the key stored in this object is either an public or private PGP key, extract the public key part ...
QString storeId() const
The id of the KeyStore for this key object.
PGPKey pgpSecretKey() const
If the key stored in this object is a private PGP key, return the contents of that key.
bool isNull() const
Test if this key is empty (null)
Key store information, outside of a KeyStore object.
Definition: qca_keystore.h:624
KeyStoreInfo()
Constructor.
KeyStore::Type type() const
The Type of KeyStore that this KeyStoreInfo object describes.
QString name() const
The descriptive name of the KeyStore that this KeyStoreInfo object describes.
KeyStoreInfo(KeyStore::Type type, const QString &id, const QString &name)
Standard constructor.
KeyStoreInfo(const KeyStoreInfo &from)
Copy constructor.
bool isNull() const
Test if this object is valid.
KeyStoreInfo & operator=(const KeyStoreInfo &from)
Assignment operator.
QString id() const
The unique identification of the KeyStore that this KeyStoreInfo object describes.
Access keystores, and monitor keystores for changes.
Definition: qca_keystore.h:710
QStringList keyStores() const
A list of all the key stores.
static QString diagnosticText()
The diagnostic result of key store operations, such as warnings and errors.
KeyStoreManager(QObject *parent=nullptr)
Create a new KeyStoreManager.
void keyStoreAvailable(const QString &id)
emitted when a new key store becomes available
void busyStarted()
emitted when the manager has started looking for key stores
bool isBusy() const
Indicates if the manager is busy looking for key stores.
static void clearDiagnosticText()
Clears the diagnostic result log.
static void start(const QString &provider)
Initialize a specific key store provider.
void waitForBusyFinished()
Blocks until the manager is done looking for key stores.
void sync()
If you are not using the eventloop, call this to update the object state to the present.
void busyFinished()
emitted when the manager has finished looking for key stores
static void start()
Initialize all key store providers.
General purpose key storage object.
Definition: qca_keystore.h:417
void entryRemoved(bool success)
Emitted when an entry has been removed, in asynchronous mode.
bool holdsPGPPublicKeys() const
test if the KeyStore holds PGPPublicKey objects
QString writeEntry(const CRL &crl)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void unavailable()
Emitted when the KeyStore becomes unavailable.
QList< KeyStoreEntry > entryList() const
A list of the KeyStoreEntry objects in this store.
bool isValid() const
Check if this KeyStore is valid.
QString name() const
The name associated with the KeyStore.
QString writeEntry(const KeyBundle &kb)
Add a entry to the KeyStore.
void entryWritten(const QString &entryId)
Emitted when an entry has been written, in asynchronous mode.
QString id() const
The ID associated with the KeyStore.
bool holdsTrustedCertificates() const
test if the KeyStore holds trusted certificates (and CRLs)
void updated()
Emitted when the KeyStore is changed.
QString writeEntry(const PGPKey &key)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString writeEntry(const Certificate &cert)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isReadOnly() const
Test if the KeyStore is writeable or not.
KeyStore(const QString &id, KeyStoreManager *keyStoreManager)
Obtain a specific KeyStore.
bool removeEntry(const QString &id)
Delete the a specified KeyStoreEntry from this KeyStore.
Type type() const
The KeyStore Type.
void startAsynchronousMode()
Turns on asynchronous mode for this KeyStore instance.
Type
The type of keystore.
Definition: qca_keystore.h:424
@ User
objects such as Apple Keychain, KDE Wallet
Definition: qca_keystore.h:426
@ System
objects such as root certificates
Definition: qca_keystore.h:425
@ SmartCard
for smartcards
Definition: qca_keystore.h:428
@ Application
for caching accepted self-signed certificates
Definition: qca_keystore.h:427
bool holdsIdentities() const
test if the KeyStore holds identities (eg KeyBundle or PGPSecretKey)
Pretty Good Privacy key.
Definition: qca_cert.h:2407
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
Header file for PGP key and X.509 certificate related classes.
Header file for core QCA infrastructure.