[Ssc-dev] Playing a video from IOCipher

Nathan of Guardian nathan at guardianproject.info
Tue Oct 29 23:44:49 EDT 2013


In the InformaCam project, we store all photos and video in an encrypted
IOCipher data store. In order to play back video, we need to either
decrypt it to a standard, unencrypted file first for the MediaPlayer,
since it doesn't know how to directly read from IOCipher.

The other option is to server up the encrypted video stream via an HTTP
localhost server of some sort.

Below is my attempt to do this with the least amount of code as
possible. I am happy to say it works very well - almost instantly. My
ServerSocket only supports one connection at a time, and only servers up
one InputStream, no matter the request args that come in. This serves
our needs just fine.

https://github.com/n8fr8/iWitness/commit/e724a494cf16d9b595a6211946e5ef41a2248418#diff-68e092c1d4097ad3d08de850a3831b0eR255


 InputStream is =
InformaCam.getInstance().ioService.getStream(media_.dcimEntry.fileName,
Type.IOCIPHER);
 +
 +          String mType = media_.dcimEntry.mediaType;
 +
 +          mVideoServerSocket = new ServerSocket (8888);
 +
 +
 +          boolean keepRunning = true;
 +
 +          while (keepRunning)
 +          {
 +            try
 +            {
 +              Socket socket = mVideoServerSocket.accept();
 +
 +              OutputStream os = socket.getOutputStream();
 +
 +              IOUtils.write("HTTP/1.1 200\r\n",os);
 +              IOUtils.write("Content-Type: " + mType + "\r\n",os);
 +              IOUtils.write("Content-Length: " + media_.dcimEntry.size
+ "\r\n\r\n",os);
 +
 +              byte[] buffer = new byte[2048];
 +              int n = -1;
 +              while ((n = is.read(buffer))!=-1)
 +              {
 +                os.write(buffer);
 +              }
 +
 +              os.close();
 +            }
 +            catch (IOException ioe)
 +            {
 +              mVideoServerSocket.close();
 +            }


More information about the Ssc-dev mailing list