commit 5a954b7a4cc2511ff9aa4a3153d5448f9037ce27 Author: Tomás Touceda chiiph@torproject.org Date: Fri May 25 19:02:23 2012 -0300
Check that Vidalia has authenticated before allowing sending any other ControlCommand --- changes/authenticated | 2 ++ src/torcontrol/TorControl.cpp | 21 ++++++++++++++++++++- src/torcontrol/TorControl.h | 5 +++++ 3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/changes/authenticated b/changes/authenticated new file mode 100644 index 0000000..905b6c7 --- /dev/null +++ b/changes/authenticated @@ -0,0 +1,2 @@ + Internal cleanups and improvements: + o Do not send ControlCommands if Vidalia haven't authenticated yet. \ No newline at end of file diff --git a/src/torcontrol/TorControl.cpp b/src/torcontrol/TorControl.cpp index fbf602d..84de11f 100644 --- a/src/torcontrol/TorControl.cpp +++ b/src/torcontrol/TorControl.cpp @@ -26,7 +26,7 @@
/** Default constructor */ TorControl::TorControl(ControlMethod::Method method) - : QObject(), _shouldContinue(true), _reason("") { + : QObject(), _shouldContinue(true), _reason(""), _authenticated(false) { #define RELAY_SIGNAL(src, sig) \ QObject::connect((src), (sig), this, (sig))
@@ -266,6 +266,7 @@ TorControl::disconnect() { if (isConnected()) _controlConn->disconnect(); + _authenticated = false; }
/** Emits the proper bootstrapStatusChanged */ @@ -330,6 +331,15 @@ TorControl::isConnected() bool TorControl::send(ControlCommand cmd, ControlReply &reply, QString *errmsg) { + if (!_authenticated and (cmd.keyword() != "AUTHENTICATE") and + (cmd.keyword() != "PROTOCOLINFO") and + (cmd.keyword() != "QUIT")) { + if (errmsg) + *errmsg = "TorControl not authenticated"; + + return false; + } + if (_controlConn->send(cmd, reply, errmsg)) { if (reply.getStatus() == "250") { return true; @@ -397,6 +407,8 @@ TorControl::authenticate(const QString &password, QString *errmsg) void TorControl::onAuthenticated() { + _authenticated = true; + /* The version of Tor isn't going to change while we're connected to it, so * save it for later. */ getInfo("version", _torVersion); @@ -410,6 +422,13 @@ TorControl::onAuthenticated() emit authenticated(); }
+/** Returns true if the process has passed through auth successfully */ +bool +TorControl::isAuthenticated() +{ + return _authenticated; +} + /** Sends a PROTOCOLINFO command to Tor and parses the response. */ ProtocolInfo TorControl::protocolInfo(QString *errmsg) diff --git a/src/torcontrol/TorControl.h b/src/torcontrol/TorControl.h index 3c5f6d7..ec91679 100644 --- a/src/torcontrol/TorControl.h +++ b/src/torcontrol/TorControl.h @@ -81,6 +81,8 @@ public: bool authenticate(const QByteArray cookie, QString *errmsg = 0); /** Sends an authentication password to Tor. */ bool authenticate(const QString &password = QString(), QString *errmsg = 0); + /** Returns true if the process has passed through auth successfully */ + bool isAuthenticated();
/** Sends a PROTOCOLINFO command to Tor and parses the response. */ ProtocolInfo protocolInfo(QString *errmsg = 0); @@ -413,6 +415,9 @@ private: bool _shouldContinue; QString _reason;
+ /** True when the process has passed through the auth successfully */ + bool _authenticated; + /** Send a message to Tor and read the response */ bool send(ControlCommand cmd, ControlReply &reply, QString *errmsg = 0); /** Send a message to Tor and discard the response */
tor-commits@lists.torproject.org