summaryrefslogtreecommitdiffstats
path: root/wsrep-lib/include/wsrep/tls_service.hpp
blob: 07d20642895e87e70c89229848b65b8bf09a8450 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2020 Codership Oy <info@codership.com>
 *
 * This file is part of wsrep-lib.
 *
 * Wsrep-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Wsrep-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
 */


/** @file tls_service.hpp
 *
 * Service interface for interacting with DBMS provided
 * TLS and encryption facilities.
 */

#ifndef WSREP_TLS_SERVICE_HPP
#define WSREP_TLS_SERVICE_HPP

#include "compiler.hpp"

#include <sys/types.h> // ssize_t

namespace wsrep
{

    /* Type tags for TLS context and TLS stream. */
    struct tls_context { };
    struct tls_stream { };

    /** @class tls_service
     *
     * TLS service interface. This provides an interface corresponding
     * to wsrep-API TLS service. For details see wsrep-API/wsrep_tls_service.h
     */
    class tls_service
    {
    public:
        enum status
        {
            success = 0,
            want_read,
            want_write,
            eof,
            error
        };

        struct op_result
        {
            /** Status code of the operation of negative system error number. */
            ssize_t status;
            /** Bytes transferred from/to given buffer during the operation. */
            size_t bytes_transferred;
        };

        virtual ~tls_service() { }
        /**
         * @return Zero on success, system error code on failure.
         */
        virtual tls_stream* create_tls_stream(int fd) WSREP_NOEXCEPT = 0;
        virtual void destroy(tls_stream*) WSREP_NOEXCEPT = 0;

        virtual int get_error_number(const tls_stream*) const WSREP_NOEXCEPT = 0;
        virtual const void* get_error_category(const tls_stream*) const WSREP_NOEXCEPT = 0;
        virtual const char* get_error_message(const tls_stream*,
                                              int value, const void* category)
            const WSREP_NOEXCEPT = 0;
        /**
         * @return Status enum.
         */
        virtual status client_handshake(tls_stream*) WSREP_NOEXCEPT = 0;

        /**
         * @return Status enum or negative error code.
         */
        virtual status server_handshake(tls_stream*) WSREP_NOEXCEPT = 0;

        /**
         * Read at most max_count bytes into buf.
         */
        virtual op_result read(tls_stream*,
                               void* buf, size_t max_count) WSREP_NOEXCEPT = 0;

        /**
         * Write at most count bytes from buf.
         */
        virtual op_result write(tls_stream*,
                                const void* buf, size_t count) WSREP_NOEXCEPT = 0;

        /**
         * Shutdown TLS stream.
         */
        virtual status shutdown(tls_stream*) WSREP_NOEXCEPT = 0;
    };
}

#endif // WSREP_TLS_SERVICE_HPP