Sheribaby / jtorchat

Automatically exported from code.google.com/p/jtorchat
0 stars 0 forks source link

mini "webserver" for page system (To assist in distributing verification keys, and small text files) #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Normal jtorchat connections is done by creatings two socket connection bothways 
to prevent spoofing cheaply.

Normal webserver only uses one socket connection.

Since 'broadcast' verification requires a public key, and that the 'owner' of 
the public key doesn't need to know the requester of the public key, I would 
recommend that we keep it to one socket connection via 'webserving'.

Which means instead of having to fully connect to the sender and auto typing 
"/page mypublickey", you can simply initiate a standard "http" request header 
to that same port and get the file back. 

e.g. "GET ./pagefilename.txt http/1.1"

This method is also faster, as you don't have to wait for the standard "send 
back socket" connection to verify that you are not faking your identity.

Original issue reported on code.google.com by jtorc...@gmail.com on 3 Mar 2012 at 4:09

GoogleCodeExporter commented 8 years ago
Daux2a: Additional benefit of this approach is that you don't have to make a 
'GUI' that list all the publicly accessible files in jtorchat's menu. All you 
need to do is just autogenerate an 'index.txt'.

One thing we should consider, is should we allow for 'html' to be displayed, or 
enforce sending all files as txt files. (e.g. what if the user decided to embed 
'malicious' javascript?)

Original comment by jtorc...@gmail.com on 3 Mar 2012 at 4:16

GoogleCodeExporter commented 8 years ago
So you understand what I mean. Here is some example (untested) code, that 
illustrate the idea.

This code goes under TCServ.java
{{{
                                    // If its a GET request, just treat it as a PAGE request
                                    if (l.equals("GET")) {
                                        PrintWriter out = new PrintWriter(s.getOutputStream());

                                        String fileName = l.replaceFirst("/", "");
                                        if (l.equals("")) {
                                            fileName = "index";
                                        } else {
                                            //This is interpreted as a file name
                                            fileName = URLDecoder.decode(fileName, "UTF-8");
                                        }

                                        if(fileName.indexOf('.')!=-1 || fileName.indexOf('/')!=-1) {
                                            s.close();
                                        }

                                        out.println("HTTP/1.0 200 OK");
                                        out.println("Content-Type: text/html");
                                        out.println("Server: Bot");
                                        // this blank line signals the end of the headers
                                        out.println("");
                                        // Send the HTML page
                                        try{
                                            Scanner scannerObj = new Scanner(new FileInputStream(Config.PAGE_DIR + fileName));                      
                                            while (scannerObj.hasNextLine()) {
                                                    //result += "\n"+scannerObj.nextLine();
                                                    out.println(scannerObj.nextLine());
                                            }
                                        } catch (Exception FileNotFoundException) {
                                            out.println("Resource Not Found");                                          
                                        }

                                        // close send socket
                                        out.close();

                                    }
}}}

Just under this bit of code 

{{{
                                    if (l == null) {
                                        Logger.log(Logger.SEVERE, "TCServ", "wtf");
                                        s.close();
                                        return;
                                    }
}}}

Original comment by jtorc...@gmail.com on 5 Mar 2012 at 12:22