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 
00051 class QCA_EXPORT SecureMessageKey
00052 {
00053 public:
00057         enum Type
00058         {
00059                 None, 
00060                 PGP,  
00061                 X509  
00062         };
00063 
00067         SecureMessageKey();
00068 
00074         SecureMessageKey(const SecureMessageKey &from);
00075 
00076         ~SecureMessageKey();
00077 
00083         SecureMessageKey & operator=(const SecureMessageKey &from);
00084 
00088         bool isNull() const;
00089 
00093         Type type() const;
00094 
00098         PGPKey pgpPublicKey() const;
00099 
00103         PGPKey pgpSecretKey() const;
00104 
00110         void setPGPPublicKey(const PGPKey &pub);
00111 
00117         void setPGPSecretKey(const PGPKey &sec);
00118 
00122         CertificateChain x509CertificateChain() const;
00123 
00127         PrivateKey x509PrivateKey() const;
00128 
00132         void setX509CertificateChain(const CertificateChain &c);
00133 
00137         void setX509PrivateKey(const PrivateKey &k);
00138 
00142         void setX509KeyBundle(const KeyBundle &kb);
00143 
00147         bool havePrivate() const;
00148 
00156         QString name() const;
00157 
00158 private:
00159         class Private;
00160         QSharedDataPointer<Private> d;
00161 };
00162 
00166 typedef QList<SecureMessageKey> SecureMessageKeyList;
00167 
00173 class QCA_EXPORT SecureMessageSignature
00174 {
00175 public:
00179         enum IdentityResult
00180         {
00181                 Valid,            
00182                 InvalidSignature, 
00183                 InvalidKey,       
00184                 NoKey             
00185         };
00186 
00190         SecureMessageSignature();
00191 
00195         SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
00196 
00202         SecureMessageSignature(const SecureMessageSignature &from);
00203 
00204         ~SecureMessageSignature();
00205 
00211         SecureMessageSignature & operator=(const SecureMessageSignature &from);
00212 
00216         IdentityResult identityResult() const;
00217 
00221         Validity keyValidity() const;
00222 
00226         SecureMessageKey key() const;
00227 
00231         QDateTime timestamp() const;
00232 
00233 private:
00234         class Private;
00235         QSharedDataPointer<Private> d;
00236 };
00237 
00241 typedef QList<SecureMessageSignature> SecureMessageSignatureList;
00242 
00295 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
00296 {
00297         Q_OBJECT
00298 public:
00302         enum Type
00303         {
00304                 OpenPGP, 
00305                 CMS      
00306         };
00307 
00311         enum SignMode
00312         {
00313                 Message,    
00314                 Clearsign,  
00315                 Detached    
00316         };
00317 
00321         enum Format
00322         {
00323                 Binary, 
00324                 Ascii   
00325         };
00326 
00330         enum Error
00331         {
00332                 ErrorPassphrase,       
00333                 ErrorFormat,           
00334                 ErrorSignerExpired,    
00335                 ErrorSignerInvalid,    
00336                 ErrorEncryptExpired,   
00337                 ErrorEncryptUntrusted, 
00338                 ErrorEncryptInvalid,   
00339                 ErrorNeedCard,         
00340                 ErrorCertKeyMismatch,  
00341                 ErrorUnknown           
00342         };
00343 
00355         SecureMessage(SecureMessageSystem *system);
00356         ~SecureMessage();
00357 
00361         Type type() const;
00362 
00373         bool canSignMultiple() const;
00374 
00382         bool canClearsign() const;
00383 
00393         bool canSignAndEncrypt() const;
00394 
00399         void reset();
00400 
00405         bool bundleSignerEnabled() const;
00406 
00410         bool smimeAttributesEnabled() const;
00411 
00415         Format format() const;
00416 
00421         SecureMessageKeyList recipientKeys() const;
00422 
00427         SecureMessageKeyList signerKeys() const;
00428 
00438         void setBundleSignerEnabled(bool b);
00439 
00448         void setSMIMEAttributesEnabled(bool b);
00449 
00457         void setFormat(Format f);
00458 
00464         void setRecipient(const SecureMessageKey &key);
00465 
00473         void setRecipients(const SecureMessageKeyList &keys);
00474 
00483         void setSigner(const SecureMessageKey &key);
00484 
00495         void setSigners(const SecureMessageKeyList &keys);
00496 
00517         void startEncrypt();
00518 
00543         void startDecrypt();
00544 
00569         void startSign(SignMode m = Message);
00570 
00578         void startVerify(const QByteArray &detachedSig = QByteArray());
00579 
00589         void startSignAndEncrypt();
00590 
00600         void update(const QByteArray &in);
00601 
00609         QByteArray read();
00610 
00614         int bytesAvailable() const;
00615 
00628         void end();
00629 
00647         bool waitForFinished(int msecs = 30000);
00648 
00657         bool success() const;
00658 
00665         Error errorCode() const;
00666 
00673         QByteArray signature() const;
00674 
00678         QString hashName() const;
00679 
00688         bool wasSigned() const;
00689 
00696         bool verifySuccess() const;
00697 
00701         SecureMessageSignature signer() const;
00702 
00710         SecureMessageSignatureList signers() const;
00711 
00717         QString diagnosticText() const;
00718 
00719 Q_SIGNALS:
00729         void readyRead();
00730 
00735         void bytesWritten(int bytes);
00736 
00741         void finished();
00742 
00743 private:
00744         Q_DISABLE_COPY(SecureMessage)
00745 
00746         class Private;
00747         friend class Private;
00748         Private *d;
00749 };
00750 
00759 class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
00760 {
00761         Q_OBJECT
00762 public:
00763         ~SecureMessageSystem();
00764 
00765 protected:
00779         SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
00780 
00781 private:
00782         Q_DISABLE_COPY(SecureMessageSystem)
00783 };
00784 
00793 class QCA_EXPORT OpenPGP : public SecureMessageSystem
00794 {
00795         Q_OBJECT
00796 public:
00804         explicit OpenPGP(QObject *parent = 0, const QString &provider = QString());
00805         ~OpenPGP();
00806 
00807 private:
00808         Q_DISABLE_COPY(OpenPGP)
00809 
00810         class Private;
00811         Private *d;
00812 };
00813 
00836 class QCA_EXPORT CMS : public SecureMessageSystem
00837 {
00838         Q_OBJECT
00839 public:
00847         explicit CMS(QObject *parent = 0, const QString &provider = QString());
00848         ~CMS();
00849 
00853         CertificateCollection trustedCertificates() const;
00854 
00858         CertificateCollection untrustedCertificates() const;
00859 
00863         SecureMessageKeyList privateKeys() const;
00864 
00872         void setTrustedCertificates(const CertificateCollection &trusted);
00873 
00886         void setUntrustedCertificates(const CertificateCollection &untrusted);
00887 
00897         void setPrivateKeys(const SecureMessageKeyList &keys);
00898 
00899 private:
00900         Q_DISABLE_COPY(CMS)
00901 
00902         class Private;
00903         Private *d;
00904 };
00905 
00906 }
00907 
00908 #endif

Generated on Fri Jul 6 12:14:04 2007 for Qt Cryptographic Architecture by  doxygen 1.4.6