【发布时间】:2017-05-02 17:57:23
【问题描述】:
Chrome 58 弃用了省略主题备用名称 (SAN) 的自签名证书。我使用 Mono.Security.X509 X509CertificateBuilder() 在“localhost”上为 Windows OWIN 服务创建证书,使浏览器能够与 TWAIN 扫描仪进行通信。该证书目前仅设置通用名称,因此对于 Chrome 58 来说是不够的。
使用 Mono.Security.X509 创建使 Chrome 能够与 localhost 上的 OWIN 服务通信的自签名证书的正确方法是什么?
RSA subjectKey = new RSACryptoServiceProvider(2048);
X509CertificateBuilder cb = new X509CertificateBuilder(3);
cb.SerialNumber = GenerateSerialNumber();
cb.IssuerName = "CN=localhost";
cb.NotBefore = notBefore;
cb.NotAfter = notAfter;
cb.SubjectName = "CN=localhost";
cb.SubjectPublicKey = subjectKey;
cb.Hash = "SHA256";
byte[] rawcert = cb.Sign(subjectKey);
PKCS12 p12 = new PKCS12();
p12.Password = password;
Hashtable attributes = GetAttributes();
p12.AddCertificate(new X509Certificate(rawcert), attributes);
p12.AddPkcs8ShroudedKeyBag(subjectKey, attributes);
return p12.GetBytes();
【问题讨论】:
-
我猜到了这个添加 'var san = new SubjectAltNameExtension(new string[0], new string[1] { "DNS:localhost" }, new string[1] { "IP:127.0 .0.1" }, 新字符串[1] { "URI:localhost" }); cb.Extensions.Add(san);'这会导致错误 System.FormatException: Input string was not in a correct format.
标签: c# google-chrome ssl mono