Hi, Betul,
Have you read the HttpClient SSL Guide?
http://jakarta.apache.org/commons/httpclient/sslguide.html
You should try to avoid EasySSLProtocolSocketFactory. It makes the
security of "https" useless. Using EasySSLProtocolSocketFactory is
like clicking on all of the following browser popups:
"The certificate for the https site is expired. Do you still want to
continue?"
"The certificate for the https site is not signed by a trusted
authority. Do you still want to continue?"
"The hostname specified does not match the hostname in the certificate.
Do you still want to continue?"
If you have any control or influence over the server's certificate you
should try to get a new certificate.
If not, this is probably the least insecure workaround, since the only
"warning popup" it is "clicking" is the expired certificate warning,
as opposed to all three! (Nonetheless, this is still NOT RECOMMENDED.
Buying a new certificate is the best way to go.)
#1. Download not-yet-commons-ssl.jar from here:
http://juliusdavies.ca/commons-ssl/download.html
#2. Code your use of HttpClient like so:
======================================
import org.apache.commons.ssl.HttpSecureProtocol;
HttpSecureProtocol f = new HttpSecureProtocol();
// We're okay with expired certificates.
f.setCheckExpiry( false );
// To avoid deprecation warnings:
ProtocolSocketFactory psf = f;
Protocol trustHttps = new Protocol("https-expired", psf, 443);
Protocol.registerProtocol("https-expired", trustHttps);
HttpClient client = new HttpClient();
GetMethod httpget = new GetMethod("https-expired://mydomain.com/");
client.executeMethod(httpget);
String s = httpget.getStatusLine().toString();
System.out.println( "HTTPClient: " + s );
======================================
Notice that only URL's of the form "https-expired://" will allow
expired certificates after this code has executed. Regular "https://"
URL's still get full security.
Another option is to use Sun Java 1.3 with the JSSE extension. That
combination doesn't bother checking certificate expiry!
yours,
Julius
On 2/9/07, Betül AKIN <[EMAIL PROTECTED]> wrote:
Hi,
I am connecting to an Https site using Httpclient. It was working fine until
today when it started throwing the exception
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateExpiredException: NotAfter: Fri Jan 09 11:03:00
CET 2007
in line
statusCode = client.executeMethod(authpost);
I was using the following lines
Protocol myhttps = new Protocol("https", new
EasySSLProtocolSocketFactory(), Sabitler.KIK_LOGON_PORT);
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, myhttps);
to connect. I googled the problem and came across someone who had the same
problem(http://www.codeguru.com/forum/archive/index.php/t-322145.html). The
solution suggested was changing the EasySSLProtocolSocketFactory in the
following way:
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] {(TrustManager)new EasyX509TrustManager(null)},
new SecureRandom() );
it also said:
"also its important to keep javax.net.ssl apart from com.sun.net.ssl."
I tried it but it doesn't work for me. Can you suggest anything else? Also what does he
mean by "also its important to keep javax.net.ssl apart from com.sun.net.ssl.".
Thanks in advance;
Betul
**********************************************************************
Bu posta ve ekli dosyaları bilinen tüm viruslere karşı taranmıştır. Viruslere
karşı tedbir olarak tanımadığınız kişi ve kuruluşlardan gelen postaları ve
bilmediğiniz ekli dosyaları açmayınız.
This mail and its attachments have been scanned against all of the known
viruses. As a precaution to viruses and other malicious codes, please do not
open the mails and attached files coming from the people or entities that you
are not sure to know.
--
yours,
Julius Davies
416-652-0183
http://juliusdavies.ca/