【问题标题】:Silently install root certificate in WiX在 WiX 中静默安装根证书
【发布时间】:2012-11-20 17:04:17
【问题描述】:

如何从 WiX 静默安装根证书?我正在安装一些根证书和中间证书,对于根证书,系统会显示确认对话框,其中显示基本证书属性和指纹。这是我拥有的相关代码,使用在命名空间iis 中映射的WixIIsExtension

<Binary Id="RootCa" SourceFile="Certificates\RootCa.cer" />

<DirectoryRef Id="TARGETDIR">
  <Component Id="RootCa" Guid="...">
    <iis:Certificate
      Id="RootCa"
      BinaryKey="RootCa"
      Name="RootCa"
      StoreLocation="currentUser"
      StoreName="root"/>
  </Component>
</DirectoryRef>

<Feature ...>
    <ComponentRef Id="RootCa" />
</Feature>

【问题讨论】:

  • 我也发现了,但不明白答案。如果那里存在答案...
  • 你评论他寻求帮助,还是私信OP
  • 没有。现在的问题是理论上的。我有一个不需要回答问题的问题的解决方案。如果有人提供答案,那就太好了,如果没有也可以。
  • 你能不能把你的解决方案贴出来,让别人也能有,我想知道,我很好奇;)

标签: wix


【解决方案1】:

我正在使用相同的自定义操作

<CustomAction Id="InstallCertificates" Directory="TARGETDIR" ExeCommand="[SystemFolder]Certutil –addstore –f &quot;root&quot; &quot;[INSTALLLOCATION]Certificates\CertificateName.cer&quot;" Execute="immediate" Return="ignore" />

【讨论】:

  • 谢谢,你给了我一个想法,但我还是会使用标准组件。
  • 我的好像不行,你把证书放在哪里了?
【解决方案2】:

很久以前我就一直在寻找答案。所以,这就是我所拥有的:

WiX 代码:

<CustomAction Id="ImportCer.Props" Property="ImportCer" Value="[INSTALLDIR]ca\root.cer" />
<CustomAction Id="ImportCer" Execute="deferred"  FileKey="hsminst.dll" DllEntry="ImportCer" />

<CustomAction Id="ImportPfx.Props" Property="ImportPfx" Value="[INSTALLDIR]ca\super.pfx" />
<CustomAction Id="ImportPfx" Execute="deferred" FileKey="hsminst.dll" DllEntry="ImportPfx" />

C++ 代码:

 extern "C" __declspec(dllexport) UINT __stdcall ImportCer(MSIHANDLE hInstall)
 {
      char szPath[MAX_PATH];

      GetModuleFileNameA(NULL, szPath, MAX_PATH);

      char certFilePath[MAX_PATH] = {0};
  DWORD certFilePathLen = MAX_PATH;
      MsiGetProperty (
           hInstall, 
           "CustomActionData", 
           certFilePath, 
           &certFilePathLen);

      wchar_t certFilePathW[MAX_PATH];
      MultiByteToWideChar(
           CP_ACP, 
           0, 
           certFilePath, 
           -1, 
           certFilePathW, 
           MAX_PATH);

      PCCERT_CONTEXT pCertCtx = NULL;

      if (CryptQueryObject (
         CERT_QUERY_OBJECT_FILE,
         certFilePathW,
         CERT_QUERY_CONTENT_FLAG_ALL,
         CERT_QUERY_FORMAT_FLAG_ALL,
         0,
         NULL,
         NULL,
         NULL,
         NULL,
         NULL,
         (const void **)&pCertCtx) != 0)
      {
          HCERTSTORE hCertStore = CertOpenStore (
              CERT_STORE_PROV_SYSTEM,
              0,
              0,
              CERT_STORE_OPEN_EXISTING_FLAG |
              CERT_SYSTEM_STORE_LOCAL_MACHINE,
              L"root");
          if (hCertStore != NULL)
          {
               if (!CertAddCertificateContextToStore (
                  hCertStore,
                  pCertCtx,
                  CERT_STORE_ADD_ALWAYS,
                  NULL))
               {
                  return -2;
               }

               if (!CertCloseStore (hCertStore, 0))
               {
                   return -3;
               }
          }
          else
          { 
                return -1; 
          }

          if (pCertCtx)
          {
               CertFreeCertificateContext (pCertCtx);
          }
      }
      return 0;
  }

  extern "C" __declspec(dllexport) UINT __stdcall ImportPfx(MSIHANDLE hInstall)
  {
       char certFilePath[MAX_PATH] = {0};
   DWORD certFilePathLen = MAX_PATH;
       MsiGetProperty (
            hInstall, 
            "CustomActionData", 
            certFilePath, 
            &certFilePathLen);

       wchar_t certFilePathW[MAX_PATH];
       MultiByteToWideChar(
            CP_ACP, 
            0, 
            certFilePath, 
            -1, 
            certFilePathW, 
            MAX_PATH);

       CRYPTUI_WIZ_IMPORT_SRC_INFO importSrc;
       memset(
           &importSrc, 
           0, 
           sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO));

       importSrc.dwSize = sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO);
       importSrc.dwSubjectChoice = CRYPTUI_WIZ_IMPORT_SUBJECT_FILE;
       importSrc.pwszFileName = certFilePathW;
       importSrc.pwszPassword = L"111111";
       importSrc.dwFlags = CRYPT_EXPORTABLE;

       HCERTSTORE serviceStore = CertOpenStore(
            CERT_STORE_PROV_SYSTEM,
            0,
            0,
            CERT_STORE_OPEN_EXISTING_FLAG |
            CERT_SYSTEM_STORE_CURRENT_USER,
            L"my");

       if (CryptUIWizImport(
            CRYPTUI_WIZ_NO_UI ,
            NULL,
            NULL,
            &importSrc,
            serviceStore
            ) == 0)
       {
           return -1;
       }
       return 0;
  }

希望能帮到你

【讨论】:

  • 感谢您的代码。它可能很有用。然而,该代码使用CERT_SYSTEM_STORE_LOCAL_MACHINE 标志,因此它也导入到本地机器,就像我的代码使用StoreLocation="localMachine" 一样。
  • 在我的目的中是许多其他的延迟 CA,这就是为什么我设法在 c++ 中解决这样的问题
【解决方案3】:

Sunil 提供的自定义操作等价于具有StoreLocation="localMachine" 属性的Certificate 组件。就我而言,无论如何安装在机器商店中更有意义,所以我会这样做。原始问题仍然存在:如何在用户存储中静默安装根证书。如果有人对该问题有答案,我会将其标记为正确答案。

【讨论】:

    【解决方案4】:

    我在使用 WiX 安装证书时遇到了问题 - 我遇到了两个问题:

    1.如果您告诉 WiX 在本地计算机上安装受信任的根证书,它不起作用,而是安装在个人商店中。
    2。 WiX 安装的证书的权限(当它们有私钥时)没有设置 Everyone 用户。 [您可以使用MMC->证书管理器->本地机器->(使用私钥查找证书)右键单击->所有任务->管理私钥,打开文件权限对话框]。

    您可以通过使用 microsoft winhttpcertcfg.exe tool 来避免这两个问题。我在批处理文件中使用它(见下文),并使用 WiX 静默自定义操作来调用批处理文件。在执行批处理之前,我让 WiX 安装工具、证书和批处理文件。可以设置批处理以在安装后删除工具和证书。它还可用于启动 WiX 安装的依赖于证书的服务。批处理的使用大大减少了您的 WiX 文件中的自定义操作数量。

    未正确安装证书的后果是 .net 客户端在执行 http 请求时出现“无法创建 SSL/TLS 安全通道”异常的间歇性错误(有些机器正常工作,有些机器不正常)。

    REM Batch file to install certificates using WinHttpCertCfg.exe
    "[path to installed]winhttpcertcfg.exe" -i "[path to installed]ca.pfx" -a Everyone -c LOCAL_MACHINE\Root  > c:\temp\installcc.log
    "[path to installed]winhttpcertcfg.exe" -i "[path to installed]server.pfx" -a Everyone -c LOCAL_MACHINE\My  >> c:\temp\installcc.log
    

    我在产品中安装了批量安装和卸载文件。然后在 WiX 中 - 注意延迟和模拟的自定义操作。

    <CustomAction Id="InstallCustomAction_Cmd" 
        Property="InstallCustomActionQt" 
        Value="&quot;cmd.exe&quot; /c &quot;[#InstallCustomAction.cmd]&quot;" 
        Execute="immediate" />
    
    <CustomAction Id="InstallCustomActionQt" 
        BinaryKey="WixCA" 
        DllEntry="CAQuietExec"
        Execute="deferred" 
        Return="ignore" 
        Impersonate="yes"/>
    
    <InstallExecuteSequence>
        <Custom Action="InstallCustomAction_Cmd" Before="InstallFinalize">NOT REMOVE</Custom>
        <Custom Action="InstallCustomActionQt" After="InstallCustomAction_Cmd" >NOT REMOVE</Custom>
    ...
    </InstallExecuteSequence>
    ...
    <Component Id="InstallCustomAction" Guid="{your-GUID}">
        <File Id="InstallCustomAction.cmd" KeyPath="yes"  
              Source="tools\InstallCloudConnectCustomAction.cmd" />
    </Component>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      相关资源
      最近更新 更多