mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +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)
|
if (url == null)
|
||||||
throw new PaymentRequestException.InvalidPaymentRequestURL("null paymentRequestUrl");
|
throw new PaymentRequestException.InvalidPaymentRequestURL("null paymentRequestUrl");
|
||||||
try {
|
try {
|
||||||
return fetchPaymentRequest(new URI(url), true, trustStorePath);
|
return fetchPaymentRequest(new URI(url), verifyPki, trustStorePath);
|
||||||
} catch(URISyntaxException e) {
|
} catch(URISyntaxException e) {
|
||||||
throw new PaymentRequestException.InvalidPaymentRequestURL(e);
|
throw new PaymentRequestException.InvalidPaymentRequestURL(e);
|
||||||
}
|
}
|
||||||
@ -186,8 +186,7 @@ public class PaymentSession {
|
|||||||
connection.setRequestProperty("Accept", "application/bitcoin-paymentrequest");
|
connection.setRequestProperty("Accept", "application/bitcoin-paymentrequest");
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.parseFrom(connection.getInputStream());
|
Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.parseFrom(connection.getInputStream());
|
||||||
PaymentSession paymentSession = new PaymentSession(paymentRequest, verifyPki, trustStorePath);
|
return new PaymentSession(paymentRequest, verifyPki, trustStorePath);
|
||||||
return paymentSession;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -511,33 +510,33 @@ public class PaymentSession {
|
|||||||
keyStore.load(is, defaultPassword);
|
keyStore.load(is, defaultPassword);
|
||||||
return keyStore;
|
return keyStore;
|
||||||
}
|
}
|
||||||
path = System.getProperty("javax.net.ssl.trustStore");
|
try {
|
||||||
if (path == null) {
|
|
||||||
// Check if we are on Android.
|
// Check if we are on Android.
|
||||||
try {
|
Class Build = Class.forName("android.os.Build");
|
||||||
Class Build = Class.forName("android.os.Build");
|
Object version = Build.getDeclaredField("VERSION").get(Build);
|
||||||
Object version = Build.getDeclaredField("VERSION").get(Build);
|
// Build.VERSION_CODES.ICE_CREAM_SANDWICH is 14.
|
||||||
// Build.VERSION_CODES.ICE_CREAM_SANDWICH is 14.
|
if (version.getClass().getDeclaredField("SDK_INT").getInt(version) >= 14) {
|
||||||
if (version.getClass().getDeclaredField("SDK_INT").getInt(version) >= 14) {
|
// After ICS, Android provided this nice method for loading the keystore,
|
||||||
// After ICS, Android provided this nice method for loading the keystore,
|
// so we don't have to specify the location explicitly.
|
||||||
// so we don't have to specify the location explicitly.
|
KeyStore keystore = KeyStore.getInstance("AndroidCAStore");
|
||||||
KeyStore keystore = KeyStore.getInstance("AndroidCAStore");
|
keystore.load(null, null);
|
||||||
keystore.load(null, null);
|
return keystore;
|
||||||
return keystore;
|
} else {
|
||||||
} else {
|
keyStoreType = "BKS";
|
||||||
keyStoreType = "BKS";
|
path = System.getProperty("java.home") + "/etc/security/cacerts.bks".replace('/', File.separatorChar);
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
|
} 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) {
|
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);
|
path = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -546,7 +545,8 @@ public class PaymentSession {
|
|||||||
keyStore.load(is, defaultPassword);
|
keyStore.load(is, defaultPassword);
|
||||||
return keyStore;
|
return keyStore;
|
||||||
} catch (FileNotFoundException e) {
|
} 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");
|
KeyStore keyStore = KeyStore.getInstance("JKS");
|
||||||
InputStream is = getClass().getResourceAsStream("cacerts");
|
InputStream is = getClass().getResourceAsStream("cacerts");
|
||||||
keyStore.load(is, defaultPassword);
|
keyStore.load(is, defaultPassword);
|
||||||
|
@ -23,8 +23,6 @@ import com.google.protobuf.ByteString;
|
|||||||
import org.bitcoin.protocols.payments.Protos;
|
import org.bitcoin.protocols.payments.Protos;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@ -35,7 +33,6 @@ import java.util.Date;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class PaymentSessionTest {
|
public class PaymentSessionTest {
|
||||||
private static final Logger log = LoggerFactory.getLogger(PaymentSessionTest.class);
|
|
||||||
private static final NetworkParameters params = TestNet3Params.get();
|
private static final NetworkParameters params = TestNet3Params.get();
|
||||||
private static final String simplePaymentUrl = "http://a.simple.url.com/";
|
private static final String simplePaymentUrl = "http://a.simple.url.com/";
|
||||||
private static final String paymentRequestMemo = "send coinz noa plz kthx";
|
private static final String paymentRequestMemo = "send coinz noa plz kthx";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user