Skip to content

Commit

Permalink
Update @metamask/browser-passworder (#62)
Browse files Browse the repository at this point in the history
* chore: bump browser-passworder

* chore: update bundle

* chore: dedupe packages

* test: add `CryptoKey` to tests `globalThis`

* test: add unit tests `decryptVault`

* test: add test fixture for mac
  • Loading branch information
mikesposito authored Dec 12, 2023
1 parent 3bdf3d8 commit 685462b
Show file tree
Hide file tree
Showing 8 changed files with 8,171 additions and 448 deletions.
16 changes: 15 additions & 1 deletion app/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,21 @@ function extractVaultFromFile (data) {
)
}
}
// attempt 4: chromium 000005.ldb on windows
{
// attempt 4: chromium 000006.log on MacOS
// this variant also contains a 'keyMetadata' key in the vault, which should be
// a nested object.
const matches = data.match(/KeyringController":(\{"vault":".*=\\"\}"\})/);
if (matches && matches.length) {
keyringControllerState = matches[1];
try {
return JSON.parse(JSON.parse(keyringControllerState).vault);
} catch (err) {
// Not valid JSON: continue
}
}
}
// attempt 5: chromium 000005.ldb on windows
const matchRegex = /Keyring[0-9][^\}]*(\{[^\{\}]*\\"\})/gu
const captureRegex = /Keyring[0-9][^\}]*(\{[^\{\}]*\\"\})/u
const ivRegex = /\\"iv.{1,4}[^A-Za-z0-9+\/]{1,10}([A-Za-z0-9+\/]{10,40}=*)/u
Expand Down
33 changes: 33 additions & 0 deletions app/lib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ const FIXTURES = [
mnemonic: 'speed accuse odor ordinary exercise truly outer mask arrest life sibling height',
//passphrase: 'bG82kXdp3rNwJ3MCT3kLmLKFN',
},
{
path: 'chrome-119.0.6045.199-macos-arm64/000006.log',
mnemonic: 'position ship hill notice replace truth science angle merit reunion direct steak',
passphrase: 'r!chSloth14',
}
]

const VAULTS = [
{
variant: 'vault with no key metadata',
vaultData: '{"data":"s6TpYjlUNsn7ifhEFTkuDGBUM1GyOlPrim7JSjtfIxgTt8/6MiXgiR/CtFfR4dWW2xhq85/NGIBYEeWrZThGdKGarBzeIqBfLFhw9n509jprzJ0zc2Rf+9HVFGLw+xxC4xPxgCS0IIWeAJQ+XtGcHmn0UZXriXm8Ja4kdlow6SWinB7sr/WM3R0+frYs4WgllkwggDf2/Tv6VHygvLnhtzp6hIJFyTjh+l/KnyJTyZW1TkZhDaNDzX3SCOHT","iv":"FbeHDAW5afeWNORfNJBR0Q==","salt":"TxZ+WbCW6891C9LK/hbMAoUsSEW1E8pyGLVBU6x5KR8="}',
mnemonic: 'spread raise short crane omit tent fringe mandate neglect detail suspect cradle',
passphrase: 'correct horse battery staple',
},
{
variant: 'vault with key metadata and 600_000 iterations',
vaultData: '{"data":"WHaP1FrrtV4zUonudIppDifsLHF39g6oPkVksAIdWAHBRzax1uy1asfAJprR7u72t4/HuYz5yPIFQrnNnv+hwQu9GRuty88VKMnvMy+sq8MNtoXI+C54bZpWa8r4iUQfa0Mj/cfJbpFpzOdF1ZYXahTfTcU5WsrHwvJew842CiJR4B2jmCHHXfm/DxLK3WazsVQwXJGx/U71UelGoOOrT8NI28EKrAwgPn+7Xmv0j92gmhau30N7Bo2fr6Zv","iv":"LfD8/tY1EjXzxuemSmDVdA==","keyMetadata":{"algorithm":"PBKDF2","params":{"iterations":600000}},"salt":"nk4xdpmMR+1s5BYe4Vnk++XAQwrISI2bCtbMg7V1wUA="}',
mnemonic: 'spread raise short crane omit tent fringe mandate neglect detail suspect cradle',
passphrase: 'correct horse battery staple',
},
]

describe('extractVaultFromFile', () => {
Expand All @@ -47,6 +67,19 @@ describe('extractVaultFromFile', () => {
}
})

describe('decryptVault', () => {
VAULTS.forEach((vault) => {
it(`decrypts ${vault.variant}`, async () => {
const decrypted = await decryptVault(
vault.passphrase,
JSON.parse(vault.vaultData)
);

expect(decrypted[0].data.mnemonic).toBe(vault.mnemonic)
})
})
});

describe('isVaultValid', () => {
const validVault = {
data: 'foo',
Expand Down
Loading

0 comments on commit 685462b

Please sign in to comment.