Skip to content

Commit

Permalink
feat: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
phoqe committed Jun 5, 2021
1 parent 4e44e15 commit 7da5b15
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
63 changes: 63 additions & 0 deletions crypto/win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Core modules
const crypto = require("crypto");

// Third-party modules
const hkdf = require("futoin-hkdf");

// Password Versions
const PASSWORD_V10 = "v10";

// Encryption Key
const KEY_SECRET = "peanuts";
const KEY_LEN = 256 / 8; // 32 bytes
const KEY_SALT = "salt";
const KEY_INFO = "info";
const KEY_HASH = "sha-256";

const NONCE_LEN = 96 / 8; // 12 bytes
const DEC_ALGO = "aes-256-gcm";

/**
*
* @returns {Buffer}
*/
const createEncryptionKey = () => {
return hkdf(KEY_SECRET, KEY_LEN, { salt: KEY_SALT, info: "info" });
};

/**
*
* @param {object} browser
* @param {Buffer} data
* @returns {Promise<string>}
*/
exports.decrypt = (browser, data) => {
return new Promise((resolve, reject) => {
if (!browser) {
reject(new TypeError("No browser."));

return;
}

if (!data) {
reject(new TypeError("No data."));

return;
}

const ciphertext = data.toString();

if (ciphertext.startsWith(PASSWORD_V10)) {
// TODO: Unprotect data.

return;
}

const key = createEncryptionKey();
const nonce = ciphertext.substring(PASSWORD_V10.length - 1, NONCE_LEN);
const rawCiphertext = ciphertext.substring(
NONCE_LEN + PASSWORD_V10.length - 1
);
const decipher = crypto.createDecipheriv(DEC_ALGO, key, iv);
});
};
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@
"private": false,
"dependencies": {
"commander": "^7.2.0",
"futoin-hkdf": "^1.3.3",
"keytar": "^7.2.0",
"sqlite3": "^5.0.0",
"prettier": "2.2.1"
"prettier": "2.2.1",
"sqlite3": "^5.0.0"
},
"scripts": {
"format": "prettier --write --ignore-unknown ."
},
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^11.0.0",
"@semantic-release/git": "^9.0.0",
"husky": "^4.2.1",
"lint-staged": "^11.0.0",
"semantic-release": "^17.4.3",
"@semantic-release/git": "^9.0.0"
"semantic-release": "^17.4.3"
},
"husky": {
"hooks": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,11 @@ function-bind@^1.1.1:
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==

futoin-hkdf@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/futoin-hkdf/-/futoin-hkdf-1.3.3.tgz#6ee1c9c105dfa0995ba4f80633cf1c0c32defcb2"
integrity sha512-oR75fYk3B3X9/B02Y6vusrBKucrpC6VjxhRL+C6B7FwUpuSRHbhBNG3AZbcE/xPyJmEQWsyqUFp3VeNNbA3S7A==

gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
Expand Down

0 comments on commit 7da5b15

Please sign in to comment.