内部使用的测试证书生成(彻底解决IE浏览器 SCRIPT7002: XMLHttpRequest: network error 0x2ef3)

1. makecert -r -pe -n "CN=域名" -b 01/01/2005 -e 01/01/2020 -sky exchange -ss my    ;(这样颁发者和颁发给都是这个域名)

2. 在mmc里将证书导出;

3. 将导出的证书导入测试服务器;

4. 要求测试机器都安装该证书;(要放到可信任根证书颁发机构);

5. iis里导入该证书,然后在网站上添加https绑定,选择这个证书(如果证书有问题,在选择证书时会报错,或者点击查看,可以看到错误信息,比如未被信任等);




证书备用:Makecert –r –pe –n CN="域名" –b 05/10/2010 –e 12/22/2021 –eku 1.3.6.1.5.5.7.3.1 –ss my –sr localmachine -sky exchange –sp "Microsoft RSA SChannel Cryptographic Provider" –sy 12


官方参考文档: https://msdn.microsoft.com/zh-cn/library/bfsktky3(v=vs.100).aspx


问题记录:

1. 证书安装后, ie正常, 但是chrome仍然提示不安全, 这是因为证书的签名算法要升级到sha256和证书要支持SAN, 否则最新版本chrome(58版以后)仍然会提示不安全;


为了生成包含SAN的证书, 使用makecert是不行的, 建议使用openssl.  以下是参考文档:

http://www.mamicode.com/info-detail-1938899.html

http://colinzhouyj.blog.51cto.com/2265679/1566438

https://zhuanlan.zhihu.com/p/26646377

http://liaoph.com/openssl-san/


以下为我的记录:

1. 下载openssl 64bit, 我的电脑是: win10 64 bit. 其他系统未测试, 估计没问题; (下载地址:http://download.csdn.net/download/wdydxf/10126281)

2. 摘抄自 http://www.mamicode.com/info-detail-1938899.html

Chrome 58开始取消了对通用名检查的支持, 但网上大多数OpenSSL使用教程没有提及这一点, 制作出的证书总是提示ERR_CERT_COMMON_NAME_INVALID 错误, 所以分享出解决办法, 让大家少走弯路  

许多人并不知道,那个包含着SSL证书是否对某域名生效的“通用名称”字段,早在二十年前就被RFC淘汰了。取而代之的应该是SAN(主题备用名称)字段. 
然而,这一点多年来一直被忽略,通用名字段被单独使用多年. 从Chrome 58开始, 那些只使用该字段来指示有效域名的证书将不再得到支持。
由于被公开信任的SSL证书同时支持两种字段,确保与所有软件的最大兼容性,因此如果您的证书来自受信任的CA,则无需担心.

0. 实验环境

Win7 64bit 旗舰版

Win64OpenSSL_Light-1_1_0f (下载地址http://slproweb.com/products/Win32OpenSSL.html)

下面的操作, 我将建立一个 MyRootCA 的根证书颁发机构, 然后为一个域名是 myserver.com 签发证书

 

1. Win64OpenSSL_Light-1_1_0f就默认安装在C:\OpenSSL-Win64 吧, 然后将 C:\OpenSSL-Win64\bin\ 加到系统Path里, 因为我准备在其他文件夹生成证书

 

2.将 C:\OpenSSL-Win64\bin\openssl.cfg 复制到 F:\SSLTest\, 修改以下内容

  a. 将 [ req ] 下面的这行取消注释(删除前面的#)

  req_extensions = v3_req

  b. 在[ v3_req ]加入subjectAltName = @alt_names, 变成

  basicConstraints = CA:FALSE

  keyUsage = nonRepudiation, digitalSignature, keyEncipherment

  subjectAltName = @alt_names  #新增的

  c.新增 alt_names,注意括号前后的空格,DNS.x 的数量可以自己加, 这里的DNS就是你网站的地址

[ alt_names ]
DNS.1 = myserver.com
DNS.2 = *.myserver.com

d. 确保req_distinguished_name下没有 0.xxx 的标签,有的话把0.xxx的0. 去掉 



3. 在某个文件夹(比如 F:\SSLTest\)执行下列命令, 生成必要的文件夹和文件(这些文件和文件夹是 openssl.cfg 要求的)

F:\SSLTest>mkdir demoCA\private demoCA\newcerts
F:\SSLTest>type nul > demoCA\index.txt
F:\SSLTest>echo 01 > demoCA\serial

 


4.生成CA自签名证书

F:\SSLTest\ openssl req -new -x509 -newkey rsa:2048 -days 3650 -keyout demoCA\private\MyRootCA.key -out demoCA\MyRootCA.crt -passout pass:123456 -config openssl.cfg

解释一下

 -days 3650

根证书的有效期是 10年

-passout pass:123456

CA的密钥是 123456

-config openssl.cfg

使用当前文件夹的openssl.cfg作为默认设置, 如果不使用这个命令的话, 将使用C:\OpenSSL-Win64\bin \openssl.cfg

  

Generating a 2048 bit RSA private key

...............................................................+++

..........................+++

writing new private key to ‘demoCA\private\MyRootCA.key‘

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter ‘.‘, the field will be left blank.

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:SiChuan

Locality Name (eg, city) []:ChengDu

Organization Name (eg, company) [Internet Widgits Pty Ltd]:YourCompany

Organizational Unit Name (eg, section) []:YourUnitName

Common Name (e.g. server FQDN or YOUR name) []:MyRootCA

Email Address []:

 

5.生成用户的 RSA 密钥对

F:\SSLTest\ openssl genrsa -des3 -out myserver.com.key -passout pass:123456

 

6. 生成用户证书请求

openssl req -new -days 1825 -key myserver.com.key -out myserver.com.csr -config openssl.cfg, 这里会让输入一个东西, 要输入:123456, 输入时是不显示在界面上的, 其实已经输入;

下面中的CNSiChuanYourCompany必须与MyRootCA一致, 原因后面讲

Enter pass phrase for myserver.com.key:

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter ‘.‘, the field will be left blank.

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:SiChuan

Locality Name (eg, city) []:ChengDu

Organization Name (eg, company) [Internet Widgits Pty Ltd]:YourCompany

Organizational Unit Name (eg, section) []:AnotherUnitName

Common Name (e.g. server FQDN or YOUR name) []:myserver.com

Email Address []:

 

Please enter the following ‘extra‘ attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

 

7. 使用 CA 签发用户证书

F:\SSLTest\ openssl ca -in myserver.com.csr -out myserver.com.crt -cert demoCA\MyRootCA.crt -keyfile demoCA\private\MyRootCA.key -extensions v3_req -config openssl.cfg

Using configuration from openssl.cfg

Enter pass phrase for demoCA\private\MyRootCA.key:

Can‘t open ./demoCA/index.txt.attr for reading, No such file or directory

2440:error:02001002:system library:fopen:No such file or directory:crypto\bio\bss_file.c:74:fopen(‘./demoCA/index.txt.at

tr‘,‘r‘)

2440:error:2006D080:BIO routines:BIO_new_file:no such file:crypto\bio\bss_file.c:81:

Check that the request matches the signature

Signature ok

Certificate Details:

        Serial Number: 1 (0x1)

        Validity

            Not Before: Aug  3 15:17:43 2017 GMT

            Not After : Aug  3 15:17:43 2018 GMT

        Subject:

            countryName               = CN

            stateOrProvinceName       = SiChuan

            organizationName          = YourCompany

            organizationalUnitName    = AnotherUnitName

            commonName                = myserver.com

        X509v3 extensions:

            X509v3 Basic Constraints:

                CA:FALSE

            X509v3 Key Usage:

                Digital Signature, Non Repudiation, Key Encipherment

            X509v3 Subject Alternative Name:

                DNS:myserver.com, DNS:*.myserver.com

Certificate is to be certified until Aug  3 15:17:43 2018 GMT (365 days)

Sign the certificate? [y/n]:y

 

 

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

 

8.生成Windows支持的p12证书

F:\SSLTest\ openssl pkcs12 -export -inkey myserver.com.key -in myserver.com.crt -out myserver.com.p12

建议密码都是123456

 

9. 验证

在C:\Windows\System32\drivers\etc\hosts中新增一行

127.0.0.1           myserver.com

然后将 MyRootCA.crt 安装到 受信任的根证书颁发机构

在IIS中导入myserver.com.p12, 并为一个网站增加https绑定

然后就可以用Chrome看到效果了

 

10. 为什么用户证书的CNSiChuanYourCompany必须与MyRootCA一致?

openssl.cfg中有这样一段, 当然你可以按需修改

[ policy_match ]
 countryName     = match                    #证书请求与证书本身一样
 stateOrProvinceName = match                #证书请求与证书本身一样
 organizationName    = match                #证书请求与证书本身一样
 organizationalUnitName  = optional         #可选项
 commonName      = supplied                 #证书请求中必须能存在该项
 emailAddress        = optional             #可选项

 

随后在E:\SSLTest里可以找到签发的证书: 




在这里可以找到自定义的CA颁发机构:



安装时首先要安装Ca颁发机构


===============================================

解决这个问题:SCRIPT7002: XMLHttpRequest: network error 0x2ef3

实际上可以发现IE根本就没把请求发送出去, 所以可以说是IE截断了请求, 具体原因应该是和证书有关系, 因为CA颁发的证书就不存在该问题(一模一样的网站);

所以更新一下服务器上的证书为最新的证书就可以(我的测试结果是:sha256就可以了)







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值