summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mime/crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/mime/crypto.h')
-rw-r--r--framework/src/domain/mime/crypto.h123
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
32namespace Crypto {
33
34enum CryptoProtocol {
35 UnknownProtocol,
36 OpenPGP,
37 CMS
38};
39
40
41struct UserId {
42 QByteArray name;
43 QByteArray email;
44 QByteArray id;
45};
46
47struct Key {
48 QByteArray keyId;
49 QByteArray shortKeyId;
50 QByteArray fingerprint;
51 bool isExpired = false;
52 std::vector<UserId> userIds;
53};
54
55struct 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
66struct 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
75struct VerificationResult {
76 std::vector<Signature> signatures;
77 Error error;
78};
79
80struct Recipient {
81 QByteArray keyId;
82 Error status;
83};
84
85struct DecryptionResult {
86 std::vector<Recipient> recipients;
87 Error error;
88};
89
90struct KeyListResult {
91 std::vector<Key> keys;
92 Error error;
93};
94
95
96std::vector<Key> findKeys(const QStringList &filter, bool findPrivate = false, bool remote = false);
97
98Expected<Error, QByteArray> exportPublicKey(const Key &key);
99struct ImportResult {
100 int considered;
101 int imported;
102 int unchanged;
103};
104ImportResult importKeys(CryptoProtocol protocol, const QByteArray &certData);
105ImportResult 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 */
111Expected<Error, std::pair<QByteArray, QString>>
112sign(const QByteArray &content, const std::vector<Key> &signingKeys);
113Expected<Error, QByteArray> signAndEncrypt(const QByteArray &content, const std::vector<Key> &encryptionKeys, const std::vector<Key> &signingKeys);
114
115std::pair<DecryptionResult,VerificationResult> decryptAndVerify(CryptoProtocol protocol, const QByteArray &ciphertext, QByteArray &outdata);
116VerificationResult verifyDetachedSignature(CryptoProtocol protocol, const QByteArray &signature, const QByteArray &outdata);
117VerificationResult verifyOpaqueSignature(CryptoProtocol protocol, const QByteArray &signature, QByteArray &outdata);
118};
119
120Q_DECLARE_METATYPE(Crypto::Key);
121
122QDebug operator<< (QDebug d, const Crypto::Key &);
123QDebug operator<< (QDebug d, const Crypto::Error &);