pcibraro / hawknet

Hawk protocol implementation for .NET
MIT License
114 stars 35 forks source link

Time units mismatch #14

Closed luisgoncalves closed 11 years ago

luisgoncalves commented 11 years ago

The ShouldFailWithTimestampInThePast test fails if a timestamp 100 seconds behind is used. The tests are using 1 day which contains more than 1000 seconds, and that's way they succeed.

The ConvertToUnixTimestamp method returns the number of seconds since the epoc. However, the GetBewit method (and probably others) then use var expiration = Math.Floor(now / 1000) + ttlSec;. The value of now is already in seconds.

Since the timestamp in the bewit is in seconds, I'd suggest always using seconds as the time unit. This would also remove all the /1000 and *1000 code.

luisgoncalves commented 11 years ago

Another option is to just change the ConvertToUnixTimestamp method to return TotalMilliseconds but it would keep all the aritmetic operations.

technicaljoe commented 11 years ago

I seems to have encountered the same issue, but only when using dflydev-hawk to talk to hawknet, but not from hawknet to hawknet. Just thought I'd ask in case this is indeed a confirmed issue.

luisgoncalves commented 11 years ago

hawknet makes is coherent (despite wrong) when generating and verifying the bewit. That's why you may not notice the behavior when using only hawknet.

technicaljoe commented 11 years ago

Thanks for the explanation! Would it be sensible for me to create a fork version with the fix and base our solution off that? Or have you encounter other solutions?

luisgoncalves commented 11 years ago

I made the fix locally because I had to make this work quickly. I think you could do it and submit a pull request to pcibraro.

pcibraro commented 11 years ago

I am very sorry guys. I have been out for the last few days and I somehow missed this thread. Luis, feel free to send me a pull request with the fix and I will push it in the repository as soon as possible. Thanks

technicaljoe commented 11 years ago

Thanks @luisgoncalves and @pcibraro!

technicaljoe commented 11 years ago

Would this latest change be pushed into NuGet?

pcibraro commented 11 years ago

It has been pushed today. Version 1.3.1.0. Thanks