[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1845: Add support for authenticating based on a cookie or a passwo (in trunk: . src/control src/gui/network)
Author: edmanm
Date: 2007-08-21 00:34:06 -0400 (Tue, 21 Aug 2007)
New Revision: 1845
Modified:
trunk/
trunk/src/control/torcontrol.cpp
trunk/src/control/torcontrol.h
trunk/src/gui/network/netviewer.cpp
trunk/src/gui/network/netviewer.h
Log:
r2006@adrastea: edmanm | 2007-08-21 00:03:42 -0400
Add support for authenticating based on a cookie or a password; add
authenticated() and authenticationFailed(QString) signals; and, only try to
load servers and such on the network map when we've really authenticated.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r2006] on 54b3572a-7227-0410-958f-53ecd705b71a
Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp 2007-08-21 04:33:57 UTC (rev 1844)
+++ trunk/src/control/torcontrol.cpp 2007-08-21 04:34:06 UTC (rev 1845)
@@ -236,25 +236,8 @@
void
TorControl::onConnected()
{
- QString errmsg;
-
- /* Authenticate and register for any pertinent asynchronous events. */
- if (!authenticate(&errmsg) || !setEvents(&errmsg)) {
- emit connectFailed(errmsg);
- stop();
- return;
- }
- /* The control socket is connected, so we can stop reading from stdout */
- if (_torProcess) {
- _torProcess->closeStdout();
- }
- /* The version of Tor isn't going to change while we're connected to it, so
- * save it for later. */
- getInfo("version", _torVersion);
-
/* Let interested parties know that the control socket connected */
emit connected();
- emit connected(true);
}
/** Emits a signal that the control connection to Tor failed. */
@@ -268,9 +251,8 @@
void
TorControl::disconnect()
{
- if (isConnected()) {
+ if (isConnected())
_controlConn->disconnect();
- }
}
/** Emits a signal that the control socket disconnected from Tor */
@@ -288,7 +270,6 @@
/* Let interested parties know we lost our control connection */
emit disconnected();
- emit connected(false);
if (!isVidaliaRunningTor()) {
/* If we're not running our own Tor, then we interpret the closing of
@@ -331,19 +312,59 @@
return send(cmd, reply, errmsg);
}
-/** Sends an authentication token to Tor. This must be done before sending
- * any control commands to Tor. The syntax is:
+/** Sends an authentication cookie to Tor. The syntax is:
*
- * "AUTHENTICATE" [ SP 1*HEXDIG / QuotedString ] CRLF
+ * "AUTHENTICATE" SP 1*HEXDIG CRLF
*/
bool
-TorControl::authenticate(QString *errmsg)
+TorControl::authenticate(const QByteArray cookie, QString *errmsg)
{
- TorSettings settings;
- ControlCommand cmd("AUTHENTICATE", QString(settings.getAuthToken()));
- return send(cmd, errmsg);
+ ControlCommand cmd("AUTHENTICATE", base16_encode(cookie));
+ ControlReply reply;
+ QString str;
+
+ if (!send(cmd, reply, &str)) {
+ emit authenticationFailed(str);
+ return err(errmsg, str);
+ }
+ onAuthenticated();
+ return true;
}
+/** Sends an authentication password to Tor. The syntax is:
+ *
+ * "AUTHENTICATE" SP QuotedString CRLF
+ */
+bool
+TorControl::authenticate(const QString password, QString *errmsg)
+{
+ ControlCommand cmd("AUTHENTICATE", QString("\"%1\"").arg(password));
+ ControlReply reply;
+ QString str;
+
+ if (!send(cmd, reply, &str)) {
+ emit authenticationFailed(str);
+ return err(errmsg, str);
+ }
+ onAuthenticated();
+ return true;
+}
+
+/** Called when the controller has successfully authenticated to Tor. */
+void
+TorControl::onAuthenticated()
+{
+ /* The version of Tor isn't going to change while we're connected to it, so
+ * save it for later. */
+ getInfo("version", _torVersion);
+
+ /* The control socket is connected, so we can stop reading from stdout */
+ if (_torProcess)
+ _torProcess->closeStdout();
+
+ emit authenticated();
+}
+
/** Sends a GETINFO message to Tor based on the given map of keyvals. The
* syntax is:
*
Modified: trunk/src/control/torcontrol.h
===================================================================
--- trunk/src/control/torcontrol.h 2007-08-21 04:33:57 UTC (rev 1844)
+++ trunk/src/control/torcontrol.h 2007-08-21 04:34:06 UTC (rev 1845)
@@ -70,8 +70,10 @@
void disconnect();
/** Check if we're connected to Tor's control socket */
bool isConnected();
- /** Sends an authentication token to Tor */
- bool authenticate(QString *errmsg = 0);
+ /** Sends an authentication cookie to Tor. */
+ bool authenticate(const QByteArray cookie, QString *errmsg = 0);
+ /** Sends an authentication password to Tor. */
+ bool authenticate(const QString password = QString(), QString *errmsg = 0);
/** Sends a GETINFO message to Tor based on the given keys */
bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0);
@@ -176,8 +178,10 @@
void connectFailed(QString errmsg);
/** Emitted when the controller has disconnected from Tor */
void disconnected();
- /** Emitted when the connection status changes. */
- void connected(bool connected);
+ /** Emitted when the control socket is connected and authenticated. */
+ void authenticated();
+ /** Emitted when Tor rejects our authentication attempt. */
+ void authenticationFailed(QString errmsg);
private:
/** Instantiates a connection used to talk to Tor's control port */
@@ -209,6 +213,7 @@
void onConnectFailed(QString errmsg);
void onDisconnected();
void onLogStdout(QString severity, QString message);
+ void onAuthenticated();
};
#endif
Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp 2007-08-21 04:33:57 UTC (rev 1844)
+++ trunk/src/gui/network/netviewer.cpp 2007-08-21 04:34:06 UTC (rev 1845)
@@ -116,9 +116,8 @@
_torControl, SLOT(closeStream(quint64)));
/* Respond to changes in the status of the control connection */
- connect(_torControl, SIGNAL(connected(bool)), ui.actionRefresh, SLOT(setEnabled(bool)));
- connect(_torControl, SIGNAL(connected()), this, SLOT(gotConnected()));
- connect(_torControl, SIGNAL(disconnected()), this, SLOT(gotDisconnected()));
+ connect(_torControl, SIGNAL(authenticated()), this, SLOT(onAuthenticated()));
+ connect(_torControl, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
/* Connect the slot to find out when geoip information has arrived */
connect(&_geoip, SIGNAL(resolved(int, QList<GeoIp>)),
@@ -137,24 +136,26 @@
VidaliaWindow::showWindow();
}
-/** Clears map, lists and stops timer when we get disconnected */
-void
-NetViewer::gotDisconnected()
-{
- clear();
- _refreshTimer.stop();
-}
-
/** Loads data into map, lists and starts timer when we get connected*/
void
-NetViewer::gotConnected()
+NetViewer::onAuthenticated()
{
_geoip.setSocksHost(_torControl->getSocksAddress(),
_torControl->getSocksPort());
refresh();
_refreshTimer.start();
+ ui.actionRefresh->setEnabled(true);
}
+/** Clears map, lists and stops timer when we get disconnected */
+void
+NetViewer::onDisconnected()
+{
+ clear();
+ _refreshTimer.stop();
+ ui.actionRefresh->setEnabled(false);
+}
+
/** Custom event handler. Catches the new descriptor events. */
void
NetViewer::customEvent(QEvent *event)
Modified: trunk/src/gui/network/netviewer.h
===================================================================
--- trunk/src/gui/network/netviewer.h 2007-08-21 04:33:57 UTC (rev 1844)
+++ trunk/src/gui/network/netviewer.h 2007-08-21 04:34:06 UTC (rev 1845)
@@ -78,9 +78,9 @@
/** Called when the user selects a router in the list. */
void routerSelected(RouterDescriptor router);
/** Handles when we get connected to Tor network */
- void gotConnected();
+ void onAuthenticated();
/** Handles when we get disconnected from Tor network */
- void gotDisconnected();
+ void onDisconnected();
/** Resolves IP addresses in the resolve queue to geographic information. */
void resolve();