PdCom  5.0
Process data communication client
Loading...
Searching...
No Matches
SecureProcess.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vim:tw=78
3 *
4 * Copyright (C) 2021 Bjarne von Horn (vh at igh dot de).
5 *
6 * This file is part of the PdCom library.
7 *
8 * The PdCom library is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * The PdCom library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 * License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
20 *
21 *****************************************************************************/
22
25#ifndef PDCOM5_SECUREPROCESS_H
26#define PDCOM5_SECUREPROCESS_H
27
28#include "pdcom5-gnutls_export.h"
29
30#include <memory>
31#include <pdcom5/Process.h>
32
33namespace PdCom {
34
40class PDCOM5_GNUTLS_EXPORT SecureProcess : public Process
41{
42 public:
43 struct PDCOM5_GNUTLS_EXPORT EncryptionDetails
44 {
45 enum Flags {
46 Default = 0,
47 } flags_;
48 std::string server_ca_, server_hostname_, client_cert_, client_key_;
49
52 Flags flags,
53 std::string server_ca,
54 std::string hostname,
55 std::string client_cert = "",
56 std::string client_key = "") :
57 flags_(flags),
58 server_ca_(server_ca),
59 server_hostname_(hostname),
60 client_cert_(client_cert),
61 client_key_(client_key)
62 {}
64 std::string server_ca,
65 std::string hostname,
66 std::string client_cert = "",
67 std::string client_key = "") :
68 flags_(Default),
69 server_ca_(server_ca),
70 server_hostname_(hostname),
71 client_cert_(client_cert),
72 client_key_(client_key)
73 {}
74 };
75
83 static void InitLibrary();
86 static void FinalizeLibrary();
87
88 SecureProcess() = default;
89 explicit SecureProcess(EncryptionDetails const &);
90 SecureProcess(SecureProcess &&) noexcept;
91 SecureProcess &operator=(SecureProcess &&) noexcept;
92
98 bool handshake();
100 void bye();
101
102 private:
103 struct Impl;
104 std::shared_ptr<Impl> secure_impl_;
105 void write(const char *buf, size_t count) final;
106 int read(char *buf, int count) final;
107 void flush() final;
119 virtual int secureRead(char *buf, int count) = 0;
128 virtual void secureWrite(const char *buf, size_t count) = 0;
129};
130
131} // namespace PdCom
132
133#endif // PDCOM5_SECUREPROCESS_H
Base class for PdCom protocol handler.
Definition: Process.h:84
Definition: SecureProcess.h:41
static void FinalizeLibrary()
GnuTls global finalization.
static void InitLibrary()
GnuTls global initialization.
library version string as "major.minor.patch"
Definition: ClientStatistics.h:31
Definition: SecureProcess.h:44
EncryptionDetails(Flags flags, std::string server_ca, std::string hostname, std::string client_cert="", std::string client_key="")
Struct which contains certificates and options.
Definition: SecureProcess.h:51