Commit 0352aa49 authored by Marek Kotewicz's avatar Marek Kotewicz Committed by Tomasz Drwięga
Browse files

seeds are always encrypted using pin (#59)

* added ethstore as dependency

* encrypt account seed, fixes #19

* applied review suggestions

* Java bindings for encryption and decryption

* fixed #58

* cargo uses parity deps from master
parent 068d4e0a
......@@ -79,6 +79,20 @@ public class EthkeyBridge extends ReactContextBaseJavaModule {
promise.resolve(ethkeyRandomPhrase(words));
}
@ReactMethod
public void encryptData(String data, String password, Promise promise) {
promise.resolve(ethkeyEncryptData(data, password));
}
@ReactMethod
public void decryptData(String data, String password, Promise promise) {
try {
promise.resolve(ethkeyDecryptData(data, password));
} catch (Exception e) {
promise.reject("invalid password", null, null);
}
}
private static native String ethkeyBrainwalletAddress(String seed);
private static native String ethkeyBrainwalletSecret(String seed);
private static native String ethkeyBrainwalletSign(String seed, String message);
......@@ -86,4 +100,6 @@ public class EthkeyBridge extends ReactContextBaseJavaModule {
private static native String ethkeyKeccak(String data);
private static native String ethkeyBlockiesIcon(String seed);
private static native String ethkeyRandomPhrase(int words);
private static native String ethkeyEncryptData(String data, String password);
private static native String ethkeyDecryptData(String data, String password);
}
\ No newline at end of file
......@@ -91,4 +91,33 @@ class EthkeyBridge: NSObject {
rust_string_destroy(words_rust_str)
resolve(words)
}
@objc func encryptData(_ data: String, password: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
var password_ptr = password.asPtr()
let encrypted_data_rust_str = encrypt_data(&data_ptr, &password_ptr)
let encrypted_data_rust_str_ptr = rust_string_ptr(encrypted_data_rust_str)
let encrypted_data = String.fromStringPtr(ptr: encrypted_data_rust_str_ptr!.pointee)
rust_string_ptr_destroy(encrypted_data_rust_str_ptr)
rust_string_destroy(encrypted_data_rust_str)
resolve(encrypted_data)
}
@objc func decryptData(_ data: String, password: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
var password_ptr = password.asPtr()
var error: UInt32 = 0
let decrypted_data_rust_str = decrypt_data(&data_ptr, &password_ptr, &error)
let decrypted_data_rust_str_ptr = rust_string_ptr(decrypted_data_rust_str)
let decrypted_data = String.fromStringPtr(ptr: decrypted_data_rust_str_ptr!.pointee)
rust_string_ptr_destroy(decrypted_data_rust_str_ptr)
rust_string_destroy(decrypted_data_rust_str)
if error == 0 {
resolve(decrypted_data)
} else if error == 1{
reject("invalid data", nil, nil)
} else {
reject("invalid password", nil, nil)
}
}
}
......@@ -32,5 +32,7 @@ RCT_EXTERN_METHOD(rlpItem:(NSString*)rlp position:(NSUInteger)position resolve:(
RCT_EXTERN_METHOD(keccak:(NSString*)data resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(blockiesIcon:(NSString*)seed resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(randomPhrase:(NSUInteger)words resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(encryptData:(NSString*)data password:(NSString*)password resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(decryptData:(NSString*)data password:(NSString*)password resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
@end
......@@ -4,6 +4,7 @@ version = "0.1.0"
dependencies = [
"blockies 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethkey 0.2.0 (git+https://github.com/paritytech/parity)",
"ethstore 0.1.0 (git+https://github.com/paritytech/parity)",
"jni 0.3.1 (git+https://github.com/prevoty/jni-rs)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-wordlist 1.0.0 (git+https://github.com/paritytech/wordlist)",
......@@ -83,6 +84,11 @@ dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "either"
version = "1.1.0"
......@@ -124,7 +130,7 @@ dependencies = [
[[package]]
name = "ethcore-bigint"
version = "0.1.2"
source = "git+https://github.com/paritytech/parity#93ee2a9b64c5ddc9655b1927836378ac915a7813"
source = "git+https://github.com/paritytech/parity#1df30ee83e20a39baa3b416518f3b01f6c56e8ff"
dependencies = [
"bigint 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -133,10 +139,22 @@ dependencies = [
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ethcrypto"
version = "0.1.0"
source = "git+https://github.com/paritytech/parity#1df30ee83e20a39baa3b416518f3b01f6c56e8ff"
dependencies = [
"eth-secp256k1 0.5.6 (git+https://github.com/paritytech/rust-secp256k1)",
"ethcore-bigint 0.1.2 (git+https://github.com/paritytech/parity)",
"ethkey 0.2.0 (git+https://github.com/paritytech/parity)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ethkey"
version = "0.2.0"
source = "git+https://github.com/paritytech/parity#93ee2a9b64c5ddc9655b1927836378ac915a7813"
source = "git+https://github.com/paritytech/parity#1df30ee83e20a39baa3b416518f3b01f6c56e8ff"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth-secp256k1 0.5.6 (git+https://github.com/paritytech/rust-secp256k1)",
......@@ -148,6 +166,31 @@ dependencies = [
"tiny-keccak 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ethstore"
version = "0.1.0"
source = "git+https://github.com/paritytech/parity#1df30ee83e20a39baa3b416518f3b01f6c56e8ff"
dependencies = [
"ethcore-bigint 0.1.2 (git+https://github.com/paritytech/parity)",
"ethcrypto 0.1.0 (git+https://github.com/paritytech/parity)",
"ethkey 0.2.0 (git+https://github.com/paritytech/parity)",
"itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-wordlist 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gcc"
version = "0.3.43"
......@@ -198,6 +241,11 @@ dependencies = [
"either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "jni"
version = "0.3.1"
......@@ -283,6 +331,14 @@ name = "odds"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "owning_ref"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parity-wordlist"
version = "1.0.0"
......@@ -293,6 +349,38 @@ dependencies = [
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parity-wordlist"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parking_lot"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "parking_lot_core"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "png"
version = "0.6.2"
......@@ -304,6 +392,11 @@ dependencies = [
"num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.15"
......@@ -320,7 +413,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rlp"
version = "0.1.0"
source = "git+https://github.com/paritytech/parity#93ee2a9b64c5ddc9655b1927836378ac915a7813"
source = "git+https://github.com/paritytech/parity#1df30ee83e20a39baa3b416518f3b01f6c56e8ff"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"elastic-array 0.6.0 (git+https://github.com/paritytech/elastic-array)",
......@@ -365,6 +458,85 @@ name = "semver"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_codegen_internals"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syn 0.11.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen_internals 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "smallvec"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "stable_deref_trait"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.11.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempdir"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread-id"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.36"
......@@ -381,6 +553,11 @@ name = "tiny-keccak"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.2.8"
......@@ -402,13 +579,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
"checksum combine 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89749770bffc77cb34db11b60d5d4b197388b46bc7774ac8acbde33c26ad6c08"
"checksum deflate 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ebb02aaf4b775afc96684b8402510a338086974e38570a1f65bea8c202eb77a7"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
"checksum elastic-array 0.6.0 (git+https://github.com/paritytech/elastic-array)" = "<none>"
"checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180"
"checksum error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e92ecf0a508c8e074c0e6fa8fe0fa38414848ad4dfc4db6f74c5e9753330b248"
"checksum eth-secp256k1 0.5.6 (git+https://github.com/paritytech/rust-secp256k1)" = "<none>"
"checksum ethcore-bigint 0.1.2 (git+https://github.com/paritytech/parity)" = "<none>"
"checksum ethcrypto 0.1.0 (git+https://github.com/paritytech/parity)" = "<none>"
"checksum ethkey 0.2.0 (git+https://github.com/paritytech/parity)" = "<none>"
"checksum ethstore 0.1.0 (git+https://github.com/paritytech/parity)" = "<none>"
"checksum gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c758b972368e703a562686adb39125707cc1ef3399da8c019fc6c2498a75d"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "5a376f7402b85be6e0ba504243ecbc0709c48019ecc6286d0540c2e359050c88"
......@@ -416,6 +596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "979bad0502082fd60053a490282e87d6c89650942e3a270e0d4c83569c7f5899"
"checksum inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7e0062d2dc2f17d2f13750d95316ae8a2ff909af0fda957084f5defd87c43bb"
"checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc"
"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c"
"checksum jni 0.3.1 (git+https://github.com/prevoty/jni-rs)" = "<none>"
"checksum jni-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "83ba0fad4625733b25833da250d0c84058314e1a276f4939f3e87c195997c206"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
......@@ -428,8 +609,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "c2dc5ea04020a8f18318ae485c751f8cfa1c0e69dcf465c29ddaaa64a313cc44"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba"
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
"checksum parity-wordlist 1.0.0 (git+https://github.com/paritytech/wordlist)" = "<none>"
"checksum parity-wordlist 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07779ab11d958acbee30fcf644c99d3fae132d8fcb41282a25e1ee284097bdd2"
"checksum parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aebb68eebde2c99f89592d925288600fde220177e46b5c9a91ca218d245aeedf"
"checksum parking_lot_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "56a19dcbb5d1e32b6cccb8a9aa1fc2a38418c8699652e735e2bf391a3dc0aa16"
"checksum png 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3cb773e9a557edb568ce9935cf783e3cdcabe06a9449d41b3e5506d88e582c82"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753"
"checksum rlp 0.1.0 (git+https://github.com/paritytech/parity)" = "<none>"
......@@ -438,7 +624,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum serde 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)" = "231dfd55909400769e437326cfb4af8bec97c3dd56ab3d02df8ef5c7e00f179b"
"checksum serde_codegen_internals 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bc888bd283bd2420b16ad0d860e35ad8acb21941180a83a189bb2046f9d00400"
"checksum serde_derive 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)" = "d75c72ef4dd193d89eb652b73890fe2489996c9ead8b37980f57a1078f96ed50"
"checksum serde_json 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ad8bcf487be7d2e15d3d543f04312de991d631cfe1b43ea0ade69e6a8a5b16a1"
"checksum smallvec 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dca03f2f42500a9ef8ac0d16183dff8bed40e3dcf98f9d4147928548d5c4236e"
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
"checksum syn 0.11.10 (registry+https://github.com/rust-lang/crates.io-index)" = "171b739972d9a1bfb169e8077238b51f9ebeaae4ff6e08072f7ba386a8802da2"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
"checksum thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4437c97558c70d129e40629a5b385b3fb1ffac301e63941335e4d354081ec14a"
"checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade"
"checksum tiny-keccak 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8ac274ea206f5352fe553c7b5d8f5658eea51238e747e12968c48705b791b644"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
......@@ -7,6 +7,7 @@ authors = ["debris <marek.kotewicz@gmail.com>"]
libc = "0.2"
rustc-serialize = "0.3"
ethkey = { git = "https://github.com/paritytech/parity" }
ethstore = { git = "https://github.com/paritytech/parity" }
rlp = { git = "https://github.com/paritytech/parity" }
tiny-keccak = "1.1"
blockies = "0.1"
......
......@@ -74,3 +74,9 @@ struct rust_string* blockies_icon(const struct rust_string_ptr* blockies_seed);
// random phrase ffi
struct rust_string* random_phrase(const uint32_t words);
// data encryption ffi
struct rust_string* encrypt_data(const struct rust_string_ptr* data, const struct rust_string_ptr* password);
struct rust_string* decrypt_data(const struct rust_string_ptr* encrypted_data, const struct rust_string_ptr* password, unsigned* error);
......@@ -19,6 +19,7 @@ extern crate rustc_serialize;
extern crate tiny_keccak;
extern crate parity_wordlist as wordlist;
extern crate ethkey;
extern crate ethstore;
extern crate rlp;
extern crate blockies;
......@@ -28,6 +29,7 @@ use rustc_serialize::hex::{ToHex, FromHex};
use rustc_serialize::base64::{self, ToBase64};
use tiny_keccak::Keccak;
use ethkey::{KeyPair, Generator, Brain, Message, sign};
use ethstore::Crypto;
use rlp::UntrustedRlp;
use blockies::{Blockies, create_icon, ethereum};
......@@ -150,6 +152,38 @@ pub unsafe extern fn random_phrase(words: u32) -> *mut String {
Box::into_raw(Box::new(words))
}
// data encryption ffi
#[no_mangle]
pub unsafe extern fn encrypt_data(data: *mut StringPtr, password: *mut StringPtr) -> *mut String {
let data = (*data).as_str();
let password = (*password).as_str();
let crypto = Crypto::with_plain(data.as_bytes(), password, 10240);
Box::into_raw(Box::new(crypto.into()))
}
#[no_mangle]
pub unsafe extern fn decrypt_data(encrypted_data: *mut StringPtr, password: *mut StringPtr, error: *mut u32) -> *mut String {
let data = (*encrypted_data).as_str();
let password = (*password).as_str();
let crypto: Crypto = match data.parse() {
Ok(crypto) => crypto,
Err(_) => {
*error = 1;
return Box::into_raw(Box::new(String::new()))
}
};
match crypto.decrypt(password) {
Ok(decrypted) => {
Box::into_raw(Box::new(String::from_utf8_unchecked(decrypted)))
},
Err(_) => {
*error = 2;
Box::into_raw(Box::new(String::new()))
},
}
}
#[cfg(target_os = "android")]
#[allow(non_snake_case)]
pub mod android {
......@@ -224,6 +258,39 @@ pub mod android {
let words = wordlist::random_phrase(words as usize);
env.new_string(words).expect("Could not create java string").into_inner()
}
#[no_mangle]
pub unsafe extern fn Java_com_nativesigner_EthkeyBridge_ethkeyEncryptData(env: JNIEnv, _: JClass, data: JString, password: JString) -> jstring {
let data: String = env.get_string(data).expect("Invalid data").into();
let password: String = env.get_string(password).expect("Invalid password").into();
let crypto = Crypto::with_plain(data.as_bytes(), &password, 10240);
env.new_string(String::from(crypto)).expect("Could not create java string").into_inner()
}
#[no_mangle]
pub unsafe extern fn Java_com_nativesigner_EthkeyBridge_ethkeyDecryptData(env: JNIEnv, _: JClass, data: JString, password: JString) -> jstring {
let data: String = env.get_string(data).expect("Invalid data").into();
let password: String = env.get_string(password).expect("Invalid password").into();
let crypto: Crypto = match data.parse() {
Ok(crypto) => crypto,
Err(_) => {
let res = env.new_string("").expect("").into_inner();
env.throw(res.into());
return res
},
};
match crypto.decrypt(&password) {
Ok(decrypted) => {
env.new_string(String::from_utf8_unchecked(decrypted)).expect("Could not create java string").into_inner()
},
Err(_) => {
let res = env.new_string("").expect("").into_inner();
env.throw(res.into());
res
},
}
}
}
#[cfg(test)]
......
......@@ -16,14 +16,35 @@
'use strict'
import { Alert, Keyboard } from 'react-native'
import { Actions } from 'react-native-router-flux'
import {
ADD_ACCOUNT, SELECT_ACCOUNT, DELETE_ACCOUNT, MODIFY_ACCOUNT, SET_NEW_PIN, SET_ACCOUNTS
ADD_ACCOUNT, SELECT_ACCOUNT, DELETE_ACCOUNT, MODIFY_ACCOUNT, SET_NEW_PIN, SET_OLD_PIN, SET_ACCOUNTS
} from '../constants/AccountActions'
import { encryptData, decryptData } from '../util/native'
export function addAccount (account) {
return {
type: ADD_ACCOUNT,
account
export function addAccount (pin) {
return async function (dispatch, getState) {
try {
let account = getState().accounts.selected
if (!account) {
return
}
let seed = await encryptData(account.seed, pin)
dispatch({
type: ADD_ACCOUNT,
account: {
encryptedSeed: seed,
address: account.address,
name: account.name
}
})
Actions.popTo('accountList')
Alert.alert('Account Created')
} catch (e) {
console.error(e)
}
}
}
......@@ -49,10 +70,33 @@ export function modifyAccount (account, modifications) {
}
}
export function setOldPin (pin) {
return async function (dispatch, getState) {
let account = getState().accounts.selected
if (!account) {
return
}
try {
await decryptData(account.encryptedSeed, pin)
dispatch({
type: SET_OLD_PIN,
pin
})
Actions.accountSetPin()
} catch (e) {
Alert.alert('Invalid PIN')
}
}
}
export function setNewPin (pin) {
return {
type: SET_NEW_PIN,
pin
return function (dispatch) {
dispatch({
type: SET_NEW_PIN,
pin
})
Actions.accountConfirmPin()
}
}
......@@ -62,3 +106,34 @@ export function setAccounts (accounts) {
accounts
}
}
export function changePin (newPin) {
return async function (dispatch, getState) {
let account = getState().accounts.selected
if (!account) {
return
}
if (account.newPin !== newPin) {
Alert.alert('New PIN must be the same')
return
}
Keyboard.dismiss()
try {
let seed = await decryptData(account.encryptedSeed, account.oldPin)
let encryptedSeed = await encryptData(seed, newPin)
dispatch(modifyAccount(account, {
encryptedSeed: encryptedSeed
}))
Actions.popTo('accountDetails')
Alert.alert('PIN changed')
} catch (e) {
// this is unreachanle if setOldPin was called before
console.error(e)
}
}
}
......@@ -16,9 +16,10 @@
'use strict'
import { Alert } from 'react-native'
import { Actions } from 'react-native-router-flux'