Metro namespace & StreamBuffer error - am I getting this right?
That's it, I'm still working on calling a WSE 3.0 .NET web service from Java / Metro 2.0. We have security requirements in place so that we encrypt the body and header of messages and sign the headers. I can send a request to their service and get a response, but Metro cannot verify the signature and throws an error from the WSIT code. I got the latest WSIT code from CVS and here's a snippet of method code that explodes:
from com.sun.xml.ws.security.opt.impl.incoming.GenericSecuredHeader:
private XMLStreamBuffer completeHeader;
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
try {
// TODO what about in-scope namespaces
completeHeader.writeToXMLStreamWriter(w);
} catch (Exception e) {
throw new XMLStreamException(e);
}
}
As you can see, there is a TODO in there which I think indicates that the method cannot handle the situation I am having, but I'm not sure if I know what they mean by "in-scope" Namespaces.
Here's an XML snippet from the web service response that it breaks down:
<wsa:Action wsu:Id="Id-46282a5d-c7fa-403c-8ac9-f7df0dfdb0cf">
http://someAction</wsa:Action>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="#Id-46282a5d-c7fa-403c-8ac9-f7df0dfdb0cf">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>
/2ivNKDpYSLqPWHzrSxN/RuZ/e8=</DigestValue>
</Reference>
In the stack trace (see below), it complains about the inability to check the reference URI = "# Id-46282a5d-c7fa-403c-8ac9-f7df0dfdb0cf". I don't understand if this is a bug because the Reference element has no namespace attribute or prefix? If they are allowed to inherit the namespace from the parent Signature element or can the StreamBuffer classes not handle this?
For comparison, here's a similar XML snippet from my request (generated by WSIT) where the prefix is ds
Xmlns: DS = "http://www.w3.org/2000/09/xmldsig#"
<ds:Signature xmlns:ns10="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns11="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512"
xmlns:ns12="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" Id="_1">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<exc14n:InclusiveNamespaces PrefixList="wsse S"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#_5002">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<exc14n:InclusiveNamespaces PrefixList="S"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>
vtf9n+OcI1nT0exavD4/ZQy6jm8=</ds:DigestValue>
</ds:Reference>
When Metro generates these blocks, everything has a namespace prefix.
If you are still reading this, thanks! Here are some snippets from the stack trace:
Error occurred while trying to cache START_ELEMENTcom.sun.xml.stream.buffer.stax
.StreamReaderBufferProcessor$InternalNamespaceContext
[16:12:54.026] WSS1759: Following error null occured while performing canonicali
zation null
[16:12:54.026] javax.xml.stream.XMLStreamException
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.GenericSecuredHeade
r.writeTo(GenericSecuredHeader.java:303)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.StreamWriterData.wr
ite(StreamWriterData.java:101)
[16:12:54.026] at com.sun.xml.ws.security.opt.crypto.dsig.Exc14nCanonicalizer.t
ransform(Exc14nCanonicalizer.java:153)
[16:12:54.026] at com.sun.xml.ws.security.opt.crypto.dsig.Transform.transform(T
ransform.java:182)
[16:12:54.026] at com.sun.xml.ws.security.opt.crypto.dsig.Reference.transform(R
eference.java:183)
[16:12:54.026] at com.sun.xml.ws.security.opt.crypto.dsig.Reference.validate(Re
ference.java:102)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.processor.SignedInf
oProcessor.processReference(SignedInfoProcessor.java:422)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.processor.SignedInf
oProcessor.processReferences(SignedInfoProcessor.java:385)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.processor.SignedInf
oProcessor.process(SignedInfoProcessor.java:189)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.Signature.process(S
ignature.java:206)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.SecurityRecipient.h
andleSecurityHeader(SecurityRecipient.java:466)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.SecurityRecipient.c
acheHeaders(SecurityRecipient.java:281)
[16:12:54.026] at com.sun.xml.ws.security.opt.impl.incoming.SecurityRecipient.v
alidateMessage(SecurityRecipient.java:223)
[16:12:54.026] at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.verifyInboundMess
age(SecurityTubeBase.java:462)
[16:12:54.026] at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processClientRe
sponsePacket(SecurityClientTube.java:412)
[16:12:54.026] at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processResponse
javax.xml.ws.WebServiceException: com.sun.xml.wss.impl.WssSoapFaultException: WSS1722: Error occurred while validating Reference with URI: #Id-46282a5d-c7fa-403c-8ac9-f7df0dfdb0c
f
a source to share
After doing some more research, I believe my initial understanding of this is correct. Metro / WSIT code that calls StreamBuffer code on an XML stream from a SOAP response cannot process elements that do not have namespace prefixes or attributes. I have presented a question against WSIT, for those interested in follow-up:
a source to share