1

I am using .NET reflector to debug a console application calling a WSE3.0 service which requires signing & encrypting the message using username token element. Our service provider uses WSE so I need to use that or replicate that same logic of signing and encrypting if I need to use non .net client. To find out how that actual message signing happens (so that I can replicate that using NON .NET clients) I used .NET reflector to debug the code.

MessageSignature.BuildSignedInfo calls HMACSHA1SignatureFormatter.Sign which actually signs the message and returns the hmac, which is a byte[] array, to MessageSignature.BuildSignedInfo. Below are the 2 methods

private byte[] BuildSignedInfo(SignatureFormatter formatter)
{
    this.SignedInfo.SignatureMethod = formatter.AlgorithmURI;
    return formatter.Sign(this.CanonicalizeSignedInfo());
}


public override byte[] Sign(Stream data)
{
    HMACSHA1 hmacsha = new HMACSHA1(this._key);
    return hmacsha.ComputeHash(data);
}

This is how the byte array looks like in watch windows.

Watch window in sign method of HMACSHA1SignatureFormatter

watch window in sign method of HMACSHA1SignatureFormatter

Watch window of that returned byte[] array in MessageSignature.BuildSignedInfo (this calls that sign method to get byte[] array)

watch window in Buildsignedinfo method

I am stepping through the code and there are no intermediate methods which gets called in between them. Would there be any reason why that would happen?

4
  • 4
    By using QuickWatch you are re-computing the value. Try the Reevaluate button, my guess is that it will return something different each time. Most Hashers are statefull. Commented Jul 22, 2014 at 22:02
  • I did try that but reevaluate didn't change the hash value. Commented Jul 22, 2014 at 22:17
  • Then I don't know. If you own the code, do insert a few intermediate vars to make debugging easier (more reliable). Commented Jul 22, 2014 at 22:18
  • unfortunately that Microsoft code is not public. only way for me is to use that decompiled code by .NET reflector and I guess that is missing some pieces. Thanks for looking into it. Commented Jul 22, 2014 at 22:23

1 Answer 1

3

A few possibilities:

  1. Maybe ComputeHash is not rewinding the stream, so the second call from the QuickWatch window hashes a different portion of the stream? Check the stream.Position before and after each call.

  2. If you are stepping through decompiled Microsoft code, then that code is likely optimized, which can sometimes reorder calls. It may be that the hash function actually has not been called yet, or the result is not where you think it is, as you step through the method.

Sign up to request clarification or add additional context in comments.

1 Comment

awesome.. Thank you very much dbc. it is because of #1 you mentioned. At the time when I used quick watch to view the result, Stream is at its end position. So hmac of it is different than the hmac returned when stream is at position 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.