Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #7 from oganexon/develop
Browse files Browse the repository at this point in the history
v1.0.0-beta
  • Loading branch information
SteelAlloy committed Aug 16, 2019
2 parents fdcc8f4 + 97dad78 commit 4fe358a
Show file tree
Hide file tree
Showing 13 changed files with 2,049 additions and 59 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0-beta] - 2019-08-16

### Added
- More tests.

### Changed
- Documentation:
- Windows advice.
- Beautified the whole.

## [0.14.0] - 2019-08-15

### Added
Expand Down
31 changes: 12 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ To invoke the command line tool, run:
npm start -- [ARGS]
```

If you want to install all the tools, juste run:
```shell
npm run dev-setup
```

<!--### Deploying / Publishing
give instructions on how to build and release a new version
In case there's some step you have to take that publishes this project to a
Expand All @@ -37,35 +42,23 @@ And again you'd need to tell what the previous code actually does.

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [link to tags on this repository](/tags).

<!--## Configuration
Here you should write what are all of the configurations a user can enter when
using the project.
-->

### Tests

> Soon
<!--
Describe and show how to run the tests with code examples.
Explain what these tests test and why.
This project uses the framework [Jest](https://jestjs.io/). Jest is a delightful JavaScript Testing Framework with a focus on simplicity.

```shell
Give an example
```
-->
Simply run `jest` to run the tests.

There are not enough tests, you can add more.

### Style guide

[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)

This project uses [JavaScript Standard Style](https://cdn.rawgit.com/standard/standard/master/badge.svg). Please respect this convention.

We provide an easy installation for you, just run:
```shell
$ npm run style-setup
```
You can install a [plugin](https://standardjs.com/awesome.html#editor-plugins) for your favorite editor if you want.

And then `npm run style` each time you want to check style.
### Pull request

Or install a [plugin](https://standardjs.com/awesome.html#editor-plugins) for your favorite editor and ignore the recommandations above.
Please follow the [pull request template](./github/PULL_REQUEST_TEMPLATE/pull_request_template.md).
66 changes: 49 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">
<img src="./assets/secure-rm.png" alt="Logo of the project">
<img src="./assets/secure-rm.png" alt="Secure-rm">
<br>
Completely erases files by making recovery impossible.
<br>
Expand All @@ -8,28 +8,35 @@
<p align="center">
<a href="https://www.npmjs.com/package/secure-rm"><img src="https://img.shields.io/npm/v/secure-rm.svg" alt="Version"></a>
<a href="https://www.npmjs.com/package/secure-rm"><img src="https://img.shields.io/npm/dw/secure-rm.svg" alt="Downloads/week"></a>
<a href="https://github.com/oganexon/secure-rm/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/secure-rm.svg" alt="License"></a>
<a href="https://github.com/oganexon/secure-rm/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/secure-rm.svg" alt="License: MIT"></a>
<a href="https://jestjs.io"><img src="https://img.shields.io/badge/tested_with-jest-99424f.svg" alt="Tested with Jest"></a>
</p>

> v1.0.0 will be released soon, stay tuned!
## ❓ Why

## Install
When you delete a file using the `rm` command or `fs.unlink` in node, it only remove direct pointers to the data disk sectors and make the data recovery possible with common software tools.

Permanent data erasure goes beyond basic file deletion commands, which:
1. Allow for selection of a specific standard, based on unique needs, and
2. Verify the overwriting method has been successful and removed data across the entire device.

## 📦 Install

You can use this package in two different ways, the _npm module version_:

```shell
$ npm install secure-rm --save
npm install secure-rm --save
```

Or the _command-line version_:

```shell
$ npm install secure-rm -g
npm install secure-rm -g
```

Secure-rm will retry 3 times if an error occur to ensure the task succeeded.

## Getting started
## 🚀 Getting started

If you want your application to delete specific files with a pass of cryptographically strong pseudo-random data, use one of these code snippets:

Expand Down Expand Up @@ -58,10 +65,10 @@ srm('./folder/*.js')

If you want to delete files on the fly, just use the command line tool:
```shell
$ secure-rm ./folder/*.js
secure-rm ./folder/*.js
```

## Usage
## 📚 Usage

### npm module

Expand Down Expand Up @@ -110,7 +117,7 @@ srm('./*', options)
.catch((err) => {throw err})
```
See [write.js](./lib/write.js) file for more details.
If you want to make your own cutom method, see [write.js](./lib/write.js) file for more details.
#### Events
When running, secure-rm emits events to let you know the progression of the deletion.
Expand All @@ -130,7 +137,7 @@ srm.event.on('error', (file, err) => console.log('Error ' + err + file))
### Command line tool
```shell
$ secure-rm <PATHS> [OPTIONS]
secure-rm <PATHS> [OPTIONS]
```
- `PATHS`:
- one or multiple paths (e.g. `D:\data /d/data ./data/file.js ../../data`)
Expand All @@ -146,7 +153,7 @@ $ secure-rm <PATHS> [OPTIONS]
Example:
```shell
$ secure-rm ./folder/*.js ./garbage ./file.js -m 6 -f
secure-rm ./folder/*.js ./garbage ./file.js -m 6 -f
```
You can invoke the built-in help with `secure-rm -h`:
Expand All @@ -155,7 +162,7 @@ You can invoke the built-in help with `secure-rm -h`:
CLI help:
USAGE
$ secure-rm PATH
$ secure-rm PATH
OPTIONS
-f, --force avoid checks
Expand Down Expand Up @@ -193,7 +200,24 @@ ID | Name | Passes | Description
Note: Node ensures that the file is correctly written, checking the writing in these algorithms is unnecessary.
## Troubleshooting / Common issues
## 🚩 Troubleshooting / Common issues
Should works on OS X, Linux, and Windows.
### File systems
secure-rm will only work on file systems that overwrite blocks in place.
List of known file systems that will not work:
- ext3
- ext4
- AthFS – AtheOS
- OneFS
- ssd's at large
- reiserfs
- ...
- especially on the vast majority of
journaled file systems.
### "WARN Too many open files, cannot ...:"
Expand All @@ -203,18 +227,26 @@ While you don't get an error, the tool can handle this issue.
If you really need to delete millions of file in one time, split the task (e.g. ./your_folder/a* then ./your_folder/b* ...).
## Changelog
### Using Windows:
Be sure to use `secure-rm ".\path\file"` with doublequotes since back-slashes will always be interpreted as escape characters, not path separators.
Another solution is to double the back-slashes like: `secure-rm .\\path\\file`
Or if you can, use forward slashes!
## 📜 Changelog
See the [changelog](/CHANGELOG.md) or [releases](https://github.com/oganexon/secure-rm/releases).
## TODO
## 📌 TODO
- [ ] Release of 1.0.0 (stable API)
- [ ] Implement more tests
- [ ] TypeScript
- [ ] Support of 64bit files
## Contributing
## 🏗 Contributing
See [contributing guidelines](/CONTRIBUTING.md)
Expand Down
4 changes: 3 additions & 1 deletion bin/cli/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ function check (argv, { method, retries, force, globbing }) {
let paths = []
if (globbing) {
for (let i = 0, len = argv.length; i < len; i++) {
if (path.isAbsolute(argv[i])) {
if (path.sep !== '/') {
argv[i] = argv[i].split(path.sep).join('/')
paths = paths.concat(argv[i])
} else {
paths = paths.concat(glob.sync(path.join(process.cwd(), argv[i])))
}
console.log(paths)
}
} else paths = argv
if (paths.length === 0) console.log(chalk.bold.yellow('No such file or directory.'))
Expand Down
2 changes: 1 addition & 1 deletion lib/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Pass 32-35: Overwriting with random data.`,
.then(({ fileSize, file }) => write.random(file, fileSize, 4))
.then(({ fileSize, file }) => write.byte(file, 0x55, fileSize))
.then(({ fileSize, file }) => write.byte(file, 0xAA, fileSize))
.then(({ fileSize, file }) => write.cycleByte(file, [0x92, 0x49, 0x24], fileSize))
.then(({ fileSize, file }) => write.cycleBytes(file, [0x92, 0x49, 0x24], fileSize))
.then(({ fileSize, file }) => write.incrementByte(file, { start: 0x00, end: 0xFF, increment: 0x11 }, fileSize))
.then(({ fileSize, file }) => write.cycleByte(file, [0x92, 0x49, 0x24], fileSize))
.then(({ fileSize, file }) => write.cycleByte(file, [0x6D, 0xB6, 0xDB], fileSize))
Expand Down
2 changes: 1 addition & 1 deletion lib/secure-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function secureRm (path, options, callback) {
callback = options
options = { method: 'secure' }
}
if (options.method === undefined) options.method = 'secure'
if (options.method == null) options.method = 'secure'

if (callback) secureRmCallback(path, options, (err, path) => callback(err, path))
else return secureRmPromise(path, options)
Expand Down
24 changes: 19 additions & 5 deletions lib/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,28 @@ const write = {
})
})
},
cycleByte: (file, dataArray, fileSize, passes) => {
bytes: (file, dataArray, fileSize, passes) => {
return new Promise((resolve, reject) => {
eventEmitter.emit('info', file, `Writing ${dataArray.map(x => '0x' + x.toString(16))} `)
const dataConverted = Uint8Array.from(dataArray)
fs.writeFile(file, Buffer.alloc(fileSize, dataConverted), (err) => {
if (err) reject(err)
else if (passes > 1) {
write.bytes(file, dataArray, fileSize, passes - 1)
.then(() => resolve({ fileSize, file }))
.catch((err) => reject(err))
} else resolve({ fileSize, file })
})
})
},
cycleBytes: (file, dataArray, fileSize, passes = 1) => {
return new Promise((resolve, reject) => {
eventEmitter.emit('info', file, `Writing ${dataArray.map(x => '0x' + x.toString(16))} `)
const dataConverted = Uint8Array.from(dataArray)
fs.writeFile(file, Buffer.alloc(fileSize, dataConverted), (err) => {
if (err) reject(err)
else if (passes < dataArray.length) {
write.cycleByte(file, offset(dataArray, 1), fileSize, passes + 1)
write.cycleBytes(file, offset(dataArray, 1), fileSize, passes + 1)
.then(() => resolve({ fileSize, file }))
.catch((err) => reject(err))
} else resolve({ fileSize, file })
Expand All @@ -97,8 +111,8 @@ const write = {
eventEmitter.emit('info', file, `Writing 0x${start.toString(16)} `)
fs.writeFile(file, Buffer.alloc(fileSize, start), (err) => {
if (err) reject(err)
else if (start < end) {
write.incrementByte(file, { start: start + increment, end: end }, fileSize)
else if (start + increment <= end) {
write.incrementByte(file, { start: start + increment, end: end, increment }, fileSize)
.then(() => resolve({ fileSize, file }))
.catch((err) => reject(err))
} else resolve({ fileSize, file })
Expand Down Expand Up @@ -139,7 +153,7 @@ const write = {
},
rename: (file, fileSize) => {
return new Promise((resolve, reject) => {
const newName = Math.random().toString(36).substring(2, 15)
const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a')
const newPath = path.join(path.dirname(file), newName)
eventEmitter.emit('info', file, `Renaming to ${newName} `)
fs.rename(file, newPath, (err) => {
Expand Down
Loading

0 comments on commit 4fe358a

Please sign in to comment.