/src/curl_fuzzer/proto_fuzzer/ldaps_mock_server.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | /// @file |
8 | | /// @brief Implementation of the implicit-TLS LDAP peer. |
9 | | |
10 | | #include "proto_fuzzer/ldaps_mock_server.h" |
11 | | |
12 | | #include <cstddef> |
13 | | #include <memory> |
14 | | #include <string> |
15 | | |
16 | | #include "proto_fuzzer/mock_server.h" |
17 | | |
18 | | namespace proto_fuzzer { |
19 | | |
20 | | /// Construct the OpenSSL server carrier used by every LDAPS scenario. LDAP |
21 | | /// sends no ALPN extension, so the closed HTTP/1.1 default is never selected |
22 | | /// and the handshake completes without an application protocol. |
23 | 2.93k | LdapsMockServer::LdapsMockServer() : transport_(TlsApplicationProtocol::kHttp11) {} |
24 | | |
25 | | /// Release the TLS connection before the carrier-owned server context. The |
26 | | /// inherited BER parser holds no transport state of its own. |
27 | 2.93k | LdapsMockServer::~LdapsMockServer() { connection_.reset(); } |
28 | | |
29 | | /// Install the shared socket callbacks and a stable local trust anchor. Curl |
30 | | /// copies the blob descriptor during setopt and borrows the inline certificate |
31 | | /// bytes, whose program lifetime safely exceeds every easy handle. Scenario |
32 | | /// options run afterwards and can still disable verification. |
33 | | /// @param easy Easy handle that will initiate the LDAPS exchange. |
34 | 2.92k | void LdapsMockServer::Install(CURL* easy) { |
35 | 2.92k | LdapMockServer::Install(easy); |
36 | 2.92k | transport_.Install(easy); |
37 | 2.92k | } |
38 | | |
39 | | /// Wrap one socketpair endpoint in an OpenSSL acceptor. The inherited BER loop |
40 | | /// advances the handshake and then parses only decrypted LDAPMessages. |
41 | | /// @return Newly allocated nonblocking TLS connection. |
42 | 2.64k | std::unique_ptr<MockConnection> LdapsMockServer::CreateConnection() { return transport_.CreateConnection(); } |
43 | | |
44 | | /// @return Protocol version selected by the most recent handshake, or zero. |
45 | 2.92k | int LdapsMockServer::negotiated_tls_version() const { return transport_.negotiated_tls_version(); } |
46 | | |
47 | | /// @return Number of connections that completed TLS negotiation. |
48 | 2.92k | std::size_t LdapsMockServer::completed_handshake_count() const { return transport_.completed_handshake_count(); } |
49 | | |
50 | | /// @return ALPN protocol selected by curl, or an empty string when absent. |
51 | 2.92k | std::string LdapsMockServer::negotiated_alpn() const { return transport_.negotiated_alpn(); } |
52 | | |
53 | | } // namespace proto_fuzzer |