[tor-commits] [vidalia/alpha] Tries HashedAuth if CookieAuth fails

chiiph at torproject.org chiiph at torproject.org
Sat Dec 24 20:54:40 UTC 2011


commit c195275f448cca06e61041fe4dc3ab7f0603d824
Author: Tomás Touceda <chiiph at torproject.org>
Date:   Wed Sep 7 10:44:10 2011 -0300

    Tries HashedAuth if CookieAuth fails
    
    wrt ticket #3898.
---
 src/vidalia/MainWindow.cpp |   98 +++++++++++++++++++++++++++-----------------
 src/vidalia/MainWindow.h   |    4 ++
 2 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 8dbf8ae..02986e8 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -1204,8 +1204,9 @@ MainWindow::authenticate()
 
   authMethod = settings.getAuthenticationMethod(); 
   pi = _torControl->protocolInfo();
+  QStringList authMethods;
   if (!pi.isEmpty()) {
-    QStringList authMethods = pi.authMethods();
+    authMethods = pi.authMethods();
     if (authMethods.contains("COOKIE"))
       authMethod = TorSettings::CookieAuth;
     else if (authMethods.contains("HASHEDPASSWORD"))
@@ -1213,47 +1214,19 @@ MainWindow::authenticate()
     else if (authMethods.contains("NULL"))
       authMethod = TorSettings::NullAuth;
   }
-  
+
   if (authMethod == TorSettings::CookieAuth) {
-    /* Try to load an auth cookie and send it to Tor */
-    QByteArray cookie = loadControlCookie(pi.cookieAuthFile());
-    while (cookie.isEmpty()) {
-      /* Prompt the user to find their control_auth_cookie */
-      int ret = VMessageBox::question(this,
-                  tr("Cookie Authentication Required"),
-                  p(tr("The Tor software requires Vidalia to send the "
-                       "contents of an authentication cookie, but Vidalia "
-                       "was unable to find one."))
-                  + p(tr("Would you like to browse for the file "
-                         "'control_auth_cookie' yourself?")),
-                VMessageBox::Browse|VMessageBox::Default,
-                VMessageBox::Cancel|VMessageBox::Escape);
-      
-      if (ret == VMessageBox::Cancel)
-        goto cancel;
-      QString cookieDir = QFileDialog::getOpenFileName(this,
-                            tr("Data Directory"),
-                            settings.getDataDirectory(),
-                            tr("Control Cookie (control_auth_cookie)"));
-      if (cookieDir.isEmpty())
+    if(!tryCookie(pi)) {
+      if(authMethods.contains("HASHEDPASSWORD") and !tryHashed()) {
         goto cancel;
-      cookieDir = QFileInfo(cookieDir).absolutePath();
-      cookie = loadControlCookie(cookieDir);
+      } else {
+        return true;
+      }
+    } else {
+      return true;
     }
-    vNotice("Authenticating using 'cookie' authentication.");
-    return _torControl->authenticate(cookie);
   } else if (authMethod == TorSettings::PasswordAuth) {
-    /* Get the control password and send it to Tor */
-    vNotice("Authenticating using 'hashed password' authentication.");
-    if (_useSavedPassword) {
-      TorSettings settings;
-      _controlPassword = settings.getControlPassword();
-    }
-
-    qputenv("TOR_CONTROL_PASSWD",
-            _controlPassword.toAscii().toHex());
-
-    return _torControl->authenticate(_controlPassword);
+    return tryHashed();
   }
   /* No authentication. Send an empty password. */
   vNotice("Authenticating using 'null' authentication.");
@@ -1268,6 +1241,55 @@ cancel:
   return false;
 }
 
+bool
+MainWindow::tryCookie(const ProtocolInfo &pi)
+{
+  TorSettings settings;
+  /* Try to load an auth cookie and send it to Tor */
+  QByteArray cookie = loadControlCookie(pi.cookieAuthFile());
+  while (cookie.isEmpty()) {
+    /* Prompt the user to find their control_auth_cookie */
+    int ret = VMessageBox::question(this,
+                                    tr("Cookie Authentication Required"),
+                                    p(tr("The Tor software requires Vidalia to send the "
+                                         "contents of an authentication cookie, but Vidalia "
+                                         "was unable to find one."))
+                                    + p(tr("Would you like to browse for the file "
+                                           "'control_auth_cookie' yourself?")),
+                                    VMessageBox::Browse|VMessageBox::Default,
+                                    VMessageBox::Cancel|VMessageBox::Escape);
+      
+    if (ret == VMessageBox::Cancel)
+      return false;
+    QString cookieDir = QFileDialog::getOpenFileName(this,
+                                                     tr("Data Directory"),
+                                                     settings.getDataDirectory(),
+                                                     tr("Control Cookie (control_auth_cookie)"));
+    if (cookieDir.isEmpty())
+      return false;
+    cookieDir = QFileInfo(cookieDir).absolutePath();
+    cookie = loadControlCookie(cookieDir);
+  }
+  vNotice("Authenticating using 'cookie' authentication.");
+  return _torControl->authenticate(cookie);
+}
+
+bool
+MainWindow::tryHashed()
+{
+  /* Get the control password and send it to Tor */
+  vNotice("Authenticating using 'hashed password' authentication.");
+  if (_useSavedPassword) {
+    TorSettings settings;
+    _controlPassword = settings.getControlPassword();
+  }
+
+  qputenv("TOR_CONTROL_PASSWD",
+          _controlPassword.toAscii().toHex());
+
+  return _torControl->authenticate(_controlPassword);
+}
+
 /** Checks the status of the current version of Tor to see if it's old,
  * unrecommended, or obsolete. */
 void
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index d30c059..834d6c1 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -88,6 +88,10 @@ private slots:
   void disconnected();
   /** Called when Vidalia has successfully authenticated to Tor. */
   void authenticated();
+  /** Called when authenticated() detects that you can do auth with a cookie */
+  bool tryCookie(const ProtocolInfo &pi);
+  /** Called when cookie auth fails or when it's the only method configured */
+  bool tryHashed();
   /** Called when Vidalia fails to authenticate to Tor. The failure reason is
    * specified in <b>errmsg</b>. */
   void authenticationFailed(QString errmsg);





More information about the tor-commits mailing list