首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> Perl教程
VB与ActiveX控件签名谈-.NET教程,VB.Net语言
作者:网友供稿 点击:184
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
 

在vs安装后发现路径**vc7\common7\tools\bin\下有许多小工具,我对带有cert的文件比较感兴趣。经过研究,发现是有关证书和签名的,当然,该证书未被证书认证机构认可。下面列出这些工具和我的使用心得。
1。makecert.exe ---证书创建工具
2。cert2spc.exe ---发行者证书测试工具
3。signcode.exe ---文件签名工具
面对其众多参数,我只好一一尝试。经过不断的创建,我已经能够做好证书的自我创建,子证书的创建,文件签名。嘿嘿,这下activex控件的自动下载问题也算解决了一大半,有事没事就给自己编的小软件签个名又何妨?
建立自己的根证书:
makecert -sk mypk -ss myname -n "cn=luo31工作室" -r c:\luo31.cer
sk-表示主题的密钥容器位置,ss-主题的证书存储名称, n-证书颁发对象,r-证书存储位置;
如果你需要导出私钥文件,请不要使用sk,而换作s,eg:makecert -ss myname -n "cn=luo31工作室" -sv c:\luo31.pvk -r c:\luo31.cer
建立自根跟证书授权的子证书:
makecert -sk "mypk" -is myname -n "cn=luo31" -$ commercial -ic c:\luo31.cer c:\31.cer
sk-表示主题的密钥容器位置,is-颁发者的证书存储名称, n-证书颁发对象,ic-颁发者的证书存储位置,-$-授权范围(用于代码签名);
使用cert2spc生成spc发行者证书(可选):
cert2spc c:\31.cer c:\31.spc
使用signcode为你的程序,库或cab包签名:
双击signcode,或在控制台键入signcode,不带参数会启动签名向导。在第三步选择“自定义选项”,第四步选择“从文件选择”选择31.spc或31.cer,第五步选择“csp中的私钥”,在密钥容器中选择我们定义的mypk,其他步骤默认即可,如果想添加时间戳,请在时间戳服务器地址上键入:(免费时间戳认证)http: //timestamp.verisign.com/scripts/timstamp.dll
完成后,观察你所签名的文件属性,应该已经添加数字签名项。

 

1. 下载数字签名工具
在m$的网站上下载:codesigningx86.exe 文件。解压缩

2. 使用vb的打包向导将主要使用的dll,ocx 文件等打包为 .cab 文件。
3. 使用说明

 

首先去ms的网站上下载codesign.exep这个文件,这是个自解压文件,然后按以下示例做。
这四个工具在c:\program files\microsoft visual studio .net 2003\sdk\v1.1\bin也有
工具包包括以下几个软件:
makecert.exe 制作cer格式的证书,即x.509证书,同时可以创建私钥
cert2spc.exe 将cer格式证书转换成spc格式证书,即pkcs #7证书
signcode.exe 将证书签署到ocx上去
chktrust.exe 检查签署证书后的ocx是否正确
还有一个certmgr.exe,是管理证书用的。可以从这里面导出root.cer来,
网上很多文章写到这个证书,但是在vc的安装盘中却找不到。其实,没
有也没关系的。这几个软件可以从vc的安装盘中找到。

下面是具体的步骤:
1、创建一个自己的证书文件:
makecert /sv "record.pvk" /n "cn=北京美髯公科技发展有限公司" dream.cer
这里,record.pvk表示新创建的私人密钥保存文件名
dreamcaptial是你想显示的公司名
dream.cer是你创建最后的证书文件名
这些根据你自己的要求填写,最后得到record.pvk和dream.cer两个文件。
其中,运行过程中需要输入私人密钥的保护密码,一定要输入一致,不要出错。

2、转换cer格式为spc格式(可以省略)
cert2spc dream.cer dream.spc
得到dream.spc文件。

3、给ocx进行签名
运行signcode,命令行的我没有试验通过,我是通过界面实现的。
signcode运行后会出现数字签名向导,首先选择你要签名的ocx,
下一步后会出现签名选项,一种是典型,一种是自定义。选择自定义,
这样才能从文件选择证书,选择前面制作的dream.spc,再下一步是
选择私钥文件,选择record.pvk,输入私人密钥的保护密码,选择散
列算法,一般用md5就可以了,下一步是选择其他证书,直接下一步,
填写一下这个控件的声明,用户用ie浏览的时候,会弹出证书说明,
再下一步是加盖时间戳,我不会,直接下一步就完成了。

4、用chktrust检查是否正确
chktrust -v recordproj.ocx

 

用下列批命令做证书
makecert -sv "denghan.pvk" -n "cn=kinsoft" test.cer
cert2spc test.cer test.spc
---------------------------------------------
用下列命令给cab文件签名
signcode -spc test.spc -v denghan.pvk -n "这个是cab数字签名" -t

添加时间戳

http://timestamp.verisign.com/scripts/timstamp.dll rx80.cab

rx80.cab文件用rx80.inf的内容

[version]
signature="$chicago$"
advancedinf=2.0

[add.code]
test.dll=test.dll
rx80.inf=rx80.inf

[test.dll]
file=rx80.cab
registerserver=yes
clsid={7e0cdee7-dc80-4f37-9410-790bb5e9270e}
destdir=10
fileversion=1,0,0,1

[rx80.inf]
file=rx80.cab

把这个cab文件放到你的服务器上,用下列代码说明你的codebase,就会自动下载了。
<object classid="clsid:7e0cdee7-dc80-4f37-9410-790bb5e9270e"

codebase="http://yourhosturl/rx80.cab#version=1,0,0,1" width="800" height="191">
...


4. 参考资料

http://msdn.microsoft.com/library/default.asp?url=/library/en-

us/dnaxctrl/html/msdn_deplactx.asp
http://www.verisign.com


预览该网页,会弹出提示框
http://support.microsoft.com/?kbid=182598
http://www.china-askpro.com/msg40/qa13.shtml

 

how to implement iobjectsafety in visual basic controls

article id : 182598
last review : september 1, 2005
revision : 3.1
this article was previously published under q182598

summary

this article describes how to implement the iobjectsafety interface in visual basic controls to mark the controls safe for scripting and initialization. by default, visual basic controls use component category entries in the registry to mark the control safe for scripting and initialization. implementing the iobjectsafety interface is the preferred method. this article contains all the code that is required to implement this interface in visual basic controls.

please keep in mind that a control should only be marked as safe if it is, in fact, safe. this article does not describe the details of marking controls as safe for scripting and initialization; it simply demonstrates how to do it in code. please refer to the internet client software development kit (sdk) documentation for a detailed description of this. see "safe initialization and scripting for activex controls" under the component development section.

more information

warning: one or more of the following functions are discussed in this article: varptr, varptrarray, varptrstringarray, strptr, and objptr. these functions are not supported by microsoft technical support. they are not documented in the visual basic documentation and are provided in this knowledge base article "as is." microsoft does not guarantee that they will be available in future releases of visual basic. for additional information about these functions, click the article number below to view the article in the microsoft knowledge base:
199824 (http://support.microsoft.com/kb/199824/en-us/) how to get the address of variables in visual basic
the following steps illustrate how to create a simple visual basic control and mark it safe for scripting and initialization.
1. create a new folder where you can save all files that you create in this example.
2. get the ole automation type library generator from the visual basic cd-rom. to do this, copy all four files from the \common\tools\vb\unsupprt\typlib\ folder to your project folder.
3. copy the following text into notepad, and save the file in the project folder as objsafe.odl:
      [
          uuid(c67830e0-d11d-11cf-bd80-00aa00575603),
          helpstring("vb iobjectsafety interface"),
          version(1.0)
      ]
      library iobjectsafetytlb
      {
          importlib("stdole2.tlb");
          [
              uuid(cb5bdc81-93c1-11cf-8f20-00805f2cd064),
              helpstring("iobjectsafety interface"),
              odl
          ]
          interface iobjectsafety:iunknown {
              [helpstring("getinterfacesafetyoptions")]
              hresult getinterfacesafetyoptions(
                        [in]  long  riid,
                        [in]  long *pdwsupportedoptions,
                        [in]  long *pdwenabledoptions);

              [helpstring("setinterfacesafetyoptions")]
              hresult setinterfacesafetyoptions(
                        [in]  long  riid,
                        [in]  long  dwoptionssetmask,
                        [in]  long  dwenabledoptions);
           }
       }
					
4. at a command prompt, use the cd <path> command to move to the project folder, and type the following command to generate a .tlb file:
mktyplib objsafe.odl /tlb objsafe.tlb
5. from visual basic, create an activex control project. in the properties list, change the name of the project to iobjsafety and the name of the control to democtl. put a commandbutton named cmdtest on the control. in the click event handler of the cmdtest, put a msgbox "test" statement.
6. on the project menu, click references, browse to and add objsafe.tlb, which you created earlier.
7. add a new module to your project with the following code, and name the module bassafectl:
      option explicit

      public const iid_idispatch = "{00020400-0000-0000-c000-000000000046}"
      public const iid_ipersiststorage = _
        "{0000010a-0000-0000-c000-000000000046}"
      public const iid_ipersiststream = _
        "{00000109-0000-0000-c000-000000000046}"
      public const iid_ipersistpropertybag = _
        "{37d84f60-42cb-11ce-8135-00aa004bb851}"

      public const interfacesafe_for_untrusted_caller = &h1
      public const interfacesafe_for_untrusted_data = &h2
      public const e_nointerface = &h80004002
      public const e_fail = &h80004005
      public const max_guidlen = 40

      public declare sub copymemory lib "kernel32" alias "rtlmovememory" _
         (pdest as any, psource as any, byval bytelen as long)
      public declare function stringfromguid2 lib "ole32.dll" (rguid as _
         any, byval lpstrclsid as long, byval cbmax as integer) as long

      public type udtguid
          data1 as long
          data2 as integer
          data3 as integer
          data4(7) as byte
      end type

      public m_fsafeforscripting as boolean
      public m_fsafeforinitializing as boolean

      sub main()
          m_fsafeforscripting = true
          m_fsafeforinitializing = true
      end sub
					
8. from project properties, change the startup object to sub main to execute the sub main above. use the m_fsafeforscripting and m_fsafeforinitializing variables to specify the values of safe for the scripting and/or initialization variables.
9. open the code window of your control. add the following line of code to the declaration section (right after option explicit or as the first):
implements iobjectsafety
					
10. copy the following two procedures to your controls code:
      private sub iobjectsafety_getinterfacesafetyoptions(byval riid as _
      long, pdwsupportedoptions as long, pdwenabledoptions as long)

          dim rc      as long
          dim rclsid  as udtguid
          dim iid     as string
          dim biid()  as byte

          pdwsupportedoptions = interfacesafe_for_untrusted_caller or _
                                interfacesafe_for_untrusted_data

          if (riid <> 0) then
              copymemory rclsid, byval riid, len(rclsid)

              biid = string$(max_guidlen, 0)
              rc = stringfromguid2(rclsid, varptr(biid(0)), max_guidlen)
              rc = instr(1, biid, vbnullchar) - 1
              iid = left$(ucase(biid), rc)

              select case iid
                  case iid_idispatch
                      pdwenabledoptions = iif(m_fsafeforscripting, _
                    interfacesafe_for_untrusted_caller, 0)
                      exit sub
                  case iid_ipersiststorage, iid_ipersiststream, _
                     iid_ipersistpropertybag
                      pdwenabledoptions = iif(m_fsafeforinitializing, _
                    interfacesafe_for_untrusted_data, 0)
                      exit sub
                  case else
                      err.raise e_nointerface
                      exit sub
              end select
          end if
      end sub

      private sub iobjectsafety_setinterfacesafetyoptions(byval riid as _
      long, byval dwoptionssetmask as long, byval dwenabledoptions as long)
          dim rc          as long
          dim rclsid      as udtguid
          dim iid         as string
          dim biid()      as byte

          if (riid <> 0) then
              copymemory rclsid, byval riid, len(rclsid)

              biid = string$(max_guidlen, 0)
              rc = stringfromguid2(rclsid, varptr(biid(0)), max_guidlen)
              rc = instr(1, biid, vbnullchar) - 1
              iid = left$(ucase(biid), rc)

              select case iid
                  case iid_idispatch
                      if ((dwenabledoptions and dwoptionssetmask) <> _
                   interfacesafe_for_untrusted_caller) then
                          err.raise e_fail
                          exit sub
                      else
                          if not m_fsafeforscripting then
                              err.raise e_fail
                          end if
                          exit sub
                      end if

                  case iid_ipersiststorage, iid_ipersiststream, _
                iid_ipersistpropertybag
                      if ((dwenabledoptions and dwoptionssetmask) <> _
                    interfacesafe_for_untrusted_data) then
                          err.raise e_fail
                          exit sub
                      else
                          if not m_fsafeforinitializing then
                              err.raise e_fail
                          end if
                          exit sub
                      end if

                  case else
                      err.raise e_nointerface
                      exit sub
              end select
          end if
      end sub
					
11. on the file menu, save your project and files. make an ocx file from your project. your control now implements the iobjectsafety interface. to test it, insert the control in an .htm file.
http://bbs.nsfocus.net/index.php?act=st&f=2&t=138429&view=old
本文介绍如何创建自己的代码证书(有ca证书签署的代码签名证书)

各位同学在自己动手操作之前请通篇阅读本文。尤其是各条注意事项。
不要看了前文不看后文就动手。否则很容易走上我曾经走过的弯路。

准备工作:
在http://ftp.intron.ac/pub/security/里面下载以下软件包:
openssl_0.9.6a-binary-win32.zip
pvknew.zip
signcode_for_ie4.exe
将它们分别解压缩。将以下文件解压缩至一个目录中:
openssl_0.9.6a-binary-win32.zip包中的libeay32.dll,openssl.cnf,openssl.exe,
ssleay32.dll
pvknew.zip中的pvk.exe(这个程序要用到ssleay32.dll)
signcode_for_ie4.exe中的makecert.exe,cert2spc.exe,signcode.exe


1.用openssl创建ca证书的rsa密钥(pem格式):
openssl genrsa -des3 -out ca.key 1024

2.用openssl创建ca证书(pem格式,假如有效期为一年):
openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config openssl.cnf

openssl是可以生成der格式的ca证书的,很奇怪windows却说那证书是“无效的”,
无奈,只好用ie将pem格式的ca证书转换成der格式的ca证书。

3.将ca.crt导入至ie中(我用的是winme带的ie5.5)。
导入时注意一定要将证书存储至“本地计算机”。
具体步骤如下:
1)在“我的电脑”或“资源管理器”里双击该文件图标。
2)在“常规”卡片上选择“安装证书”。
3)点“下一步”至“证书导入向导”,选择“将所有的证书放入下列存储区”,
点下面的“浏览”。勾上“显示物理存储区”。选择“受信任的根目录...”下一级的
“本地计算机”。点“确定”,再点“下一步”。
4)点“完成”。

可以检查一下导入是否完全成功:
在ie的internet选项中的“证书”中“受信任根证书颁发机构”中应该可以
看见上述的根证书。

4.ie的internet选项中的“证书”中“受信任根证书颁发机构”中将刚才
导入的证书导出。格式为“der编码的二进制x.509(.cer)”。
假设导出的文件名为ca.cer

5.将pem格式的ca.key转换为microsoft可以识别的pvk格式。
  pvk -in ca.key -out ca.pvk -nocrypt -topvk

6.用codesign for ie4(不可用其它版本的签名工具,比方说for ie5的
或是vc5中带的cab&sign或是.net framework sdk)中的makecert.exe制作
自己的有ca证书签署的证书。假设证书通用名为"intronsoft",有效期六个月:
makecert -sv soft.pvk -iv ca.pvk -ic ca.cer -n cn=intron的软件 -m 6 soft.cer

这时在“我的电脑”点击ca.cer的文件图标,就可以看见里面的内容了。

7.将soft.cer转换为soft.spc:
cert2spc soft.cer soft.spc

8.用signcode.exe签署自己的软件。假如是.cab文件,需要在用cabarc.exe制作的时候
用-s参数留出签名的空间(一般6144字节即可)。
cabarc.exe在http://ftp.intron.ac/pub/security/cabsign/

signcode -spc soft.spc -v soft.pvk -n intron的软件 intronsoft.cab

文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·无刷新聊天室(短信陪聊程序)-ASP教程,ASP应用
·C#中使用Excel-.NET教程,C#语言
·简要JAVA数据类型转换-JSP教程,Java技巧及代码
·Recordset对象方法详解-ASP教程,ASP应用
·选用和配置ups时应注意的几个问题
·新型无源元件的现状与发展
·用正则表达式解析C#文件(updated)-.NET教程,C#语言
·正则表达式大全-ASP教程,ASP应用
·VB与ActiveX控件签名谈-.NET教程,VB.Net语言
·IIS6 和Tomcat5 的整合-ASP教程,ASP应用
最新文章
·网上能免费赚钱?想要网上创业吗?_网赚技巧
·孙中伟:聚合文学网站资源的功能_站长访谈
·网站最令人讨厌的用户体验_站长心得
·设计理论:谈用户体验,别落下商业利益_站长心得
·经营个人网站需要脚踏实地_站长心得
·google adwords关键词广告须注意的7个问题_google推广
·网站提交google注册应注意的问题_google推广
·伦敦mecompany网站设计师谈网页布局艺术2_站长心得
·搜索引擎不收录页面的常见原因_seo网站优化
·搜索引擎注册九大秘法_站长心得
相关主题
西部数码虚拟主机

友情链接
CNNIC 西部数码
万网 自助建站
虚拟主机 asp空间
域名注册 域名
域名申请 主页空间
论坛空间 网站空间
国际域名 虚拟空间
空间租用 DDOS防火墙
成都主机托管 四川主机托管
主机租用 服务器租用
网站目录 自助建站
虚拟主机 网址大全
软件下载
自助链接
虚拟主机资讯 特价虚拟主机
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
发表评论 打印  刷新     关闭