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

Ensure TOTP codes cannot be reused. #2908

Merged
merged 2 commits into from
Jun 23, 2017
Merged

Ensure TOTP codes cannot be reused. #2908

merged 2 commits into from
Jun 23, 2017

Conversation

jefferai
Copy link
Member

Fixes #2775

@jefferai jefferai added this to the 0.7.4 milestone Jun 22, 2017
err = b.usedCodes.Add(usedName, nil, time.Duration(
int64(time.Second)*
int64(key.Period)*
int64((2+key.Skew))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add the skew and not multiple it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about (time.Second * key.Period) + 2 * key.Skew? Multiplying the skew but adding the multiplied number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skew isn't seconds, it's periods. So that will give you 2 extra nanoseconds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the equation should be time.Second * (key.Period + 2 * key.Skew). Otherwise, the value will bump up multifold.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key.Period is not a duration, it's an integer number of seconds. If the period is 30 seconds and the skew is 1 period, that equation will give you time.Second * 32. What we want is time.Second * 90.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. Skew was something different in my mind. Looks good.

@@ -25,11 +27,15 @@ func Backend(conf *logical.BackendConfig) *backend {
Secrets: []*framework.Secret{},
}

b.usedCodes = cache.New(0, 1*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add comments here about the expiration and cleanup durations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if we can afford to wait a little longer to look for expired items instead of doing it every second.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can make it be longer.

@jefferai jefferai merged commit 2575704 into master Jun 23, 2017
@jefferai jefferai deleted the issue-2775 branch June 23, 2017 15:21
@jefferai jefferai modified the milestones: 0.7.4, 0.8.0 Jul 24, 2017
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

Successfully merging this pull request may close these issues.

2 participants