打印本文 打印本文 关闭窗口 关闭窗口
VB与ActiveX控件签名谈
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2168  更新时间:2009/4/23 15:04:02  文章录入:mintao  责任编辑:mintao
.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

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口