Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Do not store default salt into database
Browse files Browse the repository at this point in the history
Refs #1661
  • Loading branch information
M66B committed May 28, 2014
1 parent b6ba631 commit 518939b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
10 changes: 0 additions & 10 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
Expand Down Expand Up @@ -165,15 +164,6 @@ protected void onCreate(Bundle savedInstanceState) {
if (!PrivacyService.checkClient())
return;

// Salt should be the same when exporting/importing
String salt = PrivacyManager.getSetting(userId, PrivacyManager.cSettingSalt, null, false);
if (salt == null) {
salt = Build.SERIAL;
if (salt == null)
salt = "";
PrivacyManager.setSetting(userId, PrivacyManager.cSettingSalt, salt);
}

// Import license file
if (getIntent().getAction().equals(Intent.ACTION_VIEW))
Util.importProLicense(new File(getIntent().getData().getEncodedPath()));
Expand Down
7 changes: 6 additions & 1 deletion src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class PrivacyManager {
public final static String cSettingSortInverted = "SortInverted";
public final static String cSettingModifyTime = "ModifyTime";
public final static String cSettingTheme = "Theme";
public final static String cSettingSalt = "Salt";
private final static String cSettingSalt = "Salt";
public final static String cSettingVersion = "Version";
public final static String cSettingFirstRun = "FirstRun";
public final static String cSettingTutorialMain = "TutorialMain";
Expand Down Expand Up @@ -551,6 +551,11 @@ public static void deleteUsage(int uid) {

// Settings

public static String getSalt(int userId) {
String def = (Build.SERIAL == null ? "" : Build.SERIAL);
return getSetting(userId, PrivacyManager.cSettingSalt, def, true);
}

public static boolean getSettingBool(int uid, String name, boolean defaultValue, boolean useCache) {
return Boolean.parseBoolean(getSetting(uid, name, Boolean.toString(defaultValue), useCache));
}
Expand Down
4 changes: 2 additions & 2 deletions src/biz/bokhorst/xprivacy/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ private static boolean verifyData(byte[] data, byte[] signature, PublicKey publi
public static String sha1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
// SHA1
int userId = Util.getUserId(Process.myUid());
String salt = PrivacyManager.getSetting(userId, PrivacyManager.cSettingSalt, "", true);
String salt = PrivacyManager.getSalt(userId);
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] bytes = (text + salt).getBytes("UTF-8");
digest.update(bytes, 0, bytes.length);
Expand All @@ -448,7 +448,7 @@ public static String sha1(String text) throws NoSuchAlgorithmException, Unsuppor
public static String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
// MD5
int userId = Util.getUserId(Process.myUid());
String salt = PrivacyManager.getSetting(userId, PrivacyManager.cSettingSalt, "", true);
String salt = PrivacyManager.getSalt(userId);
byte[] bytes = MessageDigest.getInstance("MD5").digest((text + salt).getBytes("UTF-8"));
StringBuilder sb = new StringBuilder();
for (byte b : bytes)
Expand Down

0 comments on commit 518939b

Please sign in to comment.