Skip to content

Commit

Permalink
Codecov, compression, start of usb implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fishylunar committed Aug 25, 2023
1 parent c0b4104 commit ffd4da4
Show file tree
Hide file tree
Showing 10 changed files with 910 additions and 62 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ So files encrypted with one version might not be decryptable with new versions.

### Resonably secure encryption

Changelog 8/25/23 12; :
- General code coverage improvements

- Starting to implement encryption using a removable USB drive as an identifier.

- Added support for compression

Changelog 7/19/23 03~ :
- General code quality improvements (Ongoing)

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
collectCoverage: true,
coverageReporters: ['json'],
coverageReporters: ['json', 'lcov'],
moduleDirectories: [
"node_modules"
],
Expand Down
496 changes: 487 additions & 9 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
"dependencies": {
"clipboardy": "^3.0.0",
"commander": "^11.0.0",
"drivelist": "^11.1.0",
"esbuild": "0.18.13",
"ip": "^1.1.8",
"md6-hash": "^1.0.0",
"node-machine-id": "^1.1.12",
"qrcode-terminal": "^0.12.0",
"readline-sync": "^1.4.10",
"totp.js": "^0.0.1"
"totp.js": "^0.0.1",
"usb": "^2.9.0",
"usb-detection": "^4.14.2"
},
"devDependencies": {
"eslint": "^8.45.0",
Expand Down
20 changes: 15 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ program // Set basic info
"Include the name of the file being encrypted as part of the encryption process")
.option('--totp',
"Require TOTP authentacation before decrypting")
.option('--compression',
"Compress output")
.option('--usb',
"Require specefic USB drive to be connected before decrypting")
.action((file, pass, options) => {
let aaa = handleOpts(options);
let features = aaa[0];
Expand Down Expand Up @@ -99,10 +103,13 @@ program // Set basic info
createIDFile: options.createID,
isString: options.string,
doCopy: options.copy,
userkey: pass || "cHaNgE-mE"
userkey: pass || "cHaNgE-mE",
compression: options.compression || false
}
);



// Define variables here so we can use them in the switch statement
let outputStr, outputMessage;

Expand Down Expand Up @@ -150,6 +157,8 @@ program // Set basic info
"Delete original file after encryption")
.option('-s, --string',
"Encrypt a string instead of a file")
.option('--compression',
'Decompress output')
.option('-c, --copy',
"Copy the decrypted file or string to the clipboard after decryption")
.action((file, pass, idfile, options) => {
Expand All @@ -170,7 +179,7 @@ program // Set basic info
✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨`;

// Check if we're gonna be using an ID file to decrypt
if (Object.prototype.hasOwnProperty.call(options, 'useID') || options.useID) {
if (options.useID) {
// Use ID to decrypt fiie
// 🦈--> Implement logic
throw new Error("Not implemented");
Expand All @@ -182,7 +191,8 @@ program // Set basic info
file,
options.deleteOriginal,
options.string,
options.copy
options.copy,
options.compression
);
} catch (err) {
console.log("[πŸ¦ˆπŸ”‘] We were unable to decrypt the data with the info you provided.");
Expand Down Expand Up @@ -263,9 +273,9 @@ program.parse(process.argv);

function handleOpts(opts) {
let features = [];
let values = { deleteOriginal: false, createID: false, string: false, copy: false, useID: false, verbose: false };
let values = { deleteOriginal: false, createID: false, string: false, copy: false, useID: false, verbose: false, compression: false };
for (const opt in opts) {
if (["deleteOriginal", "createID", "string", "copy", "useID", "verbose"].includes(opt)) {
if (["deleteOriginal", "createID", "string", "copy", "useID", "verbose", "compression"].includes(opt)) {
values[opt] = true;
continue;
}
Expand Down
61 changes: 60 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("files", () => {

test("encrypt file", () => {
fs.writeFileSync("jestFile.txt", "hello world", "utf8");
fs.writeFileSync("jestFile2.txt", "hello world", "utf8");
expect(shark.cryptography.encrypt(hashKey, "./jestFile.txt", true, {
features: [],
createIDFile: false,
Expand All @@ -24,6 +25,34 @@ describe("files", () => {
}))
.toBe(true);
});
test("encrypt file with compression", () => {
fs.writeFileSync("jestFile2.txt", "hello world", "utf8");
expect(shark.cryptography.encrypt(hashKey, "./jestFile2.txt", true, {
features: [],
createIDFile: false,
isString: false,
doCopy: false,
userkey: "cHaNgE-mE",
compression: true
}))
.toBe(true);
});
test("encrypt file with features", () => {
fs.writeFileSync("jestFile3.txt", "features test", "utf8");
let localHashKey = shark.cryptography.calculateKey(
"cHaNgE-mE", ['hwid', 'distro', 'lip', 'username', 'timezone', 'locale', 'hostname', 'platform', 'serial', 'filename'],
false,
"./jestFile3.txt");
expect(shark.cryptography.encrypt(localHashKey, "./jestFile3.txt", true, {
features: ['hwid', 'distro', 'lip', 'username', 'timezone', 'locale', 'hostname', 'platform', 'serial', 'filename'],
createIDFile: false,
isString: false,
doCopy: false,
userkey: "cHaNgE-mE",
compression: false
}))
.toBe(true);
});
test("encrypt file with id", () => {
fs.writeFileSync("jestFileId.txt", "hello world", "utf8");
let hk = shark.cryptography.calculateKey(
Expand Down Expand Up @@ -54,9 +83,29 @@ describe("files", () => {
.toHaveProperty('id', { '0': '992469a97b348ca4', '1': '502c4b8f4ae94915' });
});
test("decrypt file", () => {
expect(shark.cryptography.decrypt("jestPass", "./jestFile.txt.πŸ¦ˆπŸ”‘", true, false, false))
expect(shark.cryptography.decrypt("jestPass", "./jestFile.txt.πŸ¦ˆπŸ”‘", true, false, false, false))
.toBe(true);
if (fs.existsSync("jestFile.txt")) fs.unlinkSync("jestFile.txt");
if (fs.existsSync("jestFile2.txt")) fs.unlinkSync("jestFile2.txt");
if (fs.existsSync("jestFileId.txt.πŸ¦ˆπŸ”‘")) fs.unlinkSync("jestFileId.txt.πŸ¦ˆπŸ”‘");
if (fs.existsSync("jestFileId.txt.πŸ¦ˆπŸ”‘πŸͺͺ")) fs.unlinkSync("jestFileId.txt.πŸ¦ˆπŸ”‘πŸͺͺ");
if (fs.existsSync("jestFileTOTP.txt.πŸ¦ˆπŸ”‘")) fs.unlinkSync("jestFileTOTP.txt.πŸ¦ˆπŸ”‘");
});
test("decrypt file with compression", () => {
expect(shark.cryptography.decrypt("jestPass", "./jestFile2.txt.πŸ¦ˆπŸ”‘", true, false, false, true))
.toBe(true);
if (fs.existsSync("jestFile.txt")) fs.unlinkSync("jestFile.txt");
if (fs.existsSync("jestFile2.txt")) fs.unlinkSync("jestFile2.txt");
if (fs.existsSync("jestFileId.txt.πŸ¦ˆπŸ”‘")) fs.unlinkSync("jestFileId.txt.πŸ¦ˆπŸ”‘");
if (fs.existsSync("jestFileId.txt.πŸ¦ˆπŸ”‘πŸͺͺ")) fs.unlinkSync("jestFileId.txt.πŸ¦ˆπŸ”‘πŸͺͺ");
if (fs.existsSync("jestFileTOTP.txt.πŸ¦ˆπŸ”‘")) fs.unlinkSync("jestFileTOTP.txt.πŸ¦ˆπŸ”‘");
});
test("decrypt file with features", () => {
expect(shark.cryptography.decrypt("cHaNgE-mE", "./jestFile3.txt.πŸ¦ˆπŸ”‘", true, false, false, false))
.toBe(true);
if (fs.existsSync("jestFile.txt")) fs.unlinkSync("jestFile.txt");
if (fs.existsSync("jestFile2.txt")) fs.unlinkSync("jestFile2.txt");
if (fs.existsSync("jestFile3.txt")) fs.unlinkSync("jestFile3.txt");
if (fs.existsSync("jestFileId.txt.πŸ¦ˆπŸ”‘")) fs.unlinkSync("jestFileId.txt.πŸ¦ˆπŸ”‘");
if (fs.existsSync("jestFileId.txt.πŸ¦ˆπŸ”‘πŸͺͺ")) fs.unlinkSync("jestFileId.txt.πŸ¦ˆπŸ”‘πŸͺͺ");
if (fs.existsSync("jestFileTOTP.txt.πŸ¦ˆπŸ”‘")) fs.unlinkSync("jestFileTOTP.txt.πŸ¦ˆπŸ”‘");
Expand Down Expand Up @@ -137,4 +186,14 @@ describe("fish hash", () => {
expect(h.fish512("hello world", "utf8"))
.toBe("0b876d42c8e72587b32b443feaeac514305046146b0cc9152194c80ce53994ae0c5f8484cb3c8ea6350db144a857a3d45876371980a24f109717424cd56ba934889dc38f657a8fe499f924a51146fa8ae1a0d6d68dfed639084f261ce5fffc5a5298798fed6f230f5846d2a9d424d0a154a642d673514f8f73e62a03778af865");
});
});
describe("disklist", () => {
test("async", async() => {
expect(typeof await shark.disklist.listDrives() === 'object')
.toBeTruthy();
});
test("sync", () => {
expect(typeof shark.disklist.listDrivesSync() === 'object')
.toBeTruthy();
});
});
Loading

0 comments on commit ffd4da4

Please sign in to comment.