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:
Mike Hearn
2014-03-23 19:21:42 +01:00
parent feecc8f486
commit 0ed260bae2
3 changed files with 45 additions and 10 deletions

View File

@@ -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();
}
}
}