Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Conversation

@vbudhram
Copy link
Contributor

Fixes #302

@vbudhram vbudhram added the WIP label Mar 15, 2018
@vbudhram vbudhram added this to the FxA-143: MFA milestone Mar 15, 2018
@vbudhram vbudhram self-assigned this Mar 15, 2018
@ghost ghost added the waffle:active label Mar 15, 2018
## createTotpToken(uid, sharedSecret, epoch)

Creates a new TOTP token for the user.
Creates a new TOTP token for the user.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed TOTP section didn't have correct indention, fixed.

const INSERT_RECOVERY_CODE = 'CALL createRecoveryCode_1(?, ?)'
MySql.prototype.replaceRecoveryCodes = function (uid, count) {

// Because of the hashing requirements the process of replacing
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open to suggestions here. Instead of building out one dynamic insert statement, I choose to insert each recovery code individually. This solution, while less efficient, seemed to be a good compromise on readability and security.

The stored procedure I used for dynamic insertion, was technically executing an arbitrary sql statement.

After #320, I will update this to use MySql.prototype.writeMultiple.

@vbudhram
Copy link
Contributor Author

@mozilla/fxa-devs This is ready for review. Couple of notes

var bufferize = require('./lib/bufferize')
var version = require('../package.json').version
var errors = require('./lib/error')
const RECOVERY_CODE_COUNT = 8
Copy link
Contributor

Choose a reason for hiding this comment

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

COUNT seems like the wrong suffix here, unless I misunderstood. Should it be LENGTH?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, I misunderstood. It should be COUNT. 😊

Copy link
Contributor

@philbooth philbooth Mar 16, 2018

Choose a reason for hiding this comment

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

Will we ever want to change this from 8? Any case to be made for it coming from config?

(...and even if it doesn't come from config, this module feels like the wrong place for it I think, it doesn't seem API-related)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will we ever want to change this from 8

👍🏽, the procedure is flexible so I'll push passing the count from the auth-server.

@vbudhram vbudhram force-pushed the feature.recovery branch 2 times, most recently from 04bf9e4 to 2c259ab Compare March 19, 2018 22:45
@vbudhram
Copy link
Contributor Author

@philbooth Rebased and updated!

lib/db/mem.js Outdated
.then(() => {
let codes = []
return dbUtil.generateRecoveryCodes(count)
.then((result) => {
Copy link
Contributor

@philbooth philbooth Mar 20, 2018

Choose a reason for hiding this comment

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

If codes moved up a level we could flatten this promise chain.

lib/db/mem.js Outdated
codeHash: dbUtil.createHashSha512(code)
}
})
return Promise.resolve(codes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Or just return codes.

lib/db/mem.js Outdated
const codes = recoveryCodes[uid]

if (! codes) {
return Promise.reject(error.notFound())
Copy link
Contributor

Choose a reason for hiding this comment

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

Or throw error.notFound().

lib/db/mem.js Outdated

codes.splice(foundIndex, 1)

return Promise.resolve({
Copy link
Contributor

Choose a reason for hiding this comment

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

etc

lib/db/mysql.js Outdated
return this.readFirstResult(CONSUME_RECOVERY_CODE, [uid, dbUtil.createHashSha512(code)])
.then((result) => {
return P.resolve({
remaining: result['COUNT(*)']
Copy link
Contributor

@philbooth philbooth Mar 20, 2018

Choose a reason for hiding this comment

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

Not sure if it's worth it, but would this be a simple result.count if you used SELECT COUNT(*) AS count in the stored procedure?

randomByteCodes.push(randomBytes(4))
}

return P.all(randomByteCodes)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

lib/db/util.js Outdated
codes = result.map((randomCode) => {
return randomCode.toString('hex')
})
return Promise.resolve(codes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Or return codes.

Copy link
Contributor

@philbooth philbooth left a comment

Choose a reason for hiding this comment

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

Looks good! Feel free to ignore the inline comments, they're kind of bike-sheddy.

@vbudhram
Copy link
Contributor Author

@philbooth Thanks! Circle is having a bad day, tests pass, but it is not pushing to docker hub because of AWS degraded service. Merging

@vbudhram vbudhram merged commit 995d52b into master Mar 20, 2018
@shane-tomlinson shane-tomlinson deleted the feature.recovery branch April 18, 2018 12:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants