GCC Code Coverage Report


Directory: ./
File: gnutls/include/pdcom5/SecureProcess.h
Date: 2024-02-26 09:07:35
Exec Total Coverage
Lines: 0 5 0.0%
Branches: 0 6 0.0%

Line Branch Exec Source
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
23 /** @file */
24
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
33 namespace PdCom {
34
35 /** Process implementation for TLS encrypted traffic.
36 *
37 * Please note that gnutls has some internal buffering,
38 * so please do not do some buffering on your own and also do not rely on
39 * flush(). Just write directly to the socket, as in
40 * PosixProcess::posixWriteDirect().
41 *
42 * \example gnutls_example.cpp
43 *
44 */
45 class PDCOM5_GNUTLS_EXPORT SecureProcess : public Process
46 {
47 public:
48 struct PDCOM5_GNUTLS_EXPORT EncryptionDetails
49 {
50 enum Flags {
51 Default = 0,
52 } flags_;
53 std::string server_ca_, server_hostname_, client_cert_, client_key_;
54
55 /** Struct which contains certificates and options */
56 EncryptionDetails(
57 Flags flags,
58 std::string server_ca,
59 std::string hostname,
60 std::string client_cert = "",
61 std::string client_key = "") :
62 flags_(flags),
63 server_ca_(server_ca),
64 server_hostname_(hostname),
65 client_cert_(client_cert),
66 client_key_(client_key)
67 {}
68 EncryptionDetails(
69 std::string server_ca,
70 std::string hostname,
71 std::string client_cert = "",
72 std::string client_key = "") :
73 flags_(Default),
74 server_ca_(server_ca),
75 server_hostname_(hostname),
76 client_cert_(client_cert),
77 client_key_(client_key)
78 {}
79 };
80
81 /** GnuTls global initialization.
82 *
83 * Call this at startup of your application to prepare the underlying TLS
84 * library.
85 *
86 * \throws PdCom::Exception Initialization failed.
87 */
88 static void InitLibrary();
89 /** GnuTls global finalization.
90 */
91 static void FinalizeLibrary();
92
93 explicit SecureProcess(EncryptionDetails const &);
94
95 /**
96 * calls Process::asyncData() until gnutls' buffers are empty.
97 */
98 void asyncData();
99
100 /** TLS Handshake.
101 * Start a TLS Session with the server. Call this until it returns true.
102 * \return True if successful, false if another call is needed.
103 * \throw TlsError Fatal Error occured.
104 */
105 bool handshake();
106 /** Close a TLS session */
107 void bye();
108
109 private:
110 struct PDCOM5_GNUTLS_NO_EXPORT Impl;
111
112 /**
113 * Gnutls does some buffering internally, so no need to flush.
114 */
115 void flush() override;
116 };
117
118 } // namespace PdCom
119
120 #endif // PDCOM5_SECUREPROCESS_H
121