1

I'm attempting to download the content of https://slashdot.org/ with this code :

scala.io.Source.fromURL("https://slashdot.org/", "ISO-8859-1").mkString

This throws exception :

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
        at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
        at sun.security.validator.Validator.validate(Unknown Source)

To fix I export the certificate from https://slashdot.org/ via Chrome. I assign alias 'slashdot' and name the vert file 'cert'. I install using command

keytool -import -trustcacerts -keystore cacerts -storepass changeit -noprompt -alias slashdot -file cert.cer The certificate is imported successfully but same exception is thrown when I attempt to save URL :

scala.io.Source.fromURL("https://slashdot.org/", "ISO-8859-1").mkString

Have I missed a step installing the cert ?

Do I need to specify the "Certification path" as part of downloading the content as specified for the https://slashdot.org/ cert :

enter image description here

Update :

I thought this could be related to my Scala setup but Java code below throws same error :

import java.io.InputStream;
import java.nio.file.Files;
import java.net.URL;
import java.nio.file.StandardCopyOption;
import java.nio.file.Path;

public class download {
public static void main(String args[]) throws Exception{
URL website = new URL("https://slashdot.org/");
 Path target = new java.io.File("c:\\download\\myfile.txt").toPath();

try (InputStream in = website.openStream()) {
    Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
}
}
}
blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • 1
    Does your JVM have access to the certificate? This link might help: https://docs.oracle.com/cd/E19830-01/819-4712/ablqw/index.html – marios Aug 21 '16 at 21:01
  • @marios thanks for link but I'm not sure how it could help? How can I check if JVM can access certificate ? – blue-sky Aug 21 '16 at 22:21
  • 2
    http://stackoverflow.com/questions/8980364/how-do-i-find-out-what-keystore-my-jvm-is-using – Ashalynd Aug 21 '16 at 22:33

1 Answers1

0

I'm not 100% sure why I needed to explicitly set the path of cert file but this works :

System.setProperty("javax.net.ssl.trustStore", "C:\\java\\jdk1.8.0_65\\jre\\lib\\security\\cacerts");

The comments offered to this question attributed to me trying this solution.

blue-sky
  • 51,962
  • 152
  • 427
  • 752