| 77 | }; |
| 78 | |
| 79 | Status DoNegotiationSide(Socket* sock, TlsHandshake* tls, const char* side) { |
| 80 | tls->set_verification_mode(TlsVerificationMode::VERIFY_NONE); |
| 81 | |
| 82 | bool done = false; |
| 83 | string received; |
| 84 | while (!done) { |
| 85 | string to_send; |
| 86 | Status s = tls->Continue(received, &to_send); |
| 87 | if (s.ok()) { |
| 88 | done = true; |
| 89 | } else if (!s.IsIncomplete()) { |
| 90 | RETURN_NOT_OK_PREPEND(s, "unexpected tls error"); |
| 91 | } |
| 92 | if (!to_send.empty()) { |
| 93 | size_t nwritten; |
| 94 | auto deadline = MonoTime::Now() + MonoDelta::FromSeconds(10); |
| 95 | RETURN_NOT_OK_PREPEND(sock->BlockingWrite( |
| 96 | reinterpret_cast<const uint8_t*>(to_send.data()), |
| 97 | to_send.size(), &nwritten, deadline), |
| 98 | "error sending"); |
| 99 | } |
| 100 | |
| 101 | if (!done) { |
| 102 | uint8_t buf[1024]; |
| 103 | int32_t n = 0; |
| 104 | RETURN_NOT_OK_PREPEND(sock->Recv(buf, arraysize(buf), &n), |
| 105 | "error receiving"); |
| 106 | received = string(reinterpret_cast<char*>(&buf[0]), n); |
| 107 | } |
| 108 | } |
| 109 | LOG(INFO) << side << ": negotiation complete"; |
| 110 | return Status::OK(); |
| 111 | } |
| 112 | |
| 113 | void TlsSocketTest::ConnectClient(const Sockaddr& addr, unique_ptr<Socket>* sock) { |
| 114 | unique_ptr<Socket> client_sock(new Socket()); |
no test coverage detected