| 572 | } |
| 573 | |
| 574 | void TorController::authchallenge_cb(TorControlConnection& _conn, const TorControlReply& reply) |
| 575 | { |
| 576 | if (reply.code == 250) { |
| 577 | LogPrint(BCLog::TOR, "tor: SAFECOOKIE authentication challenge successful\n"); |
| 578 | std::pair<std::string,std::string> l = SplitTorReplyLine(reply.lines[0]); |
| 579 | if (l.first == "AUTHCHALLENGE") { |
| 580 | std::map<std::string,std::string> m = ParseTorReplyMapping(l.second); |
| 581 | if (m.empty()) { |
| 582 | LogPrintf("tor: Error parsing AUTHCHALLENGE parameters: %s\n", SanitizeString(l.second)); |
| 583 | return; |
| 584 | } |
| 585 | std::vector<uint8_t> serverHash = ParseHex(m["SERVERHASH"]); |
| 586 | std::vector<uint8_t> serverNonce = ParseHex(m["SERVERNONCE"]); |
| 587 | LogPrint(BCLog::TOR, "tor: AUTHCHALLENGE ServerHash %s ServerNonce %s\n", HexStr(serverHash), HexStr(serverNonce)); |
| 588 | if (serverNonce.size() != 32) { |
| 589 | LogPrintf("tor: ServerNonce is not 32 bytes, as required by spec\n"); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | std::vector<uint8_t> computedServerHash = ComputeResponse(TOR_SAFE_SERVERKEY, cookie, clientNonce, serverNonce); |
| 594 | if (computedServerHash != serverHash) { |
| 595 | LogPrintf("tor: ServerHash %s does not match expected ServerHash %s\n", HexStr(serverHash), HexStr(computedServerHash)); |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | std::vector<uint8_t> computedClientHash = ComputeResponse(TOR_SAFE_CLIENTKEY, cookie, clientNonce, serverNonce); |
| 600 | _conn.Command("AUTHENTICATE " + HexStr(computedClientHash), boost::bind(&TorController::auth_cb, this, _1, _2)); |
| 601 | } else { |
| 602 | LogPrintf("tor: Invalid reply to AUTHCHALLENGE\n"); |
| 603 | } |
| 604 | } else { |
| 605 | LogPrintf("tor: SAFECOOKIE authentication challenge failed\n"); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorControlReply& reply) |
| 610 | { |
nothing calls this directly
no test coverage detected