Merge pull request #1403 from AlphaWallet/Obfuscate-Keys

NDK key fetch
pull/1409/head
James Brown 5 years ago committed by GitHub
commit 722f766274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .gitignore
  2. 26
      app/build.gradle
  3. 6
      app/src/main/cpp/CMakeLists.txt
  4. 54
      app/src/main/cpp/keys.c
  5. 21
      app/src/main/cpp/native-lib.c
  6. 23
      app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java
  7. 15
      app/src/main/java/com/alphawallet/app/service/TickerService.java
  8. 2
      app/src/test/java/com/alphawallet/app/UniversalLinkTest.java
  9. 2
      app/src/test/java/com/alphawallet/app/UniversalLinkTypeTest.java

6
.gitignore vendored

@ -40,6 +40,12 @@ fastlane/report.xml
# Local configuration file (sdk path, etc)
local.properties
#C/C++ object files
app/.cxx/
# Secret keys
keys.secret
# Proguard folder generated by Eclipse
proguard/

@ -39,30 +39,11 @@ android {
minSdkVersion 24
targetSdkVersion 29
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
def CoinmarketCapAPI = "CoinmarketCapAPI"
def AmberdataAPI = "AmberdataAPI"
def InfuraAPI = "InfuraAPI"
def XInfuraAPI = "XInfuraAPI"
def COINMARKET_CAP_KEY = "\"ea2d0a6b-7e77-4015-bccf-4877e5c5b882\""
def AMBERDATA_API_KEY = "\"obtain-api-key-from-amberdata-io\"";
//Put your Infura key here
def DEFAULT_INFURA_API_KEY = "\"da3717f25f824cc1baa32d812386d93f\"";
def INFURA_API_KEY;
if (project.hasProperty("infuraAPI")) {
INFURA_API_KEY = infuraAPI
} else {
INFURA_API_KEY = DEFAULT_INFURA_API_KEY;
}
if (project.hasProperty("coinmarketcapAPI")) {
COINMARKET_CAP_KEY = coinmarketcapAPI
}
if (project.hasProperty("amberdataAPI")) {
AMBERDATA_API_KEY = amberdataAPI
}
buildConfigField 'int', 'DB_VERSION', '7'
buildConfigField "String", CoinmarketCapAPI, COINMARKET_CAP_KEY
buildConfigField "String", AmberdataAPI, AMBERDATA_API_KEY
buildConfigField "String", InfuraAPI, INFURA_API_KEY
buildConfigField "String", XInfuraAPI, DEFAULT_INFURA_API_KEY
ndk {
@ -99,6 +80,11 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
}
project.ext {

@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib SHARED
native-lib.c)
add_library(keys SHARED
keys.c)
# Include libraries needed for native-lib lib
target_link_libraries(native-lib
target_link_libraries(keys
android
log)

@ -0,0 +1,54 @@
#include <string.h>
#include <alloca.h>
#include <jni.h>
#if __has_include ("..\..\..\..\keys.secret")
# define HAS_KEYS 1
# include "..\..\..\..\keys.secret"
#else
# define HAS_KEYS 0
#endif
JNIEXPORT jstring JNICALL
Java_com_alphawallet_app_repository_EthereumNetworkBase_getAmberDataKey( JNIEnv* env, jobject thiz )
{
#if (HAS_KEYS == 1)
return getDecryptedKey(env, amberdataKey);
#else
const jstring key = "obtain-api-key-from-amberdata-io";
return (*env)->NewStringUTF(env, key);
#endif
}
JNIEXPORT jstring JNICALL
Java_com_alphawallet_app_repository_EthereumNetworkBase_getInfuraKey( JNIEnv* env, jobject thiz )
{
#if (HAS_KEYS == 1)
return getDecryptedKey(env, infuraKey);
#else
const jstring key = "da3717f25f824cc1baa32d812386d93f";
return (*env)->NewStringUTF(env, key);
#endif
}
JNIEXPORT jstring JNICALL
Java_com_alphawallet_app_service_TickerService_getAmberDataKey( JNIEnv* env, jobject thiz )
{
#if (HAS_KEYS == 1)
return getDecryptedKey(env, amberdataKey);
#else
const jstring key = "obtain-api-key-from-amberdata-io";
return (*env)->NewStringUTF(env, key);
#endif
}
JNIEXPORT jstring JNICALL
Java_com_alphawallet_app_service_TickerService_getCMCKey( JNIEnv* env, jobject thiz )
{
#if (HAS_KEYS == 1)
return getDecryptedKey(env, cmcKey);
#else
const jstring key = "ea2d0a6b-7e77-4015-bccf-4877e5c5b882";
return (*env)->NewStringUTF(env, key);
#endif
}

@ -1,21 +0,0 @@
#include <string.h>
#include <jni.h>
JNIEXPORT jstring JNICALL
Java_com_wallet_crypto_trustapp_controller_PasswordManager_getKeyStringFromNative( JNIEnv* env, jobject thiz )
{
// TODO: fill in your key - must be 32 bytes
const jstring key = "ThisIsNotTheKeyYoureLookingFor!!";
return (*env)->NewStringUTF(env, key);
}
JNIEXPORT jbyteArray JNICALL
Java_com_wallet_crypto_trustapp_controller_PasswordManager_getIvStringFromNative( JNIEnv* env, jobject thiz )
{
// TODO: fill in your iv - must be 16 bytes
const jstring iv = "NorTheInitVector";
return (*env)->NewStringUTF(env, iv);
}

@ -46,24 +46,31 @@ public abstract class EthereumNetworkBase implements EthereumNetworkRepositoryTy
If you wish your node to be the fallback, tried in case the primary times out then add/replace in ..._FALLBACK_RPC_URL list
*/
static {
System.loadLibrary("keys");
}
public static native String getAmberDataKey();
public static native String getInfuraKey();
//Fallback nodes: these nodes are used if there's no Amberdata key, and also as a fallback in case the primary node times out while attempting a call
public static final String MAINNET_RPC_URL = "https://mainnet.infura.io/v3/" + BuildConfig.InfuraAPI;
public static final String RINKEBY_RPC_URL = "https://rinkeby.infura.io/v3/" + BuildConfig.InfuraAPI;
public static final String MAINNET_RPC_URL = "https://mainnet.infura.io/v3/" + getInfuraKey();
public static final String RINKEBY_RPC_URL = "https://rinkeby.infura.io/v3/" + getInfuraKey();
//Note that AlphaWallet now uses a double node configuration. See class AWHttpService comment 'try primary node'.
//If you supply a main RPC and secondary it will try the secondary if the primary node times out after 10 seconds.
//See the declaration of NetworkInfo - it has a member backupNodeUrl. Put your secondary node here.
public static final String BACKUP_INFURA_KEY = BuildConfig.InfuraAPI;
public static final String MAINNET_FALLBACK_RPC_URL = !BuildConfig.AmberdataAPI.startsWith("obtain") ? "https://rpc.web3api.io?x-api-key=" + BuildConfig.AmberdataAPI : MAINNET_RPC_URL;
public static final String BACKUP_INFURA_KEY = BuildConfig.XInfuraAPI;
public static final String MAINNET_FALLBACK_RPC_URL = !getAmberDataKey().startsWith("obtain") ? "https://rpc.web3api.io?x-api-key=" + getAmberDataKey() : MAINNET_RPC_URL;
public static final String CLASSIC_RPC_URL = "https://ethereumclassic.network";
public static final String XDAI_RPC_URL = "https://dai.poa.network";
public static final String POA_RPC_URL = "https://core.poa.network/";
public static final String ROPSTEN_RPC_URL = "https://ropsten.infura.io/v3/" + BuildConfig.InfuraAPI;
public static final String RINKEBY_FALLBACK_RPC_URL = !BuildConfig.AmberdataAPI.startsWith("obtain") ? "https://rpc.web3api.io?x-api-key=" + BuildConfig.AmberdataAPI + "&x-amberdata-blockchain-id=1b3f7a72b3e99c13" : RINKEBY_RPC_URL;
public static final String KOVAN_RPC_URL = "https://kovan.infura.io/v3/" + BuildConfig.InfuraAPI;
public static final String ROPSTEN_RPC_URL = "https://ropsten.infura.io/v3/" + getInfuraKey();
public static final String RINKEBY_FALLBACK_RPC_URL = !getAmberDataKey().startsWith("obtain") ? "https://rpc.web3api.io?x-api-key=" + getAmberDataKey() + "&x-amberdata-blockchain-id=1b3f7a72b3e99c13" : RINKEBY_RPC_URL;
public static final String KOVAN_RPC_URL = "https://kovan.infura.io/v3/" + getInfuraKey();
public static final String SOKOL_RPC_URL = "https://sokol.poa.network";
public static final String GOERLI_RPC_URL = "https://goerli.infura.io/v3/" + BuildConfig.InfuraAPI;
public static final String GOERLI_RPC_URL = "https://goerli.infura.io/v3/" + getInfuraKey();
public static final String ARTIS_SIGMA1_RPC_URL = "https://rpc.sigma1.artis.network";
public static final String ARTIS_TAU1_RPC_URL = "https://rpc.tau1.artis.network";

@ -82,6 +82,13 @@ public class TickerService implements TickerServiceInterface
private static String currentCurrencySymbolTxt;
private static String currentCurrencySymbol;
public static native String getCMCKey();
public static native String getAmberDataKey();
static {
System.loadLibrary("keys");
}
public TickerService(OkHttpClient httpClient, Gson gson, Context ctx)
{
this.httpClient = httpClient;
@ -127,7 +134,7 @@ public class TickerService implements TickerServiceInterface
{
ethTickers.put(ARTIS_SIGMA1_ID, artisTicker);
ethTickers.put(ARTIS_TAU1_ID, artisTicker);
final String keyAPI = BuildConfig.CoinmarketCapAPI;
final String keyAPI = getCMCKey();
return Single.fromCallable(() -> {
try
{
@ -261,7 +268,7 @@ public class TickerService implements TickerServiceInterface
String netName = "ethereum-mainnet";
if (info.chainId != MAINNET_ID) return Single.fromCallable(() -> { return new Token[0]; });
List<Token> tokenList = new ArrayList<>();
final String keyAPI = BuildConfig.AmberdataAPI;
final String keyAPI = getAmberDataKey();
return Single.fromCallable(() -> {
try
{
@ -349,7 +356,7 @@ public class TickerService implements TickerServiceInterface
Request request = new Request.Builder()
.url("https://web3api.io/api/v2/tokens/rankings?type=erc20")
.get()
.addHeader("x-api-key", BuildConfig.AmberdataAPI)
.addHeader("x-api-key", getAmberDataKey())
.build();
okhttp3.Response response = httpClient.newCall(request)
@ -426,7 +433,7 @@ public class TickerService implements TickerServiceInterface
private Single<Map<Integer, TokenTicker>> fetchAmberData(Map<Integer, TokenTicker> tickers)
{
final String keyAPI = BuildConfig.AmberdataAPI;
final String keyAPI = getAmberDataKey();
return Single.fromCallable(() -> {
try
{

@ -34,7 +34,7 @@ import com.alphawallet.token.tools.ParseMagicLink;
public class UniversalLinkTest
{
private static ParseMagicLink parser = new ParseMagicLink(new CryptoFunctions(), EthereumNetworkRepository.extraChains());
private static ParseMagicLink parser = new ParseMagicLink(new CryptoFunctions(), null);
final String[] links = { "https://aw.app/AAAAAFroO8yg2x-t8XoYKvHWEk8mRcRZuarNIgwNDg9OYA205_-QZURILYlNp6astOo-RkQMSSefIzMWHKdjcGsc3kAaHfHYi7rrLTgmUfAMaQjFB_u8G0EbB8HewJwDAA==",
"https://aw.app/AB6EgFroX2xm8IymiSAXpF2m-3kqjpRvy-PYZRQVFhcYAlMtOEau6TvoUT-lN5HoxjxlErC2T0LJ-1u4DmORCdoVs-UNTIL33W_OJ6jGJy2ocqEyWBmV-RiYPIzQlHq0mwE=",

@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
*/
public class UniversalLinkTypeTest
{
private static ParseMagicLink parser = new ParseMagicLink(new CryptoFunctions(), EthereumNetworkRepository.extraChains());
private static ParseMagicLink parser = new ParseMagicLink(new CryptoFunctions(), null);
/**
* these values give the key format, ie

Loading…
Cancel
Save