Coverage Report

Created: 2020-05-23 13:54

/src/botan/build/include/botan/tls_client.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* TLS Client
3
* (C) 2004-2011 Jack Lloyd
4
*     2016 Matthias Gierlings
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8
9
#ifndef BOTAN_TLS_CLIENT_H_
10
#define BOTAN_TLS_CLIENT_H_
11
12
#include <botan/tls_channel.h>
13
#include <botan/tls_policy.h>
14
#include <botan/credentials_manager.h>
15
#include <vector>
16
17
namespace Botan {
18
19
namespace TLS {
20
21
/**
22
* SSL/TLS Client
23
*/
24
class BOTAN_PUBLIC_API(2,0) Client final : public Channel
25
   {
26
   public:
27
28
      /**
29
      * Set up a new TLS client session
30
      *
31
      * @param callbacks contains a set of callback function references
32
      *        required by the TLS client.
33
      *
34
      * @param session_manager manages session state
35
      *
36
      * @param creds manages application/user credentials
37
      *
38
      * @param policy specifies other connection policy information
39
      *
40
      * @param rng a random number generator
41
      *
42
      * @param server_info is identifying information about the TLS server
43
      *
44
      * @param offer_version specifies which version we will offer
45
      *        to the TLS server.
46
      *
47
      * @param next_protocols specifies protocols to advertise with ALPN
48
      *
49
      * @param reserved_io_buffer_size This many bytes of memory will
50
      *        be preallocated for the read and write buffers. Smaller
51
      *        values just mean reallocations and copies are more likely.
52
      */
53
     Client(Callbacks& callbacks,
54
            Session_Manager& session_manager,
55
            Credentials_Manager& creds,
56
            const Policy& policy,
57
            RandomNumberGenerator& rng,
58
            const Server_Information& server_info = Server_Information(),
59
            const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(),
60
            const std::vector<std::string>& next_protocols = {},
61
            size_t reserved_io_buffer_size = TLS::Client::IO_BUF_DEFAULT_SIZE
62
         );
63
64
      /**
65
      * DEPRECATED. This constructor is only provided for backward
66
      * compatibility and should not be used in new code. It will be
67
      * removed in a future release.
68
      *
69
      * Set up a new TLS client session
70
      *
71
      * @param data_output_fn is called with data for the outbound socket
72
      *
73
      * @param app_data_cb is called when new application data is received
74
      *
75
      * @param recv_alert_cb is called when a TLS alert is received
76
      *
77
      * @param hs_cb is called when a handshake is completed
78
      *
79
      * @param session_manager manages session state
80
      *
81
      * @param creds manages application/user credentials
82
      *
83
      * @param policy specifies other connection policy information
84
      *
85
      * @param rng a random number generator
86
      *
87
      * @param server_info is identifying information about the TLS server
88
      *
89
      * @param offer_version specifies which version we will offer
90
      *        to the TLS server.
91
      *
92
      * @param next_protocols specifies protocols to advertise with ALPN
93
      *
94
      * @param reserved_io_buffer_size This many bytes of memory will
95
      *        be preallocated for the read and write buffers. Smaller
96
      *        values just mean reallocations and copies are more likely.
97
      */
98
      BOTAN_DEPRECATED("Use TLS::Client(TLS::Callbacks ...)")
99
      Client(output_fn data_output_fn,
100
             data_cb app_data_cb,
101
             alert_cb recv_alert_cb,
102
             handshake_cb hs_cb,
103
             Session_Manager& session_manager,
104
             Credentials_Manager& creds,
105
             const Policy& policy,
106
             RandomNumberGenerator& rng,
107
             const Server_Information& server_info = Server_Information(),
108
             const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(),
109
             const std::vector<std::string>& next_protocols = {},
110
             size_t reserved_io_buffer_size = TLS::Client::IO_BUF_DEFAULT_SIZE
111
         );
112
113
      /**
114
       * DEPRECATED. This constructor is only provided for backward
115
       * compatibility and should not be used in new implementations.
116
       */
117
      BOTAN_DEPRECATED("Use TLS::Client(TLS::Callbacks ...)")
118
      Client(output_fn out,
119
             data_cb app_data_cb,
120
             alert_cb alert_cb,
121
             handshake_cb hs_cb,
122
             handshake_msg_cb hs_msg_cb,
123
             Session_Manager& session_manager,
124
             Credentials_Manager& creds,
125
             const Policy& policy,
126
             RandomNumberGenerator& rng,
127
             const Server_Information& server_info = Server_Information(),
128
             const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(),
129
             const std::vector<std::string>& next_protocols = {}
130
         );
131
132
      /**
133
      * @return network protocol as advertised by the TLS server, if server sent the ALPN extension
134
      */
135
0
      std::string application_protocol() const override { return m_application_protocol; }
136
   private:
137
      void init(const Protocol_Version& protocol_version,
138
                const std::vector<std::string>& next_protocols);
139
140
      std::vector<X509_Certificate>
141
         get_peer_cert_chain(const Handshake_State& state) const override;
142
143
      void initiate_handshake(Handshake_State& state,
144
                              bool force_full_renegotiation) override;
145
146
      void send_client_hello(Handshake_State& state,
147
                             bool force_full_renegotiation,
148
                             Protocol_Version version,
149
                             const std::string& srp_identifier = "",
150
                             const std::vector<std::string>& next_protocols = {});
151
152
      void process_handshake_msg(const Handshake_State* active_state,
153
                                 Handshake_State& pending_state,
154
                                 Handshake_Type type,
155
                                 const std::vector<uint8_t>& contents,
156
                                 bool epoch0_restart) override;
157
158
      Handshake_State* new_handshake_state(Handshake_IO* io) override;
159
160
      Credentials_Manager& m_creds;
161
      const Server_Information m_info;
162
      std::string m_application_protocol;
163
   };
164
165
}
166
167
}
168
169
#endif