[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [flashproxy/master] Add handling of URL registrations to facilitator.cgi.



commit f9701df16d8f7fc02fd6a1f80ffd73f64c131ef4
Author: Alexandre Allaire <alexandre.allaire@xxxxxxxxxxxxxx>
Date:   Thu Jan 17 20:37:42 2013 -0500

    Add handling of URL registrations to facilitator.cgi.
    
    Modify facilitator.cgi to accept client registrations
    through HTTP GET requests. The addresses are encrypted
    and base64 encoded, and are passed in using extra path
    info of the form /reg/<address>. The registrations are
    handed off to a daemon for precessing.
---
 facilitator/facilitator.cgi |   48 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/facilitator/facilitator.cgi b/facilitator/facilitator.cgi
index c21e67d..28c1606 100755
--- a/facilitator/facilitator.cgi
+++ b/facilitator/facilitator.cgi
@@ -5,10 +5,12 @@ import os
 import socket
 import sys
 import urllib
+import subprocess
 
 import fac
 
 FACILITATOR_ADDR = ("127.0.0.1", 9002)
+FACILITATOR_REG_URL_ADDR = ("127.0.0.1", 9003)
 
 def exit_error(status):
     print """\
@@ -16,6 +18,19 @@ Status: %d\r
 \r""" % status
     sys.exit()
 
+# Send a client registration to the helper daemon,
+# which handles decryption and registration.
+def url_reg(reg):
+    sock = socket.create_connection(FACILITATOR_REG_URL_ADDR)
+    sock.sendall(reg)
+    sock.shutdown(socket.SHUT_WR)
+    response = sock.recv(4096)
+    sock.close()
+    if response == "\x00":
+        return True
+    else:
+        return False
+
 method = os.environ.get("REQUEST_METHOD")
 remote_addr = (os.environ.get("REMOTE_ADDR"), None)
 path_info = os.environ.get("PATH_INFO") or "/"
@@ -26,20 +41,35 @@ if not method or not remote_addr[0]:
 fs = cgi.FieldStorage()
 
 def do_get():
-    if path_info != "/":
-        exit_error(400)
-    try:
-        reg = fac.get_reg(FACILITATOR_ADDR, remote_addr) or ""
-    except:
-        exit_error(500)
-    # Allow XMLHttpRequest from any domain. http://www.w3.org/TR/cors/.
-    print """\
+    args = [arg for arg in path_info.split("/") if arg]
+    # Check if we have a URL registration or a request for a client.
+    if len(args) == 2:
+        if args[0] != "reg":
+            exit_error(400)
+        reg = args[1]
+        # 256 byte RSA encryption, base64-encoded, should be no longer than 344 bytes.
+        if len(reg) > 350:
+            exit_error(400)
+        if not url_reg(reg):
+            exit_error(500)
+        print """\
+Status: 200\r
+\r"""
+    elif len(args) == 0:
+        try:
+            reg = fac.get_reg(FACILITATOR_ADDR, remote_addr) or ""
+        except:
+            exit_error(500)
+        # Allow XMLHttpRequest from any domain. http://www.w3.org/TR/cors/.
+        print """\
 Status: 200\r
 Content-Type: application/x-www-form-urlencoded\r
 Cache-Control: no-cache\r
 Access-Control-Allow-Origin: *\r
 \r"""
-    sys.stdout.write(urllib.urlencode(reg))
+        sys.stdout.write(urllib.urlencode(reg))
+    else:
+        exit_error(400)
 
 def do_post():
     if path_info != "/":



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits