Skip to content

Commit 7079d63

Browse files
committed
Merge pull request #29 from wordpress-mobile/issue/27-hash-pin
Address security issue by storing hashed password rather than encrypted
2 parents 2f3098d + 484c778 commit 7079d63

9 files changed

Lines changed: 229 additions & 230 deletions

library/gradle.properties-example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
passcodelock.password_preference_key=passcode_lock_prefs_password_key
2-
passcodelock.password_salt=11-maggio-2014-osvaldo-al-49novesimo!
32
passcodelock.password_enc_secret=5-maggio-2002-Karel-Poborsky
43

54
ossrhUsername=hello
Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,65 @@
11
package org.wordpress.passcodelock;
22

3+
import android.annotation.TargetApi;
34
import android.app.Application;
5+
import android.os.Build;
46

7+
/**
8+
* Interface for AppLock implementations.
9+
*
10+
* There are situations where the AppLock should not be required within an app. Methods for tracking
11+
* exempt {@link android.app.Activity}'s are provided and sub-class implementations are expected to
12+
* comply with requested exemptions.
13+
* @see #isExemptActivity(String)
14+
* @see #setExemptActivities(String[])
15+
* @see #getExemptActivities()
16+
*
17+
* Applications can request a one-time delay in locking the app. This can be useful for activities
18+
* that launch external applications with the expectation that the user will return to the calling
19+
* application shortly.
20+
*/
21+
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
522
public abstract class AbstractAppLock implements Application.ActivityLifecycleCallbacks {
6-
public static final int DEFAULT_TIMEOUT = 2; //2 seconds
7-
public static final int EXTENDED_TIMEOUT = 60; //60 seconds
23+
public static final String FINGERPRINT_VERIFICATION_BYPASS = "fingerprint-bypass__";
24+
public static final int DEFAULT_TIMEOUT_S = 2;
25+
public static final int EXTENDED_TIMEOUT_S = 60;
826

9-
protected static final String FINGERPRINT_VERIFICATION_BYPASS = "fingerprint-bypass__";
27+
private int mLockTimeout = DEFAULT_TIMEOUT_S;
28+
private String[] mExemptActivities;
1029

11-
protected int lockTimeOut = DEFAULT_TIMEOUT;
12-
protected String[] appLockDisabledActivities = new String[0];
30+
public boolean isExemptActivity(String name) {
31+
if (name == null) return false;
32+
for (String activityName : getExemptActivities()) {
33+
if (name.equals(activityName)) return true;
34+
}
35+
return false;
36+
}
37+
38+
public void setExemptActivities(String[] exemptActivities) {
39+
mExemptActivities = exemptActivities;
40+
}
41+
42+
public String[] getExemptActivities() {
43+
if (mExemptActivities == null) setExemptActivities(new String[0]);
44+
return mExemptActivities;
45+
}
1346

14-
/*
15-
* There are situations where an activity will start a different application with an intent.
16-
* In these situations call this method right before leaving the app.
17-
*/
1847
public void setOneTimeTimeout(int timeout) {
19-
this.lockTimeOut = timeout;
48+
mLockTimeout = timeout;
49+
}
50+
51+
public int getTimeout() {
52+
return mLockTimeout;
2053
}
2154

22-
/*
23-
* There are situations where we don't want call the AppLock on activities (sharing items to out app for example).
24-
*/
25-
public void setDisabledActivities( String[] disabledActs ) {
26-
this.appLockDisabledActivities = disabledActs;
55+
protected boolean isFingerprintPassword(String password) {
56+
return FINGERPRINT_VERIFICATION_BYPASS.equals(password);
2757
}
28-
58+
2959
public abstract void enable();
3060
public abstract void disable();
3161
public abstract void forcePasswordLock();
32-
public abstract boolean verifyPassword( String password );
62+
public abstract boolean verifyPassword(String password);
3363
public abstract boolean isPasswordLocked();
3464
public abstract boolean setPassword(String password);
3565
}

library/src/org/wordpress/passcodelock/AbstractPasscodeKeyboardActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public void onPause() {
8888
}
8989
}
9090

91+
protected AbstractAppLock getAppLock() {
92+
return AppLockManager.getInstance().getAppLock();
93+
}
94+
9195
private OnClickListener defaultButtonListener = new OnClickListener() {
9296
@Override
9397
public void onClick(View arg0) {

library/src/org/wordpress/passcodelock/AppLockManager.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,32 @@
33
import android.app.Application;
44

55
public class AppLockManager {
6-
76
private static AppLockManager instance;
87
private AbstractAppLock currentAppLocker;
9-
8+
109
public static AppLockManager getInstance() {
1110
if (instance == null) {
1211
instance = new AppLockManager();
1312
}
1413
return instance;
1514
}
16-
15+
1716
public void enableDefaultAppLockIfAvailable(Application currentApp) {
18-
if (android.os.Build.VERSION.SDK_INT >= 14) {
19-
currentAppLocker = new DefaultAppLock(currentApp);
20-
currentAppLocker.enable();
21-
}
17+
if (!DefaultAppLock.isSupportedApi()) return;
18+
currentAppLocker = new DefaultAppLock(currentApp);
19+
currentAppLocker.enable();
20+
}
21+
22+
public boolean isDefaultLock() {
23+
return getAppLock() != null && getAppLock() instanceof DefaultAppLock;
2224
}
2325

2426
/**
25-
* Default App lock is available on Android-v14 or higher.
26-
* @return True if the Passcode Lock feature is available on the device
27+
* @return true when an App lock is available. It could be either a the Default App lock on
28+
* Android-v14 or higher, or a non default App lock
2729
*/
28-
public boolean isAppLockFeatureEnabled(){
29-
if( currentAppLocker == null )
30-
return false;
31-
if( currentAppLocker instanceof DefaultAppLock)
32-
return (android.os.Build.VERSION.SDK_INT >= 14);
33-
else
34-
return true;
30+
public boolean isAppLockFeatureEnabled() {
31+
return getAppLock() != null && (!isDefaultLock() || DefaultAppLock.isSupportedApi());
3532
}
3633

3734
public void setCurrentAppLock(AbstractAppLock newAppLocker) {
@@ -41,19 +38,12 @@ public void setCurrentAppLock(AbstractAppLock newAppLocker) {
4138
currentAppLocker = newAppLocker;
4239
}
4340

44-
public AbstractAppLock getCurrentAppLock() {
41+
public AbstractAppLock getAppLock() {
4542
return currentAppLocker;
4643
}
4744

48-
/*
49-
* Convenience method used to extend the default timeout.
50-
*
51-
* There are situations where an activity will start a different application with an intent.
52-
* In these situations call this method right before leaving the app.
53-
*/
5445
public void setExtendedTimeout(){
55-
if ( currentAppLocker == null )
56-
return;
57-
currentAppLocker.setOneTimeTimeout(AbstractAppLock.EXTENDED_TIMEOUT);
46+
if (getAppLock() == null) return;
47+
getAppLock().setOneTimeTimeout(AbstractAppLock.EXTENDED_TIMEOUT_S);
5848
}
5949
}

0 commit comments

Comments
 (0)