mulesoftmule4anypoint-studiomule-esbanypoint-platform

Make HTTPS GET request using http connector in Mule with SSL certificates


I have .crt and privatekey.pem keys which can be used for making HTTPS GET API request.

We can't use these certificates directly in mulesoft for making https API requests.

As far I know it supports Trust store configuration and Key store configuration in the JCEKS, JKS and PKCS12 formats

I have tried using the command below

openssl x509 -outform der -in certificate.private.pem -out certificate.der
keytool -import -alias your-alias -keystore cacerts -file certificate.der

It's failing with the error below after running openssl command mentioned below

unable to load certificate
140706477451034:error:09A2F34C:PEM routines:CRYPTO_internal:no start line:/Library/BuildRoots/97f7341o-dq75-11ed-a4bc-863efbbaf86g/Library/Caches/Sources/libressl/libressl-3.3/crypto/pem/pem_lib.c:694:Expecting: TRUSTED CERTIFICATE

how I can convert my keys to these specific formats and how I can use it while making https get requests from Mulesoft's Anypoint Studio

I didn't find a right article for converting .CRT and .PEM files to Mule supported file formats.


Solution

  • We can convert the two .crt and privatekey.pem files into a single JKS file, as required by the Mule HTTP connector for sending HTTPS GET requests with certificates

    The commands to convert .crt and privatekey.pem certs into JKS files are listed below.

    openssl pkcs12 -export -inkey private_key.pem -in certificate.crt -out keystore.p12
    
    keytool -importkeystore -srckeystore keystore.p12 -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS
    

    The keystore.jks file will be created and then placed in the mule's project src/main/resource  folder as seen in the picture below.

    enter image description here

    After adding it, click on + under Basic Settings to add a http connector and set a configuration similar to the one shown in the following picture.

    enter image description here

    Finally, provide the GET method and the Path as per your API and then deploy the Mule application. It's done.