Skip to main content
sinanalshoker
Staff
Staff
August 9, 2024

Technical Tip: Use the FortiGate API to recover an IPsec pre-shared key in plain text format

  • August 9, 2024
  • 1 reply
  • 15628 views
Description This article describes how to recover an IPsec pre-shared key in plain text format using the FortiGate API.
Scope FortiGate.
Solution

Note:

This article assumes that the admin has an IPsec tunnel set up with a pre-shared key defined, but has forgotten the actual plain text of that key. For demonstration purposes, this article will use a VPN tunnel with a pre-shared key of 'My_PSK'.

Although the pre-shared key 'My_PSK' is known for this example, the focus is to help the admin recover the pre-shared key in plain text format.

 

Log in into the FortiGate GUI using the super_admin profile:

 

FGT.png

 

Open a new tab in the browser (such as Firefox or Google Chrome) and use the following path to obtain the PSK in plain text:

 

For all tunnels:

 

 https://FortiGate_IP/api/v2/cmdb/vpn.ipsec/phase1-interface?plain-text-password=1

 

For a specific tunnel:

 

https://FortiGate_IP/api/v2/cmdb/vpn.ipsec/phase1-interface/TEST_S2S?plain-text-password=1

     

Retreived_PSK.png

 

Important:
When the firewall is operating in multi-VDOM mode, and needs to retrieve the preshared key for a specific VDOM, ensure to access the firewall through an interface associated with the same VDOM. Accessing the firewall via an interface in a different VDOM may restrict visibility or access to the required configuration.

    1 reply

    New Member
    August 12, 2026

    If used multi-VDOM mode can added “&vdom=<vdom name>” in the api url


     • /api/v2/cmdb/vpn.ipsec/phase1-interface?plain-text-password=1&vdom=<vdomName> → vdomName is case sensitive must be exactly vdom name
     • /api/v2/cmdb/vpn.ipsec/phase1-interface?plain-text-password=1 -→ used vdom=root by default
     

    Thought Leadership Security Summit. Outpace New Threats with AI - enhanced defense. Tuesday, Septmeber 15, 8:30 AM - 2:30 PM PT. The Golf Club at Newcastle, WA.
    Virtual event | September 2026. SASE summit. The age of autonomous trust. Register here!