mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Payment protocol: re-organise code a bit to handle Android devices that have the javax property set.
This commit is contained in:
parent
f94c41e5b6
commit
b3bf4aadb7
@ -172,7 +172,7 @@ public class PaymentSession {
|
||||
if (url == null)
|
||||
throw new PaymentRequestException.InvalidPaymentRequestURL("null paymentRequestUrl");
|
||||
try {
|
||||
return fetchPaymentRequest(new URI(url), true, trustStorePath);
|
||||
return fetchPaymentRequest(new URI(url), verifyPki, trustStorePath);
|
||||
} catch(URISyntaxException e) {
|
||||
throw new PaymentRequestException.InvalidPaymentRequestURL(e);
|
||||
}
|
||||
@ -186,8 +186,7 @@ public class PaymentSession {
|
||||
connection.setRequestProperty("Accept", "application/bitcoin-paymentrequest");
|
||||
connection.setUseCaches(false);
|
||||
Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.parseFrom(connection.getInputStream());
|
||||
PaymentSession paymentSession = new PaymentSession(paymentRequest, verifyPki, trustStorePath);
|
||||
return paymentSession;
|
||||
return new PaymentSession(paymentRequest, verifyPki, trustStorePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -511,33 +510,33 @@ public class PaymentSession {
|
||||
keyStore.load(is, defaultPassword);
|
||||
return keyStore;
|
||||
}
|
||||
path = System.getProperty("javax.net.ssl.trustStore");
|
||||
if (path == null) {
|
||||
try {
|
||||
// Check if we are on Android.
|
||||
try {
|
||||
Class Build = Class.forName("android.os.Build");
|
||||
Object version = Build.getDeclaredField("VERSION").get(Build);
|
||||
// Build.VERSION_CODES.ICE_CREAM_SANDWICH is 14.
|
||||
if (version.getClass().getDeclaredField("SDK_INT").getInt(version) >= 14) {
|
||||
// After ICS, Android provided this nice method for loading the keystore,
|
||||
// so we don't have to specify the location explicitly.
|
||||
KeyStore keystore = KeyStore.getInstance("AndroidCAStore");
|
||||
keystore.load(null, null);
|
||||
return keystore;
|
||||
} else {
|
||||
keyStoreType = "BKS";
|
||||
path = System.getProperty("java.home") + "/etc/security/cacerts.bks".replace('/', File.separatorChar);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
// NOP. android.os.Build is not present, so we are not on Android.
|
||||
} catch (NoSuchFieldException e) {
|
||||
// This should never happen.
|
||||
} catch (IllegalAccessException e) {
|
||||
// This should never happen.
|
||||
Class Build = Class.forName("android.os.Build");
|
||||
Object version = Build.getDeclaredField("VERSION").get(Build);
|
||||
// Build.VERSION_CODES.ICE_CREAM_SANDWICH is 14.
|
||||
if (version.getClass().getDeclaredField("SDK_INT").getInt(version) >= 14) {
|
||||
// After ICS, Android provided this nice method for loading the keystore,
|
||||
// so we don't have to specify the location explicitly.
|
||||
KeyStore keystore = KeyStore.getInstance("AndroidCAStore");
|
||||
keystore.load(null, null);
|
||||
return keystore;
|
||||
} else {
|
||||
keyStoreType = "BKS";
|
||||
path = System.getProperty("java.home") + "/etc/security/cacerts.bks".replace('/', File.separatorChar);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
// NOP. android.os.Build is not present, so we are not on Android. Fall through.
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e); // Should never happen.
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e); // Should never happen.
|
||||
}
|
||||
if (path == null) {
|
||||
// We are not on Android. Try this default system location for Linux/Windows/OSX.
|
||||
path = System.getProperty("javax.net.ssl.trustStore");
|
||||
}
|
||||
if (path == null) {
|
||||
// Try this default system location for Linux/Windows/OSX.
|
||||
path = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
|
||||
}
|
||||
try {
|
||||
@ -546,7 +545,8 @@ public class PaymentSession {
|
||||
keyStore.load(is, defaultPassword);
|
||||
return keyStore;
|
||||
} catch (FileNotFoundException e) {
|
||||
// If we failed to find a system trust store, load our own fallback trust store.
|
||||
// If we failed to find a system trust store, load our own fallback trust store. This can fail on Android
|
||||
// but we should never reach it there.
|
||||
KeyStore keyStore = KeyStore.getInstance("JKS");
|
||||
InputStream is = getClass().getResourceAsStream("cacerts");
|
||||
keyStore.load(is, defaultPassword);
|
||||
|
@ -23,8 +23,6 @@ import com.google.protobuf.ByteString;
|
||||
import org.bitcoin.protocols.payments.Protos;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
@ -35,7 +33,6 @@ import java.util.Date;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class PaymentSessionTest {
|
||||
private static final Logger log = LoggerFactory.getLogger(PaymentSessionTest.class);
|
||||
private static final NetworkParameters params = TestNet3Params.get();
|
||||
private static final String simplePaymentUrl = "http://a.simple.url.com/";
|
||||
private static final String paymentRequestMemo = "send coinz noa plz kthx";
|
||||
|
Loading…
Reference in New Issue
Block a user