qca_securemessage.h
Go to the documentation of this file.
/*
* qca_securemessage.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef QCA_SECUREMESSAGE_H
#define QCA_SECUREMESSAGE_H
#include "qca_cert.h"
#include "qca_core.h"
#include "qca_publickey.h"
#include <QObject>
class QDateTime;
namespace QCA {
class SecureMessageSystem;
class QCA_EXPORT SecureMessageKey
{
public:
enum Type
{
None,
PGP,
X509
};
SecureMessageKey();
SecureMessageKey(const SecureMessageKey &from);
~SecureMessageKey();
SecureMessageKey &operator=(const SecureMessageKey &from);
bool isNull() const;
Type type() const;
PGPKey pgpPublicKey() const;
PGPKey pgpSecretKey() const;
void setPGPPublicKey(const PGPKey &pub);
void setPGPSecretKey(const PGPKey &sec);
CertificateChain x509CertificateChain() const;
PrivateKey x509PrivateKey() const;
void setX509CertificateChain(const CertificateChain &c);
void setX509PrivateKey(const PrivateKey &k);
void setX509KeyBundle(const KeyBundle &kb);
bool havePrivate() const;
QString name() const;
private:
class Private;
QSharedDataPointer<Private> d;
};
typedef QList<SecureMessageKey> SecureMessageKeyList;
class QCA_EXPORT SecureMessageSignature
{
public:
enum IdentityResult
{
Valid,
InvalidSignature,
InvalidKey,
NoKey
};
SecureMessageSignature();
SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
SecureMessageSignature(const SecureMessageSignature &from);
~SecureMessageSignature();
SecureMessageSignature &operator=(const SecureMessageSignature &from);
IdentityResult identityResult() const;
Validity keyValidity() const;
SecureMessageKey key() const;
QDateTime timestamp() const;
private:
class Private;
QSharedDataPointer<Private> d;
};
typedef QList<SecureMessageSignature> SecureMessageSignatureList;
class QCA_EXPORT SecureMessage : public QObject, public Algorithm
{
Q_OBJECT
public:
enum Type
{
OpenPGP,
CMS
};
enum SignMode
{
Message,
Clearsign,
Detached
};
enum Format
{
Binary,
Ascii
};
enum Error
{
ErrorPassphrase,
ErrorFormat,
ErrorSignerExpired,
ErrorSignerInvalid,
ErrorEncryptExpired,
ErrorEncryptUntrusted,
ErrorEncryptInvalid,
ErrorNeedCard,
ErrorCertKeyMismatch,
ErrorUnknown,
ErrorSignerRevoked,
ErrorSignatureExpired,
ErrorEncryptRevoked
};
SecureMessage(SecureMessageSystem *system);
~SecureMessage() override;
Type type() const;
bool canSignMultiple() const;
bool canClearsign() const;
bool canSignAndEncrypt() const;
void reset();
bool bundleSignerEnabled() const;
bool smimeAttributesEnabled() const;
Format format() const;
SecureMessageKeyList recipientKeys() const;
SecureMessageKeyList signerKeys() const;
void setBundleSignerEnabled(bool b);
void setSMIMEAttributesEnabled(bool b);
void setFormat(Format f);
void setRecipient(const SecureMessageKey &key);
void setRecipients(const SecureMessageKeyList &keys);
void setSigner(const SecureMessageKey &key);
void setSigners(const SecureMessageKeyList &keys);
void startEncrypt();
void startDecrypt();
void startSign(SignMode m = Message);
void startVerify(const QByteArray &detachedSig = QByteArray());
void startSignAndEncrypt();
void update(const QByteArray &in);
QByteArray read();
int bytesAvailable() const;
void end();
bool waitForFinished(int msecs = 30000);
bool success() const;
Error errorCode() const;
QByteArray signature() const;
QString hashName() const;
bool wasSigned() const;
bool verifySuccess() const;
SecureMessageSignature signer() const;
SecureMessageSignatureList signers() const;
QString diagnosticText() const;
Q_SIGNALS:
void readyRead();
void bytesWritten(int bytes);
void finished();
private:
Q_DISABLE_COPY(SecureMessage)
class Private;
friend class Private;
Private *d;
};
class QCA_EXPORT SecureMessageSystem : public QObject, public Algorithm
{
Q_OBJECT
public:
~SecureMessageSystem() override;
protected:
SecureMessageSystem(QObject *parent, const QString &type, const QString &provider);
private:
Q_DISABLE_COPY(SecureMessageSystem)
};
class QCA_EXPORT OpenPGP : public SecureMessageSystem
{
Q_OBJECT
public:
explicit OpenPGP(QObject *parent = nullptr, const QString &provider = QString());
~OpenPGP() override;
private:
Q_DISABLE_COPY(OpenPGP)
class Private;
Private *d;
};
class QCA_EXPORT CMS : public SecureMessageSystem
{
Q_OBJECT
public:
explicit CMS(QObject *parent = nullptr, const QString &provider = QString());
~CMS() override;
CertificateCollection trustedCertificates() const;
CertificateCollection untrustedCertificates() const;
SecureMessageKeyList privateKeys() const;
void setTrustedCertificates(const CertificateCollection &trusted);
void setUntrustedCertificates(const CertificateCollection &untrusted);
void setPrivateKeys(const SecureMessageKeyList &keys);
private:
Q_DISABLE_COPY(CMS)
class Private;
Private *d;
};
}
#endif
QCA::Algorithm::type
QString type() const
The name of the algorithm type.
QCA::Algorithm::provider
Provider * provider() const
The name of the provider.
QCA::Algorithm::Algorithm
Algorithm(const Algorithm &from)
Standard copy constructor.
QCA::CMS::trustedCertificates
CertificateCollection trustedCertificates() const
Return the trusted certificates set for this object.
QCA::CMS::CMS
CMS(QObject *parent=nullptr, const QString &provider=QString())
Standard constructor.
QCA::CMS::setTrustedCertificates
void setTrustedCertificates(const CertificateCollection &trusted)
Set the trusted certificates to use for the messages built using this CMS object.
QCA::CMS::privateKeys
SecureMessageKeyList privateKeys() const
Return the private keys set for this object.
QCA::CMS::setUntrustedCertificates
void setUntrustedCertificates(const CertificateCollection &untrusted)
Set the untrusted certificates to use for the messages built using this CMS object.
QCA::CMS::untrustedCertificates
CertificateCollection untrustedCertificates() const
Return the untrusted certificates set for this object.
QCA::CMS::setPrivateKeys
void setPrivateKeys(const SecureMessageKeyList &keys)
Set the private keys to use for the messages built using this CMS object.
QCA::CertificateChain
A chain of related Certificates.
Definition qca_cert.h:1226
QCA::CertificateCollection
Bundle of Certificates and CRLs.
Definition qca_cert.h:1929
QCA::KeyBundle
Certificate chain and private key pair.
Definition qca_cert.h:2176
QCA::OpenPGP::OpenPGP
OpenPGP(QObject *parent=nullptr, const QString &provider=QString())
Standard constructor.
QCA::PGPKey
Pretty Good Privacy key.
Definition qca_cert.h:2407
QCA::PrivateKey
Generic private key.
Definition qca_publickey.h:833
QCA::SecureMessageKey
Key for SecureMessage system.
Definition qca_securemessage.h:55
QCA::SecureMessageKey::type
Type type() const
The key type.
QCA::SecureMessageKey::SecureMessageKey
SecureMessageKey()
Construct an empty key.
QCA::SecureMessageKey::operator=
SecureMessageKey & operator=(const SecureMessageKey &from)
Standard assignment operator.
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::SecureMessageKey::setX509PrivateKey
void setX509PrivateKey(const PrivateKey &k)
Set the private key part of this X.509 key.
QCA::SecureMessageKey::setPGPPublicKey
void setPGPPublicKey(const PGPKey &pub)
Set the public key part of a PGP key.
QCA::SecureMessageKey::pgpPublicKey
PGPKey pgpPublicKey() const
Public key part of a PGP key.
QCA::SecureMessageKey::pgpSecretKey
PGPKey pgpSecretKey() const
Private key part of a PGP key.
QCA::SecureMessageKey::isNull
bool isNull() const
Returns true for null object.
QCA::SecureMessageKey::havePrivate
bool havePrivate() const
Test if this key contains a private key part.
QCA::SecureMessageKey::name
QString name() const
The name associated with this key.
QCA::SecureMessageKey::x509CertificateChain
CertificateChain x509CertificateChain() const
The X.509 certificate chain (public part) for this key.
QCA::SecureMessageKey::setX509CertificateChain
void setX509CertificateChain(const CertificateChain &c)
Set the public key part of this X.509 key.
QCA::SecureMessageKey::setX509KeyBundle
void setX509KeyBundle(const KeyBundle &kb)
Set the public and private part of this X.509 key with KeyBundle.
QCA::SecureMessageKey::setPGPSecretKey
void setPGPSecretKey(const PGPKey &sec)
Set the private key part of a PGP key.
QCA::SecureMessageKey::Type
Type
The key type.
Definition qca_securemessage.h:61
QCA::SecureMessageKey::None
@ None
no key
Definition qca_securemessage.h:62
QCA::SecureMessageKey::X509
@ X509
X.509 CMS key.
Definition qca_securemessage.h:64
QCA::SecureMessageKey::PGP
@ PGP
Pretty Good Privacy key.
Definition qca_securemessage.h:63
QCA::SecureMessageSignature
SecureMessage signature.
Definition qca_securemessage.h:185
QCA::SecureMessageSignature::identityResult
IdentityResult identityResult() const
get the results of the identity check on this signature
QCA::SecureMessageSignature::IdentityResult
IdentityResult
The result of identity verification.
Definition qca_securemessage.h:191
QCA::SecureMessageSignature::NoKey
@ NoKey
identity unknown
Definition qca_securemessage.h:195
QCA::SecureMessageSignature::InvalidSignature
@ InvalidSignature
valid key provided, but signature failed
Definition qca_securemessage.h:193
QCA::SecureMessageSignature::Valid
@ Valid
indentity is verified, matches signature
Definition qca_securemessage.h:192
QCA::SecureMessageSignature::InvalidKey
@ InvalidKey
invalid key provided
Definition qca_securemessage.h:194
QCA::SecureMessageSignature::timestamp
QDateTime timestamp() const
get the timestamp associated with this signature
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::SecureMessageSignature::keyValidity
Validity keyValidity() const
get the results of the key validation check on this signature
QCA::SecureMessageSignature::SecureMessageSignature
SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts)
Create a signature check object.
QCA::SecureMessageSignature::SecureMessageSignature
SecureMessageSignature()
Create an empty signature check object.
QCA::SecureMessageSignature::SecureMessageSignature
SecureMessageSignature(const SecureMessageSignature &from)
Standard copy constructor.
QCA::SecureMessageSystem
Abstract superclass for secure messaging systems.
Definition qca_securemessage.h:803
QCA::SecureMessageSystem::SecureMessageSystem
SecureMessageSystem(QObject *parent, const QString &type, const QString &provider)
Protected constructor for SecureMessageSystem classes.
QCA::SecureMessage::success
bool success() const
Indicates whether or not the operation was successful or failed.
QCA::SecureMessage::reset
void reset()
Reset the object state to that of original construction.
QCA::SecureMessage::setRecipient
void setRecipient(const SecureMessageKey &key)
Set the recipient for an encrypted message.
QCA::SecureMessage::SecureMessage
SecureMessage(SecureMessageSystem *system)
Create a new secure message.
QCA::SecureMessage::signerKeys
SecureMessageKeyList signerKeys() const
Return the signer(s) set for this message with setSigner() or setSigners().
QCA::SecureMessage::recipientKeys
SecureMessageKeyList recipientKeys() const
Return the recipient(s) set for this message with setRecipient() or setRecipients().
QCA::SecureMessage::verifySuccess
bool verifySuccess() const
Verify that the message signature is correct.
QCA::SecureMessage::format
Format format() const
Return the format type set for this message.
QCA::SecureMessage::smimeAttributesEnabled
bool smimeAttributesEnabled() const
Returns true if inclusion of S/MIME attributes is enabled.
QCA::SecureMessage::signature
QByteArray signature() const
The signature for the message.
QCA::SecureMessage::Type
Type
The type of secure message.
Definition qca_securemessage.h:327
QCA::SecureMessage::CMS
@ CMS
a Cryptographic Message Syntax message
Definition qca_securemessage.h:329
QCA::SecureMessage::OpenPGP
@ OpenPGP
a Pretty Good Privacy message
Definition qca_securemessage.h:328
QCA::SecureMessage::waitForFinished
bool waitForFinished(int msecs=30000)
Block until the operation (encryption, decryption, signing or verifying) completes.
QCA::SecureMessage::setFormat
void setFormat(Format f)
Set the Format used for messages.
QCA::SecureMessage::startSign
void startSign(SignMode m=Message)
Start a signing operation.
QCA::SecureMessage::readyRead
void readyRead()
This signal is emitted when there is some data to read.
QCA::SecureMessage::signer
SecureMessageSignature signer() const
Information on the signer for the message.
QCA::SecureMessage::setSigner
void setSigner(const SecureMessageKey &key)
Set the signer for a signed message.
QCA::SecureMessage::diagnosticText
QString diagnosticText() const
Returns a log of technical information about the operation, which may be useful for presenting to the...
QCA::SecureMessage::startSignAndEncrypt
void startSignAndEncrypt()
Start a combined signing and encrypting operation.
QCA::SecureMessage::bytesAvailable
int bytesAvailable() const
The number of bytes available to be read.
QCA::SecureMessage::type
Type type() const
The Type of secure message.
QCA::SecureMessage::startVerify
void startVerify(const QByteArray &detachedSig=QByteArray())
Start a verification operation.
QCA::SecureMessage::read
QByteArray read()
Read the available data.
QCA::SecureMessage::setRecipients
void setRecipients(const SecureMessageKeyList &keys)
Set the list of recipients for an encrypted message.
QCA::SecureMessage::setBundleSignerEnabled
void setBundleSignerEnabled(bool b)
For CMS only, this will bundle the signer certificate chain into the message.
QCA::SecureMessage::canSignAndEncrypt
bool canSignAndEncrypt() const
True if the SecureMessageSystem can both sign and encrypt (in the same operation).
QCA::SecureMessage::Error
Error
Errors for secure messages.
Definition qca_securemessage.h:355
QCA::SecureMessage::ErrorSignatureExpired
@ ErrorSignatureExpired
signature is expired
Definition qca_securemessage.h:367
QCA::SecureMessage::ErrorSignerRevoked
@ ErrorSignerRevoked
signing key is revoked
Definition qca_securemessage.h:366
QCA::SecureMessage::ErrorUnknown
@ ErrorUnknown
other error
Definition qca_securemessage.h:365
QCA::SecureMessage::ErrorEncryptRevoked
@ ErrorEncryptRevoked
encrypting key is revoked
Definition qca_securemessage.h:368
QCA::SecureMessage::ErrorSignerExpired
@ ErrorSignerExpired
signing key is expired
Definition qca_securemessage.h:358
QCA::SecureMessage::ErrorEncryptExpired
@ ErrorEncryptExpired
encrypting key is expired
Definition qca_securemessage.h:360
QCA::SecureMessage::ErrorSignerInvalid
@ ErrorSignerInvalid
signing key is invalid in some way
Definition qca_securemessage.h:359
QCA::SecureMessage::ErrorEncryptUntrusted
@ ErrorEncryptUntrusted
encrypting key is untrusted
Definition qca_securemessage.h:361
QCA::SecureMessage::ErrorEncryptInvalid
@ ErrorEncryptInvalid
encrypting key is invalid in some way
Definition qca_securemessage.h:362
QCA::SecureMessage::ErrorCertKeyMismatch
@ ErrorCertKeyMismatch
certificate and private key don't match
Definition qca_securemessage.h:364
QCA::SecureMessage::ErrorFormat
@ ErrorFormat
input format was bad
Definition qca_securemessage.h:357
QCA::SecureMessage::ErrorPassphrase
@ ErrorPassphrase
passphrase was either wrong or not provided
Definition qca_securemessage.h:356
QCA::SecureMessage::ErrorNeedCard
@ ErrorNeedCard
pgp card is missing
Definition qca_securemessage.h:363
QCA::SecureMessage::end
void end()
Complete an operation.
QCA::SecureMessage::SignMode
SignMode
The type of message signature.
Definition qca_securemessage.h:336
QCA::SecureMessage::Message
@ Message
the message includes the signature
Definition qca_securemessage.h:337
QCA::SecureMessage::Clearsign
@ Clearsign
the message is clear signed
Definition qca_securemessage.h:338
QCA::SecureMessage::Detached
@ Detached
the signature is detached
Definition qca_securemessage.h:339
QCA::SecureMessage::bundleSignerEnabled
bool bundleSignerEnabled() const
Returns true if bundling of the signer certificate chain is enabled.
QCA::SecureMessage::canSignMultiple
bool canSignMultiple() const
Test if the message type supports multiple (parallel) signatures.
QCA::SecureMessage::signers
SecureMessageSignatureList signers() const
Information on the signers for the message.
QCA::SecureMessage::Format
Format
Formats for secure messages.
Definition qca_securemessage.h:346
QCA::SecureMessage::Binary
@ Binary
DER/binary.
Definition qca_securemessage.h:347
QCA::SecureMessage::Ascii
@ Ascii
PEM/ascii-armored.
Definition qca_securemessage.h:348
QCA::SecureMessage::finished
void finished()
This signal is emitted when the message is fully processed.
QCA::SecureMessage::errorCode
Error errorCode() const
Returns the failure code.
QCA::SecureMessage::wasSigned
bool wasSigned() const
Test if the message was signed.
QCA::SecureMessage::hashName
QString hashName() const
The name of the hash used for the signature process.
QCA::SecureMessage::startDecrypt
void startDecrypt()
Start an decryption operation.
QCA::SecureMessage::setSigners
void setSigners(const SecureMessageKeyList &keys)
Set the list of signers for a signed message.
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::SecureMessage::startEncrypt
void startEncrypt()
Start an encryption operation.
QCA::SecureMessage::bytesWritten
void bytesWritten(int bytes)
This signal is emitted when data has been accepted by the message processor.
QCA::SecureMessage::update
void update(const QByteArray &in)
Process a message (or the next part of a message) in the current operation.
QCA::SecureMessage::canClearsign
bool canClearsign() const
True if the SecureMessageSystem can clearsign messages.
QList
QObject
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::SecureMessageKeyList
QList< SecureMessageKey > SecureMessageKeyList
A list of message keys.
Definition qca_securemessage.h:175
QCA::Validity
Validity
The validity (or otherwise) of a certificate.
Definition qca_cert.h:497
qca_cert.h
Header file for PGP key and X.509 certificate related classes.
qca_core.h
Header file for core QCA infrastructure.
qca_publickey.h
Header file for PublicKey and PrivateKey related classes.