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 
00136         void setX509CertificateChain(const CertificateChain &c);
00137 
00143         void setX509PrivateKey(const PrivateKey &k);
00144 
00150         void setX509KeyBundle(const KeyBundle &kb);
00151 
00155         bool havePrivate() const;
00156 
00164         QString name() const;
00165 
00166 private:
00167         class Private;
00168         QSharedDataPointer<Private> d;
00169 };
00170 
00174 typedef QList<SecureMessageKey> SecureMessageKeyList;
00175 
00183 class QCA_EXPORT SecureMessageSignature
00184 {
00185 public:
00189         enum IdentityResult
00190         {
00191                 Valid,            
00192                 InvalidSignature, 
00193                 InvalidKey,       
00194                 NoKey             
00195         };
00196 
00203         SecureMessageSignature();
00204 
00216         SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
00217 
00223         SecureMessageSignature(const SecureMessageSignature &from);
00224 
00225         ~SecureMessageSignature();
00226 
00232         SecureMessageSignature & operator=(const SecureMessageSignature &from);
00233 
00237         IdentityResult identityResult() const;
00238 
00242         Validity keyValidity() const;
00243 
00247         SecureMessageKey key() const;
00248 
00252         QDateTime timestamp() const;
00253 
00254 private:
00255         class Private;
00256         QSharedDataPointer<Private> d;
00257 };
00258 
00262 typedef QList<SecureMessageSignature> SecureMessageSignatureList;
00263 
00264 
00319 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
00320 {
00321         Q_OBJECT
00322 public:
00326         enum Type
00327         {
00328                 OpenPGP, 
00329                 CMS      
00330         };
00331 
00335         enum SignMode
00336         {
00337                 Message,    
00338                 Clearsign,  
00339                 Detached    
00340         };
00341 
00345         enum Format
00346         {
00347                 Binary, 
00348                 Ascii   
00349         };
00350 
00354         enum Error
00355         {
00356                 ErrorPassphrase,       
00357                 ErrorFormat,           
00358                 ErrorSignerExpired,    
00359                 ErrorSignerInvalid,    
00360                 ErrorEncryptExpired,   
00361                 ErrorEncryptUntrusted, 
00362                 ErrorEncryptInvalid,   
00363                 ErrorNeedCard,         
00364                 ErrorCertKeyMismatch,  
00365                 ErrorUnknown           
00366         };
00367 
00379         SecureMessage(SecureMessageSystem *system);
00380         ~SecureMessage();
00381 
00385         Type type() const;
00386 
00397         bool canSignMultiple() const;
00398 
00406         bool canClearsign() const;
00407 
00417         bool canSignAndEncrypt() const;
00418 
00423         void reset();
00424 
00429         bool bundleSignerEnabled() const;
00430 
00434         bool smimeAttributesEnabled() const;
00435 
00439         Format format() const;
00440 
00445         SecureMessageKeyList recipientKeys() const;
00446 
00451         SecureMessageKeyList signerKeys() const;
00452 
00464         void setBundleSignerEnabled(bool b);
00465 
00476         void setSMIMEAttributesEnabled(bool b);
00477 
00485         void setFormat(Format f);
00486 
00494         void setRecipient(const SecureMessageKey &key);
00495 
00505         void setRecipients(const SecureMessageKeyList &keys);
00506 
00517         void setSigner(const SecureMessageKey &key);
00518 
00531         void setSigners(const SecureMessageKeyList &keys);
00532 
00553         void startEncrypt();
00554 
00579         void startDecrypt();
00580 
00605         void startSign(SignMode m = Message);
00606 
00614         void startVerify(const QByteArray &detachedSig = QByteArray());
00615 
00625         void startSignAndEncrypt();
00626 
00636         void update(const QByteArray &in);
00637 
00645         QByteArray read();
00646 
00650         int bytesAvailable() const;
00651 
00664         void end();
00665 
00683         bool waitForFinished(int msecs = 30000);
00684 
00693         bool success() const;
00694 
00701         Error errorCode() const;
00702 
00709         QByteArray signature() const;
00710 
00714         QString hashName() const;
00715 
00724         bool wasSigned() const;
00725 
00732         bool verifySuccess() const;
00733 
00737         SecureMessageSignature signer() const;
00738 
00746         SecureMessageSignatureList signers() const;
00747 
00753         QString diagnosticText() const;
00754 
00755 Q_SIGNALS:
00765         void readyRead();
00766 
00773         void bytesWritten(int bytes);
00774 
00779         void finished();
00780 
00781 private:
00782         Q_DISABLE_COPY(SecureMessage)
00783 
00784         class Private;
00785         friend class Private;
00786         Private *d;
00787 };
00788 
00799 class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
00800 {
00801         Q_OBJECT
00802 public:
00803         ~SecureMessageSystem();
00804 
00805 protected:
00819         SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
00820 
00821 private:
00822         Q_DISABLE_COPY(SecureMessageSystem)
00823 };
00824 
00836 class QCA_EXPORT OpenPGP : public SecureMessageSystem
00837 {
00838         Q_OBJECT
00839 public:
00847         explicit OpenPGP(QObject *parent = 0, const QString &provider = QString());
00848         ~OpenPGP();
00849 
00850 private:
00851         Q_DISABLE_COPY(OpenPGP)
00852 
00853         class Private;
00854         Private *d;
00855 };
00856 
00882 class QCA_EXPORT CMS : public SecureMessageSystem
00883 {
00884         Q_OBJECT
00885 public:
00893         explicit CMS(QObject *parent = 0, const QString &provider = QString());
00894         ~CMS();
00895 
00899         CertificateCollection trustedCertificates() const;
00900 
00904         CertificateCollection untrustedCertificates() const;
00905 
00909         SecureMessageKeyList privateKeys() const;
00910 
00918         void setTrustedCertificates(const CertificateCollection &trusted);
00919 
00932         void setUntrustedCertificates(const CertificateCollection &untrusted);
00933 
00943         void setPrivateKeys(const SecureMessageKeyList &keys);
00944 
00945 private:
00946         Q_DISABLE_COPY(CMS)
00947 
00948         class Private;
00949         Private *d;
00950 };
00951 
00952 }
00953 
00954 #endif

Generated on Thu Sep 6 19:13:35 2007 for Qt Cryptographic Architecture by  doxygen 1.5.2