This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
Implement 2FA for Umbrel-Manager #111
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
const passport = require('passport'); | ||
const passportJWT = require('passport-jwt'); | ||
const passportHTTP = require('passport-http'); | ||
const passportTOTP = require('passport-totp'); | ||
const bcrypt = require('bcrypt'); | ||
const diskLogic = require('logic/disk.js'); | ||
const authLogic = require('logic/auth.js'); | ||
const NodeError = require('models/errors.js').NodeError; | ||
const UUID = require('utils/UUID.js'); | ||
const rsa = require('node-rsa'); | ||
const notp = require('notp'); | ||
|
||
const JwtStrategy = passportJWT.Strategy; | ||
const BasicStrategy = passportHTTP.BasicStrategy; | ||
const TotpStrategy = passportTOTP.Strategy; | ||
|
||
|
||
const ExtractJwt = passportJWT.ExtractJwt; | ||
|
||
const JWT_AUTH = 'jwt'; | ||
const REGISTRATION_AUTH = 'register'; | ||
const BASIC_AUTH = 'basic'; | ||
const TOTP_AUTH = 'totp'; | ||
|
||
const SYSTEM_USER = UUID.fetchBootUUID() || 'admin'; | ||
|
||
|
@@ -56,6 +62,10 @@ passport.use(BASIC_AUTH, new BasicStrategy(function (username, password, next) { | |
return next(null, user); | ||
})); | ||
|
||
passport.use(new TotpStrategy(function(user, done) { | ||
done(null, user.totpKey, 30) | ||
})); | ||
|
||
createJwtOptions().then(function (data) { | ||
const jwtOptions = data; | ||
|
||
|
@@ -106,6 +116,17 @@ function basic(req, res, next) { | |
.then(userData => { | ||
const storedPassword = userData.password; | ||
|
||
// check 2FA token when enabled | ||
if(userData.totpEnabled) { | ||
let vres = notp.totp.verify(req.body.totpToken, userData.totpKey) | ||
|
||
if(vres && vres.delta == 0) { | ||
|
||
} else { | ||
return next(new NodeError('Unable to authenticate', 401)); | ||
} | ||
dsbaars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
bcrypt.compare(user.password, storedPassword) | ||
.then(handleCompare) | ||
.catch(next); | ||
|
@@ -136,7 +157,10 @@ async function accountJWTProtected(req, res, next) { | |
if (error || user === false) { | ||
return next(new NodeError('Invalid JWT', 401)); // eslint-disable-line no-magic-numbers | ||
} | ||
|
||
req.logIn(user, function (err) { | ||
|
||
|
||
Comment on lines
+158
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this too to keep changes minimal. |
||
if (err) { | ||
return next(new NodeError('Unable to authenticate', 401)); // eslint-disable-line no-magic-numbers | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reverting these changes would help getting this merged. I recommend to not lint any of your PRs, Umbrel hasn't used a configured linter in any project for over a year now, even though that could've prevented some bugs.