You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Jorge Ferreira <jm...@criticalsoftware.com> on 2010/11/02 11:49:17 UTC

RE: Error processing response returned by WSE 3.0 secured Web Service

After some debugging .

 

The exception is caused in this line:

 

P_SHA1.class(86): SecretKeySpec key = new SecretKeySpec(secret, "HMACSHA1");

 

Because secret (first parameter for SecreteKeySpec ctor) is null.

 

secret is passed from DerivedKeyTokenProcessor (member variable
this.secret).

 

DerivedKeyTokenProcessor.class (114): this.keyBytes =
algo.createKey(this.secret, seed, offset, length);

 

this.secret was assigned from method
DerivedKeyTokenProcessor#extractSecret(.)

 

DerivedKeyTokenProcessor.class(161): this.secret = this.getSecret(cb,
keyIdentifierValue, keyIdentifierValueType);

 

Method getSecret uses WSPasswordCallbacks to get the value for secret. In
this case it will fall into TokenCallbackHandler#handle(.) method with usage
WSPasswordCallback.ENCRYPTED_KEY_TOKEN. More precisely this block:

 

TokenCallbackHandler.class(69):

 

try {

  String[] tokenIdentifiers = this.store.getTokenIdentifiers();

  Token tok;

  for (int j = 0 ; j < tokenIdentifiers.length ; j++) {


 

    tok = this.store.getToken(tokenIdentifiers[j]);

                                     

    if (tok instanceof EncryptedKeyToken &&
((EncryptedKeyToken)tok).getSHA1().equals(id)){

      pc.setKey(tok.getSecret());

      pc.setCustomToken((Element)tok.getToken());

    }

  }

                          

} catch (TrustException e) {

  e.printStackTrace();

  throw new IOException(e.getMessage());

}

 

At this point this.store only contains one token (let us refer to it as
Token1) of type org.apache.rahas.Token. Like such the condition that tests
for type EncryptedKeyToken will fail and, as such, pc.setKey is never
called.

 

Because pc.setKey was never called DerivedKeyTokenProcessor#getSecret(.)
returns null.

 

DerivedKeyTokenProcessor.class(246): return pwcb.getKey();

 

That will ultimately cause the reported exception when reaching:

 

DerivedKeyTokenProcessor.class(114): this.keyBytes =
algo.createKey(this.secret, seed, offset, length);

 

With this.secret = null.

 

Now, if during debug, I force the condition in TokenCallbackHandler to be
true and invoke setKey and setCustomToken with the values from the only
token on store the exception does not occurs and the response is correctly
validated.

 

Token1 (referred above) is added to the  store from:

 

AsymmetricBindingBuilder.class(872): rmd.getTokenStorage().add(tok);

 

And was built as (preceding lines):

 

org.apache.rahas.Token tok = new org.apache.rahas.Token(encryptedKeyId,
(OMElement)encrTokenElement , null, null);

tok.setSecret(encryptedKeyValue);

 

And is not of EncryptedKeyToken type, although it will be serialized into
the envelope as such. This is what caused the condition in
TokenCallbackHandler.class(76) to evaluate to false + no SHA1 match (but due
to short-circuit of "if and" evaluation we will not get to that point).

 

Is this a bug or I am missing some important configuration? Can be a bug in
the response returned by .NET WSE 3.0 web service?

 

Just to remember that the same response can be successfully processed by a
WSE 3.0 enabled .NET client.

 

I noticed that EncryptedKeyToken is only built from SymmetricBindingBuilder
while I use an AsymmetricBindingBuilder (see relevant policy fragment
below). Is this design intentional?

 

<wsp:Policy wsu:Id="SigOnly"

 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurit
y-utility-1.0.xsd"

            xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">

  <wsp:ExactlyOne>

    <wsp:All>

      <sp:AsymmetricBinding
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">

      [.]

      </sp:AsymmetricBinding>

      [.]

    </wsp:All>

  </wsp:ExactlyOne>

</wsp:Policy>

 

Because axis2/rampart seems to have all the parts I am inclined for the bug
conclusion but I would like to hear from you.

 

-- jmf

 

From: Jorge Ferreira [mailto:jmferreira@criticalsoftware.com] 
Sent: sexta-feira, 29 de Outubro de 2010 19:39
To: java-user@axis.apache.org
Subject: Error processing response returned by WSE 3.0 secured Web Service

 

Hello,

 

Rampart 1.5

Axis 1.5.1

jdk1.6.0_21

 

I have an axis2 client that uses rampart and a custom security policy
(attached policy.xml) to access a WSE 3.0 secured Web Service.

 

Request is sent by axis2 and successfully processed by the .NET web service
(see attached request.txt and response.txt with the SOAP envelopes being
exchanged).

 

The response fails to be processed by axis2 with the following stack trace.
If I use a .NET WSE 3.0 client to consume the secure web service the SOAP
response is correctly processed.

 

SEVERE: General security error; nested exception is: 

      org.apache.ws.security.conversation.ConversationException: Error in
key derivation

org.apache.axis2.AxisFault: General security error; nested exception is: 

      org.apache.ws.security.conversation.ConversationException: Error in
key derivation

      at
org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(Ram
partReceiver.java:166)

      at
org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:95)

      at org.apache.axis2.engine.Phase.invoke(Phase.java:318)

      at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:251)

      at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:160)

      at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAx
isOperation.java:364)

      at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperatio
n.java:417)

      at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisO
peration.java:229)

      at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

      at
com.contoso.stockservice.wse.samples._2005._10.WSSecurityCertificateServiceS
tub.stockQuoteRequest(WSSecurityCertificateServiceStub.java:184)

      at
com.csw.test.MainCallCSWebService.main(MainCallCSWebService.java:68)

Caused by: org.apache.ws.security.WSSecurityException: General security
error; nested exception is: 

      org.apache.ws.security.conversation.ConversationException: Error in
key derivation

      at
org.apache.ws.security.processor.DerivedKeyTokenProcessor.deriveKey(DerivedK
eyTokenProcessor.java:117)

      at
org.apache.ws.security.processor.DerivedKeyTokenProcessor.handleToken(Derive
dKeyTokenProcessor.java:86)

      at
org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngi
ne.java:326)

      at
org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngi
ne.java:243)

      at org.apache.rampart.RampartEngine.process(RampartEngine.java:154)

      at
org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)

      ... 9 more

Caused by: org.apache.ws.security.conversation.ConversationException: Error
in key derivation

      at
org.apache.ws.security.conversation.dkalgo.P_SHA1.createKey(P_SHA1.java:65)

      at
org.apache.ws.security.processor.DerivedKeyTokenProcessor.deriveKey(DerivedK
eyTokenProcessor.java:114)

      ... 14 more

Caused by: java.lang.IllegalArgumentException: Missing argument

      at javax.crypto.spec.SecretKeySpec.<init>(DashoA13*..)

      at
org.apache.ws.security.conversation.dkalgo.P_SHA1.P_hash(P_SHA1.java:86)

      at
org.apache.ws.security.conversation.dkalgo.P_SHA1.createKey(P_SHA1.java:55)

      ... 15 more

Exception in thread "main" org.apache.axis2.AxisFault: General security
error; nested exception is: 

      org.apache.ws.security.conversation.ConversationException: Error in
key derivation

      at
org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(Ram
partReceiver.java:166)

      at
org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:95)

      at org.apache.axis2.engine.Phase.invoke(Phase.java:318)

      at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:251)

      at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:160)

      at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAx
isOperation.java:364)

      at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperatio
n.java:417)

      at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisO
peration.java:229)

      at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

      at
com.contoso.stockservice.wse.samples._2005._10.WSSecurityCertificateServiceS
tub.stockQuoteRequest(WSSecurityCertificateServiceStub.java:184)

      at
com.csw.test.MainCallCSWebService.main(MainCallCSWebService.java:68)

Caused by: org.apache.ws.security.WSSecurityException: General security
error; nested exception is: 

      org.apache.ws.security.conversation.ConversationException: Error in
key derivation

      at
org.apache.ws.security.processor.DerivedKeyTokenProcessor.deriveKey(DerivedK
eyTokenProcessor.java:117)

      at
org.apache.ws.security.processor.DerivedKeyTokenProcessor.handleToken(Derive
dKeyTokenProcessor.java:86)

      at
org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngi
ne.java:326)

      at
org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngi
ne.java:243)

      at org.apache.rampart.RampartEngine.process(RampartEngine.java:154)

      at
org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)

      ... 9 more

Caused by: org.apache.ws.security.conversation.ConversationException: Error
in key derivation

      at
org.apache.ws.security.conversation.dkalgo.P_SHA1.createKey(P_SHA1.java:65)

      at
org.apache.ws.security.processor.DerivedKeyTokenProcessor.deriveKey(DerivedK
eyTokenProcessor.java:114)

      ... 14 more

Caused by: java.lang.IllegalArgumentException: Missing argument

      at javax.crypto.spec.SecretKeySpec.<init>(DashoA13*..)

      at
org.apache.ws.security.conversation.dkalgo.P_SHA1.P_hash(P_SHA1.java:86)

      at
org.apache.ws.security.conversation.dkalgo.P_SHA1.createKey(P_SHA1.java:55)

      ... 15 more

 

Any help would be greatly appreciated. Feel free to ask any other
information that you think would be useful.

 

Jorge Ferreira
Senior Engineer

 <ma...@criticalsoftware.com>
jorge.m.ferreira@criticalsoftware.com

 <http://www.criticalsoftware.com/> Critical Software, S.A.
Dependable Technologies for Critical Systems

Parque Industrial de Taveiro, Lote 48
3045-504 Coimbra
PORTUGAL
Phone: +351 239 989 100 
Fax: +351 239 989 119

DISCLAIMER: This message is confidential and may contain privileged
information. It is for use only by the persons or entities to whom it is
addressed. If you are not an intended recipient, you should not disclose,
distribute, copy, print, rely on or otherwise make use of this message. If
an addressing or transmission error has misdirected it to you we would be
grateful if you would please notify the sender by return, before deleting it
from your system.