diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java index f4faaf43..3d086aec 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKey.java @@ -16,10 +16,12 @@ import org.jetbrains.annotations.NotNull; public abstract class MasterKey { @SuppressWarnings("UnusedDeclaration") - private static final Logger logger = Logger.get( MasterKey.class ); + private static final Logger logger = Logger.get( MasterKey.class ); + private static boolean allowNativeByDefault = true; @Nonnull private final String fullName; + private boolean allowNative = allowNativeByDefault; @Nullable private byte[] masterKey; @@ -46,6 +48,23 @@ public abstract class MasterKey { throw new UnsupportedOperationException( "Unsupported version: " + version ); } + public static boolean isAllowNativeByDefault() { + return allowNativeByDefault; + } + + /** + * Native libraries are useful for speeding up the performance of cryptographical functions. + * Sometimes, however, we may prefer to use Java-only code. + * For instance, for auditability / trust or because the native code doesn't work on our CPU/platform. + *

+ * This setter affects the default setting for any newly created {@link MasterKey}s. + * + * @param allowNative false to disallow the use of native libraries. + */ + public static void setAllowNativeByDefault(final boolean allowNative) { + allowNativeByDefault = allowNative; + } + protected MasterKey(@NotNull final String fullName) { this.fullName = fullName; @@ -63,6 +82,15 @@ public abstract class MasterKey { return fullName; } + public boolean isAllowNative() { + return allowNative; + } + + public MasterKey setAllowNative(final boolean allowNative) { + this.allowNative = allowNative; + return this; + } + @Nonnull protected byte[] getKey() { diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java index 4ece61c3..b84872ab 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV0.java @@ -65,8 +65,15 @@ public class MasterKeyV0 extends MasterKey { mpBytesBuf.get( mpBytes, 0, mpBytes.length ); Arrays.fill( mpBytesBuf.array(), (byte) 0 ); + return scrypt( masterKeySalt, mpBytes ); + } + + protected byte[] scrypt(final byte[] masterKeySalt, final byte[] mpBytes) { try { - return SCrypt.scrypt( mpBytes, masterKeySalt, MP_N, MP_r, MP_p, MP_dkLen ); + if (isAllowNative()) + return SCrypt.scrypt( mpBytes, masterKeySalt, MP_N, MP_r, MP_p, MP_dkLen ); + else + return SCrypt.scryptJ( mpBytes, masterKeySalt, MP_N, MP_r, MP_p, MP_dkLen ); } catch (GeneralSecurityException e) { logger.bug( e ); diff --git a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java index db8d87d5..bc620a5d 100644 --- a/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java +++ b/MasterPassword/Java/masterpassword-algorithm/src/main/java/com/lyndir/masterpassword/MasterKeyV3.java @@ -14,7 +14,7 @@ import javax.annotation.Nullable; /** * bugs: * - no known issues. - * + * * @author lhunath, 2014-08-30 */ public class MasterKeyV3 extends MasterKeyV2 { @@ -46,17 +46,8 @@ public class MasterKeyV3 extends MasterKeyV2 { ByteBuffer mpBytesBuf = MP_charset.encode( CharBuffer.wrap( masterPassword ) ); byte[] mpBytes = new byte[mpBytesBuf.remaining()]; mpBytesBuf.get( mpBytes, 0, mpBytes.length ); - Arrays.fill( mpBytesBuf.array(), (byte)0 ); + Arrays.fill( mpBytesBuf.array(), (byte) 0 ); - try { - return SCrypt.scrypt( mpBytes, masterKeySalt, MP_N, MP_r, MP_p, MP_dkLen ); - } - catch (GeneralSecurityException e) { - logger.bug( e ); - return null; - } - finally { - Arrays.fill( mpBytes, (byte) 0 ); - } + return scrypt( masterKeySalt, mpBytes ); } } diff --git a/MasterPassword/Java/masterpassword-android/AndroidManifest.xml b/MasterPassword/Java/masterpassword-android/AndroidManifest.xml index 2f9c1f5f..a3947036 100644 --- a/MasterPassword/Java/masterpassword-android/AndroidManifest.xml +++ b/MasterPassword/Java/masterpassword-android/AndroidManifest.xml @@ -12,13 +12,13 @@ android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="true"> - + - + diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_gears.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_gears.png new file mode 100644 index 00000000..c939369e Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_gears.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_key.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_key.png new file mode 100644 index 00000000..25ea04cf Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_key.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_plus.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_plus.png new file mode 100644 index 00000000..53fec014 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/icon_plus.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/identity.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/identity.png new file mode 100644 index 00000000..b166f8f9 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/identity.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_identity.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_identity.png new file mode 100644 index 00000000..74b24312 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_identity.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_key.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_key.png new file mode 100644 index 00000000..3156342d Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_key.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_stats.png b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_stats.png new file mode 100644 index 00000000..13be8b1d Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-mdpi/img_stats.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_gears.png b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_gears.png new file mode 100644 index 00000000..e4cbaf04 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_gears.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_key.png b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_key.png new file mode 100644 index 00000000..af6c44cd Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_key.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_plus.png b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_plus.png new file mode 100644 index 00000000..cffdd7d9 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/icon_plus.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_identity.png b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_identity.png new file mode 100644 index 00000000..1455cdb9 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_identity.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_key.png b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_key.png new file mode 100644 index 00000000..336ddd36 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_key.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_stats.png b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_stats.png new file mode 100644 index 00000000..61bfa3f3 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable-xhdpi/img_stats.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/drawable/divider.png b/MasterPassword/Java/masterpassword-android/res/drawable/divider.png new file mode 100644 index 00000000..35cf2a23 Binary files /dev/null and b/MasterPassword/Java/masterpassword-android/res/drawable/divider.png differ diff --git a/MasterPassword/Java/masterpassword-android/res/layout/activity_emergency.xml b/MasterPassword/Java/masterpassword-android/res/layout/activity_emergency.xml index 2d8c6d95..4d578ce4 100644 --- a/MasterPassword/Java/masterpassword-android/res/layout/activity_emergency.xml +++ b/MasterPassword/Java/masterpassword-android/res/layout/activity_emergency.xml @@ -1,5 +1,6 @@ + + + android:textSize="16sp" /> @@ -46,16 +54,24 @@ android:hint="@string/masterPassword_hint" android:gravity="center" android:textColor="#FFFFFF" - android:textSize="18sp" /> + android:textSize="16sp" /> + + + android:textSize="16sp" /> @@ -115,54 +130,136 @@ android:id="@+id/maskPasswordField" android:layout_width="match_parent" android:layout_height="wrap_content" - android:textSize="14sp" + android:textSize="12sp" android:textColor="@android:color/tertiary_text_dark" android:text="@string/maskPassword" /> - + android:layout_marginTop="20dp" + android:layout_marginBottom="8dp" + android:importantForAccessibility="no" + android:src="@drawable/divider" /> - + style="?android:buttonBarStyle" + android:orientation="horizontal" + android:gravity="center"> - + - +