MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / authchallenge_cb

Method authchallenge_cb

src/torcontrol.cpp:609–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

607}
608
609void 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
648void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorControlReply& reply)
649{

Callers 1

torcontrol.cppFile · 0.80

Calls 9

SplitTorReplyLineFunction · 0.85
ParseTorReplyMappingFunction · 0.85
SanitizeStringFunction · 0.85
ParseHexFunction · 0.85
ComputeResponseFunction · 0.85
CommandMethod · 0.80
HexStrFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected