From b23dc901c8d0303f8fff6696b4dbaf991ab852e8 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 15 Apr 2019 17:23:27 +0200 Subject: [PATCH] Fix Error: Activity class --- mobile/android/app/BUCK | 4 +- mobile/android/app/src/main/AndroidManifest.xml | 3 +- .../app/src/main/java/com/lesspass/Crypto.java | 46 ------------------- .../src/main/java/com/lesspass/LessPassModule.java | 37 ---------------- .../java/com/lesspass/LessPassReactPackage.java | 24 ---------- .../src/main/java/com/lesspass/MainActivity.java | 23 ---------- .../main/java/com/lesspass/MainApplication.java | 51 ---------------------- .../src/main/java/com/lesspass/android/Crypto.java | 46 +++++++++++++++++++ .../java/com/lesspass/android/LessPassModule.java | 37 ++++++++++++++++ .../com/lesspass/android/LessPassReactPackage.java | 24 ++++++++++ .../java/com/lesspass/android/MainActivity.java | 23 ++++++++++ .../java/com/lesspass/android/MainApplication.java | 51 ++++++++++++++++++++++ .../app/src/test/java/com/lesspass/CryptoTest.java | 2 +- 13 files changed, 186 insertions(+), 185 deletions(-) delete mode 100644 mobile/android/app/src/main/java/com/lesspass/Crypto.java delete mode 100644 mobile/android/app/src/main/java/com/lesspass/LessPassModule.java delete mode 100644 mobile/android/app/src/main/java/com/lesspass/LessPassReactPackage.java delete mode 100644 mobile/android/app/src/main/java/com/lesspass/MainActivity.java delete mode 100644 mobile/android/app/src/main/java/com/lesspass/MainApplication.java create mode 100644 mobile/android/app/src/main/java/com/lesspass/android/Crypto.java create mode 100644 mobile/android/app/src/main/java/com/lesspass/android/LessPassModule.java create mode 100644 mobile/android/app/src/main/java/com/lesspass/android/LessPassReactPackage.java create mode 100644 mobile/android/app/src/main/java/com/lesspass/android/MainActivity.java create mode 100644 mobile/android/app/src/main/java/com/lesspass/android/MainApplication.java diff --git a/mobile/android/app/BUCK b/mobile/android/app/BUCK index 40c6480..51cee98 100644 --- a/mobile/android/app/BUCK +++ b/mobile/android/app/BUCK @@ -35,12 +35,12 @@ android_library( android_build_config( name = "build_config", - package = "com.lesspass", + package = "com.lesspass.android", ) android_resource( name = "res", - package = "com.lesspass", + package = "com.lesspass.android", res = "src/main/res", ) diff --git a/mobile/android/app/src/main/AndroidManifest.xml b/mobile/android/app/src/main/AndroidManifest.xml index a4b6f49..cb66f48 100644 --- a/mobile/android/app/src/main/AndroidManifest.xml +++ b/mobile/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + + package="com.lesspass.android"> diff --git a/mobile/android/app/src/main/java/com/lesspass/Crypto.java b/mobile/android/app/src/main/java/com/lesspass/Crypto.java deleted file mode 100644 index 89525a0..0000000 --- a/mobile/android/app/src/main/java/com/lesspass/Crypto.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.lesspass; - -import java.math.BigInteger; - -import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; -import org.spongycastle.crypto.digests.SHA256Digest; -import org.spongycastle.crypto.params.KeyParameter; -import org.spongycastle.crypto.macs.HMac; - -public class Crypto { - public String pbkdf2(String secret, String salt, int iterations, int keyLength) { - try - { - PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest()); - byte[] secretData = secret.getBytes(); - byte[] saltData = salt.getBytes(); - gen.init(secretData, saltData, iterations); - byte[] derivedKey = ((KeyParameter)gen.generateDerivedParameters(keyLength * 8)).getKey(); - return toHex(derivedKey); - } - catch (Exception e){ - throw new RuntimeException(e); - } - } - - public String hmac(String key) { - try - { - HMac hmac = new HMac(new SHA256Digest()); - KeyParameter secret_key = new KeyParameter(key.getBytes()); - hmac.init(secret_key); - byte[] result = new byte[hmac.getMacSize()]; - hmac.doFinal(result, 0); - return toHex(result); - } - catch (Exception e){ - throw new RuntimeException(e); - } - } - - private static String toHex(byte[] bytes) { - BigInteger bi = new BigInteger(1, bytes); - return String.format("%0" + (bytes.length << 1) + "x", bi); - } -} - diff --git a/mobile/android/app/src/main/java/com/lesspass/LessPassModule.java b/mobile/android/app/src/main/java/com/lesspass/LessPassModule.java deleted file mode 100644 index d31e3cf..0000000 --- a/mobile/android/app/src/main/java/com/lesspass/LessPassModule.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.lesspass; - -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.bridge.Promise; - - -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; - -public class LessPassModule extends ReactContextBaseJavaModule { - - public LessPassModule(ReactApplicationContext reactContext) { - super(reactContext); - } - - @Override - public String getName() { - return "LessPass"; - } - - @ReactMethod - public void calcEntropy(String site, String login, String masterPassword, String counter, Promise promise) { - String salt = site + login + counter; - String result = new Crypto().pbkdf2(masterPassword, salt, 100000, 32); - promise.resolve(result); - } - - @ReactMethod - public void createFingerprint(String masterPassword, Promise promise) { - String result = new Crypto().hmac(masterPassword); - promise.resolve(result); - } -} \ No newline at end of file diff --git a/mobile/android/app/src/main/java/com/lesspass/LessPassReactPackage.java b/mobile/android/app/src/main/java/com/lesspass/LessPassReactPackage.java deleted file mode 100644 index 0746ff7..0000000 --- a/mobile/android/app/src/main/java/com/lesspass/LessPassReactPackage.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.lesspass; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class LessPassReactPackage implements ReactPackage { - @Override - public List createViewManagers(ReactApplicationContext reactContext) { - return Collections.emptyList(); - } - - @Override - public List createNativeModules(ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); - modules.add(new LessPassModule(reactContext)); - return modules; - } -} \ No newline at end of file diff --git a/mobile/android/app/src/main/java/com/lesspass/MainActivity.java b/mobile/android/app/src/main/java/com/lesspass/MainActivity.java deleted file mode 100644 index e57db94..0000000 --- a/mobile/android/app/src/main/java/com/lesspass/MainActivity.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.lesspass; - -import com.facebook.react.ReactActivity; -import com.facebook.react.ReactActivityDelegate; -import com.facebook.react.ReactRootView; -import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView; - -public class MainActivity extends ReactActivity { - @Override - protected String getMainComponentName() { - return "LessPass"; - } - - @Override - protected ReactActivityDelegate createReactActivityDelegate() { - return new ReactActivityDelegate(this, getMainComponentName()) { - @Override - protected ReactRootView createRootView() { - return new RNGestureHandlerEnabledRootView(MainActivity.this); - } - }; - } -} diff --git a/mobile/android/app/src/main/java/com/lesspass/MainApplication.java b/mobile/android/app/src/main/java/com/lesspass/MainApplication.java deleted file mode 100644 index 12d6300..0000000 --- a/mobile/android/app/src/main/java/com/lesspass/MainApplication.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.lesspass; - -import android.app.Application; -import com.facebook.react.ReactApplication; -import com.swmansion.gesturehandler.react.RNGestureHandlerPackage; -import com.oblador.keychain.KeychainPackage; -import com.rnfingerprint.FingerprintAuthPackage; -import com.facebook.react.ReactNativeHost; -import com.facebook.react.ReactPackage; -import com.facebook.react.shell.MainReactPackage; -import com.facebook.soloader.SoLoader; - -import java.util.Arrays; -import java.util.List; - -public class MainApplication extends Application implements ReactApplication { - - private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { - @Override - public boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } - - @Override - protected List getPackages() { - return Arrays.asList( - new MainReactPackage(), - new RNGestureHandlerPackage(), - new KeychainPackage(), - new FingerprintAuthPackage(), - new LessPassReactPackage() - ); - } - - @Override - protected String getJSMainModuleName() { - return "index"; - } - }; - - @Override - public ReactNativeHost getReactNativeHost() { - return mReactNativeHost; - } - - @Override - public void onCreate() { - super.onCreate(); - SoLoader.init(this, /* native exopackage */ false); - } -} diff --git a/mobile/android/app/src/main/java/com/lesspass/android/Crypto.java b/mobile/android/app/src/main/java/com/lesspass/android/Crypto.java new file mode 100644 index 0000000..ce9b1e7 --- /dev/null +++ b/mobile/android/app/src/main/java/com/lesspass/android/Crypto.java @@ -0,0 +1,46 @@ +package com.lesspass.android; + +import java.math.BigInteger; + +import org.spongycastle.crypto.generators.PKCS5S2ParametersGenerator; +import org.spongycastle.crypto.digests.SHA256Digest; +import org.spongycastle.crypto.params.KeyParameter; +import org.spongycastle.crypto.macs.HMac; + +public class Crypto { + public String pbkdf2(String secret, String salt, int iterations, int keyLength) { + try + { + PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest()); + byte[] secretData = secret.getBytes(); + byte[] saltData = salt.getBytes(); + gen.init(secretData, saltData, iterations); + byte[] derivedKey = ((KeyParameter)gen.generateDerivedParameters(keyLength * 8)).getKey(); + return toHex(derivedKey); + } + catch (Exception e){ + throw new RuntimeException(e); + } + } + + public String hmac(String key) { + try + { + HMac hmac = new HMac(new SHA256Digest()); + KeyParameter secret_key = new KeyParameter(key.getBytes()); + hmac.init(secret_key); + byte[] result = new byte[hmac.getMacSize()]; + hmac.doFinal(result, 0); + return toHex(result); + } + catch (Exception e){ + throw new RuntimeException(e); + } + } + + private static String toHex(byte[] bytes) { + BigInteger bi = new BigInteger(1, bytes); + return String.format("%0" + (bytes.length << 1) + "x", bi); + } +} + diff --git a/mobile/android/app/src/main/java/com/lesspass/android/LessPassModule.java b/mobile/android/app/src/main/java/com/lesspass/android/LessPassModule.java new file mode 100644 index 0000000..fced134 --- /dev/null +++ b/mobile/android/app/src/main/java/com/lesspass/android/LessPassModule.java @@ -0,0 +1,37 @@ +package com.lesspass.android; + +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.Promise; + + +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; + +public class LessPassModule extends ReactContextBaseJavaModule { + + public LessPassModule(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public String getName() { + return "LessPass"; + } + + @ReactMethod + public void calcEntropy(String site, String login, String masterPassword, String counter, Promise promise) { + String salt = site + login + counter; + String result = new Crypto().pbkdf2(masterPassword, salt, 100000, 32); + promise.resolve(result); + } + + @ReactMethod + public void createFingerprint(String masterPassword, Promise promise) { + String result = new Crypto().hmac(masterPassword); + promise.resolve(result); + } +} \ No newline at end of file diff --git a/mobile/android/app/src/main/java/com/lesspass/android/LessPassReactPackage.java b/mobile/android/app/src/main/java/com/lesspass/android/LessPassReactPackage.java new file mode 100644 index 0000000..9dc98e6 --- /dev/null +++ b/mobile/android/app/src/main/java/com/lesspass/android/LessPassReactPackage.java @@ -0,0 +1,24 @@ +package com.lesspass.android; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class LessPassReactPackage implements ReactPackage { + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + modules.add(new LessPassModule(reactContext)); + return modules; + } +} \ No newline at end of file diff --git a/mobile/android/app/src/main/java/com/lesspass/android/MainActivity.java b/mobile/android/app/src/main/java/com/lesspass/android/MainActivity.java new file mode 100644 index 0000000..aca3501 --- /dev/null +++ b/mobile/android/app/src/main/java/com/lesspass/android/MainActivity.java @@ -0,0 +1,23 @@ +package com.lesspass.android; + +import com.facebook.react.ReactActivity; +import com.facebook.react.ReactActivityDelegate; +import com.facebook.react.ReactRootView; +import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView; + +public class MainActivity extends ReactActivity { + @Override + protected String getMainComponentName() { + return "LessPass"; + } + + @Override + protected ReactActivityDelegate createReactActivityDelegate() { + return new ReactActivityDelegate(this, getMainComponentName()) { + @Override + protected ReactRootView createRootView() { + return new RNGestureHandlerEnabledRootView(MainActivity.this); + } + }; + } +} diff --git a/mobile/android/app/src/main/java/com/lesspass/android/MainApplication.java b/mobile/android/app/src/main/java/com/lesspass/android/MainApplication.java new file mode 100644 index 0000000..ce08024 --- /dev/null +++ b/mobile/android/app/src/main/java/com/lesspass/android/MainApplication.java @@ -0,0 +1,51 @@ +package com.lesspass.android; + +import android.app.Application; +import com.facebook.react.ReactApplication; +import com.swmansion.gesturehandler.react.RNGestureHandlerPackage; +import com.oblador.keychain.KeychainPackage; +import com.rnfingerprint.FingerprintAuthPackage; +import com.facebook.react.ReactNativeHost; +import com.facebook.react.ReactPackage; +import com.facebook.react.shell.MainReactPackage; +import com.facebook.soloader.SoLoader; + +import java.util.Arrays; +import java.util.List; + +public class MainApplication extends Application implements ReactApplication { + + private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { + @Override + public boolean getUseDeveloperSupport() { + return BuildConfig.DEBUG; + } + + @Override + protected List getPackages() { + return Arrays.asList( + new MainReactPackage(), + new RNGestureHandlerPackage(), + new KeychainPackage(), + new FingerprintAuthPackage(), + new LessPassReactPackage() + ); + } + + @Override + protected String getJSMainModuleName() { + return "index"; + } + }; + + @Override + public ReactNativeHost getReactNativeHost() { + return mReactNativeHost; + } + + @Override + public void onCreate() { + super.onCreate(); + SoLoader.init(this, /* native exopackage */ false); + } +} diff --git a/mobile/android/app/src/test/java/com/lesspass/CryptoTest.java b/mobile/android/app/src/test/java/com/lesspass/CryptoTest.java index 565849e..406679b 100644 --- a/mobile/android/app/src/test/java/com/lesspass/CryptoTest.java +++ b/mobile/android/app/src/test/java/com/lesspass/CryptoTest.java @@ -4,7 +4,7 @@ import org.junit.Test; import java.util.Map; import java.util.HashMap; -import com.lesspass.Crypto; +import com.lesspass.android.Crypto; public class CryptoTest { @Test