public BitcoinURI processWalletNameUrl ( URL url , boolean verifyTLSA ) throws WalletNameLookupException { HttpsURLConnection conn = null ; InputStream ins ; InputStreamReader isr ; BufferedReader in = null ; Certificate possibleRootCert = null ; if ( verifyTLSA ) { try { if ( ! this . tlsaValidator . validateTLSA ( url ) ) { throw new WalletNameTlsaValidationException ( "TLSA Validation Failed" ) ; } } catch ( ValidSelfSignedCertException ve ) { // TLSA Uses a Self-Signed Root Cert, We Need to Add to CACerts possibleRootCert = ve . getRootCert ( ) ; } catch ( Exception e ) { throw new WalletNameTlsaValidationException ( "TLSA Validation Failed" , e ) ; } } try { conn = ( HttpsURLConnection ) url . openConnection ( ) ; // If we have a self-signed cert returned during TLSA Validation, add it to the SSLContext for the HTTPS Connection if ( possibleRootCert != null ) { try { KeyStore ssKeystore = KeyStore . getInstance ( KeyStore . getDefaultType ( ) ) ; ssKeystore . load ( null , null ) ; ssKeystore . setCertificateEntry ( ( ( X509Certificate ) possibleRootCert ) . getSubjectDN ( ) . toString ( ) , possibleRootCert ) ; TrustManagerFactory tmf = TrustManagerFactory . getInstance ( TrustManagerFactory . getDefaultAlgorithm ( ) ) ; tmf . init ( ssKeystore ) ; SSLContext ctx = SSLContext . getInstance ( "TLS" ) ; ctx . init ( null , tmf . getTrustManagers ( ) , null ) ; conn . setSSLSocketFactory ( ctx . getSocketFactory ( ) ) ; } catch ( Exception e ) { throw new WalletNameTlsaValidationException ( "Failed to Add TLSA Self Signed Certificate to HttpsURLConnection" , e ) ; } } ins = conn . getInputStream ( ) ; isr = new InputStreamReader ( ins ) ; in = new BufferedReader ( isr ) ; String inputLine ; String data = "" ; while ( ( inputLine = in . readLine ( ) ) != null ) { data += inputLine ; } try { return new BitcoinURI ( data ) ; } catch ( BitcoinURIParseException e ) { throw new WalletNameLookupException ( "Unable to create BitcoinURI" , e ) ; } } catch ( IOException e ) { throw new WalletNameURLFailedException ( "WalletName URL Connection Failed" , e ) ; } finally { if ( conn != null && in != null ) { try { in . close ( ) ; } catch ( IOException e ) { // Do Nothing } conn . disconnect ( ) ; } } }
Resolve a Wallet Name URL Endpoint