-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced usage of Sha1 hash generation with UTF-8 encoding, without hyphens #49
Introduced usage of Sha1 hash generation with UTF-8 encoding, without hyphens #49
Conversation
- added regression tests in order to trigger changes in hash generation
sorry for the closing/reopening, clicked the wrong button. |
As discussed implemented usage of UTF8 encoding for hash generation instead of "default" encoding which depends on the environment. |
Should I also remove the usage of md5 here? Then we are rid of it as we change the API anyway. You already mentioned that
|
- removed md5 hash method - implemented usage of Sha1 hash generation method => SetNewVisitorId changed from md5 to sha1; GetUserIdHashed changed from Sha1 with hyphens to sha1 without hyphens
As discussed I removed the MD5 hash method in favour for sha1 (which breaks SetNewVisitorId()), removed hyphens from Sha1 hash method (which breaks GetUserIdHashed()). |
renaming CreateSha1 -> ToSha1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Piwik.Tracker/PiwikTracker.cs
Outdated
@@ -431,8 +429,7 @@ public void ClearCustomTrackingParameters() | |||
/// </summary> | |||
public void SetNewVisitorId() | |||
{ | |||
var encodedGuidBytes = new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(Guid.NewGuid().ToString())); | |||
_randomVisitorId = BitConverter.ToString(encodedGuidBytes).Replace("-", "").Substring(0, LengthVisitorId).ToLower(); | |||
_randomVisitorId = Guid.NewGuid().ToByteArray().ToSha1().Substring(0, LengthVisitorId).ToLower(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal but I think ToLower
is not required here since ToSha1
produces lower case chars right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, thats right "x2" formats as lowercase hex. Done.
Yes, thats right, I will remove it on Monday. |
Added tests to prevent changes in hash representation before changing the hash provider concerning #35.
CryptoExtensions
As we discussed,
Encoding.Default
will not work in different environments (tests did not fail on my side, but on Travis). Therefore we should discuss another API change (VisitorId, CookieName, UserId would be affected) towards using explicit UTF-8 encoding instead of environment dependentEncoding.Default
.