Skip to content

WIP: Password + Two Factor Authentication Support #1

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/routers/vault/middlewares/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const update_account = async (req, res, next) => {
primary: +validate.get_prop(req, "primary"),
allow: validate.get_prop(req, "allow") === "true",
strict: validate.get_prop(req, "strict") === "true",
2fa: validate.get_prop(req, "2fa") === "true",
};

const update_fields = {};
Expand Down Expand Up @@ -62,6 +63,10 @@ const update_account = async (req, res, next) => {
// update allow non-primary
update_fields.strictIPCheck = data.strict;
}
if (session.allow2FA !== data.2fa) {
// update allow 2FA auth
update_fields.allow2FA = data.2fa;
}

// update SQL
if (Object.keys(update_fields).length) {
Expand All @@ -73,6 +78,7 @@ const update_account = async (req, res, next) => {
// now update our cache
session.allowNonPrimary = data.allow;
session.strictIPCheck = data.strict;
session.allow2FA = data.allow2FA;

for (const ident of session.identities) {
if (ident.id === session.primaryIdentity.id) {
Expand Down
2 changes: 2 additions & 0 deletions src/routers/vault/middlewares/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const auth_session = async (req, res) => {
session.primaryIdentity = ident;
session.allowNonPrimary = user.allowNonPrimary;
session.strictIPCheck = user.strictIPCheck;
session.allow2FA = user.allow2FA;
session.identities.push(ident);
} else {
if (session.identity !== session.primaryIdentity && !session.allowNonPrimary) {
Expand Down Expand Up @@ -351,6 +352,7 @@ const new_session = async (req, res, next) => {
session.primaryIdentity = primary;
session.allowNonPrimary = account.allowNonPrimary;
session.strictIPCheck = account.strictIPCheck;
session.allow2FA = account.allow2FA;
session.identity = identity;
req.app.locals.session.set(uuid, session);

Expand Down
8 changes: 8 additions & 0 deletions src/routers/vault/models/vault/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ module.exports = {
type: Sequelize.STRING(320),
allowNull: false,
},
totp: {
type: Sequelize.STRING(32),
allowNull: true,
},
pass: {
type: Sequelize.STRING(128),
allowNull: true,
},
addedDate: {
type: Sequelize.DATE,
allowNull: false,
Expand Down
6 changes: 6 additions & 0 deletions src/routers/vault/models/vault/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ module.exports = {
defaultValue: false,
allowNull: false,
},
allow2FA: {
field: "allow_2fa_login",
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false,
},
creationDate: {
type: Sequelize.DATE,
allowNull: false,
Expand Down
10 changes: 10 additions & 0 deletions src/routers/vault/types/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class Identity extends Model {
* the Vault user id
* @type {number}
*/
//totp;
/**
* TOTP 16-chars base64 secret (optional)
* @type {string}
*/
//pass;
/**
* Optional PBKDF2 cryptographic secret to use with 2FA.
* @type {string}
*/
//userId;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/routers/vault/types/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ module.exports = class Session {
* refuse to authenticate a session with a different IP
*/
strictIPCheck = true;
/**
* allow to authenticate a session with 2FA + PBKDF2 password
*/
allow2FA = false;

constructor (ip, email) {
this.ip = ip;
Expand Down Expand Up @@ -109,6 +113,7 @@ module.exports = class Session {
primaryIdentity: this.primaryIdentity.id,
allowNonPrimary: this.allowNonPrimary,
strictIPCheck: this.strictIPCheck,
allow2FA: this.allow2FA,
vaultId: this.vault,
};
}
Expand Down