Merge #7703: tor: Change auth order to only use password auth if -torpassword

2e49448 tor: Change auth order to only use HASHEDPASSWORD if -torpassword (Wladimir J. van der Laan)
This commit is contained in:
Wladimir J. van der Laan 2016-06-08 13:09:01 +02:00
commit 761cddb690
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
1 changed files with 10 additions and 8 deletions

View File

@ -574,7 +574,15 @@ void TorController::protocolinfo_cb(TorControlConnection& conn, const TorControl
* password: "password" * password: "password"
*/ */
std::string torpassword = GetArg("-torpassword", ""); std::string torpassword = GetArg("-torpassword", "");
if (methods.count("NULL")) { if (!torpassword.empty()) {
if (methods.count("HASHEDPASSWORD")) {
LogPrint("tor", "tor: Using HASHEDPASSWORD authentication\n");
boost::replace_all(torpassword, "\"", "\\\"");
conn.Command("AUTHENTICATE \"" + torpassword + "\"", boost::bind(&TorController::auth_cb, this, _1, _2));
} else {
LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n");
}
} else if (methods.count("NULL")) {
LogPrint("tor", "tor: Using NULL authentication\n"); LogPrint("tor", "tor: Using NULL authentication\n");
conn.Command("AUTHENTICATE", boost::bind(&TorController::auth_cb, this, _1, _2)); conn.Command("AUTHENTICATE", boost::bind(&TorController::auth_cb, this, _1, _2));
} else if (methods.count("SAFECOOKIE")) { } else if (methods.count("SAFECOOKIE")) {
@ -595,13 +603,7 @@ void TorController::protocolinfo_cb(TorControlConnection& conn, const TorControl
} }
} }
} else if (methods.count("HASHEDPASSWORD")) { } else if (methods.count("HASHEDPASSWORD")) {
if (!torpassword.empty()) { LogPrintf("tor: The only supported authentication mechanism left is password, but no password provided with -torpassword\n");
LogPrint("tor", "tor: Using HASHEDPASSWORD authentication\n");
boost::replace_all(torpassword, "\"", "\\\"");
conn.Command("AUTHENTICATE \"" + torpassword + "\"", boost::bind(&TorController::auth_cb, this, _1, _2));
} else {
LogPrintf("tor: Password authentication required, but no password provided with -torpassword\n");
}
} else { } else {
LogPrintf("tor: No supported authentication method\n"); LogPrintf("tor: No supported authentication method\n");
} }