\r
private static final int ENCRYPT_ID = 2;\r
private static final int DECRYPT_ID = 3;\r
+ private static final int DECRYPT_FILE_ID = 4;\r
\r
private static final UriMatcher sUriMatcher;\r
\r
sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);\r
sUriMatcher.addURI(AUTHORITY, "encrypt/*", ENCRYPT_ID);\r
sUriMatcher.addURI(AUTHORITY, "decrypt/*", DECRYPT_ID);\r
+ sUriMatcher.addURI(AUTHORITY, "decryptfile", DECRYPT_FILE_ID); // [Peli] can be renamed to "decrypt/*" if first two options are made obsolete\r
}\r
\r
@Override\r
String path=filesDir;\r
String cryptSession;\r
String sessionFile;\r
+ String originalFile;\r
int modeBits = 0;\r
switch (sUriMatcher.match(uri)) {\r
case ENCRYPT_ID:\r
sessionFile=SESSION_FILE+"."+cryptSession;\r
path += "/"+sessionFile;\r
break;\r
+ case DECRYPT_FILE_ID:\r
+ if (debug) Log.d(TAG,"openFile: DECRYPT_FILE");\r
+ modeBits = ParcelFileDescriptor.MODE_READ_ONLY;\r
+ originalFile = "file://" + uri.getQueryParameter("file");\r
+ String sessionKey = uri.getQueryParameter("sessionkey");\r
+ // TODO: Check that sessionKey is valid.\r
+ \r
+ // Decrypt file\r
+ CryptoHelper ch = IntentHandler.ch; // Use the global crypto helper that is connected to the single service we have.\r
+ \r
+ Log.d(TAG, "Original file path: " + originalFile);\r
+ \r
+ if (ch == null) {\r
+ throw new CryptoHelperException("CryptoHelper not available. Are you logged in?");\r
+ }\r
+ Log.d(TAG, "Decrypt..");\r
+ Uri newuri = ch.decryptFileWithSessionKey(this.getContext(), Uri.parse(originalFile));\r
+ cryptSession = newuri.getPathSegments().get(1);\r
+ sessionFile=SESSION_FILE+"."+cryptSession;\r
+ path += "/"+sessionFile;\r
+ Log.d(TAG, "New path: " + path);\r
+ break;\r
default:\r
throw new IllegalArgumentException("Unknown URI " + uri);\r
}\r
throw e;\r
} catch (IllegalArgumentException e) {\r
throw e;\r
+ } catch (CryptoHelperException e) {\r
+ if (debug) Log.d(TAG,"openFile: CryptoHelperException");\r
+ pfd = null;\r
+ //throw e;\r
}\r
\r
return pfd;\r