Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Ratner committed Apr 26, 2014
1 parent 61adce1 commit a5ae262
Show file tree
Hide file tree
Showing 10 changed files with 725 additions and 0 deletions.
82 changes: 82 additions & 0 deletions BlindStorageServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Blind Storage Server
*/
package mp3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class BlindStorageServer {

public static final int SERVER_PORT=8888; /* Make sure the port number is sufficiently high */
public static final String LOOKUP_CMD="LOOKUP ";
public static final String BYE_CMD="BYE";
public static final String DOWNLOAD_CMD="DOWNLD ";
public static final String REPLY_DATA ="REPLY ";

public static void Lookup(String documentId,PrintWriter out) {
// THIS SHOULD BE IMPLEMENTED FOR PART-1
/* NOTE: The document id can be in any format you can come up with*/
// Lookup the document-id in the encrypted documents
// return the document contents (which are encrypted) to the client
// out.println("REPLY "+contents);
}

public static void Download(String blockIndex,PrintWriter out) {
// THIS SHOULD BE IMPLEMENTED FOR PART-2
// NOTE: The blockIndex can be in any format you like
// Lookup the block-index in the encrypted documents and return it to the clients
// out.println("REPLY "+contents);
}

public static void main(String[] args) {
ServerSocket serverSocket;
Socket clientSocket;
InputStreamReader inputStreamReader;
BufferedReader bufferedReader;

// NOTE: Here you need to send arguments for the encrypted store location and any additional
// parameters you may need

try {
serverSocket = new ServerSocket(SERVER_PORT); //Server socket
} catch (IOException e) {
System.err.println("ERROR: Could not listen on server port: " + SERVER_PORT);
return;
}
while (true) {
// NOTE: For implementation efficiency, you can handle the client connection (or parts of the client operation) as threads

try {
clientSocket = serverSocket.accept(); //accept the client connection
inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); //get the client message
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String message = bufferedReader.readLine();
if(message.equalsIgnoreCase(BYE_CMD)) {
inputStreamReader.close();
clientSocket.close();
break;
}
else if(message.startsWith(LOOKUP_CMD)) {
String documentId = message.substring(LOOKUP_CMD.length());
Lookup(documentId,out);
}
else if(message.startsWith(DOWNLOAD_CMD)) {
String blockIndex = message.substring(DOWNLOAD_CMD.length());
Download(blockIndex,out);
}else {
System.err.println("ERROR: Unknown command sent to server "+message);
}

} catch (IOException ex) {
System.err.println("ERROR: Problem in reading a message" + ex);
}
}

}
}
85 changes: 85 additions & 0 deletions ClientActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.example.cs463mp3;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Scanner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ClientActivity extends Activity {

private Socket client;
private PrintWriter output;
private EditText textField;
private Button button;
private String messsage;
public static final String SERVER_IP = ""; /* Set your VM's server IP here */
public static final int SERVER_PORT = 8888; /*
* Set your VM's server port
* here: Make sure the port
* number is sufficiently high
* for your program to listen on
* that number
*/
public static final String LOOKUP_CMD = "LOOKUP ";

public static void Lookup(String keyword, PrintWriter output) {
String documentId = "";

// For Part-1
// USE Local Index (cached) and find the documentId from there
// For Part-2
// (a) if index is present in local cache use it to find the document id
// (otherwise) use the download functionality to get the appropriate
// document-ids from the server
// and use them to download the files: This would be done by
// implementing SSE.Search functionality

//PrintWriter.write("LOOKUP " + documentId); // write the message to
// output stream
// Get the output and show to the user
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

textField = (EditText) findViewById(R.id.editText1); //reference to the text field
button = (Button) findViewById(R.id.button1); //reference to the send button
//read in stopwords file

//Button press event listener
button.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
String keyword = textField.getText().toString(); //get the keyword from the textfield
textField.setText(""); //Reset the text field to blank

try {
client = new Socket(SERVER_IP, SERVER_PORT); //connect to server
output= new PrintWriter(client.getOutputStream(),true);
Lookup(keyword,output);
//printwriter.flush();
//printwriter.close();
//client.close(); //closing the connection

} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});

}
}
10 changes: 10 additions & 0 deletions build_index_part1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
#Takes as
# argument 1: a directory consisting of small email directory in MP3 for input
# argument 2: a file consisting the encryption key
#Generates an output consisting of
# argument 3: index stored by the client on the phone as well
# argument 4 : (possibly a directory or a single tarred file) encrypted files to to be stored on the server

#NOTE: Your index generation should be in Java
#Call your java code with the arguments here
10 changes: 10 additions & 0 deletions build_index_part2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
#Takes as
# argument 1: a directory consisting of large email directory in MP3 for input
# argument 2: a file consisting the encryption key
#Generates an output consisting of
# argument 3: (cached partial) index stored by the client on the phone as well as
# argument 4 : (possibly a directory or a single tarred file) encrypted files to to be stored on the server

#NOTE: Your index generation should be in Java. This should follow the SSE.indexgen described in Figure 8 of paper
#Call your java code with the arguments here
4 changes: 4 additions & 0 deletions compile_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

#make any changes needed to compile the server
javac BlindStorageServer.java
15 changes: 15 additions & 0 deletions main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">

<edittext android:id="@+id/editText1" android:inputtype="textMultiLine" android:layout_height="wrap_content" android:layout_width="match_parent">

<requestfocus>

</requestfocus>
</edittext>


<button android:id="@+id/button1" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Send">


</button>
</linearlayout>
16 changes: 16 additions & 0 deletions mainifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<manifest android:versioncode="1" android:versionname="1.0" package="mp3" xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minsdkversion="10">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".SimpleClientActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN">

<category android:name="android.intent.category.LAUNCHER">
</category></action></intent-filter>
</activity>
</application>

</uses-sdk></manifest>
2 changes: 2 additions & 0 deletions run_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
#make any changes need to run the server (including passing the arguments to the encrypted storage location or any other parameters)
1 change: 1 addition & 0 deletions separators.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'\t\n\x0b\x0c\r '
Loading

0 comments on commit a5ae262

Please sign in to comment.