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

Include 'generation' field in signed certificates. #530

Merged
merged 1 commit into from Jan 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/signer.js
Expand Up @@ -34,7 +34,10 @@ process.on('message', function (message) {
issuedAt: new Date(now - (10 * 1000)),
expiresAt: new Date(now + message.duration)
},
null,
{
// include additional keys in the cert payload
'fxa-generation': message.generation,
},
_privKey,
function (err, cert) {
process.send({ err: err, cert: cert})
Expand Down
6 changes: 4 additions & 2 deletions routes/account.js
Expand Up @@ -85,7 +85,8 @@ module.exports = function (
uid: account.uid,
email: account.email,
emailCode: account.emailCode,
emailVerified: account.emailVerified
emailVerified: account.emailVerified,
verifierSetAt: account.verifierSetAt
}
)
.then(
Expand Down Expand Up @@ -196,7 +197,8 @@ module.exports = function (
uid: emailRecord.uid,
email: emailRecord.email,
emailCode: emailRecord.emailCode,
emailVerified: emailRecord.emailVerified
emailVerified: emailRecord.emailVerified,
verifierSetAt: emailRecord.verifierSetAt
Copy link
Contributor

Choose a reason for hiding this comment

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

since we're adding verifierSetAt I think we should add it to the "getter" db.sessionToken too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, its already there. I'll look at this again when the 💊 has worn off.

}
)
}
Expand Down
3 changes: 2 additions & 1 deletion routes/sign.js
Expand Up @@ -68,7 +68,8 @@ module.exports = function (log, isA, error, signer, domain) {
{
email: sessionToken.uid.toString('hex') + '@' + domain,
publicKey: publicKey,
duration: duration
duration: duration,
generation: sessionToken.verifierSetAt,
},
function (err, result) {
if (err) {
Expand Down
23 changes: 23 additions & 0 deletions test/local/signer_tests.js
Expand Up @@ -227,6 +227,29 @@ test(
}
)

test(
'the cert includes a generation number if given',
function (t) {
var email = 'test@example.com'
var duration = 100
var generation = 1234
signer.enqueue(
{
email: email,
publicKey: validKey,
duration: duration,
generation: generation
},
function (err, result) {
t.ok(result, 'got cert')
var payload = jwcrypto.extractComponents(result.cert).payload
t.equal(payload['fxa-generation'], generation, 'generation, check')
t.end()
}
)
}
)

test(
'teardown',
function (t) {
Expand Down
1 change: 1 addition & 0 deletions test/remote/certificate_sign_tests.js
Expand Up @@ -35,6 +35,7 @@ TestServer.start(config)
t.equal(typeof(cert), 'string', 'cert exists')
var payload = jwcrypto.extractComponents(cert).payload
t.equal(payload.principal.email.split('@')[0], client.uid, 'cert has correct uid')
t.ok(payload['fxa-generation'] > 0, 'cert has non-zero generation number')
}
)
.then(
Expand Down
1 change: 1 addition & 0 deletions tokens/session_token.js
Expand Up @@ -9,6 +9,7 @@ module.exports = function (log, inherits, Token) {
this.email = details.email || null
this.emailCode = details.emailCode || null
this.emailVerified = !!details.emailVerified
this.verifierSetAt = details.verifierSetAt
}
inherits(SessionToken, Token)

Expand Down