Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
Fixati una serie di bug di chiusura e apertura applicazione, integrata relazione wireless con nuove screenshot
Marco Ziccardi82e3534be4df
diff --git a/AndroidManifest.xml b/AndroidManifest.xmlindex 7aebf07..9f87e48 100644--- a/AndroidManifest.xml+++ b/AndroidManifest.xml@@ -37,6 +37,7 @@<activityandroid:label="@string/app_name"android:name=".MonitorActivity"+ android:launchMode="singleTop"android:screenOrientation="portrait"/><service android:name=".service.BluetoothService"/></application>diff --git a/relazioni/wireless/paper.tex b/relazioni/wireless/paper.texindex f098cec..13e278c 100644--- a/relazioni/wireless/paper.tex+++ b/relazioni/wireless/paper.tex@@ -43,13 +43,13 @@\begin{document}-\title{SecureIt: home security has never been so easy\\-Anno Accademico 2011/2012}+\title{SecureIt\\+Wireless networks project\\+2012/2013}\author{\IEEEauthorblockN{Luca Bonato, Marco Ziccardi}\IEEEauthorblockA{Corso di studi in Informatica\\-Facoltà di Scienze MM.FF.NN.\\Università degli Studi di Padova\\Email: \{lohathe,marco.ziccard\}@gmail.com}}@@ -79,6 +79,25 @@ The aim of the application development was not only the creation of a home securTo the mobile application is associated a back-end where the application itself uploads images and audio got at the instant of intrusion detection.\\+In order to allow the end user to select the type of monitoring and the type of alerting according to his security needs, CPU and power consumption constraints a configuration panel (shown in figure ref{img:config}) is presented at each start of the application.\\++\begin{figure}[!ht]+\begin{center}+\makebox[\linewidth]{\includegraphics[scale=0.3]{resources/config.png}}+\caption{Configuration view}+\label{img:config}+\end{center}+\end{figure}++\begin{enumerate}+ \item Asks the application to use the accelerometer, shown only if the accelerometer is available on the phone+ \item Asks the application to use the camera, allows to choose wich camera to use and to start the flash+ \item Asks the application to use the microphone+ \item Asks the application to send an SMS to the specified phone number to alert an intrusion+ \item Asks the application to authenticate and send images, audio and location to the back-end (images are sent only if camera has been activated). A username and a password have to be specified+ \item Allows to set the unlock code. Application can be closed only by writing that code+\end{enumerate}+\section{\textbf{Intrusion detection}}Intrusion detection is done in three complementary ways:\begin{itemize}@@ -286,12 +305,7 @@ Android offers two ways for creating a bluetooth server socket: \texttt{listenUs\subsection{Delegated authorization}In the authentication phase a \texttt{delegated\allowbreak\_access\allowbreak\_token} is retrieved in order to not use the same token for both direct and delegated authentication. However such a token should not be shared with other devices and in order to do so a little protocol has been developed.\\-The presented protocol is slightly inspired by Kerberos (\texttt{[1]}) and is based on three messages:\\-\begin{itemize}- \item \texttt{HelloMessage}: sent from the requesting phone, simply contains a timestamp and the phone's identifier- \item \texttt{KeyRequest}: sent from a delegated phone to the requesting one, contains latitude, longitude and a timestamp- \item \texttt{KeyResponse}: sent from the requesting phone, contains an \texttt{authorization\_key} based on \texttt{delegated\_access\_token}, latitude, longitude and received timestamp-\end{itemize}+The protocolo in figure \ref{img:bluetooth} is slightly inspired by Kerberos (\texttt{[1]}) and is based on three messages:\\\begin{figure}[!ht]\begin{center}@@ -301,48 +315,61 @@ The presented protocol is slightly inspired by Kerberos (\texttt{[1]}) and is ba\end{center}\end{figure}-\texttt{authorization\_key} is computed via \texttt{AES} password encryption, using as password the value \texttt{delegated\_access\_token} and encrypting the \texttt{JSON} string:-\begin{lstlisting}[language=Java, caption=JSON encrypted with AES]-{"lat": "latitude",- "long": "longitude",- "timestamp": "timestamp"}-\end{lstlisting}--The following code shows how to compute \texttt{AES} password encryption of the string in Java.--\begin{lstlisting}[language=Java, caption=AES password encryption]-SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");-AlgorithmParameterSpec paramSpec = new IvParameterSpec(password.substring(0, 16).getBytes());-Cipher cipher;-cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");-cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);-byte[] ecrypted = cipher.doFinal(accessKey.getBytes());-accessKey = Base64.encodeToString(ecrypted, Base64.DEFAULT);-\end{lstlisting}--Using that tecnique the \texttt{delegated\_access\_token} is never transmitted over the network. If the delegated phone sends latitude, longitude, timestamp and \texttt{authorization\_key} to the \texttt{REST API [POST] /api/phones/:phoneid/position/delegated} the back-end is able to decrypt \texttt{authorization\_key} using \texttt{delegated\_access\_token} of phone's owner and verify that the owner has authorized the upload of latitude and longitude.--\subsection{\textbf{Communication workflow}}-Each application running on a device with active bluetooth offers an insecure \texttt{RFCOMM} server socket able to accept insecure requests for a specified \texttt{UIID}.\\When on any device running the application an intrusion is detected and no connectivity is available the bluetooth alert workflow starts:\\\begin{enumerate}- \item A discovery is started- \item A listener is registered and each device discovered is stored- \item At discovery finished for each device the application tries to create a connection, if it fails the device is discarded else a messaging workflow is started:- \begin{itemize}- \item An \texttt{HelloMessage} is sent- \item A \texttt{KeyRequest} is received- \item The \texttt{access\_key} is build and a \texttt{KeyResponse} is sent- \end{itemize}+ \item A bluetooth discovery is started+ \item A listener is registered to the process of discovery and each new device identified is stored+ \item As soon as discovery finishes the application tries to create a connection for each device, if it fails the device is discarded else a messaging workflow is started:+ \begin{enumerate}++ %Hello message+ \item An \texttt{HelloMessage} is sent. It contains a timestamp and the phone's identifier. \texttt{phoneId} is used by the delegated device to know who is requesting delegation, and where to upload location+ %Key request+ \item A \texttt{KeyRequest} is received. It is sent from the delegated device and contains latitude, longitude and a timestamp intended to be sent to the back-end+ %authorization_key creation+ \item An \texttt{authorization\_key} is computed via \texttt{AES} password encryption, using as password the value \texttt{delegated\_access\_token} and encrypting the following \texttt{JSON} string:++ \begin{lstlisting}[language=Java, caption=JSON encrypted with AES]+ {"lat": "latitude",+ "long": "longitude",+ "timestamp": "timestamp"}+ \end{lstlisting}++ The following code shows how to compute \texttt{AES} password encryption of the string in Java.++ \begin{lstlisting}[language=Java, caption=AES password encryption]+ SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");+ AlgorithmParameterSpec paramSpec = new IvParameterSpec(password.substring(0, 16).getBytes());+ Cipher cipher;+ cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");+ cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);+ byte[] ecrypted = cipher.doFinal(accessKey.getBytes());+ accessKey = Base64.encodeToString(ecrypted, Base64.DEFAULT);+ \end{lstlisting}+ %Key response+ \item A \texttt{KeyResponse} is sent. It contains the \texttt{authorization\_key} that can be computed only by the requesting client since \texttt{delegated\_access\_token} is never shared+ %Data upload+ \item The delegated phone sends latitude, longitude, timestamp and \texttt{authorization\_key} to the \texttt{REST API [POST] /api\allowbreak/phones\allowbreak/:phoneid\allowbreak/position/delegated}+ %Authorization+ \item The back-end is able to decrypt \texttt{authorization\_key} using \texttt{delegated\_access\_token} of the requesting phone (\texttt{phoneId}) and verify that the owner has authorized the upload of latitude and longitude+ \end{enumerate}\item If location is sent correctly 1 hour is waited before next retransmission, else only 1 minute is waited\end{enumerate}\section{\textbf{Back-end}}The back-end offers a set of \texttt{REST API} in order to authenticate the user, register a phone, upload images, audio and location. It organizes that data in a non relation database (\texttt{REDIS}) and allows to view it.\\-Images are captured and sent by Android phone in \textit{JPEG} format and are sent and displayed by the web application as they are.\\+Images are captured and sent by Android phone in \textit{JPEG} format and are sent and displayed by the web application as they are (as shown in figure \ref{img:slideshow}).\\++\begin{figure}[!ht]+\begin{center}+\makebox[\linewidth]{\includegraphics[scale=0.25]{resources/slideshow.png}}+\caption{Slideshow for captured images}+\label{img:slideshow}+\end{center}+\end{figure}Audio is captured by Android phone using \texttt{AAC} encoding, unfortunately Firefox and other browsers do not support \texttt{ACC} encoding. In order to make audio available for all modern browser as soon as it is received by the web application it is converted into \texttt{vorbis} encoding using \texttt{ffmpeg}:@@ -354,6 +381,14 @@ Such a conversion is done with a background system process.\\Uploaded location data is organized on a map created via Google Maps \texttt{APIs}.+\begin{figure}[!ht]+\begin{center}+\makebox[\linewidth]{\includegraphics[scale=0.25]{resources/map.png}}+\caption{Map showing last know device position}+\label{img:slideshow}+\end{center}+\end{figure}+\begin{thebibliography}{1}diff --git a/relazioni/wireless/resources/config.png b/relazioni/wireless/resources/config.pngnew file mode 100644index 0000000..a770365Binary files /dev/null and b/relazioni/wireless/resources/config.png differdiff --git a/relazioni/wireless/resources/firstpage.png b/relazioni/wireless/resources/firstpage.pngnew file mode 100644index 0000000..af96d52Binary files /dev/null and b/relazioni/wireless/resources/firstpage.png differdiff --git a/relazioni/wireless/resources/map.png b/relazioni/wireless/resources/map.pngnew file mode 100644index 0000000..069a2e5Binary files /dev/null and b/relazioni/wireless/resources/map.png differdiff --git a/relazioni/wireless/resources/slideshow.png b/relazioni/wireless/resources/slideshow.pngnew file mode 100644index 0000000..82813e0Binary files /dev/null and b/relazioni/wireless/resources/slideshow.png differdiff --git a/res/layout/microphone_fragment.xml b/res/layout/microphone_fragment.xmlindex 339a114..2af03ed 100644--- a/res/layout/microphone_fragment.xml+++ b/res/layout/microphone_fragment.xml@@ -18,6 +18,7 @@<TextView xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/microphone"+ android:layout_gravity="center_horizontal"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>\ No newline at end of filediff --git a/src/me/ziccard/secureit/MicrophoneVolumePicker.java b/src/me/ziccard/secureit/MicrophoneVolumePicker.javaindex fc315ff..aa420c5 100644--- a/src/me/ziccard/secureit/MicrophoneVolumePicker.java+++ b/src/me/ziccard/secureit/MicrophoneVolumePicker.java@@ -111,7 +111,7 @@ public class MicrophoneVolumePicker extends View {// draw plotdrawPlot(canvas, colomnWidth);-+}private void drawVolumeRect(Canvas canvas,diff --git a/src/me/ziccard/secureit/MonitorActivity.java b/src/me/ziccard/secureit/MonitorActivity.javaindex 01fd1db..6aff642 100644--- a/src/me/ziccard/secureit/MonitorActivity.java+++ b/src/me/ziccard/secureit/MonitorActivity.java@@ -15,6 +15,7 @@ import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import android.support.v4.view.ViewPager;import android.text.InputType;+import android.util.Log;import android.view.Menu;import android.view.MenuItem;import android.widget.EditText;@@ -64,6 +65,13 @@ public class MonitorActivity extends FragmentActivity {}class MonitorAdapter extends FragmentPagerAdapter {++ private Fragment accelerometerFragment;++ private Fragment cameraFragment;++ private Fragment microphoneFragment;+public MonitorAdapter(FragmentManager fm) {super(fm);}@@ -72,20 +80,26 @@ public class MonitorActivity extends FragmentActivity {public Fragment getItem(int position) {switch(position) {case 0:- if (preferences.getAccelerometerActivation())- return new AccelerometerFragment();- else+ if (preferences.getAccelerometerActivation()) {+ if (accelerometerFragment == null)+ accelerometerFragment = new AccelerometerFragment();+ return accelerometerFragment;+ } elsereturn EmptyFragment.newInstance(CONTENT[0]);case 1:- if (preferences.getCameraActivation())- return new CameraFragment();- else+ if (preferences.getCameraActivation()) {+ if (cameraFragment == null)+ cameraFragment = new CameraFragment();+ return cameraFragment;+ } elsereturn EmptyFragment.newInstance(CONTENT[1]);case 2:- if (preferences.getMicrophoneActivation())- return new MicrophoneFragment();- else+ if (preferences.getMicrophoneActivation()) {+ if (microphoneFragment == null)+ microphoneFragment = new MicrophoneFragment();+ return microphoneFragment;+ } elsereturn EmptyFragment.newInstance(CONTENT[2]);}return null;@@ -156,6 +170,8 @@ public class MonitorActivity extends FragmentActivity {builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton) {if (input.getText().toString().equals(preferences.getUnlockCode())) {+ Log.i("MonitorActivity", "INPUT "+input.getText().toString());+ Log.i("MonitorActivity", "STORED "+preferences.getUnlockCode());dialog.dismiss();close();} else {diff --git a/src/me/ziccard/secureit/fragment/AccelerometerFragment.java b/src/me/ziccard/secureit/fragment/AccelerometerFragment.javaindex 6fd3d5d..cddf14c 100644--- a/src/me/ziccard/secureit/fragment/AccelerometerFragment.java+++ b/src/me/ziccard/secureit/fragment/AccelerometerFragment.java@@ -158,6 +158,7 @@ public class AccelerometerFragment extends Fragment implements SensorEventListensuper.onDestroy();sensorMgr.unregisterListener(this);getActivity().unbindService(mConnection);+ Log.i("AccelerometerFragment", "Fragment destroyed");}@Overridediff --git a/src/me/ziccard/secureit/fragment/MicrophoneFragment.java b/src/me/ziccard/secureit/fragment/MicrophoneFragment.javaindex 4eb28d1..f4d0cb9 100644--- a/src/me/ziccard/secureit/fragment/MicrophoneFragment.java+++ b/src/me/ziccard/secureit/fragment/MicrophoneFragment.java@@ -84,7 +84,7 @@ public final class MicrophoneFragment extends Fragment implements MicSamplerTask}getActivity().bindService(new Intent(getActivity(),- BluetoothService.class), mConnection, Context.BIND_ABOVE_CLIENT);+ BluetoothService.class), mConnection, Context.BIND_ABOVE_CLIENT);}@Override@@ -96,6 +96,8 @@ public final class MicrophoneFragment extends Fragment implements MicSamplerTaskpublic void onResume() {super.onResume();+ Log.i("MicrophoneFragment", "Resumed");+microphoneText = (TextView) getActivity().findViewById(R.id.microphone);LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(@@ -103,10 +105,12 @@ public final class MicrophoneFragment extends Fragment implements MicSamplerTaskLinearLayout.LayoutParams.WRAP_CONTENT);LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.linear_layout);- picker = new MicrophoneVolumePicker(this.getActivity());- picker.setNoiseThreshold(NOISE_THRESHOLD);- layout.addView(picker, params);-+ if (layout.getChildCount() == 1) {+ picker = new MicrophoneVolumePicker(this.getActivity());+ picker.setNoiseThreshold(NOISE_THRESHOLD);+ layout.addView(picker, params);+ }+if (microphone == null) {microphone = new MicSamplerTask();microphone.setMicListener(this);@@ -116,8 +120,8 @@ public final class MicrophoneFragment extends Fragment implements MicSamplerTask@Overridepublic void onDestroy() {- Log.i("MicrophoneFramgnet", "Fragment destroyed");super.onDestroy();+ Log.i("MicrophoneFramgnet", "Fragment destroyed");getActivity().unbindService(mConnection);microphone.cancel(true);}diff --git a/src/me/ziccard/secureit/service/BluetoothService.java b/src/me/ziccard/secureit/service/BluetoothService.javaindex ebebff9..129f093 100644--- a/src/me/ziccard/secureit/service/BluetoothService.java+++ b/src/me/ziccard/secureit/service/BluetoothService.java@@ -150,6 +150,15 @@ public class BluetoothService extends Service {*/@SuppressWarnings("deprecation")private void showNotification() {+++ Intent toLaunch = new Intent(getApplicationContext(),+ MonitorActivity.class);++ toLaunch.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT+ |Intent.FLAG_ACTIVITY_REORDER_TO_FRONT+ |Intent.FLAG_ACTIVITY_NEW_TASK);+// In this sample, we'll use the same text for the ticker and the expanded notificationCharSequence text = getText(R.string.secure_service_started);@@ -158,7 +167,7 @@ public class BluetoothService extends Service {// The PendingIntent to launch our activity if the user selects this notificationPendingIntent contentIntent = PendingIntent.getActivity(this, 0,- new Intent(this, MonitorActivity.class), 0);+ toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);notification.setLatestEventInfo(this, "SecureService",text, contentIntent);