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 <QObject>
37 #include "qca_core.h"
38 #include "qca_publickey.h"
39 #include "qca_cert.h"
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 
87 
91  bool isNull() const;
92 
96  Type type() const;
97 
102 
107 
113  void setPGPPublicKey(const PGPKey &pub);
114 
120  void setPGPSecretKey(const PGPKey &sec);
121 
126 
131 
138 
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 
234 
239 
244 
249 
253  QDateTime timestamp() const;
254 
255 private:
256  class Private;
257  QSharedDataPointer<Private> d;
258 };
259 
264 
265 
320 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
321 {
322  Q_OBJECT
323 public:
327  enum Type
328  {
330  CMS
331  };
332 
336  enum SignMode
337  {
340  Detached
341  };
342 
346  enum Format
347  {
349  Ascii
350  };
351 
355  enum Error
356  {
369  ErrorEncryptRevoked
370  };
371 
384  ~SecureMessage() override;
385 
389  Type type() const;
390 
401  bool canSignMultiple() const;
402 
410  bool canClearsign() const;
411 
421  bool canSignAndEncrypt() const;
422 
427  void reset();
428 
433  bool bundleSignerEnabled() const;
434 
439 
443  Format format() const;
444 
450 
456 
469 
481 
489  void setFormat(Format f);
490 
498  void setRecipient(const SecureMessageKey &key);
499 
510 
521  void setSigner(const SecureMessageKey &key);
522 
535  void setSigners(const SecureMessageKeyList &keys);
536 
557  void startEncrypt();
558 
583  void startDecrypt();
584 
609  void startSign(SignMode m = Message);
610 
618  void startVerify(const QByteArray &detachedSig = QByteArray());
619 
630 
640  void update(const QByteArray &in);
641 
649  QByteArray read();
650 
654  int bytesAvailable() const;
655 
668  void end();
669 
687  bool waitForFinished(int msecs = 30000);
688 
697  bool success() const;
698 
705  Error errorCode() const;
706 
713  QByteArray signature() const;
714 
718  QString hashName() const;
719 
728  bool wasSigned() const;
729 
736  bool verifySuccess() const;
737 
742 
751 
757  QString diagnosticText() const;
758 
759 Q_SIGNALS:
769  void readyRead();
770 
777  void bytesWritten(int bytes);
778 
783  void finished();
784 
785 private:
786  Q_DISABLE_COPY(SecureMessage)
787 
788  class Private;
789  friend class Private;
790  Private *d;
791 };
792 
803 class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
804 {
805  Q_OBJECT
806 public:
807  ~SecureMessageSystem() override;
808 
809 protected:
823  SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
824 
825 private:
826  Q_DISABLE_COPY(SecureMessageSystem)
827 };
828 
840 class QCA_EXPORT OpenPGP : public SecureMessageSystem
841 {
842  Q_OBJECT
843 public:
851  explicit OpenPGP(QObject *parent = nullptr, const QString &provider = QString());
852  ~OpenPGP() override;
853 
854 private:
855  Q_DISABLE_COPY(OpenPGP)
856 
857  class Private;
858  Private *d;
859 };
860 
886 class QCA_EXPORT CMS : public SecureMessageSystem
887 {
888  Q_OBJECT
889 public:
897  explicit CMS(QObject *parent = nullptr, const QString &provider = QString());
898  ~CMS() override;
899 
904 
909 
914 
923 
937 
948 
949 private:
950  Q_DISABLE_COPY(CMS)
951 
952  class Private;
953  Private *d;
954 };
955 
956 }
957 
958 #endif
QCA::SecureMessage::success
bool success() const
Indicates whether or not the operation was successful or failed.
QCA::SecureMessage::read
QByteArray read()
Read the available data.
QCA::SecureMessageSignature::IdentityResult
IdentityResult
The result of identity verification.
Definition: qca_securemessage.h:191
QCA::SecureMessage::SecureMessage
SecureMessage(SecureMessageSystem *system)
Create a new secure message.
QObject
QCA::CMS::setPrivateKeys
void setPrivateKeys(const SecureMessageKeyList &keys)
Set the private keys to use for the messages built using this CMS object.
QCA::SecureMessage::diagnosticText
QString diagnosticText() const
Returns a log of technical information about the operation, which may be useful for presenting to the...
QCA::SecureMessageSignature::SecureMessageSignature
SecureMessageSignature(const SecureMessageSignature &from)
Standard copy constructor.
QCA::SecureMessage::errorCode
Error errorCode() const
Returns the failure code.
QCA::SecureMessage::recipientKeys
SecureMessageKeyList recipientKeys() const
Return the recipient(s) set for this message with setRecipient() or setRecipients()
QCA::SecureMessage::type
Type type() const
The Type of secure message.
QCA::SecureMessage::end
void end()
Complete an operation.
QCA::SecureMessage::wasSigned
bool wasSigned() const
Test if the message was signed.
QCA::CMS::untrustedCertificates
CertificateCollection untrustedCertificates() const
Return the untrusted certificates set for this object.
QCA::SecureMessage::OpenPGP
@ OpenPGP
a Pretty Good Privacy message
Definition: qca_securemessage.h:329
QCA::SecureMessage::canClearsign
bool canClearsign() const
True if the SecureMessageSystem can clearsign messages.
QCA::SecureMessage::bytesAvailable
int bytesAvailable() const
The number of bytes available to be read.
QCA::SecureMessage::canSignMultiple
bool canSignMultiple() const
Test if the message type supports multiple (parallel) signatures.
QCA::SecureMessageKey::SecureMessageKey
SecureMessageKey()
Construct an empty key.
QCA::SecureMessage::setRecipients
void setRecipients(const SecureMessageKeyList &keys)
Set the list of recipients for an encrypted message.
QCA::SecureMessageKey
Key for SecureMessage system.
Definition: qca_securemessage.h:55
QCA::SecureMessage::Error
Error
Errors for secure messages.
Definition: qca_securemessage.h:356
QCA::SecureMessage::canSignAndEncrypt
bool canSignAndEncrypt() const
True if the SecureMessageSystem can both sign and encrypt (in the same operation).
QCA::SecureMessage::startEncrypt
void startEncrypt()
QCA::SecureMessageKey::name
QString name() const
The name associated with this key.
QCA::SecureMessage::setSMIMEAttributesEnabled
void setSMIMEAttributesEnabled(bool b)
For CMS only, this will put extra attributes into the message related to S/MIME, such as the preferre...
QCA::SecureMessageSignature::identityResult
IdentityResult identityResult() const
get the results of the identity check on this signature
QCA::CMS
Cryptographic Message Syntax messaging system.
Definition: qca_securemessage.h:887
QCA::CMS::trustedCertificates
CertificateCollection trustedCertificates() const
Return the trusted certificates set for this object.
QCA::SecureMessage::ErrorEncryptUntrusted
@ ErrorEncryptUntrusted
encrypting key is untrusted
Definition: qca_securemessage.h:362
QCA::PrivateKey
Generic private key.
Definition: qca_publickey.h:827
QCA::SecureMessage::smimeAttributesEnabled
bool smimeAttributesEnabled() const
Returns true if inclusion of S/MIME attributes is enabled.
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
General superclass for an algorithm.
Definition: qca_core.h:1152
QCA::CMS::privateKeys
SecureMessageKeyList privateKeys() const
Return the private keys set for this object.
QCA::SecureMessageSignature::Valid
@ Valid
indentity is verified, matches signature
Definition: qca_securemessage.h:192
QCA::SecureMessage::setBundleSignerEnabled
void setBundleSignerEnabled(bool b)
For CMS only, this will bundle the signer certificate chain into the message.
QList
QCA::SecureMessage::signerKeys
SecureMessageKeyList signerKeys() const
Return the signer(s) set for this message with setSigner() or setSigners()
QCA::SecureMessage::startVerify
void startVerify(const QByteArray &detachedSig=QByteArray())
Start a verification operation.
QCA::SecureMessage::Binary
@ Binary
DER/binary.
Definition: qca_securemessage.h:348
qca_cert.h
Header file for PGP key and X.509 certificate related classes.
QCA::SecureMessage::ErrorCertKeyMismatch
@ ErrorCertKeyMismatch
certificate and private key don't match
Definition: qca_securemessage.h:365
QCA::SecureMessage::startSign
void startSign(SignMode m=Message)
QCA::SecureMessage::ErrorSignerInvalid
@ ErrorSignerInvalid
signing key is invalid in some way
Definition: qca_securemessage.h:360
QCA::SecureMessageKey::setX509CertificateChain
void setX509CertificateChain(const CertificateChain &c)
Set the public key part of this X.509 key.
QCA::SecureMessage::update
void update(const QByteArray &in)
Process a message (or the next part of a message) in the current operation.
QCA::CertificateCollection
Bundle of Certificates and CRLs.
Definition: qca_cert.h:1891
QCA::SecureMessage::ErrorFormat
@ ErrorFormat
input format was bad
Definition: qca_securemessage.h:358
QCA::SecureMessageSystem
Abstract superclass for secure messaging systems.
Definition: qca_securemessage.h:804
QCA::SecureMessage::verifySuccess
bool verifySuccess() const
Verify that the message signature is correct.
QCA::SecureMessageSignature::operator=
SecureMessageSignature & operator=(const SecureMessageSignature &from)
Standard assignment operator.
QCA::SecureMessageSignature::key
SecureMessageKey key() const
get the key associated with this signature
QCA::SecureMessageKey::isNull
bool isNull() const
Returns true for null object.
QCA::SecureMessageSignature
SecureMessage signature.
Definition: qca_securemessage.h:185
QCA::SecureMessage::setSigner
void setSigner(const SecureMessageKey &key)
Set the signer for a signed message.
QCA::SecureMessageSystem::SecureMessageSystem
SecureMessageSystem(QObject *parent, const QString &type, const QString &provider)
Protected constructor for SecureMessageSystem classes.
QCA::SecureMessageSignature::InvalidKey
@ InvalidKey
invalid key provided
Definition: qca_securemessage.h:194
QCA::CMS::setTrustedCertificates
void setTrustedCertificates(const CertificateCollection &trusted)
Set the trusted certificates to use for the messages built using this CMS object.
QCA::SecureMessage::ErrorEncryptExpired
@ ErrorEncryptExpired
encrypting key is expired
Definition: qca_securemessage.h:361
QCA::SecureMessage::ErrorPassphrase
@ ErrorPassphrase
passphrase was either wrong or not provided
Definition: qca_securemessage.h:357
QCA::CertificateChain
A chain of related Certificates.
Definition: qca_cert.h:1208
QCA::SecureMessage::waitForFinished
bool waitForFinished(int msecs=30000)
Block until the operation (encryption, decryption, signing or verifying) completes.
QCA::SecureMessageKey::setX509KeyBundle
void setX509KeyBundle(const KeyBundle &kb)
Set the public and private part of this X.509 key with KeyBundle.
QCA::SecureMessage::ErrorSignerExpired
@ ErrorSignerExpired
signing key is expired
Definition: qca_securemessage.h:359
QCA::SecureMessage::ErrorNeedCard
@ ErrorNeedCard
pgp card is missing
Definition: qca_securemessage.h:364
QCA::SecureMessage::readyRead
void readyRead()
This signal is emitted when there is some data to read.
QCA::SecureMessage::Format
Format
Formats for secure messages.
Definition: qca_securemessage.h:347
QCA::SecureMessage::ErrorSignatureExpired
@ ErrorSignatureExpired
signature is expired
Definition: qca_securemessage.h:368
QCA::SecureMessage::Clearsign
@ Clearsign
the message is clear signed
Definition: qca_securemessage.h:339
QCA::SecureMessageSignature::SecureMessageSignature
SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts)
Create a signature check object.
QCA::SecureMessageKey::setPGPPublicKey
void setPGPPublicKey(const PGPKey &pub)
Set the public key part of a PGP key.
QCA::OpenPGP::OpenPGP
OpenPGP(QObject *parent=nullptr, const QString &provider=QString())
Standard constructor.
QCA::SecureMessage
Class representing a secure message.
Definition: qca_securemessage.h:321
QCA::SecureMessage::bytesWritten
void bytesWritten(int bytes)
This signal is emitted when data has been accepted by the message processor.
QCA::SecureMessageKey::setX509PrivateKey
void setX509PrivateKey(const PrivateKey &k)
Set the private key part of this X.509 key.
QCA::KeyBundle
Certificate chain and private key pair.
Definition: qca_cert.h:2136
QCA::SecureMessage::Type
Type
The type of secure message.
Definition: qca_securemessage.h:328
QCA::SecureMessageSignature::keyValidity
Validity keyValidity() const
get the results of the key validation check on this signature
QCA::SecureMessageKey::x509CertificateChain
CertificateChain x509CertificateChain() const
The X.509 certificate chain (public part) for this key.
QCA::SecureMessage::reset
void reset()
Reset the object state to that of original construction.
QCA::SecureMessageKey::pgpSecretKey
PGPKey pgpSecretKey() const
Private key part of a PGP key.
QCA::SecureMessage::signers
SecureMessageSignatureList signers() const
Information on the signers for the message.
QCA::SecureMessage::signature
QByteArray signature() const
The signature for the message.
QCA::SecureMessage::ErrorUnknown
@ ErrorUnknown
other error
Definition: qca_securemessage.h:366
QCA::SecureMessageKey::operator=
SecureMessageKey & operator=(const SecureMessageKey &from)
Standard assignment operator.
QCA::SecureMessageKey::setPGPSecretKey
void setPGPSecretKey(const PGPKey &sec)
Set the private key part of a PGP key.
QCA::OpenPGP
Pretty Good Privacy messaging system.
Definition: qca_securemessage.h:841
QCA::SecureMessageKey::type
Type type() const
The key type.
qca_core.h
Header file for core QCA infrastructure.
QCA::SecureMessage::ErrorSignerRevoked
@ ErrorSignerRevoked
signing key is revoked
Definition: qca_securemessage.h:367
QCA::CMS::CMS
CMS(QObject *parent=nullptr, const QString &provider=QString())
Standard constructor.
QCA::SecureMessage::setSigners
void setSigners(const SecureMessageKeyList &keys)
Set the list of signers for a signed message.
QCA::SecureMessageKeyList
QList< SecureMessageKey > SecureMessageKeyList
A list of message keys.
Definition: qca_securemessage.h:175
QCA::SecureMessage::bundleSignerEnabled
bool bundleSignerEnabled() const
Returns true if bundling of the signer certificate chain is enabled.
QCA::SecureMessage::ErrorEncryptInvalid
@ ErrorEncryptInvalid
encrypting key is invalid in some way
Definition: qca_securemessage.h:363
QCA::SecureMessage::Message
@ Message
the message includes the signature
Definition: qca_securemessage.h:338
QCA::SecureMessageKey::SecureMessageKey
SecureMessageKey(const SecureMessageKey &from)
Standard copy constructor.
QCA::SecureMessageKey::x509PrivateKey
PrivateKey x509PrivateKey() const
The X.509 private key part of this key.
QCA::PGPKey
Pretty Good Privacy key.
Definition: qca_cert.h:2361
QCA::SecureMessageSignature::SecureMessageSignature
SecureMessageSignature()
Create an empty signature check object.
QCA::SecureMessageKey::havePrivate
bool havePrivate() const
Test if this key contains a private key part.
QCA::SecureMessage::hashName
QString hashName() const
The name of the hash used for the signature process.
qca_publickey.h
Header file for PublicKey and PrivateKey related classes.
QCA::SecureMessage::format
Format format() const
Return the format type set for this message.
QCA::SecureMessage::setFormat
void setFormat(Format f)
Set the Format used for messages.
QCA::Validity
Validity
The validity (or otherwise) of a certificate.
Definition: qca_cert.h:490
QCA::SecureMessage::signer
SecureMessageSignature signer() const
Information on the signer for the message.
QCA::SecureMessageKey::None
@ None
no key
Definition: qca_securemessage.h:62
QCA::SecureMessage::startSignAndEncrypt
void startSignAndEncrypt()
Start a combined signing and encrypting operation.
QCA::SecureMessageKey::PGP
@ PGP
Pretty Good Privacy key.
Definition: qca_securemessage.h:63
QCA::SecureMessageKey::pgpPublicKey
PGPKey pgpPublicKey() const
Public key part of a PGP key.
QCA::SecureMessage::startDecrypt
void startDecrypt()
QCA::CMS::setUntrustedCertificates
void setUntrustedCertificates(const CertificateCollection &untrusted)
Set the untrusted certificates to use for the messages built using this CMS object.
QCA::SecureMessageSignature::timestamp
QDateTime timestamp() const
get the timestamp associated with this signature
QCA::SecureMessage::setRecipient
void setRecipient(const SecureMessageKey &key)
Set the recipient for an encrypted message.
QCA::SecureMessage::finished
void finished()
This signal is emitted when the message is fully processed.
QCA::SecureMessageKey::Type
Type
The key type.
Definition: qca_securemessage.h:61
QCA::SecureMessage::SignMode
SignMode
The type of message signature.
Definition: qca_securemessage.h:337