【问题标题】:Error using XAdES4j to produce a detached signature with a xpath transform使用 XAdES4j 通过 xpath 转换生成分离签名时出错
【发布时间】:2014-09-11 12:29:11
【问题描述】:

我正在使用 xades4j 来生成 xades 签名。 我想在参考中包含 xpath 转换。我的问题是它是一个分离的签名并且 xpath 有命名空间......

我尝试使用以下 xml(摘录):

<collection xmlns:t="http://test.xades4j/tracks" Id="root">
    <album>
        <title>Questions, unanswered</title>
        <artist>Steve and the flubberblubs</artist>
        <year>1989</year>
        <t:tracks xmlns:t="http://test.xades4j/tracks">
            <t:song length="4:05" tracknumber="1">
                <t:title>What do you know?</t:title>
                <t:artist>Steve and the flubberblubs</t:artist>
                <t:lastplayed>2006-10-17-08:31</t:lastplayed>
            </t:song>
            <t:song length="3:45" tracknumber="2">
                <t:title>Who do you know?</t:title>
                <t:artist>Steve and the flubberblubs</t:artist>
                <t:lastplayed>2006-10-17-08:35</t:lastplayed>
            </t:song>

如果我尝试对此文档进行信封签名,请使用以下代码:

String xpathString = "/collection/album/t:tracks/t:song[ @tracknumber = 1 ]";

DataObjectDesc obj1 = new DataObjectReference("");
obj1.withTransform(new EnvelopedSignatureTransform());
obj1.withTransform(XPath2Filter.intersect( xpathString ));

SignedDataObjects objs = new SignedDataObjects( obj1 );         
Document doc = getDocument(path+fileName);

signer.sign( objs, doc.getDocumentElement() );

它工作正常,参考如下:

<ds:Reference Id="xmldsig-44c42d30-9a42-4290-afba-b89dc807a668-ref0" URI="">
                <ds:Transforms>
                    <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                    <ds:Transform Algorithm="http://www.w3.org/2002/06/xmldsig-filter2">
                        <dsig-xpath:XPath xmlns:dsig-xpath="http://www.w3.org/2002/06/xmldsig-filter2" Filter="intersect">/collection/album/t:tracks/t:song[ @tracknumber = 1 ]</dsig-xpath:XPath>
                    </ds:Transform>
                </ds:Transforms>

但是,如果我尝试分离版本,代码:

String xpathString = "/collection/album/t:tracks/t:song[ @tracknumber = 1 ]";

DataObjectDesc obj1 = new DataObjectReference( fileName );
obj1.withTransform(XPath2Filter.intersect( xpathString ));

SignedDataObjects objs = new SignedDataObjects( obj1 );
objs.withBaseUri( "file:///"+path );

signer.sign( objs, db.newDocument());

我收到错误:前缀必须解析为命名空间:t

我的问题与这里描述的类似:namespace and xpath 但是没有答案,我所拥有的有点不同。我请客,这个问题的答案可能对我有帮助......

那么,如何在 xades4j 中将命名空间设置为转换?

【问题讨论】:

    标签: xpath digital-signature xades4j xml-dsig


    【解决方案1】:

    不错的收获!目前没有办法指定这一点。但是,我认为底层 Apache Santuario API 使用 setXPathNamespaceContext 方法支持这一点。看起来输出 XPath 元素将包含命名空间声明。如果可能,我会对此进行测试并添加支持。

    【讨论】:

    • 是的,我环顾四周看看可以在哪里设置 setXPathNamespaceContext。我看到了一个 xpath 元素具有命名空间的示例: w3.org/2002/06/xmldsig-filter2" xmlns:t="test.xades4j/tracks" Filter="intersect">
    • 已添加对 XPath 查询命名空间的支持。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    相关资源
    最近更新 更多