Qt Cryptographic Architecture
qca_securemessage.h
Go to the documentation of this file.
1 /*
2  * qca_securemessage.h - Qt Cryptographic Architecture
3  * Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
4  * Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22 
33 #ifndef QCA_SECUREMESSAGE_H
34 #define QCA_SECUREMESSAGE_H
35 
36 #include "qca_cert.h"
37 #include "qca_core.h"
38 #include "qca_publickey.h"
39 #include <QObject>
40 
41 class QDateTime;
42 
43 namespace QCA {
44 
45 class SecureMessageSystem;
46 
54 class QCA_EXPORT SecureMessageKey
55 {
56 public:
60  enum Type
61  {
62  None,
63  PGP,
64  X509
65  };
66 
71 
78 
80 
86  SecureMessageKey &operator=(const SecureMessageKey &from);
87 
91  bool isNull() const;
92 
96  Type type() const;
97 
101  PGPKey pgpPublicKey() const;
102 
106  PGPKey pgpSecretKey() const;
107 
113  void setPGPPublicKey(const PGPKey &pub);
114 
120  void setPGPSecretKey(const PGPKey &sec);
121 
125  CertificateChain x509CertificateChain() const;
126 
130  PrivateKey x509PrivateKey() const;
131 
137  void setX509CertificateChain(const CertificateChain &c);
138 
144  void setX509PrivateKey(const PrivateKey &k);
145 
151  void setX509KeyBundle(const KeyBundle &kb);
152 
156  bool havePrivate() const;
157 
165  QString name() const;
166 
167 private:
168  class Private;
169  QSharedDataPointer<Private> d;
170 };
171 
176 
184 class QCA_EXPORT SecureMessageSignature
185 {
186 public:
191  {
195  NoKey
196  };
197 
205 
217  SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
218 
225 
227 
233  SecureMessageSignature &operator=(const SecureMessageSignature &from);
234 
238  IdentityResult identityResult() const;
239 
243  Validity keyValidity() const;
244 
248  SecureMessageKey key() const;
249 
253  QDateTime timestamp() const;
254 
255 private:
256  class Private;
257  QSharedDataPointer<Private> d;
258 };
259 
264 
319 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
320 {
321  Q_OBJECT
322 public:
326  enum Type
327  {
330  };
331 
335  enum SignMode
336  {
339  Detached
340  };
341 
345  enum Format
346  {
348  Ascii
349  };
350 
354  enum Error
355  {
368  ErrorEncryptRevoked
369  };
370 
383  ~SecureMessage() override;
384 
388  Type type() const;
389 
400  bool canSignMultiple() const;
401 
409  bool canClearsign() const;
410 
420  bool canSignAndEncrypt() const;
421 
426  void reset();
427 
432  bool bundleSignerEnabled() const;
433 
437  bool smimeAttributesEnabled() const;
438 
442  Format format() const;
443 
448  SecureMessageKeyList recipientKeys() const;
449 
454  SecureMessageKeyList signerKeys() const;
455 
467  void setBundleSignerEnabled(bool b);
468 
479  void setSMIMEAttributesEnabled(bool b);
480 
488  void setFormat(Format f);
489 
497  void setRecipient(const SecureMessageKey &key);
498 
508  void setRecipients(const SecureMessageKeyList &keys);
509 
520  void setSigner(const SecureMessageKey &key);
521 
534  void setSigners(const SecureMessageKeyList &keys);
535 
556  void startEncrypt();
557 
582  void startDecrypt();
583 
608  void startSign(SignMode m = Message);
609 
617  void startVerify(const QByteArray &detachedSig = QByteArray());
618 
628  void startSignAndEncrypt();
629 
639  void update(const QByteArray &in);
640 
648  QByteArray read();
649 
653  int bytesAvailable() const;
654 
667  void end();
668 
686  bool waitForFinished(int msecs = 30000);
687 
696  bool success() const;
697 
704  Error errorCode() const;
705 
712  QByteArray signature() const;
713 
717  QString hashName() const;
718 
727  bool wasSigned() const;
728 
735  bool verifySuccess() const;
736 
740  SecureMessageSignature signer() const;
741 
749  SecureMessageSignatureList signers() const;
750 
756  QString diagnosticText() const;
757 
758 Q_SIGNALS:
768  void readyRead();
769 
776  void bytesWritten(int bytes);
777 
782  void finished();
783 
784 private:
785  Q_DISABLE_COPY(SecureMessage)
786 
787  class Private;
788  friend class Private;
789  Private *d;
790 };
791 
802 class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
803 {
804  Q_OBJECT
805 public:
806  ~SecureMessageSystem() override;
807 
808 protected:
822  SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
823 
824 private:
825  Q_DISABLE_COPY(SecureMessageSystem)
826 };
827 
839 class QCA_EXPORT OpenPGP : public SecureMessageSystem
840 {
841  Q_OBJECT
842 public:
850  explicit OpenPGP(QObject *parent = nullptr, const QString &provider = QString());
851  ~OpenPGP() override;
852 
853 private:
854  Q_DISABLE_COPY(OpenPGP)
855 
856  class Private;
857  Private *d;
858 };
859 
885 class QCA_EXPORT CMS : public SecureMessageSystem
886 {
887  Q_OBJECT
888 public:
896  explicit CMS(QObject *parent = nullptr, const QString &provider = QString());
897  ~CMS() override;
898 
902  CertificateCollection trustedCertificates() const;
903 
907  CertificateCollection untrustedCertificates() const;
908 
912  SecureMessageKeyList privateKeys() const;
913 
921  void setTrustedCertificates(const CertificateCollection &trusted);
922 
935  void setUntrustedCertificates(const CertificateCollection &untrusted);
936 
946  void setPrivateKeys(const SecureMessageKeyList &keys);
947 
948 private:
949  Q_DISABLE_COPY(CMS)
950 
951  class Private;
952  Private *d;
953 };
954 
955 }
956 
957 #endif
QCA::SecureMessageSignature::IdentityResult
IdentityResult
The result of identity verification.
Definition: qca_securemessage.h:190
QObject
QCA::SecureMessage::OpenPGP
@ OpenPGP
a Pretty Good Privacy message
Definition: qca_securemessage.h:328
QCA::SecureMessageKey
Definition: qca_securemessage.h:54
QCA::SecureMessage::Error
Error
Errors for secure messages.
Definition: qca_securemessage.h:354
QCA::CMS
Definition: qca_securemessage.h:885
QCA::SecureMessage::ErrorEncryptUntrusted
@ ErrorEncryptUntrusted
encrypting key is untrusted
Definition: qca_securemessage.h:361
QCA::PrivateKey
Definition: qca_publickey.h:832
QCA::SecureMessageSignature::InvalidSignature
@ InvalidSignature
valid key provided, but signature failed
Definition: qca_securemessage.h:193
QCA
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
QCA::SecureMessageSignatureList
QList< SecureMessageSignature > SecureMessageSignatureList
A list of signatures.
Definition: qca_securemessage.h:263
QCA::Algorithm
Definition: qca_core.h:1163
QCA::SecureMessageSignature::Valid
@ Valid
indentity is verified, matches signature
Definition: qca_securemessage.h:192
QList
QCA::SecureMessage::Binary
@ Binary
DER/binary.
Definition: qca_securemessage.h:347
qca_cert.h
QCA::SecureMessage::ErrorCertKeyMismatch
@ ErrorCertKeyMismatch
certificate and private key don't match
Definition: qca_securemessage.h:364
QCA::SecureMessage::ErrorSignerInvalid
@ ErrorSignerInvalid
signing key is invalid in some way
Definition: qca_securemessage.h:359
QCA::CertificateCollection
Definition: qca_cert.h:1928
QCA::SecureMessage::ErrorFormat
@ ErrorFormat
input format was bad
Definition: qca_securemessage.h:357
QCA::SecureMessageSystem
Definition: qca_securemessage.h:802
QCA::SecureMessageSignature
Definition: qca_securemessage.h:184
QCA::SecureMessageSignature::InvalidKey
@ InvalidKey
invalid key provided
Definition: qca_securemessage.h:194
QCA::SecureMessage::ErrorEncryptExpired
@ ErrorEncryptExpired
encrypting key is expired
Definition: qca_securemessage.h:360
QCA::SecureMessage::ErrorPassphrase
@ ErrorPassphrase
passphrase was either wrong or not provided
Definition: qca_securemessage.h:356
QCA::CertificateChain
Definition: qca_cert.h:1225
QCA::SecureMessage::ErrorSignerExpired
@ ErrorSignerExpired
signing key is expired
Definition: qca_securemessage.h:358
QCA::SecureMessage::ErrorNeedCard
@ ErrorNeedCard
pgp card is missing
Definition: qca_securemessage.h:363
QCA::SecureMessage::Format
Format
Formats for secure messages.
Definition: qca_securemessage.h:345
QCA::SecureMessage::ErrorSignatureExpired
@ ErrorSignatureExpired
signature is expired
Definition: qca_securemessage.h:367
QCA::SecureMessage::Clearsign
@ Clearsign
the message is clear signed
Definition: qca_securemessage.h:338
QCA::SecureMessage
Definition: qca_securemessage.h:319
QCA::KeyBundle
Definition: qca_cert.h:2175
QCA::SecureMessage::Type
Type
The type of secure message.
Definition: qca_securemessage.h:326
QCA::SecureMessage::ErrorUnknown
@ ErrorUnknown
other error
Definition: qca_securemessage.h:365
QCA::OpenPGP
Definition: qca_securemessage.h:839
qca_core.h
QCA::SecureMessage::ErrorSignerRevoked
@ ErrorSignerRevoked
signing key is revoked
Definition: qca_securemessage.h:366
QCA::SecureMessageKeyList
QList< SecureMessageKey > SecureMessageKeyList
A list of message keys.
Definition: qca_securemessage.h:175
QCA::SecureMessage::ErrorEncryptInvalid
@ ErrorEncryptInvalid
encrypting key is invalid in some way
Definition: qca_securemessage.h:362
QCA::SecureMessage::Message
@ Message
the message includes the signature
Definition: qca_securemessage.h:337
QCA::PGPKey
Definition: qca_cert.h:2406
qca_publickey.h
QCA::Validity
Validity
The validity (or otherwise) of a certificate.
Definition: qca_cert.h:496
QCA::SecureMessageKey::None
@ None
no key
Definition: qca_securemessage.h:62
QCA::SecureMessageKey::PGP
@ PGP
Pretty Good Privacy key.
Definition: qca_securemessage.h:63
QCA::SecureMessageKey::Type
Type
The key type.
Definition: qca_securemessage.h:60
QCA::SecureMessage::SignMode
SignMode
The type of message signature.
Definition: qca_securemessage.h:335