diff options
Diffstat (limited to 'framework/src/domain/mime/crypto.h')
-rw-r--r-- | framework/src/domain/mime/crypto.h | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/framework/src/domain/mime/crypto.h b/framework/src/domain/mime/crypto.h new file mode 100644 index 00000000..fa79785a --- /dev/null +++ b/framework/src/domain/mime/crypto.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include "framework/src/errors.h" | ||
23 | |||
24 | #include <QByteArray> | ||
25 | #include <QVariant> | ||
26 | |||
27 | #include <functional> | ||
28 | #include <memory> | ||
29 | #include <gpgme.h> | ||
30 | #include <QDateTime> | ||
31 | |||
32 | namespace Crypto { | ||
33 | |||
34 | enum CryptoProtocol { | ||
35 | UnknownProtocol, | ||
36 | OpenPGP, | ||
37 | CMS | ||
38 | }; | ||
39 | |||
40 | |||
41 | struct UserId { | ||
42 | QByteArray name; | ||
43 | QByteArray email; | ||
44 | QByteArray id; | ||
45 | }; | ||
46 | |||
47 | struct Key { | ||
48 | QByteArray keyId; | ||
49 | QByteArray shortKeyId; | ||
50 | QByteArray fingerprint; | ||
51 | bool isExpired = false; | ||
52 | std::vector<UserId> userIds; | ||
53 | }; | ||
54 | |||
55 | struct Error { | ||
56 | gpgme_error_t error; | ||
57 | gpgme_err_code_t errorCode() const { | ||
58 | return gpgme_err_code(error); | ||
59 | } | ||
60 | operator bool() const | ||
61 | { | ||
62 | return error != GPG_ERR_NO_ERROR; | ||
63 | } | ||
64 | }; | ||
65 | |||
66 | struct Signature { | ||
67 | QByteArray fingerprint; | ||
68 | gpgme_sigsum_t summary; | ||
69 | Error status; | ||
70 | gpgme_validity_t validity; | ||
71 | gpgme_error_t validity_reason; | ||
72 | QDateTime creationTime; | ||
73 | }; | ||
74 | |||
75 | struct VerificationResult { | ||
76 | std::vector<Signature> signatures; | ||
77 | Error error; | ||
78 | }; | ||
79 | |||
80 | struct Recipient { | ||
81 | QByteArray keyId; | ||
82 | Error status; | ||
83 | }; | ||
84 | |||
85 | struct DecryptionResult { | ||
86 | std::vector<Recipient> recipients; | ||
87 | Error error; | ||
88 | }; | ||
89 | |||
90 | struct KeyListResult { | ||
91 | std::vector<Key> keys; | ||
92 | Error error; | ||
93 | }; | ||
94 | |||
95 | |||
96 | std::vector<Key> findKeys(const QStringList &filter, bool findPrivate = false, bool remote = false); | ||
97 | |||
98 | Expected<Error, QByteArray> exportPublicKey(const Key &key); | ||
99 | struct ImportResult { | ||
100 | int considered; | ||
101 | int imported; | ||
102 | int unchanged; | ||
103 | }; | ||
104 | ImportResult importKeys(CryptoProtocol protocol, const QByteArray &certData); | ||
105 | ImportResult importKey(const QByteArray &key); | ||
106 | |||
107 | /** | ||
108 | * Sign the given content and returns the signing data and the algorithm used | ||
109 | * for integrity check in the "pgp-<algorithm>" format. | ||
110 | */ | ||
111 | Expected<Error, std::pair<QByteArray, QString>> | ||
112 | sign(const QByteArray &content, const std::vector<Key> &signingKeys); | ||
113 | Expected<Error, QByteArray> signAndEncrypt(const QByteArray &content, const std::vector<Key> &encryptionKeys, const std::vector<Key> &signingKeys); | ||
114 | |||
115 | std::pair<DecryptionResult,VerificationResult> decryptAndVerify(CryptoProtocol protocol, const QByteArray &ciphertext, QByteArray &outdata); | ||
116 | VerificationResult verifyDetachedSignature(CryptoProtocol protocol, const QByteArray &signature, const QByteArray &outdata); | ||
117 | VerificationResult verifyOpaqueSignature(CryptoProtocol protocol, const QByteArray &signature, QByteArray &outdata); | ||
118 | }; | ||
119 | |||
120 | Q_DECLARE_METATYPE(Crypto::Key); | ||
121 | |||
122 | QDebug operator<< (QDebug d, const Crypto::Key &); | ||
123 | QDebug operator<< (QDebug d, const Crypto::Error &); | ||