Qt Cryptographic Architecture: qca_securemessage.h Source File

Qt Cryptographic Architecture

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

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
70 SecureMessageKey();
71
77 SecureMessageKey(const SecureMessageKey &from);
78
79 ~SecureMessageKey();
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
175 typedef QList<SecureMessageKey> SecureMessageKeyList;
176
184 class QCA_EXPORT SecureMessageSignature
185 {
186 public:
190 enum IdentityResult
191 {
192 Valid,
193 InvalidSignature,
194 InvalidKey,
195 NoKey
196 };
197
204 SecureMessageSignature();
205
217 SecureMessageSignature(IdentityResult r, Validity v, const SecureMessageKey &key, const QDateTime &ts);
218
224 SecureMessageSignature(const SecureMessageSignature &from);
225
226 ~SecureMessageSignature();
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
263 typedef QList<SecureMessageSignature> SecureMessageSignatureList;
264
265
320 class QCA_EXPORT SecureMessage : public QObject, public Algorithm
321 {
322 Q_OBJECT
323 public:
327 enum Type
328 {
329 OpenPGP,
330 CMS
331 };
332
336 enum SignMode
337 {
338 Message,
339 Clearsign,
340 Detached
341 };
342
346 enum Format
347 {
348 Binary,
349 Ascii
350 };
351
355 enum Error
356 {
357 ErrorPassphrase,
358 ErrorFormat,
359 ErrorSignerExpired,
360 ErrorSignerInvalid,
361 ErrorEncryptExpired,
362 ErrorEncryptUntrusted,
363 ErrorEncryptInvalid,
364 ErrorNeedCard,
365 ErrorCertKeyMismatch,
366 ErrorUnknown,
367 ErrorSignerRevoked,
368 ErrorSignatureExpired,
369 ErrorEncryptRevoked
370 };
371
383 SecureMessage(SecureMessageSystem *system);
384 ~SecureMessage();
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
438 bool smimeAttributesEnabled() const;
439
443 Format format() const;
444
449 SecureMessageKeyList recipientKeys() const;
450
455 SecureMessageKeyList signerKeys() const;
456
468 void setBundleSignerEnabled(bool b);
469
480 void setSMIMEAttributesEnabled(bool b);
481
489 void setFormat(Format f);
490
498 void setRecipient(const SecureMessageKey &key);
499
509 void setRecipients(const SecureMessageKeyList &keys);
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
629 void startSignAndEncrypt();
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
741 SecureMessageSignature signer() const;
742
750 SecureMessageSignatureList signers() const;
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();
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 = 0, const QString &provider = QString());
852 ~OpenPGP();
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 = 0, const QString &provider = QString());
898 ~CMS();
899
903 CertificateCollection trustedCertificates() const;
904
908 CertificateCollection untrustedCertificates() const;
909
913 SecureMessageKeyList privateKeys() const;
914
922 void setTrustedCertificates(const CertificateCollection &trusted);
923
936 void setUntrustedCertificates(const CertificateCollection &untrusted);
937
947 void setPrivateKeys(const SecureMessageKeyList &keys);
948
949 private:
950 Q_DISABLE_COPY(CMS)
951
952 class Private;
953 Private *d;
954 };
955
956 }
957
958 #endif
QCA::SecureMessageSystem
Abstract superclass for secure messaging systems.
Definition: qca_securemessage.h:803
QCA::SecureMessage::OpenPGP
a Pretty Good Privacy message
Definition: qca_securemessage.h:329
QCA::SecureMessageKey::Type
Type
The key type.
Definition: qca_securemessage.h:60
QCA::Algorithm
General superclass for an algorithm.
Definition: qca_core.h:1121
QCA::SecureMessage::ErrorEncryptUntrusted
encrypting key is untrusted
Definition: qca_securemessage.h:362
QCA::SecureMessageSignature::Valid
indentity is verified, matches signature
Definition: qca_securemessage.h:192
QCA::SecureMessageSignature::IdentityResult
IdentityResult
The result of identity verification.
Definition: qca_securemessage.h:190
QCA::SecureMessageKey
Key for SecureMessage system.
Definition: qca_securemessage.h:54
QCA::PrivateKey
Generic private key.
Definition: qca_publickey.h:826
QCA::KeyBundle
Certificate chain and private key pair.
Definition: qca_cert.h:2135
qca_cert.h
Header file for PGP key and X.509 certificate related classes.
QCA::Validity
Validity
The validity (or otherwise) of a certificate.
Definition: qca_cert.h:489
qca_publickey.h
Header file for PublicKey and PrivateKey related classes.
QObject
QCA::SecureMessage::ErrorEncryptExpired
encrypting key is expired
Definition: qca_securemessage.h:361
QCA::SecureMessage::ErrorPassphrase
passphrase was either wrong or not provided
Definition: qca_securemessage.h:357
QCA::SecureMessage::ErrorFormat
input format was bad
Definition: qca_securemessage.h:358
QCA::SecureMessage::ErrorNeedCard
pgp card is missing
Definition: qca_securemessage.h:364
QCA::SecureMessage::ErrorSignerExpired
signing key is expired
Definition: qca_securemessage.h:359
QCA::SecureMessage::Type
Type
The type of secure message.
Definition: qca_securemessage.h:327
QCA::SecureMessage::Binary
DER/binary.
Definition: qca_securemessage.h:348
QCA::SecureMessage::ErrorSignatureExpired
signature is expired
Definition: qca_securemessage.h:368
QCA::SecureMessage::ErrorSignerInvalid
signing key is invalid in some way
Definition: qca_securemessage.h:360
QCA::SecureMessage::Error
Error
Errors for secure messages.
Definition: qca_securemessage.h:355
QCA::SecureMessageSignature::InvalidSignature
valid key provided, but signature failed
Definition: qca_securemessage.h:193
qca_core.h
Header file for core QCA infrastructure.
QCA::SecureMessageSignature::InvalidKey
invalid key provided
Definition: qca_securemessage.h:194
QCA::SecureMessage::ErrorCertKeyMismatch
certificate and private key don't match
Definition: qca_securemessage.h:365
QCA::SecureMessage::Format
Format
Formats for secure messages.
Definition: qca_securemessage.h:346
QCA
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:45
QCA::OpenPGP
Pretty Good Privacy messaging system.
Definition: qca_securemessage.h:840
QCA::SecureMessage::Clearsign
the message is clear signed
Definition: qca_securemessage.h:339
QCA::SecureMessageKey::PGP
Pretty Good Privacy key.
Definition: qca_securemessage.h:63
QCA::SecureMessageSignature
SecureMessage signature.
Definition: qca_securemessage.h:184
QCA::SecureMessageSignatureList
QList< SecureMessageSignature > SecureMessageSignatureList
A list of signatures.
Definition: qca_securemessage.h:263
QCA::CertificateChain
A chain of related Certificates.
Definition: qca_cert.h:1207
QCA::SecureMessage::ErrorSignerRevoked
signing key is revoked
Definition: qca_securemessage.h:367
QCA::SecureMessageKey::None
no key
Definition: qca_securemessage.h:62
QCA::SecureMessage::SignMode
SignMode
The type of message signature.
Definition: qca_securemessage.h:336
QCA::SecureMessage::ErrorUnknown
other error
Definition: qca_securemessage.h:366
QCA::SecureMessage::ErrorEncryptInvalid
encrypting key is invalid in some way
Definition: qca_securemessage.h:363
QCA::SecureMessage::Message
the message includes the signature
Definition: qca_securemessage.h:338
QCA::SecureMessageKeyList
QList< SecureMessageKey > SecureMessageKeyList
A list of message keys.
Definition: qca_securemessage.h:175
QCA::PGPKey
Pretty Good Privacy key.
Definition: qca_cert.h:2360
QCA::CertificateCollection
Bundle of Certificates and CRLs.
Definition: qca_cert.h:1890
QCA::SecureMessage
Class representing a secure message.
Definition: qca_securemessage.h:320
QCA::CMS
Cryptographic Message Syntax messaging system.
Definition: qca_securemessage.h:886
QList