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
00019  * 02110-1301  USA
00020  *
00021  */
00022 
00033 #ifndef QCA_SECUREMESSAGE_H
00034 #define QCA_SECUREMESSAGE_H
00035 
00036 #include <QObject>
00037 #include "qca_core.h"
00038 #include "qca_publickey.h"
00039 #include "qca_cert.h"
00040 
00041 class QDateTime;
00042 
00043 namespace QCA {
00044 
00045 class SecureMessageSystem;
00046 
00054 class QCA_EXPORT SecureMessageKey
00055 {
00056 public:
00060         enum Type
00061         {
00062                 None, 
00063                 PGP,  
00064                 X509  
00065         };
00066 
00070         SecureMessageKey();
00071 
00077         SecureMessageKey(const SecureMessageKey &from);
00078 
00079         ~SecureMessageKey();
00080 
00086         SecureMessageKey & operator=(const SecureMessageKey &from);
00087 
00091         bool isNull() const;
00092 
00096         Type type() const;
00097 
00101         PGPKey pgpPublicKey() const;
00102 
00106         PGPKey pgpSecretKey() const;
00107 
00113         void setPGPPublicKey(const PGPKey &pub);
00114 
00120         void setPGPSecretKey(const PGPKey &sec);
00121 
00125         CertificateChain x509CertificateChain() const;
00126 
00130         PrivateKey x509PrivateKey() const;
00131 
00137         void setX509CertificateChain(const CertificateChain &c);
00138 
00144         void setX509PrivateKey(const PrivateKey &k);
00145 
00151         void setX509KeyBundle(const KeyBundle &kb);
00152 
00156         bool havePrivate() const;
00157 
00165         QString name() const;
00166 
00167 private:
00168         class Private;
00169         QSharedDataPointer<Private> d;
00170 };
00171 
00175 typedef QList<SecureMessageKey> SecureMessageKeyList;
00176 
00184 class QCA_EXPORT SecureMessageSignature
00185 {
00186 public:
00190         enum IdentityResult
00191         {
00192                 Valid,            
00193                 InvalidSignature, 
00194                 InvalidKey,       
00195                 NoKey             
00196         };
00197 
00204         SecureMessageSignature();
00205 
00217         SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
00218 
00224         SecureMessageSignature(const SecureMessageSignature &from);
00225 
00226         ~SecureMessageSignature();
00227 
00233         SecureMessageSignature & operator=(const SecureMessageSignature &from);
00234 
00238         IdentityResult identityResult() const;
00239 
00243         Validity keyValidity() const;
00244 
00248         SecureMessageKey key() const;
00249 
00253         QDateTime timestamp() const;
00254 
00255 private:
00256         class Private;
00257         QSharedDataPointer<Private> d;
00258 };
00259 
00263 typedef QList<SecureMessageSignature> SecureMessageSignatureList;
00264 
00265 
00320 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
00321 {
00322         Q_OBJECT
00323 public:
00327         enum Type
00328         {
00329                 OpenPGP, 
00330                 CMS      
00331         };
00332 
00336         enum SignMode
00337         {
00338                 Message,    
00339                 Clearsign,  
00340                 Detached    
00341         };
00342 
00346         enum Format
00347         {
00348                 Binary, 
00349                 Ascii   
00350         };
00351 
00355         enum Error
00356         {
00357                 ErrorPassphrase,       
00358                 ErrorFormat,           
00359                 ErrorSignerExpired,    
00360                 ErrorSignerInvalid,    
00361                 ErrorEncryptExpired,   
00362                 ErrorEncryptUntrusted, 
00363                 ErrorEncryptInvalid,   
00364                 ErrorNeedCard,         
00365                 ErrorCertKeyMismatch,  
00366                 ErrorUnknown           
00367         };
00368 
00380         SecureMessage(SecureMessageSystem *system);
00381         ~SecureMessage();
00382 
00386         Type type() const;
00387 
00398         bool canSignMultiple() const;
00399 
00407         bool canClearsign() const;
00408 
00418         bool canSignAndEncrypt() const;
00419 
00424         void reset();
00425 
00430         bool bundleSignerEnabled() const;
00431 
00435         bool smimeAttributesEnabled() const;
00436 
00440         Format format() const;
00441 
00446         SecureMessageKeyList recipientKeys() const;
00447 
00452         SecureMessageKeyList signerKeys() const;
00453 
00465         void setBundleSignerEnabled(bool b);
00466 
00477         void setSMIMEAttributesEnabled(bool b);
00478 
00486         void setFormat(Format f);
00487 
00495         void setRecipient(const SecureMessageKey &key);
00496 
00506         void setRecipients(const SecureMessageKeyList &keys);
00507 
00518         void setSigner(const SecureMessageKey &key);
00519 
00532         void setSigners(const SecureMessageKeyList &keys);
00533 
00554         void startEncrypt();
00555 
00580         void startDecrypt();
00581 
00606         void startSign(SignMode m = Message);
00607 
00615         void startVerify(const QByteArray &detachedSig = QByteArray());
00616 
00626         void startSignAndEncrypt();
00627 
00637         void update(const QByteArray &in);
00638 
00646         QByteArray read();
00647 
00651         int bytesAvailable() const;
00652 
00665         void end();
00666 
00684         bool waitForFinished(int msecs = 30000);
00685 
00694         bool success() const;
00695 
00702         Error errorCode() const;
00703 
00710         QByteArray signature() const;
00711 
00715         QString hashName() const;
00716 
00725         bool wasSigned() const;
00726 
00733         bool verifySuccess() const;
00734 
00738         SecureMessageSignature signer() const;
00739 
00747         SecureMessageSignatureList signers() const;
00748 
00754         QString diagnosticText() const;
00755 
00756 Q_SIGNALS:
00766         void readyRead();
00767 
00774         void bytesWritten(int bytes);
00775 
00780         void finished();
00781 
00782 private:
00783         Q_DISABLE_COPY(SecureMessage)
00784 
00785         class Private;
00786         friend class Private;
00787         Private *d;
00788 };
00789 
00800 class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
00801 {
00802         Q_OBJECT
00803 public:
00804         ~SecureMessageSystem();
00805 
00806 protected:
00820         SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
00821 
00822 private:
00823         Q_DISABLE_COPY(SecureMessageSystem)
00824 };
00825 
00837 class QCA_EXPORT OpenPGP : public SecureMessageSystem
00838 {
00839         Q_OBJECT
00840 public:
00848         explicit OpenPGP(QObject *parent = 0, const QString &provider = QString());
00849         ~OpenPGP();
00850 
00851 private:
00852         Q_DISABLE_COPY(OpenPGP)
00853 
00854         class Private;
00855         Private *d;
00856 };
00857 
00883 class QCA_EXPORT CMS : public SecureMessageSystem
00884 {
00885         Q_OBJECT
00886 public:
00894         explicit CMS(QObject *parent = 0, const QString &provider = QString());
00895         ~CMS();
00896 
00900         CertificateCollection trustedCertificates() const;
00901 
00905         CertificateCollection untrustedCertificates() const;
00906 
00910         SecureMessageKeyList privateKeys() const;
00911 
00919         void setTrustedCertificates(const CertificateCollection &trusted);
00920 
00933         void setUntrustedCertificates(const CertificateCollection &untrusted);
00934 
00944         void setPrivateKeys(const SecureMessageKeyList &keys);
00945 
00946 private:
00947         Q_DISABLE_COPY(CMS)
00948 
00949         class Private;
00950         Private *d;
00951 };
00952 
00953 }
00954 
00955 #endif

Generated on Wed Apr 29 15:15:45 2009 for Qt Cryptographic Architecture by  doxygen 1.5.5