-
Notifications
You must be signed in to change notification settings - Fork 816
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
Require verifying password before chaning it #1246
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0023143
Verify current password before changing it.
mymindstorm 5b32b32
split out verifyPassword into two functions
mymindstorm 5dc3615
typo
mymindstorm a89337f
change incorrect password message
mymindstorm 26cfb55
Merge branch 'dev' into mymindstorm/verify-password
mymindstorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { BrowserStorage, isOldKey } from "./storage"; | ||
|
||
export async function argonHash( | ||
value: string, | ||
salt: string | ||
): Promise<string | undefined> { | ||
const iframe = document.getElementById("argon-sandbox"); | ||
const message = { | ||
action: "hash", | ||
value, | ||
salt, | ||
}; | ||
|
||
if (!iframe) { | ||
throw new Error("argon-sandbox missing!"); | ||
} | ||
|
||
const argonPromise: Promise<string | undefined> = new Promise((resolve) => { | ||
window.addEventListener("message", (response) => { | ||
resolve(response.data.response); | ||
}); | ||
// @ts-expect-error bad typings | ||
iframe.contentWindow.postMessage(message, "*"); | ||
|
||
}); | ||
|
||
return argonPromise; | ||
} | ||
|
||
export async function argonVerify( | ||
value: string, | ||
hash: string | ||
): Promise<boolean> { | ||
const iframe = document.getElementById("argon-sandbox"); | ||
const message = { | ||
action: "verify", | ||
value, | ||
hash, | ||
}; | ||
|
||
if (!iframe) { | ||
throw new Error("argon-sandbox missing!"); | ||
} | ||
|
||
const argonPromise: Promise<boolean> = new Promise((resolve) => { | ||
window.addEventListener("message", (response) => { | ||
resolve(response.data.response); | ||
}); | ||
// @ts-expect-error bad typings | ||
iframe.contentWindow.postMessage(message, "*"); | ||
}); | ||
|
||
return argonPromise; | ||
} | ||
|
||
// Verify a password using keys in BrowserStorage | ||
export async function verifyPasswordUsingKeyID( | ||
keyId: string, | ||
password: string | ||
): Promise<boolean> { | ||
// Get key for current encryption | ||
const keys = await BrowserStorage.getKeys(); | ||
if (isOldKey(keys)) { | ||
throw new Error( | ||
"v3 encryption not being used with verifyPassword. This should never happen!" | ||
); | ||
} | ||
|
||
const key = keys.find((key) => key.id === keyId); | ||
if (!key) { | ||
throw new Error(`Key ${keyId} not in BrowserStorage`); | ||
} | ||
|
||
return verifyPasswordUsingKey(key, password); | ||
} | ||
|
||
export async function verifyPasswordUsingKey( | ||
key: Key, | ||
password: string | ||
): Promise<boolean> { | ||
// Hash password with argon | ||
const rawHash = await argonHash(password, key.salt); | ||
if (!rawHash) { | ||
throw new Error("argon2 did not return a hash!"); | ||
} | ||
// https://passlib.readthedocs.io/en/stable/lib/passlib.hash.argon2.html#format-algorithm | ||
const possibleHash = rawHash.split("$")[5]; | ||
|
||
// verify user password by comparing their password hash with the | ||
// hash of their password's hash | ||
return await argonVerify(possibleHash, key.hash); | ||
} |
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.
We should distinguish between the situations where the user has entered an incorrect current password and where the two new passwords do not match, to avoid causing confusion for the user.