I am trying to write a step template for binding a SSL certificate to an application (self hosted owin).
This script works when executed under Octopus’s Script Console
using System.Diagnostics;
var url = "0.0.0.0:443";
var cert = "df197c1f658f0f6daccccc6c4a97356a6a3e6151c7";
var app = "c04dbe3a-0d58-4c22-9da8-63af7ec427fa";
try
{
Console.WriteLine("Deleting existing binding...");
var add = Process.Start(new ProcessStartInfo
{
FileName = "netsh",
Arguments = "http delete sslcert ipport=" + url,
RedirectStandardOutput = true,
UseShellExecute = false
});
add.WaitForExit();
if (add.ExitCode != 0)
Console.WriteLine(add.StandardOutput.ReadToEnd());
}
catch (Exception) {
}
Console.WriteLine("Creating new binding for cert: {0}, app: {1}", cert, app);
var add = Process.Start(new ProcessStartInfo
{
FileName = "netsh",
Arguments = string.Format(
"http add sslcert ipport={0} certhash={1} appid={{{2}}}",
url,
cert,
app
),
RedirectStandardOutput = true,
UseShellExecute = false
});
add.WaitForExit();
if (add.ExitCode != 0)
{
Console.WriteLine(add.StandardOutput.ReadToEnd());
throw new InvalidOperationException();
}
However, when it is added as a Step Template (completely verbaitem, hardcoded app and cert variables, rather than from parameters), I get the following error:
Deleting existing binding...
SSL Certificate deletion failed, Error: 2
The system cannot find the file specified.
Creating new binding for cert: df197c1f658f0f6daccccc6c4a97356a6a3e6151c7, app: c04dbe3a-0d58-4c22-9da8-63af7ec427fa
SSL Certificate add failed, Error: 1312
A specified logon session does not exist. It may already have been terminated.
ERROR: Script execution failed. [InvalidOperationException] Operation is not valid due to the current state of the object.
The remote script failed with exit code 1
If it makes any odds, I am targeting a Windows Server 2012 R2 machine.
I have been trying all kinds of different things, but am at a loss now - do you have any idea what might be causing this?