您的位置:首页 > 运维架构 > 网站架构

SSL网站自动安装根目录证书(整理备用)javascript

2010-03-09 17:45 676 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>自动安装根证书</title>
</head>
<body>

<!--xenroll.dll在C:\WINDOWS\system32中可以找到-->

<object id="XEnroll" classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1" codebase="xenroll.dll">
</object>

<object id="capicom" codebase="http://download.microsoft.com/download/E/1/8/E18ED994-8005-4377-A7D7-0A8E13025B94/capicom.cab#version=2,0,0,3" classid="clsid:A996E48C-D3DC-4244-89F7-AFA33EC60679" VIEWASTEXT>
</object >
<script language="javascript">

// 此方法为打开根证书目录,读取证书信息,判断当前证书是否包含"myCertificates"这个名字的证书,如果包含则返回true

function getClientID()
{
var CAPICOM_CURRENT_USER_STORE = 2;
var CAPICOM_MY_STORE = "root";//读取的目录名称,如果读取个人证书则应该写入变量"my"
var CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME = 1 ;
var CAPICOM_STORE_OPEN_READ_WRITE=1;
var myStore = new ActiveXObject("CAPICOM.Store");

    //open时会有提示,找了很久没有找到如何不弹出提示。

myStore.Open(CAPICOM_CURRENT_USER_STORE,CAPICOM_MY_STORE,CAPICOM_STORE_OPEN_READ_WRITE);
var myStoreCerts = myStore.Certificates;

for(i = 1; i<= myStoreCerts.Count; i++)
{
if(myStoreCerts.Item(i).SubjectName.indexOf("myCertificates") > 0)
return true;
return false;
}
}
</script>

<script type="text/javascript">
try
{
var sPKCS7="";

//以下值为证书导出来的Base64编码信息

sPKCS7=sPKCS7 + "-----BEGIN CERTIFICATE-----" + "\n\r";
sPKCS7=sPKCS7 + "MIIDfjCCAmagAwIBAgIQTxKm7es6U71PO6wA/atvJzANBgkqhkiG9w0BAQUFADAV" + "\n\r";
sPKCS7=sPKCS7 +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
sPKCS7=sPKCS7 + "BgkqhkiG9w0BAQUFAAOCAQEAc9J1IC4dA4JE2ZmxP5uKdwMd46YScAV2fheRjhmp" + "\n\r";
sPKCS7=sPKCS7 + "5zzYdi00sLpsAYz21PRv52Cs9j+7QtLYH6O2+340vHfN85a66+aVvEjO1BbpSbSg" + "\n\r";
sPKCS7=sPKCS7 + "5PhnVdXuGuL3vnnmmDXEkWRrews82IWJyUfl3ycm4DxjmzMrFrkyPhvo+fZJ7J" + "\n\r";
sPKCS7=sPKCS7 + "TyQEJQL5xhYokCwqs2XKBz2zutlnTNETH2VWShcfskr+dgL/0edQp1wt7rbvkp6M" + "\n\r";
sPKCS7=sPKCS7 + "/T2ueUfjcefHIM9v3oZPnWjHt9OdsVFvGw3AuNCm6otcNCHiii5JKls+/j9PH" + "\n\r";
sPKCS7=sPKCS7 + "H4L+oPW/bdIqgPQPFhfAQaUOZ8+8R57iAjrk8qIpkkvSWg==" + "\n\r";
sPKCS7=sPKCS7 + "-----END CERTIFICATE-----" + "\n\r";

var flag=getClientID();
if(!flag)
{

    //安装证书

XEnroll.InstallPKCS7(sPKCS7);
alert("证书安装成功!请继续浏览网页");
}
}
catch(err)
{
if (err.number == 438)
alert( "证书安装失败,请选择“是”,请重新安装.");
else if( err.number != 0 )
alert( "证书安装失败,请选择“是”,请重新安装.");
else
alert( "恭喜!证书安装成功");
}
</script>

<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

<!--此方法目前不太好用,每次检验客户端机器是否安装某个证书时均会弹出提示,很不方便-->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: