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_core.h"
37 #include "qca_cert.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
QCA::KeyStoreEntry::isNull
bool isNull() const
Test if this key is empty (null)
QCA::KeyStore::KeyStore
KeyStore(const QString &id, KeyStoreManager *keyStoreManager)
Obtain a specific KeyStore.
QCA::KeyStoreEntry::id
QString id() const
The ID associated with the key stored in this object.
QObject
QCA::KeyStore::Application
@ Application
for caching accepted self-signed certificates
Definition: qca_keystore.h:427
QCA::KeyStoreEntry::storeId
QString storeId() const
The id of the KeyStore for this key object.
QCA::KeyStore::writeEntry
QString writeEntry(const KeyBundle &kb)
Add a entry to the KeyStore.
QCA::KeyStoreEntry
Single entry in a KeyStore.
Definition: qca_keystore.h:141
QCA::KeyStoreEntry::storeName
QString storeName() const
The name of the KeyStore for this key object.
QCA::KeyStoreInfo
Key store information, outside of a KeyStore object.
Definition: qca_keystore.h:624
QCA::KeyStoreManager::busyStarted
void busyStarted()
emitted when the manager has started looking for key stores
QCA::KeyStoreEntry::KeyStoreEntry
KeyStoreEntry(const QString &serialized)
Create a passive KeyStoreEntry based on a serialized string.
QCA::KeyStoreEntryWatcher::entry
KeyStoreEntry entry() const
The KeyStoreEntry that is being monitored.
QCA::KeyStoreEntry::fromString
static KeyStoreEntry fromString(const QString &serialized)
Load a passive entry by using a serialized string as input.
QCA::KeyStoreEntry::ensureAvailable
bool ensureAvailable()
Returns true if the entry is available, otherwise false.
QCA::KeyStoreManager::keyStoreAvailable
void keyStoreAvailable(const QString &id)
emitted when a new key store becomes available
QCA::KeyStore::writeEntry
QString writeEntry(const PGPKey &key)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QCA::KeyStoreEntryWatcher
Class to monitor the availability of a KeyStoreEntry.
Definition: qca_keystore.h:351
QCA::KeyStore::writeEntry
QString writeEntry(const Certificate &cert)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QCA::KeyStoreManager
Access keystores, and monitor keystores for changes.
Definition: qca_keystore.h:710
QCA::KeyStoreInfo::KeyStoreInfo
KeyStoreInfo(const KeyStoreInfo &from)
Copy constructor.
QCA::KeyStore::holdsTrustedCertificates
bool holdsTrustedCertificates() const
test if the KeyStore holds trusted certificates (and CRLs)
QCA::KeyStoreManager::start
static void start(const QString &provider)
Initialize a specific key store provider.
QCA::KeyStoreEntryWatcher::unavailable
void unavailable()
This signal is emitted when the entry that is being monitored becomes unavailble.
QCA::KeyStoreEntry::ensureAccess
bool ensureAccess()
Like ensureAvailable, but will also ensure that the PIN is provided if needed.
QCA::KeyStoreEntry::pgpPublicKey
PGPKey pgpPublicKey() const
If the key stored in this object is either an public or private PGP key, extract the public key part ...
QCA
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
QCA::Algorithm
General superclass for an algorithm.
Definition: qca_core.h:1152
QCA::KeyStoreEntry::name
QString name() const
The name associated with the key stored in this object.
QCA::KeyStoreManager::clearDiagnosticText
static void clearDiagnosticText()
Clears the diagnostic result log.
QList
QCA::KeyStoreEntry::Type
Type
The type of entry in the KeyStore.
Definition: qca_keystore.h:147
qca_cert.h
Header file for PGP key and X.509 certificate related classes.
QCA::KeyStore::isValid
bool isValid() const
Check if this KeyStore is valid.
QCA::KeyStore::User
@ User
objects such as Apple Keychain, KDE Wallet
Definition: qca_keystore.h:426
QCA::KeyStoreEntry::KeyStoreEntry
KeyStoreEntry()
Create an empty KeyStoreEntry.
QCA::KeyStore::System
@ System
objects such as root certificates
Definition: qca_keystore.h:425
QCA::KeyStore::isReadOnly
bool isReadOnly() const
Test if the KeyStore is writeable or not.
QCA::KeyStoreInfo::operator=
KeyStoreInfo & operator=(const KeyStoreInfo &from)
Assignment operator.
QCA::KeyStoreEntry::isAccessible
bool isAccessible() const
Test if the key is currently accessible.
QCA::KeyStoreEntry::operator=
KeyStoreEntry & operator=(const KeyStoreEntry &from)
Standard assignment operator.
QCA::KeyStoreManager::keyStores
QStringList keyStores() const
A list of all the key stores.
QCA::KeyStoreManager::sync
void sync()
If you are not using the eventloop, call this to update the object state to the present.
QCA::KeyStore::unavailable
void unavailable()
Emitted when the KeyStore becomes unavailable.
QCA::KeyStore::entryWritten
void entryWritten(const QString &entryId)
Emitted when an entry has been written, in asynchronous mode.
QCA::KeyStore
General purpose key storage object.
Definition: qca_keystore.h:417
QCA::KeyStore::updated
void updated()
Emitted when the KeyStore is changed.
QCA::KeyStore::id
QString id() const
The ID associated with the KeyStore.
QCA::KeyStoreManager::busyFinished
void busyFinished()
emitted when the manager has finished looking for key stores
QCA::Certificate
Public Key (X.509) certificate.
Definition: qca_cert.h:849
QCA::CRL
Certificate Revocation List
Definition: qca_cert.h:1703
QCA::KeyBundle
Certificate chain and private key pair.
Definition: qca_cert.h:2136
QCA::KeyStore::holdsPGPPublicKeys
bool holdsPGPPublicKeys() const
test if the KeyStore holds PGPPublicKey objects
QCA::KeyStoreInfo::KeyStoreInfo
KeyStoreInfo(KeyStore::Type type, const QString &id, const QString &name)
Standard constructor.
QCA::KeyStoreManager::isBusy
bool isBusy() const
Indicates if the manager is busy looking for key stores.
QCA::KeyStoreInfo::name
QString name() const
The descriptive name of the KeyStore that this KeyStoreInfo object describes.
QCA::KeyStoreManager::diagnosticText
static QString diagnosticText()
The diagnostic result of key store operations, such as warnings and errors.
QCA::KeyStoreEntryWatcher::available
void available()
This signal is emitted when the entry that is being monitored becomes available.
QCA::KeyStoreEntry::toString
QString toString() const
Serialize into a string for use as a passive entry.
qca_core.h
Header file for core QCA infrastructure.
QCA::KeyStore::SmartCard
@ SmartCard
for smartcards
Definition: qca_keystore.h:428
QCA::KeyStoreEntry::keyBundle
KeyBundle keyBundle() const
If a KeyBundle is stored in this object, return that bundle.
QCA::KeyStoreManager::KeyStoreManager
KeyStoreManager(QObject *parent=nullptr)
Create a new KeyStoreManager.
QCA::KeyStoreEntry::isAvailable
bool isAvailable() const
Test if the key is available for use.
QCA::KeyStore::name
QString name() const
The name associated with the KeyStore.
QCA::KeyStore::Type
Type
The type of keystore.
Definition: qca_keystore.h:424
QCA::KeyStoreEntry::certificate
Certificate certificate() const
If a Certificate is stored in this object, return that certificate.
QCA::KeyStoreManager::start
static void start()
Initialize all key store providers.
QCA::KeyStore::type
Type type() const
The KeyStore Type.
QCA::KeyStoreEntry::KeyStoreEntry
KeyStoreEntry(const KeyStoreEntry &from)
Standard copy constructor.
QCA::KeyStore::writeEntry
QString writeEntry(const CRL &crl)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QCA::KeyStore::removeEntry
bool removeEntry(const QString &id)
Delete the a specified KeyStoreEntry from this KeyStore.
QCA::KeyStoreInfo::isNull
bool isNull() const
Test if this object is valid.
QCA::KeyStoreInfo::KeyStoreInfo
KeyStoreInfo()
Constructor.
QCA::KeyStoreManager::waitForBusyFinished
void waitForBusyFinished()
Blocks until the manager is done looking for key stores.
QCA::KeyStore::startAsynchronousMode
void startAsynchronousMode()
Turns on asynchronous mode for this KeyStore instance.
QCA::KeyStoreInfo::id
QString id() const
The unique identification of the KeyStore that this KeyStoreInfo object describes.
QCA::PGPKey
Pretty Good Privacy key.
Definition: qca_cert.h:2361
QCA::KeyStore::holdsIdentities
bool holdsIdentities() const
test if the KeyStore holds identities (eg KeyBundle or PGPSecretKey)
QCA::KeyStoreEntry::pgpSecretKey
PGPKey pgpSecretKey() const
If the key stored in this object is a private PGP key, return the contents of that key.
QCA::KeyStoreEntry::crl
CRL crl() const
If a CRL is stored in this object, return the value of the CRL.
QCA::KeyStoreEntryWatcher::KeyStoreEntryWatcher
KeyStoreEntryWatcher(const KeyStoreEntry &e, QObject *parent=nullptr)
Standard constructor.
QCA::KeyStore::entryRemoved
void entryRemoved(bool success)
Emitted when an entry has been removed, in asynchronous mode.
QCA::KeyStoreEntry::type
Type type() const
Determine the type of key stored in this object.
QCA::KeyStoreInfo::type
KeyStore::Type type() const
The Type of KeyStore that this KeyStoreInfo object describes.
QCA::KeyStore::entryList
QList< KeyStoreEntry > entryList() const
A list of the KeyStoreEntry objects in this store.