| 76 | } |
| 77 | |
| 78 | std::string HandshakeWithServer(std::vector<std::string> alpns) { |
| 79 | // Init client ssl ctx and set alpn. |
| 80 | brpc::ChannelSSLOptions options; |
| 81 | SSL_CTX* ssl_ctx = brpc::CreateClientSSLContext(options); |
| 82 | EXPECT_NE(nullptr, ssl_ctx); |
| 83 | |
| 84 | std::string raw_alpn; |
| 85 | for (auto&& alpn : alpns) { |
| 86 | raw_alpn.append(brpc::ALPNProtocolToString(brpc::AdaptiveProtocolType(alpn))); |
| 87 | } |
| 88 | SSL_CTX_set_alpn_protos(ssl_ctx, |
| 89 | reinterpret_cast<const unsigned char*>(raw_alpn.data()), raw_alpn.size()); |
| 90 | |
| 91 | // TCP connect. |
| 92 | butil::EndPoint endpoint; |
| 93 | butil::str2endpoint(FLAGS_listen_addr.data(), &endpoint); |
| 94 | |
| 95 | int cli_fd = butil::tcp_connect(endpoint, nullptr); |
| 96 | butil::fd_guard guard(cli_fd); |
| 97 | EXPECT_NE(0, cli_fd); |
| 98 | |
| 99 | // SSL handshake. |
| 100 | SSL* ssl = brpc::CreateSSLSession(ssl_ctx, 0, cli_fd, false); |
| 101 | EXPECT_NE(nullptr, ssl); |
| 102 | EXPECT_EQ(1, SSL_do_handshake(ssl)); |
| 103 | |
| 104 | // Get handshake result. |
| 105 | const unsigned char* select_alpn = nullptr; |
| 106 | unsigned int len = 0; |
| 107 | SSL_get0_alpn_selected(ssl, &select_alpn, &len); |
| 108 | return std::string(reinterpret_cast<const char*>(select_alpn), len); |
| 109 | } |
| 110 | |
| 111 | private: |
| 112 | brpc::Server _server; |
nothing calls this directly
no test coverage detected