Problem with Sentinel PB Fortigate - Function Fortinet-GetEntityDetails
Describe the bug When I try to run the PB to find if the IP is created in the Forti I get the error "The remote certificate is invalid according to the validation procedure." and I can't get past this step. If I just execute the function, the same thing happens to me.
To Reproduce
I execute this code:

Screenshots Error

Can you help me?
Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.
To me it looks like the error is with your authentication. Maybe try using this outdated method that I wrote:
Function for getting token - use the correct API values etc, would be good to first test values using Postman. The current values for the GetToken() fucntion are for a connection to a Log Analytics workspace.
private static string GetToken(){
var request = (HttpWebRequest)WebRequest.Create("REQUEST TO LA");
var postData = "grant_type=" + Uri.EscapeDataString("client_credentials");
postData += "&client_id=" + Uri.EscapeDataString(""); //add client ID
postData += "&client_secret=" + Uri.EscapeDataString(""); //add client secret
postData += "&resource=" + Uri.EscapeDataString("https://api.loganalytics.io");
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
//convert token to string
dynamic stuff = JsonConvert.DeserializeObject(responseString);
string token = stuff.access_token;
return token;
}
Perform the request using the token that you just got. Remember to fill in the correct accept and other values for the request.
private static string Request() {
var access = GetToken();
var request = (HttpWebRequest)WebRequest.Create("REQUESTHERE");
request.Method = "GET";
request.Accept = "application/json";
request.Headers["Authorization"] = "Bearer "+access;
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
//convert token to string
dynamic results = JsonConvert.DeserializeObject(responseString);
return results.ToString(); //I'm returing this in a string format, but if you can parse it and think of a better way, please do make the change
}
Sorry, but I don't quite understand your code. I explain to you, this function in the photo is used to connect via API to a FortiGate using the key that we have added in the key vault and the predefined values in the APP(Picture) function. I don't know why my code fails and I don't know if yours is compatible with what I want to do. I can't use PostMan due to permission issues. Can you help me?
Thank you.

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.
Any updates??
Hello?
Any updates?
Hi @Joaquin1912 - Sorry for delay in responding. We are not able to replicate this issue, but I am thinking this might be caused by 2 reasons 1) Invalid Key 2) Your host is not enabled with SSL certificate. Since you have mentioned that you can't use postman, can you please try with curl ? Sample API call is given below, you can replace with your fortigate host details
curl -X POST "https://'fwurl'/api/v2/cmdb/firewall/address" -H "accept: application/json" -H "Authorization: Bearer 'api key'" -H "Content-Type: application/json" -d "{ "name": "test1000", "type": "iprange", "start-ip": "20.1.1.12", "end-ip": "20.1.1.12"}"
Hello!!
Thanks for the reply, I get this above when I run it
Regards
Hi @Joaquin1912 - Thanks for checking. So based on this, it clearly indicates that these is an issue with Fortigate hosts SSL configuration. This is generic issue and nothing to do with this Playbook or Sentinel. So please try to address this issue by contacting system administrator or fortigate team.

Hi all, Greetings !!!
I just wanted to create a playbook in sentinel for auto-blocking an IP address in FortiGate Firewall. by using the below link. could anyone tell me the step by step how i can achieve it.
like we need function app, custom connector and API key. but how playbook will communicate with On-Prem Fortigate firewall. what configuration we have to do in FortiGate Firewall side.
https://github.com/Azure/Azure-Sentinel/tree/master/Playbooks/Fortinet-FortiGate
Regards
Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.
Hi @raj009970, Thank you for your comment. Can you please create a new issue as this issue is not related to the actual issue opened here.
Hi @Joaquin1912, As per earlier comment this issue is from Fortinet hosts SSL so closing this issue as it is not related to playbook or Sentinel.
Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.
Hello,
I resolved the issue on the run.csx of the function please update by writing this code :
#r "Newtonsoft.Json"
#r "System.Net.Http"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography.X509Certificates;
public static async Task
//response = response.ToString() var responseJson = response.Content.ReadAsStringAsync().Result; if (responseJson != null) { JObject json = new JObject(); dynamic obj = JsonConvert.DeserializeObject(responseJson); json = (JObject)obj; results = json.SelectToken("results"); return new OkObjectResult(results); } return new OkObjectResult(results); }
Hi @NinaSec, thank you very much for the code you provided; it has been extremely helpful to us! May I inquire which template you are using? We are utilizing this Fortinet SOAR: https://github.com/Azure/Azure-Sentinel/tree/master/Solutions/Fortinet%20FortiGate%20Next-Generation%20Firewall%20connector%20for%20Microsoft%20Sentinel/Playbooks/FortinetFortigateFunctionApp. However, its runtime version is 3.2, which is already out of support.