首页 技术 正文
技术 2022年11月19日
0 收藏 339 点赞 4,625 浏览 1460 个字

1、自建根证书

makecert -r -pe -n "CN=WebSSLTestRoot" -b 12/22/2013 -e 12/23/2024 -ss root -sr localmachine -len 2048

 

2、建网站用的证书

makecert -pe -n "CN=www.aaa.com" -b 12/22/2013 -e 12/23/2024 -eku 1.3.6.1.5.5.7.3.1 -is root -ir localmachine -in WebSSLTestRoot -len 2048 -ss WebHosting -sr localmachine

cn是网站对应的域名

3、建客户端证书

makecert -pe -n "CN=czcz1024" -eku 1.3.6.1.5.5.7.3.2 -is root -ir localmachine -in WebSSLTestRoot -ss my -sr currentuser -len 2048

cn可以是用户名

根证书在 本地计算机-受信任的根证书颁发机构

网站证书在 本地计算机-Web宿主

客户端证书在 当前用户-个人

 

iis中,建立网站用web宿主的

使用ie,访问,当客户端有证书试,会要求选择证书

iis https 客户端证书

string r;
HttpClientCertificate cert = Request.ClientCertificate;
if (cert.IsPresent)
r = cert.ServerSubject + "---" + cert.Subject;
else
r = "No certificate was found.";
return Content(r);

我们可以通过代码来获取证书信息

 

iis https 客户端证书

 

4、程序自动创建用户客户端证书

var path = @"…\makecert.exe";
var cmd = " -pe -n \"CN=czcz1024\" -eku 1.3.6.1.5.5.7.3.2 -is root -ir localmachine -in WebSSLTestRoot -ss my -sr currentuser -len 2048";
var p = Process.Start(path, cmd);
p.WaitForExit();
p.Close();

调用cmd去执行,需要iis已administrator身份运行

iis https 客户端证书

5、导出,并提供客户下载

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.MaxAllowed);
foreach (X509Certificate2 myX509Certificate2 in store.Certificates)
{
if (myX509Certificate2.Subject == "CN=czcz1024")
{
byte[] CertByte = myX509Certificate2.Export(X509ContentType.Pfx,"123456");
return File(CertByte, "application/octet-stream", "cert.pfx");
}
}return Content("not found");

同样,这个也需要administrator才能获取到

需要导出成pfx,客户端才可以导入,导入的时候,需要密码,密码为代码中的“123456”那部分

6、iis的ssl设置

iis https 客户端证书

如果是必需,当客户端没有证书时

iis https 客户端证书

 

当选择

iis https 客户端证书

没有证书则显示

iis https 客户端证书

对应上面代码的else分支

 

选择 忽略 则不会要求客户端提供证书了

 

自建根,当客户端访问时,需要导入根证书到受信任的根

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918