Gemalto is now part of the Thales Group, find out more.

You are here

BGS5 - Certificate verification failure for https connection | Thales IoT Developer Community

October 7, 2016 - 2:32pm, 2341 views

Hello,

I am trying to connect to a webserver via https. I am using google.pt as a test server as I am getting the same error using our temporarly self-signed server.

I have downloaded google.pt certificate encoded in .der and converted it into a command:

java -jar jseccmd.jar -cmd AddHttpsCertificateUntrusted -filename ./google.der > AddGoogleCertificate.bin



I have run the following commands:

AT^SJMSEC="cmd","0B00310001000500020001"

AT^SJMSEC="file","AddGoogleCertificate.bin"



I always get a Certificate failed verification exception when attempting to connect to either google.pt or our self-signed server. I follow the same steps I do with google.pt as with our server's with the same results. I believe that I am following the correct procedures but I am unsuccesfull in getting a connection.

Thank you.



My java code is (url= "https://google.pt" or our server):



public synchronized String sendHttps (String url) throws Exception{

        String resp = "";

        HttpsConnection c = null;

        InputStream is = null;

        try {

            c = (HttpsConnection) Connector.open(url,Connector.READ_WRITE,true);

            c.setRequestMethod(HttpConnection.GET);

            c.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");



            is = c.openDataInputStream();



            if (c.getResponseCode() == HttpConnection.HTTP_OK) {

                // Get the length and process the data

                int len = (int) c.getLength();

                if (len > 0) {

                    byte[] data = new byte[len];

                    is.read(data);

                    resp = String.valueOf(data);

                } else {

                    System.out.println("[GPRS] No data ");



                }

                System.out.println("Message: " + c.getResponseMessage() + " Type: " + c.getType());

            } else {

                System.out.println("Error code: " + c.getResponseCode() + " Message: " + c.getResponseMessage() + " Type: " + c.getType());

            }



        } finally {

            if (is != null) {

                is.close();

            }

            if (c != null) {

                c.close();

            }

        }

        return resp;



    }





at^sjmsec?



^SJMSEC: 1,1,1,0

ati1



Cinterion

BGS5

REVISION 01.100

A-REVISION 00.000.18