我试图用数字签名验证MS Word *.docx文件。为了进行验证,我必须计算引用节点的摘要,并检查它是否与签名中给定的摘要相同(sig1.xml)。我找不到关于ti如何实现关系转换的信息,以便计算该摘要。
签名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...../_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>因此,我需要计算/_ SHA1 /.rels,但在计算之前,我必须应用关系转换和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> 一切都很好,只需对引用的URI执行SHA1 (在本例中为/word/document.xml),就会给出与给定的int (签名节点)相同的散列。但是,当涉及到具有关系转换的节点时,计算永远不会给出与签名中声明的值相同的值。
我的问题是,在哪里可以找到关于这种关系转变的信息,以及如何实现它?
谢谢,
乔吉
发布于 2017-02-16 11:39:45
在这种情况下,有关转换和关系转换的主要信息来源可以在ECMA的"Office文件格式-开放包装约定“的论文中找到。链接这里。
重要部分为13.2.4.24。
关系转换应该创建.rels文件的副本,在本例中是"/_rels/.rels“,并删除与SourceId不匹配的所有关系节点。这个文件最终会被散列并创建摘要。
在转换定义中指定的和SourceType值中,包实现者应该删除所有没有匹配任何SourceId值的SourceId Id值或匹配任何SourceType值的类型值的关系元素。
在第3步,“为规范化做好准备”中还规定:
如果关系元素中缺少该可选属性,则包实现者将添加一个TargetMode属性及其默认值。
因为我们在同一个包中创建文件之间的关系,所以我们有“内部”的值。您需要在散列该属性之前添加该属性。
因此,在转换和c14n之后,您应该有:
<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。
https://stackoverflow.com/questions/36063375
复制相似问题