download file over https with p12 cert
Hi all,
I have a huuuuuge problem. I ' ve searched the last 2 days for a solution but found... nothing that works.
I want to download videos from a https location with my java app. To download these files a p12 certificate is required.
What I have done so far:
I have imported the p12 cert into my keystore (after i have imported the p12 cert to JKS).
The result of
keytool -list -keystore C:\...\jre1.5.0_04\lib\security\cacerts -storepass changeit
contains my certificate:
"matthias(virat), 02.09.2005, keyEntry,
Zertifikatsfingerabdruck (MD5): D7:09:2E:C8:27:E9:AC:92:3E:7C:36:CD:4C:XX:XX:XX"
Now here is my code:
package src;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Security;
publicclass test1{
publicstaticvoid main(String[] args){
try{
// Set the system and security properties
System.setProperty("javax.net.ssl.trustStore",
"C:\\Programme\\Java\\jre1.5.0_04\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");
System.setProperty("javax.net.ssl.keyStoreType","JKS");
// Keystore location and password
System.setProperty("javax.net.ssl.keyStore",
"C:\\Programme\\Java\\jre1.5.0_04\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// connect to get the web page
URL url =new URL(
"https://sedna.statsbiblioteket.dk:8280/urn/urn:dk:statsbiblioteket:commercials:movie-1");
URLConnection connection = url.openConnection();
// get the contents of the web page
InputStream stream = connection.getInputStream();
BufferedReader reader =new BufferedReader(new InputStreamReader(
stream));
// read in the entire web page
StringBuffer webPage =new StringBuffer();
// String line = null;
while (reader.readLine() !=null){
webPage = webPage.append(reader.readLine());
System.out.println(reader.readLine());
}
// close all resources that we do not need
// now that the web page has been obtained
stream.close();
reader.close();
}catch (MalformedURLException e){
System.out.println("MalformedURLException");
}catch (IOException e){
System.out.println(e.toString());
}
}
}
If I execute the app i get the following exception:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I have no idea what I can do to fix the problem.
Thanks in advance for any kind of suggestion.
Regards
anja

