I'm having considerable problems with the 'nimongo' library, which uses scram.nim for generating the authentication messages back and forth during SCRAM-SHA-1 authentication. I've created 3 accounts on different public MongoDB providers and am seeing the same problem with all three.
So, I dove down and started doing diagnostics; added "echo" statements all over the place to deduce the point of failure.
The information received back from prepareFinalMessage
is being rejected by the servers.
I went ahead and found an equivalent algo on a python library and compared the results. Given the same password digest and first message (the unencoded payload), the python library returns a different result.
Looking even deeper, the python equivalent of line 55's:
saltedPassword = hi[T](password, salt, iterations)
is also returning a different result given the exact same inputs.
So, I was wondering if you are seeing any different behavior of the library when compiled with Nim's most recent standard libraries. (Among other things, the 'std/sha1' algorithm was changed completely back on October 9, 2018.)
I'll still keep looking for answers; but I figured I'd ask. Unfortunately the library does not have any unit tests to check against. I might do a PR with some once I get my bearings. Right now I've been diagnosing this for over 12 hours and my eyes are losing focus.
(Off-topic, sort of: on line 15 of utils.nim, the salt is appended with a 00 00 00 01. I assume this is because MongoDB tends to send a salt of 16 bytes instead of 20? Also, why the 01 at the end? I was under the impression that the algo called for all-zeroes for salt padding.)