Hi Kireet,
This took a bit longer than expected but I think I know where the problem
lies.
You have this clause:
if ((calcSignature.length() % 2) != 0) {
calcSignature = "0" + calcSignature;
}
It "fixes" signatures that start with one leading zero, such
as 02c8a97dd9b808f3d2dcce9581fd883ecc5f7f2a, but it's helpless against
signatures with several leading zeros, such as
00c8a97dd9b808f3d2dcce9581fd883ecc5f7f2a. In other
words, calcSignature.length() can be less than 40 when you return it.
To fix this problem, change your code to the following:
while (calcSignature.length() < 40) {
calcSignature = "0" + calcSignature;
}
HTH,
Roman.
On Sun, May 26, 2013 at 4:31 AM, Kireet <[email protected]> wrote:
> I have implemented some PuSH subscription code and usually it works well.
> But on about 1% of the pushes I get a signature mismatch, especially with
> this feed, http://feeds.feedburner.com/TechCrunch (wordpress). I have had
> occasional issues with the google hub also, e.g.
> http://looksgoodworkswell.blogspot.com/feeds/posts/default
>
> My code is below (java). It's a bit hard to debug, I captured the content
> bytes as a hex string and ran my signature algorithm on it and it matched
> what my code was doing, but was different than the value produced by the
> hub. Beyond that I am not sure what to try next.
>
> Mac mac = Mac.getInstance("HmacSHA1");
>
> String secret = tokenize(feedUri);
>
> mac.init(new SecretKeySpec(secret.getBytes(), "HmacSHA1"));
>
> byte[] digest = mac.doFinal(payload);
>
> BigInteger hash = new BigInteger(1, digest);
>
> String calcSignature = hash.toString(16);
>
> if ((calcSignature.length() % 2) != 0) {
>
> calcSignature = "0" + calcSignature;
>
> }
>
> return calcSignature;
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Pubsubhubbub" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
---
You received this message because you are subscribed to the Google Groups
"Pubsubhubbub" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.