*/\r
public static final String EXTRA_TEXT_ARRAY = "org.openintents.extra.TEXT_ARRAY";\r
\r
+ /**\r
+ * A session key for encryption or decryption through a content provider.\r
+ * \r
+ * Include this extra with non-empty value to the ENCRYPT or DECRYPT action,\r
+ * and the resulting intent will contain the current session key, valid until\r
+ * OI Safe logs out.\r
+ * \r
+ * <p>Constant Value: "org.openintents.extra.SESSION_KEY"</p>\r
+ */\r
+ public static final String EXTRA_SESSION_KEY = "org.openintents.extra.SESSION_KEY";\r
+ \r
/**\r
* Required input parameter to GET_PASSWORD and SET_PASSWORD. Corresponds to the "description"\r
* field in passwordsafe. Should be a unique name for the password you're using,\r
// Decrypt file\r
CryptoHelper ch = ServiceDispatchImpl.ch; // Use the global crypto helper that is connected to the single service we have.\r
\r
+ if (ch == null) {\r
+ if (debug) Log.d(TAG, "OI Safe currently logged out.");\r
+ return null;\r
+ }\r
+ \r
+ if (!sessionKey.equals(ch.getCurrentSessionKey())) {\r
+ if (debug) Log.d(TAG, "Session keys do not match! " + sessionKey + " != " + ch.getCurrentSessionKey());\r
+ return null;\r
+ }\r
+ \r
Log.d(TAG, "Original file path: " + originalFile);\r
if (CategoryList.isSignedIn()==false) {\r
Intent frontdoor = new Intent(getContext(), FrontDoor.class);\r
private static byte[] salt = null; \r
\r
private static final int count = 20;\r
+ \r
+ /**\r
+ * Session key for content provider.\r
+ */\r
+ private String sessionKey = null;\r
+ \r
\r
/**\r
* Constructor which defaults to a medium encryption level.\r
} catch (NoSuchPaddingException e) {\r
Log.e(TAG,"setPassword(): "+e.toString());\r
}\r
+ \r
+ // Every time we set a new password, also the session key changes:\r
+ sessionKey = createNewSessionKey();\r
}\r
\r
private void setSalt(String saltIn) throws CryptoHelperException {\r
salt=byteSaltIn;\r
if (debug) Log.d(TAG,"setSalt: salt="+toHexString(salt));\r
}\r
+ \r
+ /**\r
+ * Returns the current session key, which is only valid until the\r
+ * user logs out of OI Safe.\r
+ * \r
+ * The session key is used when encrypting or decrypting files\r
+ * through the content provider.\r
+ * \r
+ * @return current session key.\r
+ */\r
+ public String getCurrentSessionKey() {\r
+ return sessionKey;\r
+ }\r
+ \r
+ /**\r
+ * Creates a new random session key\r
+ * @return\r
+ */\r
+ private String createNewSessionKey() {\r
+ try {\r
+ // simply create a new salt:\r
+ return generateSalt();\r
+ } catch (NoSuchAlgorithmException e) {\r
+ return "12345"; // better than nothing... :-/\r
+ }\r
+ }\r
+ \r
/**\r
* encrypt a string\r
* \r
}\r
callbackIntent.putExtra(CryptoIntents.EXTRA_TEXT_ARRAY, out);\r
}\r
+\r
+ if (thisIntent.hasExtra(CryptoIntents.EXTRA_SESSION_KEY)) {\r
+ String sessionkey = ch.getCurrentSessionKey();\r
+ callbackIntent.putExtra(CryptoIntents.EXTRA_SESSION_KEY, sessionkey);\r
+ }\r
\r
if (thisIntent.getData() != null) {\r
// Encrypt file from file URI\r