test_class.declarator: params = TestNet3Params.get()
test_class.modifier: private static final
test_class.original_string: private static final NetworkParameters params = TestNet3Params.get();
test_class.type: NetworkParameters
test_class.var_name: params
test_class.declarator: simplePaymentUrl = "http://a.simple.url.com/"
test_class.modifier: private static final
test_class.original_string: private static final String simplePaymentUrl = "http://a.simple.url.com/";
test_class.type: String
test_class.var_name: simplePaymentUrl
test_class.declarator: paymentRequestMemo = "send coinz noa plz kthx"
test_class.modifier: private static final
test_class.original_string: private static final String paymentRequestMemo = "send coinz noa plz kthx";
test_class.type: String
test_class.var_name: paymentRequestMemo
test_class.declarator: paymentMemo = "take ze coinz"
test_class.modifier: private static final
test_class.original_string: private static final String paymentMemo = "take ze coinz";
test_class.type: String
test_class.var_name: paymentMemo
test_class.declarator: merchantData = ByteString.copyFromUtf8("merchant data")
test_class.modifier: private static final
test_class.original_string: private static final ByteString merchantData = ByteString.copyFromUtf8("merchant data");
test_class.type: ByteString
test_class.var_name: merchantData
test_class.declarator: time = System.currentTimeMillis() / 1000L
test_class.modifier: private static final
test_class.original_string: private static final long time = System.currentTimeMillis() / 1000L;
test_class.type: long
test_class.var_name: time
test_class.declarator: serverKey
test_class.modifier: private
test_class.original_string: private ECKey serverKey;
test_class.type: ECKey
test_class.var_name: serverKey
test_class.declarator: tx
test_class.modifier: private
test_class.original_string: private Transaction tx;
test_class.type: Transaction
test_class.var_name: tx
test_class.declarator: outputToMe
test_class.modifier: private
test_class.original_string: private TransactionOutput outputToMe;
test_class.type: TransactionOutput
test_class.var_name: outputToMe
test_class.declarator: nanoCoins = Utils.toNanoCoins(1, 0)
test_class.original_string: BigInteger nanoCoins = Utils.toNanoCoins(1, 0);
test_class.type: BigInteger
test_class.var_name: nanoCoins
test_class.file: core/src/test/java/com/google/bitcoin/protocols/payments/PaymentSessionTest.java
test_class.identifier: PaymentSessionTest
test_case.body: @Test
      public void testPkiVerification() throws Exception {
          InputStream in = getClass().getResourceAsStream("pki_test.bitcoinpaymentrequest");
          Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.newBuilder().mergeFrom(in).build();
          MockPaymentSession paymentSession = new MockPaymentSession(paymentRequest);
          PaymentSession.PkiVerificationData pkiData = paymentSession.verifyPki();
          assertEquals("www.bitcoincore.org", pkiData.name);
          assertEquals("The USERTRUST Network, Salt Lake City, US", pkiData.rootAuthorityName);
      }
test_case.class_method_signature: PaymentSessionTest.testPkiVerification()
test_case.full_signature: @Test public void testPkiVerification()
test_case.identifier: testPkiVerification
test_case.invocations: getResourceAsStream getClass build mergeFrom newBuilder verifyPki assertEquals assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testPkiVerification()
focal_class.declarator: executor = Threading.THREAD_POOL
focal_class.modifier: private static
focal_class.original_string: private static ListeningExecutorService executor = Threading.THREAD_POOL;
focal_class.type: ListeningExecutorService
focal_class.var_name: executor
focal_class.declarator: params
focal_class.modifier: private
focal_class.original_string: private NetworkParameters params;
focal_class.type: NetworkParameters
focal_class.var_name: params
focal_class.declarator: trustStorePath
focal_class.modifier: private
focal_class.original_string: private String trustStorePath;
focal_class.type: String
focal_class.var_name: trustStorePath
focal_class.declarator: paymentRequest
focal_class.modifier: private
focal_class.original_string: private Protos.PaymentRequest paymentRequest;
focal_class.type: Protos.PaymentRequest
focal_class.var_name: paymentRequest
focal_class.declarator: paymentDetails
focal_class.modifier: private
focal_class.original_string: private Protos.PaymentDetails paymentDetails;
focal_class.type: Protos.PaymentDetails
focal_class.var_name: paymentDetails
focal_class.declarator: totalValue = BigInteger.ZERO
focal_class.modifier: private
focal_class.original_string: private BigInteger totalValue = BigInteger.ZERO;
focal_class.type: BigInteger
focal_class.var_name: totalValue
focal_class.declarator: pkiVerificationData
focal_class.modifier: public
focal_class.original_string: public PkiVerificationData pkiVerificationData;
focal_class.type: PkiVerificationData
focal_class.var_name: pkiVerificationData
focal_class.file: core/src/main/java/com/google/bitcoin/protocols/payments/PaymentSession.java
focal_class.identifier: PaymentSession
focal_class.class_method_signature: PaymentSession.createFromBitcoinUri(final BitcoinURI uri)
focal_class.full_signature: public static ListenableFuture<PaymentSession> createFromBitcoinUri(final BitcoinURI uri)
focal_class.identifier: createFromBitcoinUri
focal_class.modifiers: public static
focal_class.parameters: (final BitcoinURI uri)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> createFromBitcoinUri(final BitcoinURI uri)
focal_class.class_method_signature: PaymentSession.createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki)
focal_class.full_signature: public static ListenableFuture<PaymentSession> createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki)
focal_class.identifier: createFromBitcoinUri
focal_class.modifiers: public static
focal_class.parameters: (final BitcoinURI uri, final boolean verifyPki)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki)
focal_class.class_method_signature: PaymentSession.createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.full_signature: public static ListenableFuture<PaymentSession> createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.identifier: createFromBitcoinUri
focal_class.modifiers: public static
focal_class.parameters: (final BitcoinURI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.class_method_signature: PaymentSession.createFromUrl(final String url)
focal_class.full_signature: public static ListenableFuture<PaymentSession> createFromUrl(final String url)
focal_class.identifier: createFromUrl
focal_class.modifiers: public static
focal_class.parameters: (final String url)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> createFromUrl(final String url)
focal_class.class_method_signature: PaymentSession.createFromUrl(final String url, final boolean verifyPki)
focal_class.full_signature: public static ListenableFuture<PaymentSession> createFromUrl(final String url, final boolean verifyPki)
focal_class.identifier: createFromUrl
focal_class.modifiers: public static
focal_class.parameters: (final String url, final boolean verifyPki)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> createFromUrl(final String url, final boolean verifyPki)
focal_class.class_method_signature: PaymentSession.createFromUrl(final String url, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.full_signature: public static ListenableFuture<PaymentSession> createFromUrl(final String url, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.identifier: createFromUrl
focal_class.modifiers: public static
focal_class.parameters: (final String url, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> createFromUrl(final String url, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.class_method_signature: PaymentSession.fetchPaymentRequest(final URI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.full_signature: private static ListenableFuture<PaymentSession> fetchPaymentRequest(final URI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.identifier: fetchPaymentRequest
focal_class.modifiers: private static
focal_class.parameters: (final URI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.return: ListenableFuture<PaymentSession>
focal_class.signature: ListenableFuture<PaymentSession> fetchPaymentRequest(final URI uri, final boolean verifyPki, @Nullable final String trustStorePath)
focal_class.class_method_signature: PaymentSession.PaymentSession(Protos.PaymentRequest request)
focal_class.full_signature: public  PaymentSession(Protos.PaymentRequest request)
focal_class.identifier: PaymentSession
focal_class.modifiers: public
focal_class.parameters: (Protos.PaymentRequest request)
focal_class.signature:  PaymentSession(Protos.PaymentRequest request)
focal_class.class_method_signature: PaymentSession.PaymentSession(Protos.PaymentRequest request, boolean verifyPki)
focal_class.full_signature: public  PaymentSession(Protos.PaymentRequest request, boolean verifyPki)
focal_class.identifier: PaymentSession
focal_class.modifiers: public
focal_class.parameters: (Protos.PaymentRequest request, boolean verifyPki)
focal_class.signature:  PaymentSession(Protos.PaymentRequest request, boolean verifyPki)
focal_class.class_method_signature: PaymentSession.PaymentSession(Protos.PaymentRequest request, boolean verifyPki, @Nullable final String trustStorePath)
focal_class.full_signature: public  PaymentSession(Protos.PaymentRequest request, boolean verifyPki, @Nullable final String trustStorePath)
focal_class.identifier: PaymentSession
focal_class.modifiers: public
focal_class.parameters: (Protos.PaymentRequest request, boolean verifyPki, @Nullable final String trustStorePath)
focal_class.signature:  PaymentSession(Protos.PaymentRequest request, boolean verifyPki, @Nullable final String trustStorePath)
focal_class.class_method_signature: PaymentSession.getMemo()
focal_class.full_signature: @Nullable public String getMemo()
focal_class.identifier: getMemo
focal_class.modifiers: @Nullable public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getMemo()
focal_class.class_method_signature: PaymentSession.getValue()
focal_class.full_signature: public BigInteger getValue()
focal_class.identifier: getValue
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: BigInteger
focal_class.signature: BigInteger getValue()
focal_class.class_method_signature: PaymentSession.getDate()
focal_class.full_signature: public Date getDate()
focal_class.identifier: getDate
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Date
focal_class.signature: Date getDate()
focal_class.class_method_signature: PaymentSession.isExpired()
focal_class.full_signature: public boolean isExpired()
focal_class.identifier: isExpired
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isExpired()
focal_class.class_method_signature: PaymentSession.getPaymentUrl()
focal_class.full_signature: public @Nullable String getPaymentUrl()
focal_class.identifier: getPaymentUrl
focal_class.modifiers: public @Nullable
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getPaymentUrl()
focal_class.class_method_signature: PaymentSession.getSendRequest()
focal_class.full_signature: public Wallet.SendRequest getSendRequest()
focal_class.identifier: getSendRequest
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Wallet.SendRequest
focal_class.signature: Wallet.SendRequest getSendRequest()
focal_class.class_method_signature: PaymentSession.sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.full_signature: public @Nullable ListenableFuture<Ack> sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.identifier: sendPayment
focal_class.modifiers: public @Nullable
focal_class.parameters: (List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.return: ListenableFuture<Ack>
focal_class.signature: ListenableFuture<Ack> sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.class_method_signature: PaymentSession.getPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.full_signature: public @Nullable Protos.Payment getPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.identifier: getPayment
focal_class.modifiers: public @Nullable
focal_class.parameters: (List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.return: Protos.Payment
focal_class.signature: Protos.Payment getPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
focal_class.class_method_signature: PaymentSession.sendPayment(final URL url, final Protos.Payment payment)
focal_class.full_signature: @VisibleForTesting protected ListenableFuture<Ack> sendPayment(final URL url, final Protos.Payment payment)
focal_class.identifier: sendPayment
focal_class.modifiers: @VisibleForTesting protected
focal_class.parameters: (final URL url, final Protos.Payment payment)
focal_class.return: ListenableFuture<Ack>
focal_class.signature: ListenableFuture<Ack> sendPayment(final URL url, final Protos.Payment payment)
focal_class.class_method_signature: PaymentSession.verifyPki()
focal_class.full_signature: public @Nullable PkiVerificationData verifyPki()
focal_class.identifier: verifyPki
focal_class.modifiers: public @Nullable
focal_class.parameters: ()
focal_class.return: PkiVerificationData
focal_class.signature: PkiVerificationData verifyPki()
focal_class.class_method_signature: PaymentSession.createKeyStore(@Nullable String path)
focal_class.full_signature: private KeyStore createKeyStore(@Nullable String path)
focal_class.identifier: createKeyStore
focal_class.modifiers: private
focal_class.parameters: (@Nullable String path)
focal_class.return: KeyStore
focal_class.signature: KeyStore createKeyStore(@Nullable String path)
focal_class.class_method_signature: PaymentSession.parsePaymentRequest(Protos.PaymentRequest request)
focal_class.full_signature: private void parsePaymentRequest(Protos.PaymentRequest request)
focal_class.identifier: parsePaymentRequest
focal_class.modifiers: private
focal_class.parameters: (Protos.PaymentRequest request)
focal_class.return: void
focal_class.signature: void parsePaymentRequest(Protos.PaymentRequest request)
focal_class.class_method_signature: PaymentSession.getPaymentRequest()
focal_class.full_signature: public Protos.PaymentRequest getPaymentRequest()
focal_class.identifier: getPaymentRequest
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Protos.PaymentRequest
focal_class.signature: Protos.PaymentRequest getPaymentRequest()
focal_class.class_method_signature: PaymentSession.getPaymentDetails()
focal_class.full_signature: public Protos.PaymentDetails getPaymentDetails()
focal_class.identifier: getPaymentDetails
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Protos.PaymentDetails
focal_class.signature: Protos.PaymentDetails getPaymentDetails()
focal_method.body: public @Nullable PkiVerificationData verifyPki() throws PaymentRequestException {
          try {
              if (pkiVerificationData != null)
                  return pkiVerificationData;
              if (paymentRequest.getPkiType().equals("none"))
                  // Nothing to verify. Everything is fine. Move along.
                  return null;
  
              String algorithm;
              if (paymentRequest.getPkiType().equals("x509+sha256"))
                  algorithm = "SHA256withRSA";
              else if (paymentRequest.getPkiType().equals("x509+sha1"))
                  algorithm = "SHA1withRSA";
              else
                  throw new PaymentRequestException.InvalidPkiType("Unsupported PKI type: " + paymentRequest.getPkiType());
  
              Protos.X509Certificates protoCerts = Protos.X509Certificates.parseFrom(paymentRequest.getPkiData());
              if (protoCerts.getCertificateCount() == 0)
                  throw new PaymentRequestException.InvalidPkiData("No certificates provided in message: server config error");
  
              // Parse the certs and turn into a certificate chain object. Cert factories can parse both DER and base64.
              // The ordering of certificates is defined by the payment protocol spec to be the same as what the Java
              // crypto API requires - convenient!
              CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
              List<X509Certificate> certs = Lists.newArrayList();
              for (ByteString bytes : protoCerts.getCertificateList())
                  certs.add((X509Certificate) certificateFactory.generateCertificate(bytes.newInput()));
              CertPath path = certificateFactory.generateCertPath(certs);
  
              // Retrieves the most-trusted CAs from keystore.
              PKIXParameters params = new PKIXParameters(createKeyStore(trustStorePath));
              // Revocation not supported in the current version.
              params.setRevocationEnabled(false);
  
              // Now verify the certificate chain is correct and trusted. This let's us get an identity linked pubkey.
              CertPathValidator validator = CertPathValidator.getInstance("PKIX");
              PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) validator.validate(path, params);
              PublicKey publicKey = result.getPublicKey();
              // OK, we got an identity, now check it was used to sign this message.
              Signature signature = Signature.getInstance(algorithm);
              // Note that we don't use signature.initVerify(certs.get(0)) here despite it being the most obvious
              // way to set it up, because we don't care about the constraints specified on the certificates: any
              // cert that links a key to a domain name or other identity will do for us.
              signature.initVerify(publicKey);
              Protos.PaymentRequest.Builder reqToCheck = paymentRequest.toBuilder();
              reqToCheck.setSignature(ByteString.EMPTY);
              signature.update(reqToCheck.build().toByteArray());
              if (!signature.verify(paymentRequest.getSignature().toByteArray()))
                  throw new PaymentRequestException.PkiVerificationException("Invalid signature, this payment request is not valid.");
  
              // Signature verifies, get the names from the identity we just verified for presentation to the user.
              X500Principal principal = certs.get(0).getSubjectX500Principal();
              // At this point the Java crypto API falls flat on its face and dies - there's no clean way to get the
              // different parts of the certificate name except for parsing the string. That's hard because of various
              // custom escaping rules and the usual crap. So, use Bouncy Castle to re-parse the string into binary form
              // again and then look for the names we want. Fail!
              org.spongycastle.asn1.x500.X500Name name = new X500Name(principal.getName());
              String entityName = null, orgName = null;
              for (RDN rdn : name.getRDNs()) {
                  AttributeTypeAndValue pair = rdn.getFirst();
                  if (pair.getType().equals(RFC4519Style.cn))
                      entityName = ((ASN1String)pair.getValue()).getString();
                  else if (pair.getType().equals(RFC4519Style.o))
                      orgName = ((ASN1String)pair.getValue()).getString();
              }
              if (entityName == null && orgName == null)
                  throw new PaymentRequestException.PkiVerificationException("Invalid certificate, no CN or O fields");
              // Everything is peachy. Return some useful data to the caller.
              PkiVerificationData data = new PkiVerificationData(entityName, orgName, publicKey, result.getTrustAnchor());
              // Cache the result so we don't have to re-verify if this method is called again.
              pkiVerificationData = data;
              return data;
          } catch (InvalidProtocolBufferException e) {
              // Data structures are malformed.
              throw new PaymentRequestException.InvalidPkiData(e);
          } catch (CertificateException e) {
              // The X.509 certificate data didn't parse correctly.
              throw new PaymentRequestException.PkiVerificationException(e);
          } catch (NoSuchAlgorithmException e) {
              // Should never happen so don't make users have to think about it. PKIX is always present.
              throw new RuntimeException(e);
          } catch (InvalidAlgorithmParameterException e) {
              throw new RuntimeException(e);
          } catch (CertPathValidatorException e) {
              // The certificate chain isn't known or trusted, probably, the server is using an SSL root we don't
              // know about and the user needs to upgrade to a new version of the software (or import a root cert).
              throw new PaymentRequestException.PkiVerificationException(e);
          } catch (InvalidKeyException e) {
              // Shouldn't happen if the certs verified correctly.
              throw new PaymentRequestException.PkiVerificationException(e);
          } catch (SignatureException e) {
              // Something went wrong during hashing (yes, despite the name, this does not mean the sig was invalid).
              throw new PaymentRequestException.PkiVerificationException(e);
          } catch (IOException e) {
              throw new PaymentRequestException.PkiVerificationException(e);
          } catch (KeyStoreException e) {
              throw new RuntimeException(e);
          }
      }
focal_method.class_method_signature: PaymentSession.verifyPki()
focal_method.full_signature: public @Nullable PkiVerificationData verifyPki()
focal_method.identifier: verifyPki
focal_method.invocations: equals getPkiType equals getPkiType equals getPkiType getPkiType parseFrom getPkiData getCertificateCount getInstance newArrayList getCertificateList add generateCertificate newInput generateCertPath createKeyStore setRevocationEnabled getInstance validate getPublicKey getInstance initVerify toBuilder setSignature update toByteArray build verify toByteArray getSignature getSubjectX500Principal get getName getRDNs getFirst equals getType getString getValue equals getType getString getValue getTrustAnchor
focal_method.modifiers: public @Nullable
focal_method.parameters: ()
focal_method.return: PkiVerificationData
focal_method.signature: PkiVerificationData verifyPki()