小编Geo*_*iev的帖子

XML 关系转换算法

我正在尝试使用数字签名验证 MS Word *.docx 文件。为了进行验证,我必须计算引用节点的摘要并检查它是否与签名(sig1.xml)中给出的摘要相同。我找不到有关如何实现关系转换以计算该摘要的信息。

签名XML(sig1.xml)部分如下:

<Object Id="idPackageObject" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature">
<Manifest><Reference URI="/_rels/.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml">
<Transforms><Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform">    
<mdssi:RelationshipReference SourceId="rId1"/></Transform>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>1vWU/YTF/7t6ZjnE44gAFTbZvvA=</DigestValue>....(next ref node ....)..
<Reference URI="/word/document.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>s2yQEJrQSfC0YoRe1hvm+IGBpJQ=</DigestValue></Reference>.....More Reference Nodes.....
Run Code Online (Sandbox Code Playgroud)

/_rels/.rels 文件本身:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin" Target="_xmlsignatures/origin.sigs"/>
</Relationships>
Run Code Online (Sandbox Code Playgroud)

所以我需要计算/_rels/.rels的SHA1,但在计算之前我必须应用关系变换和C14N。

当我计算没有关系变换的节点摘要时(例如,此节点的:)

<Reference URI="/word/document.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"> 
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>s2yQEJrQSfC0YoRe1hvm+IGBpJQ=</DigestValue>
</Reference> 
Run Code Online (Sandbox Code Playgroud)

一切都很好,只需对引用的 URI(在这种情况下为 /word/document.xml)进行 SHA1,我就会得到与给定 int 签名节点相同的哈希值。但是当涉及到具有关系变换的节点时 - 计算永远不会给出与签名中所述相同的值。

我的问题一般是在哪里可以找到有关此关系转换的信息以及如何实现它?

谢谢,

乔治

xml ms-word wordml xml-dsig

2
推荐指数
1
解决办法
882
查看次数

标签 统计

ms-word ×1

wordml ×1

xml ×1

xml-dsig ×1