0

I downloaded the Tor browser, and ran the Tor exe file. I then run the code shown below to try an access a website using SOCKS

    SocketAddress sockAddr = new InetSocketAddress("localhost",9050);
    Proxy proxy = new Proxy(Proxy.Type.SOCKS,sockAddr);
    URL url = new URL("https://check.torproject.org/");

    url.openConnection(proxy);

    InputStream in = url.openConnection(proxy).getInputStream();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    byte[] stuff = new byte[1024];
    int readBytes = 0;
    while((readBytes = in.read(stuff))>0) {
        bout.write(stuff,0,readBytes);
    }
    byte[] result = bout.toByteArray();
    System.out.print(new String(result));

When i run my code i get the following error

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I read that this could be due to an older version of Java so i upgraded Java to jdk1.8.0_121

Can anyone help with this error

0

It's a common problem for all certs issued by "Let's encrypt". Go there and add their root certificate to your trusted list - it's usually not in case of old distro's, OpenJDK and so forth. Details about their certificate root are here - grab them and import into your OS trusted certificates store

  • You can use keytool to import the cert: keytool -importcert -noprompt -trustcacerts -alias 'Ident Trust X3' -file "$downloaded_root_cert" -keystore "$keystore_path" -storepass changeit. $keystore_path is the location of your keystore. It's usually called cacerts but the location differs depending on OS and setup. (Yes, the password is changeit by default.) – Peter Gerber Apr 22 '17 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.