c# - SSL Certificate: A specified logon session does not exist -
i have created method create certificate, store certificate store , bind port. here method:
private static void createstoreandbindcertificate(string a_ipaddress, string a_ipport) { guid _appid = guid.parse("b30f5be6-2920-4fa1-b0a6-5a56b63051bc"); var _rootcert = new rootcertificatecontainer("cn=myapp root ca", 1024); var _servercert = new servercertificatecontainer("cn=myappapi", _rootcert, 1024); //here certificate created , store string _pathrootcertcer = path.combine(path.gettemppath(), "root-cert.cer"); string _pathservercerpfx = path.combine(path.gettemppath(), "server-cert.pfx"); _rootcert.x509certificate.privatekey = null; file.writeallbytes( _pathrootcertcer, _rootcert.x509certificate.export(x509contenttype.cert) ); var _servercertpfx = new pfx(_servercert.x509certificate); file.writeallbytes(_pathservercerpfx, _servercertpfx.generatepfxfile()); process.start( new processstartinfo() { createnowindow = true, windowstyle = processwindowstyle.hidden, filename = "certutil", arguments = string.format("-f -p -importpfx \"{0}\"", _pathservercerpfx) } ).waitforexit(); try { icertificatebindingconfiguration config = new certificatebindingconfiguration(); var _ipport = new ipendpoint(ipaddress.parse(a_ipaddress), convert.toint32(a_ipport)); var certificatethumbprint = _servercert.x509certificate.thumbprint.tolower(); if (config.query(_ipport).length > 0) config.delete(_ipport); config.bind(new certificatebinding(certificatethumbprint, storename.my, _ipport, _appid)); } catch (exception ex) { throw new exception(ex.message); } }
when execute method parameters: createstoreandbindcertificate("127.0.0.1", "9001")
, error: a specified logon session not exist. may have been termintaed.
missing?
for certificate bind in port want need create .pfx certificate using password. make same small changes:
const string passwordpfx = "mypassword";
should added in beginning of method. change:
var _servercertpfx = new pfx(_servercert.x509certificate);
to
var _servercertpfx = new pfx(_servercert.x509certificate, passwordpfx);
change:
process.start( new processstartinfo() { createnowindow = true, windowstyle = processwindowstyle.hidden, filename = "certutil", arguments = string.format("-f -p -importpfx \"{0}\"", _pathservercerpfx) } ).waitforexit();
to:
process.start( new processstartinfo() { createnowindow = true, windowstyle = processwindowstyle.hidden, filename = "certutil", arguments = string.format("-f -p {0} -importpfx \"{1}\"", passwordpfx, _pathservercerpfx) } ).waitforexit();
another possible solution not use password @ have remove -p
processstartinfo
arguments
. below:
process.start( new processstartinfo() { createnowindow = true, windowstyle = processwindowstyle.hidden, filename = "certutil", arguments = string.format("-f -importpfx \"{0}\"", _pathservercerpfx) } ).waitforexit();
Comments
Post a Comment