| 607 | } |
| 608 | |
| 609 | void TorController::authchallenge_cb(TorControlConnection& _conn, const TorControlReply& reply) |
| 610 | { |
| 611 | if (reply.code == TOR_REPLY_OK) { |
| 612 | LogDebug(BCLog::TOR, "SAFECOOKIE authentication challenge successful"); |
| 613 | if (reply.lines.empty()) { |
| 614 | LogWarning("tor: AUTHCHALLENGE reply was empty"); |
| 615 | return; |
| 616 | } |
| 617 | std::pair<std::string,std::string> l = SplitTorReplyLine(reply.lines[0]); |
| 618 | if (l.first == "AUTHCHALLENGE") { |
| 619 | std::map<std::string,std::string> m = ParseTorReplyMapping(l.second); |
| 620 | if (m.empty()) { |
| 621 | LogWarning("tor: Error parsing AUTHCHALLENGE parameters: %s", SanitizeString(l.second)); |
| 622 | return; |
| 623 | } |
| 624 | std::vector<uint8_t> server_hash = ParseHex(m["SERVERHASH"]); |
| 625 | std::vector<uint8_t> server_nonce = ParseHex(m["SERVERNONCE"]); |
| 626 | LogDebug(BCLog::TOR, "AUTHCHALLENGE ServerHash %s ServerNonce %s", HexStr(server_hash), HexStr(server_nonce)); |
| 627 | if (server_nonce.size() != 32) { |
| 628 | LogWarning("tor: ServerNonce is not 32 bytes, as required by spec"); |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | std::vector<uint8_t> computed_server_hash = ComputeResponse(TOR_SAFE_SERVERKEY, m_cookie, m_client_nonce, server_nonce); |
| 633 | if (computed_server_hash != server_hash) { |
| 634 | LogWarning("tor: ServerHash %s does not match expected ServerHash %s", HexStr(server_hash), HexStr(computed_server_hash)); |
| 635 | return; |
| 636 | } |
| 637 | |
| 638 | std::vector<uint8_t> computedClientHash = ComputeResponse(TOR_SAFE_CLIENTKEY, m_cookie, m_client_nonce, server_nonce); |
| 639 | _conn.Command("AUTHENTICATE " + HexStr(computedClientHash), std::bind_front(&TorController::auth_cb, this)); |
| 640 | } else { |
| 641 | LogWarning("tor: Invalid reply to AUTHCHALLENGE"); |
| 642 | } |
| 643 | } else { |
| 644 | LogWarning("tor: SAFECOOKIE authentication challenge failed"); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorControlReply& reply) |
| 649 | { |
no test coverage detected