mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-15 20:07:19 +00:00
Payment protocol: misc enhancements.
Stop using the JDK store and use our own, to make the StartSSL fix effective. Include the certs in the exception thrown if the chain doesn't verify. Support loading from a file in the PaymentProtocol tool. Print the certs out in the PaymentProtocol tool if there's an error.
This commit is contained in:
@@ -20,9 +20,14 @@ import com.google.bitcoin.protocols.payments.PaymentRequestException;
|
||||
import com.google.bitcoin.protocols.payments.PaymentSession;
|
||||
import com.google.bitcoin.uri.BitcoinURI;
|
||||
import com.google.bitcoin.uri.BitcoinURIParseException;
|
||||
import org.bitcoin.protocols.payments.Protos;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@@ -42,7 +47,12 @@ public class PaymentProtocol {
|
||||
try {
|
||||
URI uri = new URI(arg);
|
||||
PaymentSession session;
|
||||
if (uri.getScheme().equals("http")) {
|
||||
if (arg.startsWith("/")) {
|
||||
FileInputStream stream = new FileInputStream(arg);
|
||||
Protos.PaymentRequest request = Protos.PaymentRequest.parseFrom(stream);
|
||||
stream.close();
|
||||
session = new PaymentSession(request);
|
||||
} else if (uri.getScheme().equals("http")) {
|
||||
session = PaymentSession.createFromUrl(arg).get();
|
||||
} else if (uri.getScheme().equals("bitcoin")) {
|
||||
BitcoinURI bcuri = new BitcoinURI(arg);
|
||||
@@ -75,13 +85,24 @@ public class PaymentProtocol {
|
||||
System.err.println("Could not parse URI: " + e.getMessage());
|
||||
} catch (BitcoinURIParseException e) {
|
||||
System.err.println("Could not parse URI: " + e.getMessage());
|
||||
} catch (PaymentRequestException.PkiVerificationException e) {
|
||||
System.err.println(e.getMessage());
|
||||
if (e.certificates != null) {
|
||||
for (X509Certificate certificate : e.certificates) {
|
||||
System.err.println(" " + certificate);
|
||||
}
|
||||
}
|
||||
} catch (PaymentRequestException e) {
|
||||
System.err.println("Could not handle payment URL: " + e.getMessage());
|
||||
System.err.println("Could not handle payment request: " + e.getMessage());
|
||||
} catch (InterruptedException e) {
|
||||
System.err.println("Interrupted whilst processing/downloading.");
|
||||
} catch (ExecutionException e) {
|
||||
System.err.println("Failed whilst retrieving payment URL: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user