# qca_keystore.h

Go to the documentation of this file.

    00001 /*
    00002  * qca_keystore.h - Qt Cryptographic Architecture
    00003  * Copyright (C) 2003-2007  Justin Karneges <justin@affinix.com>
    00004  * Copyright (C) 2004,2005  Brad Hards <bradh@frogmouth.net>
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Lesser General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2.1 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Lesser General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU Lesser General Public
    00017  * License along with this library; if not, write to the Free Software
    00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    00019  * 02110-1301  USA
    00020  *
    00021  */
    00022
    00033 #ifndef QCA_KEYSTORE_H
    00034 #define QCA_KEYSTORE_H
    00035
    00036 #include "qca_core.h"
    00037 #include "qca_cert.h"
    00038
    00039 namespace QCA {
    00040
    00041 class KeyStoreTracker;
    00042 class KeyStoreManagerPrivate;
    00043 class KeyStorePrivate;
    00044
    00140 class QCA_EXPORT KeyStoreEntry : public Algorithm
    00141 {
    00142 public:
    00146         enum Type
    00147         {
    00148                 TypeKeyBundle,
    00149                 TypeCertificate,
    00150                 TypeCRL,
    00151                 TypePGPSecretKey,
    00152                 TypePGPPublicKey
    00153         };
    00154
    00158         KeyStoreEntry();
    00159
    00168         KeyStoreEntry(const QString &serialized);
    00169
    00175         KeyStoreEntry(const KeyStoreEntry &from);
    00176
    00177         ~KeyStoreEntry();
    00178
    00184         KeyStoreEntry & operator=(const KeyStoreEntry &from);
    00185
    00189         bool isNull() const;
    00190
    00200         bool isAvailable() const;
    00201
    00217         bool isAccessible() const;
    00218
    00222         Type type() const;
    00223
    00227         QString name() const;
    00228
    00232         QString id() const;
    00233
    00237         QString storeName() const;
    00238
    00244         QString storeId() const;
    00245
    00249         QString toString() const;
    00250
    00259         static KeyStoreEntry fromString(const QString &serialized);
    00260
    00265         KeyBundle keyBundle() const;
    00266
    00271         Certificate certificate() const;
    00272
    00277         CRL crl() const;
    00278
    00283         PGPKey pgpSecretKey() const;
    00284
    00290         PGPKey pgpPublicKey() const;
    00291
    00310         bool ensureAvailable();
    00311
    00322         bool ensureAccess();
    00323
    00324 private:
    00325         class Private;
    00326         Private *d;
    00327
    00328         friend class KeyStoreTracker;
    00329 };
    00330
    00350 class QCA_EXPORT KeyStoreEntryWatcher : public QObject
    00351 {
    00352         Q_OBJECT
    00353 public:
    00364         explicit KeyStoreEntryWatcher(const KeyStoreEntry &e, QObject *parent = 0);
    00365
    00366         ~KeyStoreEntryWatcher();
    00367
    00371         KeyStoreEntry entry() const;
    00372
    00373 Q_SIGNALS:
    00378         void available();
    00379
    00384         void unavailable();
    00385
    00386 private:
    00387         Q_DISABLE_COPY(KeyStoreEntryWatcher)
    00388
    00389         class Private;
    00390         friend class Private;
    00391         Private *d;
    00392 };
    00393
    00416 class QCA_EXPORT KeyStore : public QObject, public Algorithm
    00417 {
    00418         Q_OBJECT
    00419 public:
    00423         enum Type
    00424         {
    00425                 System,
    00426                 User,
    00427                 Application,
    00428                 SmartCard,
    00429                 PGPKeyring
    00430         };
    00431
    00438         KeyStore(const QString &id, KeyStoreManager *keyStoreManager);
    00439
    00440         ~KeyStore();
    00441
    00447         bool isValid() const;
    00448
    00452         Type type() const;
    00453
    00457         QString name() const;
    00458
    00462         QString id() const;
    00463
    00469         bool isReadOnly() const;
    00470
    00484         void startAsynchronousMode();
    00485
    00495         QList<KeyStoreEntry> entryList() const;
    00496
    00500         bool holdsTrustedCertificates() const;
    00501
    00505         bool holdsIdentities() const;
    00506
    00510         bool holdsPGPPublicKeys() const;
    00511
    00526         QString writeEntry(const KeyBundle &kb);
    00527
    00533         QString writeEntry(const Certificate &cert);
    00534
    00540         QString writeEntry(const CRL &crl);
    00541
    00549         QString writeEntry(const PGPKey &key);
    00550
    00562         bool removeEntry(const QString &id);
    00563
    00564 Q_SIGNALS:
    00571         void updated();
    00572
    00576         void unavailable();
    00577
    00585         void entryWritten(const QString &entryId);
    00586
    00593         void entryRemoved(bool success);
    00594
    00595 private:
    00596         Q_DISABLE_COPY(KeyStore)
    00597
    00598         friend class KeyStorePrivate;
    00599         KeyStorePrivate *d;
    00600
    00601         friend class KeyStoreManagerPrivate;
    00602 };
    00603
    00623 class QCA_EXPORT KeyStoreInfo
    00624 {
    00625 public:
    00633         KeyStoreInfo();
    00634
    00645         KeyStoreInfo(KeyStore::Type type, const QString &id, const QString &name);
    00646
    00652         KeyStoreInfo(const KeyStoreInfo &from);
    00653
    00654         ~KeyStoreInfo();
    00655
    00661         KeyStoreInfo & operator=(const KeyStoreInfo &from);
    00662
    00668         bool isNull() const;
    00669
    00674         KeyStore::Type type() const;
    00675
    00680         QString id() const;
    00681
    00686         QString name() const;
    00687
    00688 private:
    00689         class Private;
    00690         QSharedDataPointer<Private> d;
    00691 };
    00692
    00709 class QCA_EXPORT KeyStoreManager : public QObject
    00710 {
    00711         Q_OBJECT
    00712 public:
    00718         KeyStoreManager(QObject *parent = 0);
    00719         ~KeyStoreManager();
    00720
    00724         static void start();
    00725
    00731         static void start(const QString &provider);
    00732
    00736         bool isBusy() const;
    00737
    00741         void waitForBusyFinished();
    00742
    00746         QStringList keyStores() const;
    00747
    00752         static QString diagnosticText();
    00753
    00757         static void clearDiagnosticText();
    00758
    00763         void sync();
    00764
    00765 Q_SIGNALS:
    00769         void busyStarted();
    00770
    00774         void busyFinished();
    00775
    00781         void keyStoreAvailable(const QString &id);
    00782
    00783 private:
    00784         Q_DISABLE_COPY(KeyStoreManager)
    00785
    00786         friend class KeyStoreManagerPrivate;
    00787         KeyStoreManagerPrivate *d;
    00788
    00789         friend class Global;
    00790         friend class KeyStorePrivate;
    00791
    00792         static void scan();
    00793         static void shutdown();
    00794 };
    00795
    00796 }
    00797
    00798 #endif