qca_securemessage.h

Go to the documentation of this file.
00001 /*
00002  * qca_securemessage.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  02110-1301, USA
00019  *
00020  */
00021 
00032 #ifndef QCA_SECUREMESSAGE_H
00033 #define QCA_SECUREMESSAGE_H
00034 
00035 #include <QObject>
00036 #include "qca_core.h"
00037 #include "qca_publickey.h"
00038 #include "qca_cert.h"
00039 
00040 class QDateTime;
00041 
00042 namespace QCA {
00043 
00044 class SecureMessageSystem;
00045 
00053 class QCA_EXPORT SecureMessageKey
00054 {
00055 public:
00059         enum Type
00060         {
00061                 None, 
00062                 PGP,  
00063                 X509  
00064         };
00065 
00069         SecureMessageKey();
00070 
00076         SecureMessageKey(const SecureMessageKey &from);
00077 
00078         ~SecureMessageKey();
00079 
00085         SecureMessageKey & operator=(const SecureMessageKey &from);
00086 
00090         bool isNull() const;
00091 
00095         Type type() const;
00096 
00100         PGPKey pgpPublicKey() const;
00101 
00105         PGPKey pgpSecretKey() const;
00106 
00112         void setPGPPublicKey(const PGPKey &pub);
00113 
00119         void setPGPSecretKey(const PGPKey &sec);
00120 
00124         CertificateChain x509CertificateChain() const;
00125 
00129         PrivateKey x509PrivateKey() const;
00130 
00134         void setX509CertificateChain(const CertificateChain &c);
00135 
00139         void setX509PrivateKey(const PrivateKey &k);
00140 
00144         void setX509KeyBundle(const KeyBundle &kb);
00145 
00149         bool havePrivate() const;
00150 
00158         QString name() const;
00159 
00160 private:
00161         class Private;
00162         QSharedDataPointer<Private> d;
00163 };
00164 
00168 typedef QList<SecureMessageKey> SecureMessageKeyList;
00169 
00177 class QCA_EXPORT SecureMessageSignature
00178 {
00179 public:
00183         enum IdentityResult
00184         {
00185                 Valid,            
00186                 InvalidSignature, 
00187                 InvalidKey,       
00188                 NoKey             
00189         };
00190 
00194         SecureMessageSignature();
00195 
00199         SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
00200 
00206         SecureMessageSignature(const SecureMessageSignature &from);
00207 
00208         ~SecureMessageSignature();
00209 
00215         SecureMessageSignature & operator=(const SecureMessageSignature &from);
00216 
00220         IdentityResult identityResult() const;
00221 
00225         Validity keyValidity() const;
00226 
00230         SecureMessageKey key() const;
00231 
00235         QDateTime timestamp() const;
00236 
00237 private:
00238         class Private;
00239         QSharedDataPointer<Private> d;
00240 };
00241 
00245 typedef QList<SecureMessageSignature> SecureMessageSignatureList;
00246 
00247 
00302 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
00303 {
00304         Q_OBJECT
00305 public:
00309         enum Type
00310         {
00311                 OpenPGP, 
00312                 CMS      
00313         };
00314 
00318         enum SignMode
00319         {
00320                 Message,    
00321                 Clearsign,  
00322                 Detached    
00323         };
00324 
00328         enum Format
00329         {
00330                 Binary, 
00331                 Ascii   
00332         };
00333 
00337         enum Error
00338         {
00339                 ErrorPassphrase,       
00340                 ErrorFormat,           
00341                 ErrorSignerExpired,    
00342                 ErrorSignerInvalid,    
00343                 ErrorEncryptExpired,   
00344                 ErrorEncryptUntrusted, 
00345                 ErrorEncryptInvalid,   
00346                 ErrorNeedCard,         
00347                 ErrorCertKeyMismatch,  
00348                 ErrorUnknown           
00349         };
00350 
00362         SecureMessage(SecureMessageSystem *system);
00363         ~SecureMessage();
00364 
00368         Type type() const;
00369 
00380         bool canSignMultiple() const;
00381 
00389         bool canClearsign() const;
00390 
00400         bool canSignAndEncrypt() const;
00401 
00406         void reset();
00407 
00412         bool bundleSignerEnabled() const;
00413 
00417         bool smimeAttributesEnabled() const;
00418 
00422         Format format() const;
00423 
00428         SecureMessageKeyList recipientKeys() const;
00429 
00434         SecureMessageKeyList signerKeys() const;
00435 
00445         void setBundleSignerEnabled(bool b);
00446 
00455         void setSMIMEAttributesEnabled(bool b);
00456 
00464         void setFormat(Format f);
00465 
00471         void setRecipient(const SecureMessageKey &key);
00472 
00480         void setRecipients(const SecureMessageKeyList &keys);
00481 
00490         void setSigner(const SecureMessageKey &key);
00491 
00502         void setSigners(const SecureMessageKeyList &keys);
00503 
00524         void startEncrypt();
00525 
00550         void startDecrypt();
00551 
00576         void startSign(SignMode m = Message);
00577 
00585         void startVerify(const QByteArray &detachedSig = QByteArray());
00586 
00596         void startSignAndEncrypt();
00597 
00607         void update(const QByteArray &in);
00608 
00616         QByteArray read();
00617 
00621         int bytesAvailable() const;
00622 
00635         void end();
00636 
00654         bool waitForFinished(int msecs = 30000);
00655 
00664         bool success() const;
00665 
00672         Error errorCode() const;
00673 
00680         QByteArray signature() const;
00681 
00685         QString hashName() const;
00686 
00695         bool wasSigned() const;
00696 
00703         bool verifySuccess() const;
00704 
00708         SecureMessageSignature signer() const;
00709 
00717         SecureMessageSignatureList signers() const;
00718 
00724         QString diagnosticText() const;
00725 
00726 Q_SIGNALS:
00736         void readyRead();
00737 
00742         void bytesWritten(int bytes);
00743 
00748         void finished();
00749 
00750 private:
00751         Q_DISABLE_COPY(SecureMessage)
00752 
00753         class Private;
00754         friend class Private;
00755         Private *d;
00756 };
00757 
00768 class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
00769 {
00770         Q_OBJECT
00771 public:
00772         ~SecureMessageSystem();
00773 
00774 protected:
00788         SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
00789 
00790 private:
00791         Q_DISABLE_COPY(SecureMessageSystem)
00792 };
00793 
00805 class QCA_EXPORT OpenPGP : public SecureMessageSystem
00806 {
00807         Q_OBJECT
00808 public:
00816         explicit OpenPGP(QObject *parent = 0, const QString &provider = QString());
00817         ~OpenPGP();
00818 
00819 private:
00820         Q_DISABLE_COPY(OpenPGP)
00821 
00822         class Private;
00823         Private *d;
00824 };
00825 
00851 class QCA_EXPORT CMS : public SecureMessageSystem
00852 {
00853         Q_OBJECT
00854 public:
00862         explicit CMS(QObject *parent = 0, const QString &provider = QString());
00863         ~CMS();
00864 
00868         CertificateCollection trustedCertificates() const;
00869 
00873         CertificateCollection untrustedCertificates() const;
00874 
00878         SecureMessageKeyList privateKeys() const;
00879 
00887         void setTrustedCertificates(const CertificateCollection &trusted);
00888 
00901         void setUntrustedCertificates(const CertificateCollection &untrusted);
00902 
00912         void setPrivateKeys(const SecureMessageKeyList &keys);
00913 
00914 private:
00915         Q_DISABLE_COPY(CMS)
00916 
00917         class Private;
00918         Private *d;
00919 };
00920 
00921 }
00922 
00923 #endif

Generated on Tue Aug 28 08:19:59 2007 for Qt Cryptographic Architecture by  doxygen 1.5.2