naver / ngrinder

enterprise level performance testing solution
naver.github.io/ngrinder
Apache License 2.0
2k stars 476 forks source link

SSL Connectivity #248

Open himanshusuri opened 7 years ago

himanshusuri commented 7 years ago

Hey,

I am trying to write a client which sends requests to the server over SSL. The client needs to use the certificate(public) in its request. The certificate are stored in a keystore. The language I am using is groovy and JDK version is 1.8.

I have looked in your documentation and on internet and there is not many examples on how we can implement this client. Do you have any example for the same.

Thanks in advance for the help

Regards Himanshu

himanshusuri commented 6 years ago

I am able to solve this issue with the help of java libraries and grinder APIs. If you need I can post my solution here

jensskott commented 6 years ago

I would like that if you can post it here

himanshusuri commented 6 years ago

Hi Jens

IT has been a while since I wrote this code. I will try to recollect and write it here

  1. SET KEYSTORE // -Dhttp.proxyHost=proxynlwp.europe.intranet -Dhttp.proxyPort=8080 keyStoreStream = new FileInputStream(new File(myKSURL.toURI())) keyStore = KeyStore.getInstance("JKS") keyStore.load(keyStoreStream, keystore_password.toCharArray())

    HTTPPluginControl.getHTTPUtilities().basicAuthorizationHeader(accesstoken_key, accesstoken_value)
  2. setSSLContext private HTTPConnection setSSLContext() { try { char[] myPassword = super.keystore_password.toCharArray() SSLContext mySSLContext = SSLContext.getInstance(super.ssl_protocol) KeyManagerFactory myKeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()) myKeyManagerFactory.init(keyStore, myPassword) mySSLContext.init(myKeyManagerFactory.getKeyManagers(), null, null) HTTPConnection myHTTPSConnection = new HTTPConnection(super.protocol, super.hosts[ random.nextInt( super.hosts.length ) ], (int) Integer.parseInt(super.port))

        myHTTPSConnection.setProxyServer("PROXYHOST", PROXYPORT) //optional
        SSLSocketFactory mySSLSocketFactory = mySSLContext.getSocketFactory()
        myHTTPSConnection.setSSLSocketFactory(mySSLSocketFactory)
        return myHTTPSConnection
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace()
    } catch (KeyManagementException e) {
        e.printStackTrace()
    } catch (KeyStoreException e) {
        e.printStackTrace()
    } catch (CertificateException e) {
        e.printStackTrace()
    }

    }

  3. Use the HTTPConnection to make a request public static HTTPConnection SSLHTTPConnection = setSSLContext() HTTPResponse myResponse =SSLHTTPConnection.Post(super.url_resource, myMessageBody,(NVPair[]) myHeaders.toArray())