如何修复“根元素丢失”错误?

时间:2019-09-09 10:50:47

标签: xml windows powershell code-signing

我打算使用Powershell签署HLK提交包(.hlkx文件)。为此,首先,我加载相关的DLL:

  • Microsoft.Windows.Kits.Hardware.objectmodel.submission.dll
  • Microsoft.Windows.Kits.Hardware.objectmodel.dll

然后,我从本地证书存储中获取所需的证书。使用所需的证书,执行签名操作。在那个阶段,我收到一条错误消息,指出“根元素丢失”。

我已经使用Virtual Hardware Lab Kit生成了软件包。我已在运行Windows Server 2016的单独计算机中使用了此程序包,其中安装了Windows HLK Studio。

代码的相关部分:

$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "Microsoft.Windows.Kits.Hardware.objectmodel.dll")
$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "Microsoft.Windows.Kits.Hardware.objectmodel.submission.dll")

$packageFile = <<full path to the package>>

$Cert = Get-ChildItem -Path Cert:\LocalMachine\My |
        Where-Object {$_.<<desired conditions>> }

[Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageManager]::Sign($packageFile, $Cert)

预期输出是已签名的程序包,我可以进一步验证。我收到的错误消息是(堆栈跟踪):

at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Security.Cryptography.Xml.CanonicalXml..ctor(Stream inputStream, Boolean includeComments, XmlResolver resolver, String strBaseUri)
at System.Security.Cryptography.Xml.XmlDsigC14NTransform.LoadInput(Object obj)
at MS.Internal.IO.Packaging.XmlDigitalSignatureProcessor.TransformXml(Transform xForm, Object source)
at MS.Internal.IO.Packaging.XmlDigitalSignatureProcessor.GenerateDigestValue(Stream s, List 1 transforms, HashAlgorithm hashAlgorithm)
at MS.Internal.IO.Packaging.XmlSignatureManifest.GenerateDigestValueNode(XmlDocument xDoc, HashAlgorithm hashAlgorithm, Stream s, String transformName)
at MS.Internal.IO.Packaging.XmlSignatureManifest.GeneratePartSigningReference(PackageDigitalSignatureManager manager, XmlDocument xDoc, HashAlgorithm hashAlgorithm, Uri partName)
at MS.Internal.IO.Packaging.XmlSignatureManifest.GenerateManifest(PackageDigitalSignatureManager manager, XmlDocument xDoc, HashAlgorithm hashAlgorithm, IEnumerable 1 parts, IEnumerable 1 relationshipSelectors)
at MS.Internal.IO.Packaging.XmlDigitalSignatureProcessor.GenerateObjectTag(HashAlgorithm hashAlgorithm, IEnumerable 1 parts, IEnumerable 1 relationshipSelectors, String signatureId)
at MS.Internal.IO.Packaging.XmlDigitalSignatureProcessor.Sign(IEnumerable 1 parts, IEnumerable 1 relationshipSelectors, X509Certificate2 signer, String signatureId, Boolean embedCertificate, IEnumerable 1 signatureObjects, IEnumerable 1 objectReferences)
at System.IO.Packaging.PackageDigitalSignatureManager.Sign(IEnumerable 1 parts, X509Certificate certificate, IEnumerable 1 relationshipSelectors, String signatureId, IEnumerable 1 signatureObjects, IEnumerable 1 objectReferences)
at System.IO.Packaging.PackageDigitalSignatureManager.Sign(IEnumerable 1 parts, X509Certificate certificate, IEnumerable 1 relationshipSelectors, String signatureId)
at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageManager.Sign(String sourcePackage, X509Certificate certificate, String outputPackage)
at CallSite.Target(Closure , CallSite , Type , String , Object )

0 个答案:

没有答案