1

I am trying to make an auto login program for my schools wifi login system. I need to do a POST request to a the authentication URL (https://ccahack.bergen.org/auth/perfigo_validate.jsp) and submit some parameters.If I change the HTTPS to a HTTP and do the POST request it just redirects me back to the sign in forum. So it is imperative that I POST to the HTTPS, but the problem is that I get an SSL socket error, here is my code:

public boolean signIn() throws Exception{ //System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36"); String httpsURL = "https://ccahack.bergen.org/auth/perfigo_validate.jsp"; String username = "username"; String password = "password"; StringBuilder q = new StringBuilder(); q.append("reqFrom="+URLEncoder.encode("perfigo_simple_login.jsp","UTF-8")); q.append("&uri="+ URLEncoder.encode("https://ccahack.bergen.org/","UTF-8")); q.append("&cm=" + URLEncoder.encode("ws32vklm", "UTF-8")); q.append("&userip="+URLEncoder.encode("IP_ADDRESS HERE","UTF-8")); q.append("&os=" +URLEncoder.encode("MAC_OSX","UTF-8")); q.append("&index="+URLEncoder.encode("4","UTF-8")); q.append("&username="+URLEncoder.encode(username,"UTF-8")); q.append("&password="+URLEncoder.encode(password,"UTF-8")); q.append("&provider="+URLEncoder.encode("BCA","UTF-8")); q.append("&login_submt="+URLEncoder.encode("Continue","UTF8")); String query = q.toString(); URL myurl = new URL(httpsURL); HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-length", String.valueOf(query.length())); con.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)"); con.setDoOutput(true); con.setDoInput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); //error here output.writeBytes(query); output.close(); DataInputStream input = new DataInputStream( con.getInputStream() ); for( int c = input.read(); c != -1; c = input.read() ) System.out.print( (char)c ); input.close(); System.out.println("Resp Code:"+con.getResponseCode()); System.out.println("Resp Message:"+ con.getResponseMessage()); return false; } 
2
  • 4
    It will help if you post the error. Commented Oct 16, 2013 at 22:23
  • 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 Commented Oct 17, 2013 at 11:26

1 Answer 1

1

Based on the exception you posted in the comment, you will need to ensure that the site's certificate is in your truststore. (Assuming here that you trust it.)

Here'e something I wrote up some time back:

http://springinpractice.com/2012/04/29/fixing-pkix-path-building-issues-when-using-javamail-and-smtp/

In this case I was doing SMTP (where you are doing HTTP) so you will need to make adjustments for that.

Sign up to request clarification or add additional context in comments.

1 Comment

I am little confused on what to do. I understand that I need to download the certificate but what command do I use? Something like this?: openssl s_client -connect mail.kattare.com:2525https://ccahack.bergen.org/auth/perfigo_validate.jsp:80 -htpp http > bergen.cer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.