Skip to content
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

Clock synchronization #5

Open
doodi-v1 opened this issue Dec 1, 2016 · 0 comments
Open

Clock synchronization #5

doodi-v1 opened this issue Dec 1, 2016 · 0 comments

Comments

@doodi-v1
Copy link

doodi-v1 commented Dec 1, 2016

I've been using this component for over a year without any issue until today. Today I ran into an issue where the server was out-of-sync with the UTC clock by 10 seconds -- 10 seconds behind. This created an issue of failures because the token provided by the user was the next token as far as the component was concerned. I corrected this by adjusting the verifyGoogleToken function:

/**
* Verifies the submitted value from the user against the user secret, with optional grace for the last few
* token values
*
* @param base32secret the Base32 encoded shared secret key
* @param userValue the value that the user submitted
* @param grace the amount of previous tokens to allow (1 means allow the current, next, and last token value)
* @return a boolean whether the token was valid or not
*/
public boolean function verifyGoogleToken (required string base32Secret, required string userValue, numeric grace = 0)
{
	var result = false;
    for (var i = 0; i <= grace; i++)
    {
        result = result
				or (getGoogleToken(base32Secret, -i) == userValue)
				or (getGoogleToken(base32Secret, -i-120) == userValue)		// DST switch-over adjustment - an hour ago
				or (getGoogleToken(base32Secret, -i+120) == userValue);		// DST switch-over adjustment - an hour from now

    }
	if(!result)
	{
		// check for next token in case of clocks not being synchronized to the exact UTC millisecond - only kicks in if grace>0
		for (var i = 1; i <= grace; i++)
		{
			result = result
					or (getGoogleToken(base32Secret, i) == userValue)
					or (getGoogleToken(base32Secret, i-120) == userValue)		// DST switch-over adjustment - an hour ago
					or (getGoogleToken(base32Secret, i+120) == userValue);		// DST switch-over adjustment - an hour from now
		
		}
	}
    return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant