Hi All, I’m trying to develop a script that will export a multi SAN cert from CTW and then upload it to a FortiGate unit running FortiOS 7.0.1.
I know this version has limited ability to do it’s own request but it needs an ACME challenge server behind it so it’s much simpler if I can get it from my CTW instance uploaded to the FortiGate and then I can run an additional command to set it for a particular usage.
If anyone has even some basic clues to follow or some examples, that’d be extremely helpful.
I don’t know anything about FortiGate myself but a useful feature of Certify is Deployment Tasks (under Tasks) - these are steps you can add at the end of certificate renewal to convert and deploy the certificate in various ways. You can also add a task and run it immediately if you already have a working certificate.
Some of the tasks include:
Deploy to Generic Server: this can export as .pem format files (.crt, .key etc) and optionally copy the file over SFTP to a remote host.
Script: this can run local scripts or even SSH into a remote host and run scripts there.
Ideally you need the fortigate to have an API you can push the certificate to, or accept SSH/SFTP, or in some cases people use powershell etc to login to the web UI and post files etc, but that’s a bit brittle if the admin UI ever changes.
I had written a script prior to FortiOS 7 that could do this (not from certifytheweb but actually from Win-Acme. It used a whole bunch of commands using a script for Putty. It wasn’t elegant and wasn’t secure but it worked.
The Fortigate can now do this on it’s own, though I don’t think with multi-SAN. If that is absolutely needed I would actually look for a way to do it via the Fortigate API and then try to figure it out as a web deployment task.
If you want though I can find (I hope) and send my old scripts. But honestly it seems like in this case I would allow the Fortigate to do it on it’s own.
If you could find them I think that’d be a fantastic help. The main requirement I have is to grab the cert that CTW generates and upload it because
The FortiGate using it’s built in Let’s Encrypt option won’t allow SAN or Wildcard, only single name certs and the objective is to use the certificate for Web Load Balancing, SSL-VPN and Management interface, all with different FQDN’s
Using the built in engine also expects that there is ACME server sitting behind the requesting IP and I’m not keen on that as it adds complexity (As well as a Linux box which I’m not keen on managing)
The FortiGate definitely has an API, and being really upfront, I wouldn’t have a clue how to use it. I’m doing a bit of research at the moment however if I could do something in PowerShell like nsummer uses, I think I’d be far more competent at fixing it long term if I had to do any troubleshooting.
I believe this was the last used version of the script. Obviously I had everything export (in a task) to c:\sslcerts\fw\
The really annoying thing is that it isn’t too secure. It uses plink (which is part of Putty) to do the actual connection. I looked at doing it with Powershell but this was honestly just way easier.
So as it turns out I went to use this. I had 2 problems.
The first is for some reason it couldn’t run plink but I am sure I could give a full path and make that work.
But what I really wanted to do was use the built in SSH task. It runs in zero time flat, but doesn’t actually work. How can I tell what it is doing. I told it to run the “batch or script” of c:\fgcrt\fgscript.txt which contains exactly what I need run within the SSH session.
If you give the SSH task a script it will try to run the script on the remote host. If you view the status log for the managed certificate it may (or may not) show you extra information about what happened during ssh. Look for Executing command via SSH
Another possible trick is to create a windows scheduled task (but not schedule it) that runs whatever script you want as whichever user then use the powershell Task in Certify to start the scheduled task using Start-ScheduledTask - I haven’t tried it myself but it seems plausible for some scenarios.
So it sounds like in this case using the execution of a command via SSH is not going to work. I don’t need/can’t run a BASH script. I need the commands that I have to be run. I take it unfortunately there is no way to do this correct?
Where there’s a will there’s a way. I’m not clear on whether your script is one that should run on the remote host or if it should run on the machine running Certify? If it runs on that machine that certify is on, then it’s not a remote SSH script, it’s just a script (and should run on the local machine). I just don’t know anything about your script how it should work, maybe you could share it?