在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
View products that this article applies to.
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

作者Blog:http://blog.csdn.net/keenx/

ActiveX控件签名谈相关推荐

  1. VB与ActiveX控件签名谈

    在VS安装后发现路径**VC7/Common7/Tools/Bin/下有许多小工具,我对带有Cert的文件比较感兴趣.经过研究,发现是有关证书和签名的,当然,该证书未被证书认证机构认可.下面列出这些工 ...

  2. 怎样给 ActiveX 控件签名并打包发布

    转载自:http://www.55055.com/blog/user1/1/archives/2007/20071202322.html 必备工具: CabArc.Exe Cert2Spc.Exe ...

  3. 给COM/ActiveX控件签名(signcode,cab,pfx,pvk)

    [虎.无名]准备用到一个web页面口令保护的小控件,但是发行商自己没有购买商用的数字证书,而是使用自己用openssl生成的私有证书来签名的.公司以前倒是申请过一个用于网站的ssl证书,但不知道能否用 ...

  4. [转]使用C#开发ActiveX控件

    前言 ActiveX控件以前也叫做OLE控件,它是微软IE支持的一种软件组件或对象,可以将其插入到Web页面中,实现在浏览器端执行动态程序功能,以增强浏览器端的动态处理能力.通常ActiveX控件都是 ...

  5. 使用C#开发ActiveX控件(新)

    前言 ActiveX控件以前也叫做OLE控件,它是微软IE支持的一种软件组件或对象,可以将其插入到Web页面中,实现在浏览器端执行动态程序功能,以增强浏览器端的动态处理能力.通常ActiveX控件都是 ...

  6. ActiveX控件的另类免费签名法

    注意:一直都有人提到一个问题,就是使用支付宝的证书,会不会有安全问题,这一点是肯定的,所以这个证书只能拿来做软件签名用,不能拿来做支付的. 这几天手上在做一个项目,要用到ActiveX控件,在签名这一 ...

  7. 安装未签名的activex控件

    由于无法验证发行者,所以windows已经阻止此软件,如要安装未签名的activex控件,按如下步骤:1.打开Internet Explorer---菜单栏点"工具"---Inte ...

  8. ActiveX控件打包、签名、嵌入详解

    ActiveX控件打包.签名.嵌入详解 前言 在我们的一个项目中,使用到了大华网络监控摄像头枪机,网络上下载了其ActiveX插件,但是发现其所提供的类库没有打包处理.这就导致我们每次给用户安装的时候 ...

  9. 如何发布ActiveX 控件

    转自:http://blog.csdn.net/zougangx/archive/2008/07/30/2738147.aspx [背景] 做过ActiveX控件的朋友都知道,要想把自己做的Activ ...

最新文章

  1. CentOS下挂载硬盘(fdisk,mkfs.ext4,mount)
  2. Windows10 + WSL (Ubuntu) + Anaconda + vscode 手把手配置python运行环境(含虚拟环境)
  3. 【面向对象】面向对象的分析与设计概述
  4. MySQL进阶篇(03):合理的使用索引结构和查询
  5. 【每日算法Day 99】你们可能不知道只用20万赢到578万是什么概念
  6. mysql基础知识复习
  7. Caffe学习3:Layer
  8. Bash shell 连接字符串
  9. Java整合PayPal支付结账和支出
  10. pyinstaller包含html文件,pyinstaller打包exe
  11. 中秋节前能跟客户聊的!
  12. Font Awesome文字图标的使用
  13. 全球与中国太阳能测试仪市场现状及未来发展趋势
  14. Allegro如何设置走线自动删除重复走线操作指导
  15. ACPI相关(7)- ACPI对ata的管理
  16. 关于软件的一些哲学思考(四)软件基本要素 四要素
  17. OpenFlow网络基本介绍
  18. matlab行距,Matlab cdfplot:如何控制标记间距的间距
  19. 编译出现 warn_unused_result -Wunused-result 如何解决
  20. solo 电路 耳放_SOLO耳放分析,带PCB布线

热门文章

  1. 在Android中用纯Java代码布局
  2. 利用AOP进行简单的性能监控及用户行为审计
  3. html是什么?超文本标记语言
  4. 简单工厂模式实现-电视机工厂案例
  5. Django解决ajax跨域请求问题
  6. WIN10下启动VMware虚拟机蓝屏的解决办法
  7. Pycharm远程使用Linux环境配置步骤
  8. Eyeshot 强大CAD-3D三维组件-Crack
  9. android语音控制demo,Android简单语音控制手机应用
  10. 推荐几个实用的在线小工具~