1

My exact requirement here is that I want to do the above in automation scripts. My framework is currently a karate Framework with Python. Is there any way to do the same in my automation scripts?

NOTE: this is a 2 step process for me where STEP 1 generates the private/public keys & then I'd have to use them to execute STEP 2which is next API call I can also do a manual workaround here by manually downloading the cert & key.pem files & use them to configure ssl for the API call.

I'm only a beginner in API testing & using SSL configuration.. please help!

ram
  • 21
  • 2
  • this sounds complex, and never heard this requirement before. my suggestion is use java interop (refer the karate docs) and get a friend to help. or you may be able to call some command line program / batch file, refer: https://stackoverflow.com/a/62911366/143475 – Peter Thomas Apr 19 '23 at 02:14

1 Answers1

0

Hi, Let's make in 2 Steps !

Based on your description, it appears that you intend to create private/public keys and set up SSL for an API call. Here's a concise guide on how to accomplish this: Well let me give you a more detailed guide on generating private/public keys and using them to configure SSL for an API call, with additional examples:

STEP 1: Generate private/public keys

1- Open a command prompt or terminal window on your computer. 2- Type in the following command to generate a private key with a length of 2048 bits:

openssl genrsa -out key.pem 2048

This will create a new file called key.pem in the current directory, which contains the private key. 3-Type in the following command to generate a public key from the private key:

openssl rsa -in key.pem -outform PEM -pubout -out public.pem

This will create a new file called public.pem in the current directory, which contains the public key.

Note: The private key should be kept secure and never shared with anyone. The public key can be shared with others, as it is used to encrypt data that can only be decrypted by the private key.

STEP 2: Use private/public keys to configure SSL for API call

  1. Make sure you have the key.pem and public.pem files saved in a secure location on your computer.
  2. Determine the endpoint of the API you want to call, as well as any required headers or parameters.
  3. Use a tool such as cURL or Postman to make the API call, and configure SSL by specifying the path to the key.pem and public.pem files in the SSL certificate and key options.

Example 1: Using cURL to make a GET request with SSL

curl --cert /path/to/key.pem --key /path/to/public.pem https://api.example.com/users

In this example, the --cert and --key options are used to specify the path to the key.pem and public.pem files. The API endpoint is https://api.example.com/users, and the GET method is used to retrieve user data.

Example 2: Using Postman to make a POST request with SSL

1- Open Postman and create a new request. 2- In the request builder, select the POST method and enter the API endpoint in the URL field. 3- Click on the "Body" tab and select "Raw", then choose "JSON" from the dropdown. 4- Enter the payload data for the API call, e.g.:

{
  "name": "John Doe",
  "email": "johndoe@example.com"
}

5- Click on the "Headers" tab and add any required headers, e.g.:

MessoMan
  • 1
  • 2
  • Thanks for your response. My exact requirement here is I want to do the above in automation scripts. My framework is currently a karate Framework with Python. Is there any way to do the same in my automation scripts? – ram Apr 18 '23 at 15:30