首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XML关系变换算法

XML关系变换算法
EN

Stack Overflow用户
提问于 2016-03-17 14:24:51
回答 1查看 1.1K关注 0票数 2

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

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

代码语言:javascript
复制
<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.....

/_rels/.rels本人:

代码语言:javascript
复制
<?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>

因此,我需要计算/_ SHA1 /.rels,但在计算之前,我必须应用关系转换和C14N。

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

代码语言:javascript
复制
<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> 

一切都很好,只需对引用的URI执行SHA1 (在本例中为/word/document.xml),就会给出与给定的int (签名节点)相同的散列。但是,当涉及到具有关系转换的节点时,计算永远不会给出与签名中声明的值相同的值。

我的问题是,在哪里可以找到关于这种关系转变的信息,以及如何实现它?

谢谢,

乔吉

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-16 11:39:45

在这种情况下,有关转换和关系转换的主要信息来源可以在ECMA的"Office文件格式-开放包装约定“的论文中找到。链接这里

重要部分为13.2.4.24。

关系转换应该创建.rels文件的副本,在本例中是"/_rels/.rels“,并删除与SourceId不匹配的所有关系节点。这个文件最终会被散列并创建摘要。

在转换定义中指定的和SourceType值中,包实现者应该删除所有没有匹配任何SourceId值的SourceId Id值或匹配任何SourceType值的类型值的关系元素。

在第3步,“为规范化做好准备”中还规定:

如果关系元素中缺少该可选属性,则包实现者将添加一个TargetMode属性及其默认值

因为我们在同一个包中创建文件之间的关系,所以我们有“内部”的值。您需要在散列该属性之前添加该属性。

因此,在转换和c14n之后,您应该有:

代码语言:javascript
复制
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="word/document.xml" TargetMode="Internal" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"></Relationship></Relationships>

注意:如果您使用的是unix系统,请注意换行符,使用的是CRLF而不是LF。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36063375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档