For Programmers: Free Programming Magazines  


Home > Archive > Java Security > March 2006 > connect to https and store certification key









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author connect to https and store certification key
NOVA

2006-03-11, 7:56 am

Hi all,

I want code to connect to https by using httpunit

it is possible to get source code of http page by usin URLConnection
class
by this code :
try {
URL url = new
URL("https://hronline.aramco.com.sa/sec/login.asp");
URLConnection uc = url.openConnection();
uc.connect();
BufferedReader in = new BufferedReader(new
InputStreamReader(uc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();

} catch(UnknownHostException e){
System.out.println(e + "***one***");
System.out.println("must be on line to properly.");
}
catch(MalformedURLException e){
System.out.println(e + "***two***");
}
catch(IOException e){
System.out.println(e + "***three***");
}


and to take source code of https by using URLConnection class, I just
add this code

TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[]
getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String
authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String
authType) {
}
}
};

// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e){}


but in httpunit that is not happen
so, i should add certification key manully by export the file from
explorer browser
then add it to file in
java_src\jre\lib\security\cacerts

until this point is ok

What I want?
Is that possible to write java code to do store the certification when
I connection with https directly?

thanks,

NOVA

2006-03-13, 7:57 am

is that possible??!!
no answer !!!!


I tried read all topic that dependent to my topic
but i am not understand

please
any answer.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com