Sunday, August 30, 2020

Configuring Jmeter to use client certificate

In the current IT world, authorization is one of the important factor to consider while building the system/infrastructure and it is used to communicate securely between client and server. Authorization happens in many ways and authorization via client certificate is one of among them.

Client-side certificates are required because they are the best way for a server to "know" exactly who is connecting. Hence, In the real world, most of the servers expect client certificates when client initiates the communication with server to authorize. After successful authorization, client can send the request to server and get the response back from server. 

In this post, we will see how to send the client certificate to server and get the response from server using Jmeter.

NOTE:

Generally, Jmeter supports client certificate in three different formats. They are .jks, .p12, .pfx. In case, your certificate is in different format (sometime it is in .pem format) other than these three, you must convert your certificate to either one of the above.

There are two ways we can send the client certificate to the server using Jmeter.

1. Via SSL Manager

2. Via system.properties

We will go through one by one. Assume that, I have a client certificate in .jks format and I place this file in my local machine under C:\Project folder.

In my case, I need to send the username and password (CTCADMIN\C424051 as username and Password@123 as password) to access the server. This may not be applicable for your case. This certificate has the password as well (which is not important for this option as we are invoking the certificate directly in GUI mode).

This can be achieved using HTTP Authorization Manager in Jmeter

Option # 1: Via SSL Manager 

Step # 1: Click on Options -> SSL Manager.

Step # 2: Browse the certificate and select.

Step # 3: Click on Open. Now, client certificate is loaded (obviously with password)

Step # 4: Create the HTTP sampler and update server name, method, path, and body based on your API.

Step # 5: Add response assertion to validate the response of the request. In my case, I am expecting response code "200"

Step # 6: Add listener (View results tree) to view the output.

Step # 7: Now you are good to hit the execute button. You will get the expected response like below.

Option # 2: Via System.Properties file (under Jmeter\bin\ folder)

Step # 1: Locate the system.properties file in Jmeter installation path.

Step # 2: Open the file in any editor such as notepad/notepad++/textpad et.c

Step # 3: Search Keystore properties.

Step # 4: Uncomment the Location and the password (Remove '#' symbol before the line). Provide the certificate location in location line and update the password against password line(Remember we didn't give the password for option 1, but here it is important). Refer below.

Remember the location should contain escape sequence ("\\") in the path. If your certificate path is C:\Project\creditcardtpanconvertertest.jks, you must update this as "C:\\Project\\creditcardtpanconvertertest.jks".

Step # 5: Save the file and restart the jmeter.

Step # 6: Create the HTTP sampler and update server name, method, path, and body based on your API.


Step # 7: Add response assertion to validate the response of the request. In my case, I am expecting response code "200"

Step # 8: Add listener (View Results Tree) to view the output.

Step # 9: Now you are good to hit the execute button. You will get the expected response like below.

That's all. Simple, Isn't it? 😁.

No comments:

Post a Comment

Linux Series - SED Utility/Package - 4. Deleting Lines

Let’s explore sed’s explicit delete command, which you specify by using the option 'd'. Again, we are using the sample file named &#...