Browse Source

keystore changes

gradlePlay
Gutyn 9 years ago
parent
commit
b06f2bd011
  1. 2
      .idea/libraries/appcompat_v7_23_0_1.xml
  2. 2
      .idea/libraries/espresso_core_2_2.xml
  3. 8
      .idea/libraries/exposed_instrumentation_api_publish_0_4_1.xml
  4. 2
      .idea/libraries/rules_0_3.xml
  5. 8
      .idea/libraries/runner_0_4_1.xml
  6. 2
      .idea/libraries/support_v4_23_0_1.xml
  7. 32
      app/app.iml
  8. 3
      app/build.gradle
  9. 118
      app/src/main/java/com/breadwallet/presenter/activities/DecoderActivity.java
  10. 15
      app/src/main/java/com/breadwallet/presenter/activities/IntroActivity.java
  11. 9
      app/src/main/java/com/breadwallet/presenter/activities/MainActivity.java
  12. 1
      app/src/main/java/com/breadwallet/presenter/fragments/FragmentWipeWallet.java
  13. 11
      app/src/main/java/com/breadwallet/presenter/fragments/IntroNewWalletFragment.java
  14. 158
      app/src/main/java/com/breadwallet/tools/security/KeyStoreManager.java
  15. 27
      app/src/main/java/com/breadwallet/tools/sqlite/MerkleBlockDataSource.java
  16. 26
      app/src/main/java/com/breadwallet/tools/sqlite/PeerDataSource.java
  17. 36
      app/src/main/java/com/breadwallet/tools/sqlite/TransactionDataSource.java
  18. 13
      app/src/main/java/com/breadwallet/wallet/BRWalletManager.java
  19. 3
      app/src/main/jni/Android.mk
  20. 2
      app/src/main/jni/breadwallet-core

2
.idea/libraries/appcompat_v7_23_0_1.xml

@ -4,8 +4,8 @@
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/annotations.zip!/" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>

2
.idea/libraries/espresso_core_2_2.xml

@ -1,8 +1,8 @@
<component name="libraryTable">
<library name="espresso-core-2.2">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>

8
.idea/libraries/exposed_instrumentation_api_publish_0_4.xml → .idea/libraries/exposed_instrumentation_api_publish_0_4_1.xml

@ -1,12 +1,12 @@
<component name="libraryTable">
<library name="exposed-instrumentation-api-publish-0.4">
<library name="exposed-instrumentation-api-publish-0.4.1">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.4/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.4/res" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.4.1/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.4.1/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/Library/Android/sdk/extras/android/m2repository/com/android/support/test/exposed-instrumentation-api-publish/0.4/exposed-instrumentation-api-publish-0.4-sources.jar!/" />
<root url="jar://$USER_HOME$/Library/Android/sdk/extras/android/m2repository/com/android/support/test/exposed-instrumentation-api-publish/0.4.1/exposed-instrumentation-api-publish-0.4.1-sources.jar!/" />
</SOURCES>
</library>
</component>

2
.idea/libraries/rules_0_3.xml

@ -1,8 +1,8 @@
<component name="libraryTable">
<library name="rules-0.3">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/rules/0.3/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/rules/0.3/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/rules/0.3/res" />
</CLASSES>
<JAVADOC />
<SOURCES>

8
.idea/libraries/runner_0_4.xml → .idea/libraries/runner_0_4_1.xml

@ -1,12 +1,12 @@
<component name="libraryTable">
<library name="runner-0.4">
<library name="runner-0.4.1">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/runner/0.4/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/runner/0.4/res" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/runner/0.4.1/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support.test/runner/0.4.1/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/Library/Android/sdk/extras/android/m2repository/com/android/support/test/runner/0.4/runner-0.4-sources.jar!/" />
<root url="jar://$USER_HOME$/Library/Android/sdk/extras/android/m2repository/com/android/support/test/runner/0.4.1/runner-0.4.1-sources.jar!/" />
</SOURCES>
</library>
</component>

2
.idea/libraries/support_v4_23_0_1.xml

@ -4,8 +4,8 @@
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/annotations.zip!/" />
</ANNOTATIONS>
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars/libs/internal_impl-23.0.1.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />

32
app/app.iml

@ -21,7 +21,7 @@
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res/layouts/activities" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/src/main/res/layouts;file://$MODULE_DIR$/src/main/res/layouts/activities;file://$MODULE_DIR$/src/main/res/layouts/toasts;file://$MODULE_DIR$/src/main/res/layouts/fragments" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res/layouts/toasts;file://$MODULE_DIR$/src/main/res/layouts/fragments;file://$MODULE_DIR$/src/main/res/layouts;file://$MODULE_DIR$/src/main/res/layouts/activities;file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
@ -78,9 +78,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-idling-resource/2.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/exposed-instrumentation-api-publish/0.4.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/rules/0.3/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/runner/0.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/runner/0.4.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
@ -100,25 +100,25 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="TEST" name="runner-0.4.1" level="project" />
<orderEntry type="library" exported="" name="xmlwise-1_2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="espresso-idling-resource-2.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="runner-0.4" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.4" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
<orderEntry type="library" exported="" name="acra-4.6.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2" level="project" />
<orderEntry type="library" exported="" name="core-3.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.4.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" name="acra-4.6.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="rules-0.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-integration-1.3" level="project" />
<orderEntry type="library" exported="" name="rebound-0.3.8" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="core-3.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="rules-0.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
</component>
</module>

3
app/build.gradle

@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
buildToolsVersion "23.0.0 "
lintOptions {
// set to true to turn off analysis progress reporting by lint
@ -15,6 +15,7 @@ android {
packagingOptions {
exclude 'LICENSE.txt'
// exclude 'app/src/main/jni/breadwallet-core' //for API 19 to work
}

118
app/src/main/java/com/breadwallet/presenter/activities/DecoderActivity.java

@ -1,118 +0,0 @@
//
//package com.breadwallet.presenter.activities;
//
//import android.app.Activity;
//import android.graphics.PointF;
//import android.os.AsyncTask;
//import android.os.Bundle;
//import android.util.Log;
//
//import com.breadwallet.R;
//import com.breadwallet.presenter.fragments.FragmentScanResult;
//import com.breadwallet.tools.animation.FragmentAnimator;
//import com.breadwallet.tools.qrcode.QRCodeReaderView;
//
///**
// * BreadWallet
// *
// * Created by Mihail on 8/4/15.
// * Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
// *
// * Permission is hereby granted, free of charge, to any person obtaining a copy
// * of this software and associated documentation files (the "Software"), to deal
// * in the Software without restriction, including without limitation the rights
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// * copies of the Software, and to permit persons to whom the Software is
// * furnished to do so, subject to the following conditions:
// *
// * The above copyright notice and this permission notice shall be included in
// * all copies or substantial portions of the Software.
// *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// * THE SOFTWARE.
// */
//
//public class DecoderActivity extends Activity implements QRCodeReaderView.OnQRCodeReadListener {
//
// public static final String TAG = "DecoderActivity";
//
// private boolean accessGranted = true;
// private QRCodeReaderView mydecoderview;
// private DecoderActivity decoderActivity;
//
// public DecoderActivity() {
// decoderActivity = this;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_decoder);
////
// }
//
// /**
// * Called when a QR is decoded
// * "text" : the text encoded in QR
// * "points" : points where QR control points are placed
// */
// @Override
// public void onQRCodeRead(String text, PointF[] points) {
// Log.e(TAG, "QRCode was read!");
// if (accessGranted) {
// accessGranted = false;
// if(text!= null){
// FragmentScanResult.address = text;
// FragmentAnimator.animateScanResultFragment();
// } else {
// throw new NullPointerException("The scanned text is null!");
// }
// finish();
// }
// }
//
//
// // Called when your device have no camera
// @Override
// public void cameraNotFound() {
//
// }
//
// // Called when there's no QR codes in the camera preview image
// @Override
// public void QRCodeNotFoundOnCamImage() {
//
// }
//
// @Override
// protected void onResume() {
// super.onResume();
// new CameraOpenerTask().execute();
//
// }
//
// @Override
// protected void onPause() {
// super.onPause();
// Log.e(TAG, "In onPause");
// mydecoderview.getCameraManager().stopPreview();
//
//
// }
//
// private class CameraOpenerTask extends AsyncTask {
//
// @Override
// protected Object doInBackground(Object[] params) {
// mydecoderview = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
// mydecoderview.setOnQRCodeReadListener(decoderActivity);
// mydecoderview.getCameraManager().startPreview();
// return null;
// }
// }
//}

15
app/src/main/java/com/breadwallet/presenter/activities/IntroActivity.java

@ -87,6 +87,7 @@ public class IntroActivity extends FragmentActivity {
private IntroRecoverWalletFragment introRecoverWalletFragment;
private Button leftButton;
private boolean backPressAvailable = false;
private boolean hardwareBacked;
//loading the native library
static {
@ -108,8 +109,6 @@ public class IntroActivity extends FragmentActivity {
}
byte[] walletRaw = m.wallet();
// testSQLiteConnectivity(this); //do some SQLite testing
introWelcomeFragment = new IntroWelcomeFragment();
introNewRestoreFragment = new IntroNewRecoverFragment();
@ -169,18 +168,6 @@ public class IntroActivity extends FragmentActivity {
}
}
}, 800);
//testing plist:
//
// Iterator<String> it = wordList.iterator();
// int count = 0;
// while (it.hasNext()) {
// System.out.println(it.next() + (++count));
//
// }
//end testing
}
}

9
app/src/main/java/com/breadwallet/presenter/activities/MainActivity.java

@ -444,9 +444,14 @@ public class MainActivity extends FragmentActivity implements Observer {
}
public boolean isEmulatorOrDebug() {
return Build.BRAND.equalsIgnoreCase("generic") || BuildConfig.DEBUG;
}
String fing = Build.FINGERPRINT;
boolean isEmulator = false;
if (fing != null) {
isEmulator = fing.contains("vbox") || fing.contains("generic");
}
return isEmulator || BuildConfig.DEBUG;
}
}

1
app/src/main/java/com/breadwallet/presenter/fragments/FragmentWipeWallet.java

@ -61,6 +61,7 @@ public class FragmentWipeWallet extends Fragment {
close = (Button) rootView.findViewById(R.id.wipe_wallet_close);
recoveryPhraseEditText = (EditText) rootView.findViewById(R.id.editText_phrase);
wipe = (Button) rootView.findViewById(R.id.wipe_wallet_wipe);
recoveryPhraseEditText.setText("");
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

11
app/src/main/java/com/breadwallet/presenter/fragments/IntroNewWalletFragment.java

@ -1,6 +1,7 @@
package com.breadwallet.presenter.fragments;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -37,20 +38,26 @@ import com.breadwallet.wallet.BRWalletManager;
*/
public class IntroNewWalletFragment extends Fragment {
public Button introGenerate;
private BRWalletManager m;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
final BRWalletManager m = BRWalletManager.getInstance();
m = BRWalletManager.getInstance();
View rootView = inflater.inflate(
R.layout.intro_fragment_new_wallet, container, false);
introGenerate = (Button) rootView.findViewById(R.id.intro_new_wallet_generate);
introGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
m.generateRandomSeed(getActivity());
new Handler().post(new Runnable() {
@Override
public void run() {
m.generateRandomSeed(getActivity());
}
});
((IntroActivity) getActivity()).showWarningFragment();
}
});

158
app/src/main/java/com/breadwallet/tools/security/KeyStoreManager.java

@ -1,5 +1,29 @@
package com.breadwallet.tools.security;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.security.KeyPairGeneratorSpec;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.security.auth.x500.X500Principal;
/**
* BreadWallet
* <p/>
@ -24,7 +48,141 @@ package com.breadwallet.tools.security;
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class KeyStoreManager {
public static final String TAG = KeyStoreManager.class.getName();
static final String CIPHER_TYPE = "RSA/ECB/PKCS1Padding";
static final String CIPHER_PROVIDER = "AndroidOpenSSL";
static List<String> keyAliases;
private static KeyStoreManager instance;
public static final String ALIAS = "phrase";
public static final String ANDROID_KEY_STORE = "AndroidKeyStore";
private static KeyStore keyStore;
private KeyStoreManager(Context context) {
try {
keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
keyStore.load(null);
creteKey(context);
} catch (Exception e) {
Log.e(TAG, "Cannot access keystore!", e);
}
}
public static synchronized KeyStoreManager getInstance(Context context) {
if (instance == null) {
instance = new KeyStoreManager(context);
}
return instance;
}
private void creteKey(Context context) {
try {
// Create new key if needed
if (!keyStore.containsAlias(ALIAS)) {
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
end.add(Calendar.YEAR, 1);
KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context)
.setAlias(ALIAS)
.setSubject(new X500Principal("CN=Mihail Gutan, O=BreadWallet"))
.setSerialNumber(BigInteger.ONE)
.setStartDate(start.getTime())
.setEndDate(end.getTime())
.build();
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", ANDROID_KEY_STORE);
generator.initialize(spec);
KeyPair keyPair = generator.generateKeyPair();
}
} catch (Exception e) {
Toast.makeText(context, "Exception " + e.getMessage() + " occured", Toast.LENGTH_LONG).show();
Log.e(TAG, Log.getStackTraceString(e));
}
}
public void deleteKey(final Context context) {
AlertDialog alertDialog = new AlertDialog.Builder(context)
.setTitle("Delete Key")
.setMessage("Do you want to delete the key \"" + ALIAS + "\" from the keystore?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
keyStore.deleteEntry(ALIAS);
} catch (KeyStoreException e) {
Toast.makeText(context, "Exception " + e.getMessage() + " occured",
Toast.LENGTH_LONG).show();
Log.e(TAG, Log.getStackTraceString(e));
}
dialog.dismiss();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create();
alertDialog.show();
}
public void encryptString(String stringToEncrypt,Context context) {
try {
KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(ALIAS, null);
RSAPublicKey publicKey = (RSAPublicKey) privateKeyEntry.getCertificate().getPublicKey();
if (stringToEncrypt.isEmpty()) {
Toast.makeText(context, "Enter text in the 'Initial Text' widget", Toast.LENGTH_LONG).show();
return;
}
Cipher inCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
inCipher.init(Cipher.ENCRYPT_MODE, publicKey);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CipherOutputStream cipherOutputStream = new CipherOutputStream(outputStream, inCipher);
cipherOutputStream.write(stringToEncrypt.getBytes("UTF-8"));
cipherOutputStream.close();
} catch (Exception e) {
Toast.makeText(context, "Exception " + e.getMessage() + " occurred", Toast.LENGTH_LONG).show();
Log.e(TAG, Log.getStackTraceString(e));
}
}
public String decryptString(Context context) {
try {
KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(ALIAS, null);
RSAPrivateKey privateKey = (RSAPrivateKey) privateKeyEntry.getPrivateKey();
Cipher output = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
output.init(Cipher.DECRYPT_MODE, privateKey);
String cipherText = "Some string to decode";
CipherInputStream cipherInputStream = new CipherInputStream(
new ByteArrayInputStream(Base64.decode(cipherText, Base64.DEFAULT)), output);
ArrayList<Byte> values = new ArrayList<>();
int nextByte;
while ((nextByte = cipherInputStream.read()) != -1) {
values.add((byte) nextByte);
}
byte[] bytes = new byte[values.size()];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = values.get(i).byteValue();
}
String finalText = new String(bytes, 0, bytes.length, "UTF-8");
return finalText;
} catch (Exception e) {
Toast.makeText(context, "Exception " + e.getMessage() + " occurred", Toast.LENGTH_LONG).show();
Log.e(TAG, Log.getStackTraceString(e));
}
return null;
}
}

27
app/src/main/java/com/breadwallet/tools/sqlite/MerkleBlockDataSource.java

@ -77,15 +77,24 @@ public class MerkleBlockDataSource {
values.put(BRSQLiteHelper.MB_COLUMN_TIME_STAMP, merkleBlock.getTimeStamp());
values.put(BRSQLiteHelper.MB_COLUMN_TOTAL_TRANSACTIONS, merkleBlock.getTotalTransactions());
values.put(BRSQLiteHelper.MB_COLUMN_VERSION, merkleBlock.getVersion());
long insertId = database.insert(BRSQLiteHelper.MB_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.MB_TABLE_NAME,
allColumns, BRSQLiteHelper.MB_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRMerkleBlockEntity newMerkleBlock = cursorToMerkleBlock(cursor);
cursor.close();
return newMerkleBlock;
database.beginTransaction();
try {
long insertId = database.insert(BRSQLiteHelper.MB_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.MB_TABLE_NAME,
allColumns, BRSQLiteHelper.MB_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRMerkleBlockEntity newMerkleBlock = cursorToMerkleBlock(cursor);
cursor.close();
database.setTransactionSuccessful();
return newMerkleBlock;
} catch (Exception ex) {
Log.e(TAG, "Error inserting into SQLite", ex);
//Error in between database transaction
} finally {
database.endTransaction();
}
return null;
}
public void deleteMerkleBlock(BRMerkleBlockEntity merkleBlock) {

26
app/src/main/java/com/breadwallet/tools/sqlite/PeerDataSource.java

@ -69,15 +69,25 @@ public class PeerDataSource {
values.put(BRSQLiteHelper.PEER_PORT, peer.getPort());
values.put(BRSQLiteHelper.PEER_SERVICES, peer.getServices());
values.put(BRSQLiteHelper.PEER_TIME_STAMP, peer.getTimeStamp());
database.beginTransaction();
try {
long insertId = database.insert(BRSQLiteHelper.PEER_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.PEER_TABLE_NAME,
allColumns, BRSQLiteHelper.PEER_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRPeerEntity peerEntity = cursorToPeer(cursor);
cursor.close();
database.setTransactionSuccessful();
return peerEntity;
} catch (Exception ex) {
Log.e(TAG, "Error inserting into SQLite", ex);
//Error in between database transaction
} finally {
database.endTransaction();
}
return null;
long insertId = database.insert(BRSQLiteHelper.PEER_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.PEER_TABLE_NAME,
allColumns, BRSQLiteHelper.PEER_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRPeerEntity peerEntity = cursorToPeer(cursor);
cursor.close();
return peerEntity;
}
public void deletePeer(BRPeerEntity peerEntity) {

36
app/src/main/java/com/breadwallet/tools/sqlite/TransactionDataSource.java

@ -70,9 +70,9 @@ public class TransactionDataSource {
values.put(BRSQLiteHelper.TX_TIME_STAMP, transactionEntity.getTimeStamp());
values.put(BRSQLiteHelper.TX_HASH, transactionEntity.getTxHash());
for(BRTxInputEntity input : transactionEntity.getInputs()){
for (BRTxInputEntity input : transactionEntity.getInputs()) {
ContentValues inputValues = new ContentValues();
inputValues.put(BRSQLiteHelper.IN_INDEX,input.getIndex());
inputValues.put(BRSQLiteHelper.IN_INDEX, input.getIndex());
inputValues.put(BRSQLiteHelper.IN_PREV_OUT_INDEX, input.getPrevOutIndex());
inputValues.put(BRSQLiteHelper.IN_PREV_OUT_TX_HASH, input.getPrevOutTxHash());
inputValues.put(BRSQLiteHelper.IN_SEQUENCE, input.getSequence());
@ -81,23 +81,35 @@ public class TransactionDataSource {
database.insert(BRSQLiteHelper.IN_TABLE_NAME, null, values);
}
for(BRTxOutputEntity output : transactionEntity.getOutputs()){
for (BRTxOutputEntity output : transactionEntity.getOutputs()) {
ContentValues outputValues = new ContentValues();
outputValues.put(BRSQLiteHelper.OUT_INDEX,output.getIndex());
outputValues.put(BRSQLiteHelper.OUT_INDEX, output.getIndex());
outputValues.put(BRSQLiteHelper.OUT_TX_HASH, output.getTxHash());
outputValues.put(BRSQLiteHelper.OUT_VALUE, output.getValue());
database.insert(BRSQLiteHelper.OUT_TABLE_NAME, null, values);
}
long insertId = database.insert(BRSQLiteHelper.TX_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.TX_TABLE_NAME,
allColumns, BRSQLiteHelper.TX_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRTransactionEntity transactionEntity1 = cursorToTransaction(cursor);
cursor.close();
return transactionEntity1;
database.beginTransaction();
try {
long insertId = database.insert(BRSQLiteHelper.TX_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.TX_TABLE_NAME,
allColumns, BRSQLiteHelper.TX_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRTransactionEntity transactionEntity1 = cursorToTransaction(cursor);
cursor.close();
database.setTransactionSuccessful();
return transactionEntity1;
} catch (Exception ex) {
Log.e(TAG, "Error inserting into SQLite", ex);
//Error in between database transaction
} finally {
database.endTransaction();
}
return null;
}
public void deleteTransaction(BRTransactionEntity transaction) {

13
app/src/main/java/com/breadwallet/wallet/BRWalletManager.java

@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.security.KeyPairGeneratorSpec;
import android.security.keystore.KeyProperties;
import android.util.Log;
import java.io.File;
@ -75,7 +76,7 @@ public class BRWalletManager {
public static final String FEE_PER_KB_URL = "https://api.breadwallet.com/v1/fee-per-kb";
public static final int SEED_ENTROPY_LENGTH = 128 / 8;
public static final String SEC_ATTR_SERVICE = "org.voisine.breadwallet";
public static final String ANDROID_KEY_STORE = "BreadWalletKeyStore";
public static final String ANDROID_KEY_STORE = "AndroidKeyStore";
public static final String ALIAS = "phrase";
ByteBuffer masterPublicKey; // master public key used to generate wallet addresses
@ -101,7 +102,7 @@ public class BRWalletManager {
}
public void initManager() {
connect();
// connect();
}
public static synchronized BRWalletManager getInstance() {
if (instance == null) {
@ -110,7 +111,7 @@ public class BRWalletManager {
return instance;
}
public native byte[] connect();
// public native byte[] connect();
public native byte[] wallet();
@ -148,7 +149,7 @@ public class BRWalletManager {
KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx)
.setAlias(ALIAS)
.setKeyType("RSA")
.setKeyType(KeyProperties.KEY_ALGORITHM_RSA)
.setKeySize(2048)
.setSubject(new X500Principal("CN=test"))
.setSerialNumber(BigInteger.ONE)
@ -158,7 +159,7 @@ public class BRWalletManager {
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", ANDROID_KEY_STORE);
generator.initialize(spec);
KeyPair keyPair = generator.generateKeyPair();
KeyPair keyPair = generator.generateKeyPair(); // needs to be here
}
int nAfter = keyStore.size();
Log.v(TAG, "Before = " + nBefore + " After = " + nAfter);
@ -363,7 +364,7 @@ public class BRWalletManager {
public boolean noWallet(Context ctx) {
String phrase = getKeyStoreString(null, ctx);
return phrase.length() == 0;
return phrase.length() < 10;
}
/**

3
app/src/main/jni/Android.mk

@ -1,5 +1,6 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := BreadWalletCore
LOCAL_SRC_FILES := core.c
FILE_LIST := $(wildcard $(LOCAL_PATH)/breadwallet-core/*.h)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)

2
app/src/main/jni/breadwallet-core

@ -1 +1 @@
Subproject commit 8fbb6fe62e0706e9ce0501fa945600e20d844b70
Subproject commit 866ff4d0e078b202609ca0f79425b280e318a91c
Loading…
Cancel
Save