Wednesday, February 22, 2017

Client / Server Authentication using openssl

Steps to Create CSR (Certificate Signing Request) using OpenSSL and create JKS file to interact with Server

What is client authentication?
Client Authentication is the process by which users securely access a server or remote computer by exchanging a Digital Certificate.

#To create CSR and Private Key
openssl req -new -newkey rsa:2048 -nodes -out star_yourdomainname_com.csr -keyout star_yourdomainname_com.key -subj "/C=US/ST=New Jersey/L=Bedminster/O=Organization Name/OU=Organization Unit/CN=*.yourdomainname.com"

# Combine private key and public key file received from 3rd party
cat star_yourdomainname_com.key star_yourdomainname_com.pem_SIGNED.pem > projectName.pem

# Generate pkcs12 file from private + public key file
openssl pkcs12 -export -in projectName.pem -out projectNamekeystore.pkcs12 -name projectName -noiter -nomaciter

# Create jks File from pkcs12 file generated
keytool -importkeystore -srckeystore projectNamekeystore.pkcs12 -srcstoretype pkcs12 -srcalias projectName -destkeystore projectNameKeyStore.jks -deststoretype jks -deststorepass pass@123 -destalias projectName

# To list the keystore stored
keytool -v -list -keystore keystore

Write Java program using HttpClient to test this JKS file and Get / Post the data from 3rd party server

Curl : Through curl also same works and testing can be done

# Combine private key and public key file received from 3rd party
cat star_yourdomainname_com.key star_yourdomainname_com.pem_SIGNED.pem > projectName.pem

Curl Command :
curl -k -vvvv --request GET -H "Accept: application/json" -H "Content-Type: application/json" -a --cert projectName.pem "https://thirdpartydomainname.com/WebGateway/rest/Location/query/location?userId=1234"

No comments :

// Below script tag for SyntaxHighLighter