Skip to content

Commit 3188032

Browse files
committed
first commit
0 parents  commit 3188032

File tree

11 files changed

+293
-0
lines changed

11 files changed

+293
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
lib

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v5

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
src

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v5

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Leonardo Gatica
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# node-totp-cli
2+
3+
[![npm version](https://img.shields.io/npm/v/totp-cli.svg?style=flat-square)](https://www.npmjs.com/package/totp-cli)
4+
[![npm downloads](https://img.shields.io/npm/dm/totp-cli.svg?style=flat-square)](https://www.npmjs.com/package/totp-cli)
5+
[![dependency Status](https://img.shields.io/david/lgaticaq/totp-cli.svg?style=flat-square)](https://david-dm.org/lgaticaq/totp-cli#info=dependencies)
6+
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/totp-cli.svg?style=flat-square)](https://david-dm.org/lgaticaq/totp-cli#info=devDependencies)
7+
[![Join the chat at https://gitter.im/lgaticaq/node-totp-cli](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg?style=flat-square)](https://gitter.im/lgaticaq/node-totp-cli?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8+
9+
Insert/Generate a TOTP for a service from pass. Inspired by [totp-cli](https://github.com/hobarrera/totp-cli)
10+
11+
## Requirements
12+
13+
- [pass](http://www.passwordstore.org/)
14+
- [xclip (for Linux and OpenBSD)](http://linux.die.net/man/1/xclip)
15+
16+
## Installation
17+
18+
```bash
19+
npm i -g totp-cli
20+
```
21+
22+
## Use
23+
24+
Insert a new service
25+
26+
```bash
27+
totp insert <service>
28+
? Enter code for <service>: ************
29+
? Re-Enter code for <service>: ************
30+
```
31+
32+
Generate code for a service. Print and copy to clipboard the code.
33+
34+
```bash
35+
totp generate <service>
36+
123456
37+
```

package.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"name": "totp-cli",
3+
"version": "1.0.0",
4+
"description": "Insert/Generate a TOTP for a service from pass",
5+
"main": "lib",
6+
"scripts": {
7+
"prepublish": "npm run build -s",
8+
"prebuild": "npm run lint -s && npm run clean -s",
9+
"build": "babel src --out-dir lib --source-maps",
10+
"lint": "eslint src",
11+
"clean": "rimraf lib"
12+
},
13+
"engines": {
14+
"node": ">=0.12"
15+
},
16+
"bin": {
17+
"totp": "lib/totp.js"
18+
},
19+
"preferGlobal": true,
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/lgaticaq/node-totp-cli.git"
23+
},
24+
"keywords": [
25+
"totp",
26+
"pass",
27+
"cli"
28+
],
29+
"author": "Leonardo Gatica <lgatica@protonmail.com> (https://about.me/lgatica)",
30+
"license": "MIT",
31+
"bugs": {
32+
"url": "https://github.com/lgaticaq/node-totp-cli/issues"
33+
},
34+
"homepage": "https://github.com/lgaticaq/node-totp-cli#readme",
35+
"dependencies": {
36+
"commander": "^2.9.0",
37+
"copy-paste": "^1.1.4",
38+
"inquirer": "^0.11.1",
39+
"notp": "^2.0.3",
40+
"thirty-two": "^1.0.1"
41+
},
42+
"devDependencies": {
43+
"babel-cli": "^6.3.17",
44+
"babel-core": "^6.3.26",
45+
"babel-preset-es2015": "^6.3.13",
46+
"eslint": "^1.10.3",
47+
"rimraf": "^2.5.0"
48+
},
49+
"eslintConfig": {
50+
"rules": {
51+
"indent": [
52+
2,
53+
2
54+
],
55+
"quotes": [
56+
2,
57+
"single"
58+
],
59+
"linebreak-style": [
60+
2,
61+
"unix"
62+
],
63+
"semi": [
64+
2,
65+
"always"
66+
],
67+
"no-console": [
68+
0
69+
]
70+
},
71+
"ecmaFeatures": {
72+
"modules": true
73+
},
74+
"env": {
75+
"es6": true,
76+
"node": true,
77+
"mocha": true
78+
},
79+
"extends": "eslint:recommended"
80+
},
81+
"babel": {
82+
"presets": [
83+
"es2015"
84+
]
85+
}
86+
}

src/totp-generate.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
import {exec} from 'child_process';
6+
import program from 'commander';
7+
import notp from 'notp';
8+
import ncp from 'copy-paste';
9+
import base32 from 'thirty-two';
10+
11+
12+
const getCode = (service) => {
13+
let key;
14+
const pass = exec(`pass 2fa/${service}/code`);
15+
16+
pass.stdout.on('data', (data) => {
17+
key = data;
18+
});
19+
pass.stderr.on('data', (data) => {
20+
console.log(`Error: ${data}`);
21+
});
22+
pass.on('close', () => {
23+
const totp = notp.totp.gen(base32.decode(key));
24+
console.log(totp);
25+
ncp.copy(totp.toString());
26+
process.exit(0);
27+
});
28+
};
29+
30+
program
31+
.usage('<service>')
32+
.parse(process.argv);
33+
34+
if (program.args.length === 0) {
35+
console.error('service required');
36+
process.exit(1);
37+
} else {
38+
getCode(program.args[0]);
39+
}

src/totp-insert.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
import {exec} from 'child_process';
6+
import program from 'commander';
7+
import inquirer from 'inquirer';
8+
9+
const setCode = (service) => {
10+
inquirer.prompt([
11+
{
12+
type: 'password',
13+
message: `Enter code for ${service}:`,
14+
name: 'code1'
15+
},
16+
{
17+
type: 'password',
18+
message: `Re-Enter code for ${service}:`,
19+
name: 'code2'
20+
}
21+
], (answers) => {
22+
if (answers.code1 === answers.code2) {
23+
const pass = exec(`pass insert 2fa/${service}/code`);
24+
pass.stdin.write(`${answers.code1}\n`);
25+
pass.stdin.write(`${answers.code1}\n`);
26+
27+
pass.stderr.on('data', (data) => {
28+
console.log(`Error: ${data}`);
29+
});
30+
pass.on('close', () => {
31+
process.exit(0);
32+
});
33+
} else {
34+
console.log('Wrong code');
35+
}
36+
});
37+
};
38+
39+
program
40+
.usage('<service>')
41+
.parse(process.argv);
42+
43+
if (program.args.length === 0) {
44+
console.error('service required');
45+
process.exit(1);
46+
} else {
47+
setCode(program.args[0]);
48+
}

0 commit comments

Comments
 (0)