| 1025 | } |
| 1026 | |
| 1027 | Status ServerNegotiation::RecvConnectionContext(faststring* recv_buf) { |
| 1028 | TRACE("Waiting for connection context"); |
| 1029 | RequestHeader header; |
| 1030 | Slice param_buf; |
| 1031 | RETURN_NOT_OK(ReceiveFramedMessageBlocking( |
| 1032 | socket_.get(), recv_buf, &header, ¶m_buf, deadline_)); |
| 1033 | DCHECK(header.IsInitialized()); |
| 1034 | |
| 1035 | if (header.call_id() != kConnectionContextCallId) { |
| 1036 | return Status::NotAuthorized("expected ConnectionContext callid, received", |
| 1037 | std::to_string(header.call_id())); |
| 1038 | } |
| 1039 | |
| 1040 | ConnectionContextPB conn_context; |
| 1041 | if (!conn_context.ParseFromArray(param_buf.data(), param_buf.size())) { |
| 1042 | return Status::NotAuthorized("invalid ConnectionContextPB message, missing fields", |
| 1043 | conn_context.InitializationErrorString()); |
| 1044 | } |
| 1045 | |
| 1046 | if (nonce_) { |
| 1047 | Status s; |
| 1048 | // Validate that the client returned the correct SASL protected nonce. |
| 1049 | if (!conn_context.has_encoded_nonce()) { |
| 1050 | return Status::NotAuthorized("ConnectionContextPB wrapped nonce missing"); |
| 1051 | } |
| 1052 | |
| 1053 | Slice decoded_nonce; |
| 1054 | s = SaslDecode(sasl_conn_.get(), conn_context.encoded_nonce(), &decoded_nonce); |
| 1055 | if (!s.ok()) { |
| 1056 | return Status::NotAuthorized("failed to decode nonce", s.message()); |
| 1057 | } |
| 1058 | |
| 1059 | if (*nonce_ != decoded_nonce) { |
| 1060 | Sockaddr addr; |
| 1061 | RETURN_NOT_OK(socket_->GetPeerAddress(&addr)); |
| 1062 | LOG(WARNING) << "Received an invalid connection nonce from client " |
| 1063 | << addr.ToString() |
| 1064 | << ", this could indicate a replay attack"; |
| 1065 | return Status::NotAuthorized("nonce mismatch"); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | return Status::OK(); |
| 1070 | } |
| 1071 | |
| 1072 | int ServerNegotiation::GetOptionCb(const char* plugin_name, |
| 1073 | const char* option, |
nothing calls this directly
no test coverage detected