[tor-commits] [vidalia/master] Delegate bridge line validation to Tor

chiiph at torproject.org chiiph at torproject.org
Fri Jan 6 13:56:50 UTC 2012


commit 9508770e7465997654b1b8a64477447449a0795d
Author: Tomás Touceda <chiiph at torproject.org>
Date:   Fri Jan 6 10:47:07 2012 -0300

    Delegate bridge line validation to Tor
---
 changes/newBridgeLines             |    3 ++
 src/vidalia/config/NetworkPage.cpp |   62 ++----------------------------------
 src/vidalia/config/NetworkPage.h   |    7 ----
 3 files changed, 6 insertions(+), 66 deletions(-)

diff --git a/changes/newBridgeLines b/changes/newBridgeLines
new file mode 100644
index 0000000..0834912
--- /dev/null
+++ b/changes/newBridgeLines
@@ -0,0 +1,3 @@
+  o Vidalia only validates IPv4 bridge lines. IPv6 bridges are now
+    available, and there will be pluggable transport bridge lines. So
+    the validation is now delegated to Tor through SETCONF.
\ No newline at end of file
diff --git a/src/vidalia/config/NetworkPage.cpp b/src/vidalia/config/NetworkPage.cpp
index e67686c..c51d1b6 100644
--- a/src/vidalia/config/NetworkPage.cpp
+++ b/src/vidalia/config/NetworkPage.cpp
@@ -122,74 +122,18 @@ NetworkPage::onLinkActivated(const QString &url)
   emit helpRequested(url);
 }
 
-/** Verifies that <b>bridge</b> is a valid bridge identifier and places a 
- * normalized identifier in <b>out</b>. The normalized identifier will have
- * all spaces removed from the fingerprint portion (if any) and all
- * hexadecimal characters converted to uppercase. Returns true if
- * <b>bridge</b> is a valid bridge identifier, false otherwise. */
-bool
-NetworkPage::validateBridge(const QString &bridge, QString *out)
-{
-  QString temp = bridge;
-  if (temp.startsWith("bridge ", Qt::CaseInsensitive))
-    temp = temp.remove(0, 7); /* remove "bridge " */
-
-  QStringList parts = temp.split(" ", QString::SkipEmptyParts);
-  if (parts.isEmpty())
-    return false;
-
-  QString s = parts.at(0);
-  QRegExp re("(\\d{1,3}\\.){3}\\d{1,3}(:\\d{1,5})?");
-  if (re.exactMatch(s)) {
-    if (s.endsWith(":"))
-      return false;
-
-    int index = s.indexOf(":");
-    QString host = s.mid(0, index);
-    if (QHostAddress(host).isNull()
-          || QHostAddress(host).protocol() != QAbstractSocket::IPv4Protocol) {
-      return false;
-    }
-    if (index > 0) {
-      QString port = s.mid(index + 1);
-      if (port.toUInt() < 1 || port.toUInt() > 65535)
-        return false;
-    }
-
-    temp = s;
-    if (parts.size() > 1) {
-      QString fp = static_cast<QStringList>(parts.mid(1)).join("");
-      if (fp.length() != 40 || !string_is_hex(fp))
-        return false;
-      temp += " " + fp.toUpper();
-    }
-  } else {
-    return false;
-  }
-  *out = temp;
-  return true;
-}
-
 /** Adds a bridge to the bridge list box. */
 void
 NetworkPage::addBridge()
 {
-  QString bridge;
   QString input = ui.lineBridge->text().trimmed();
 
   if (input.isEmpty())
     return;
-  if (!validateBridge(input, &bridge)) {
-    VMessageBox::warning(this,
-                  tr("Invalid Bridge"),
-                  tr("The specified bridge identifier is not valid."),
-                  VMessageBox::Ok|VMessageBox::Default);
-    return;
-  }
-  if (!ui.listBridges->findItems(bridge, Qt::MatchFixedString).isEmpty())
+  if (!ui.listBridges->findItems(input, Qt::MatchFixedString).isEmpty())
     return; /* duplicate bridge */
 
-  ui.listBridges->addItem(bridge);
+  ui.listBridges->addItem(input);
   ui.lineBridge->clear();
 }
 
@@ -319,7 +263,7 @@ NetworkPage::save(QString &errmsg)
 
   if (ui.chkUseBridges->isChecked()) {
     if (ui.listBridges->count() < 1) {
-      errmsg = tr("You must specify one or more briges.");
+      errmsg = tr("You must specify one or more bridges.");
       return false;
     }
   }
diff --git a/src/vidalia/config/NetworkPage.h b/src/vidalia/config/NetworkPage.h
index c198573..2193be7 100644
--- a/src/vidalia/config/NetworkPage.h
+++ b/src/vidalia/config/NetworkPage.h
@@ -81,13 +81,6 @@ private slots:
   void proxyTypeChanged(int selection);
 
 private:
-  /** Verifies that <b>bridge</b> is a valid bridge identifier and places a 
-   * normalized identifier in <b>out</b>. The normalized identifier will have
-   * all spaces removed from the fingerprint portion (if any) and all
-   * hexadecimal characters converted to uppercase. Returns true if
-   * <b>bridge</b> is a valid bridge identifier, false otherwise. */
-  bool validateBridge(const QString &bridge, QString *out);
-
   /** Helper class used to facilitate downloading one or more bridge
    * addresses. */
   BridgeDownloader* _bridgeDownloader;



More information about the tor-commits mailing list