totpc 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 436943f9428dcef824c2969223674f2b7a8c328a
4
+ data.tar.gz: 1709e306c9da328034a854c6eb8f8b690013cfc5
5
+ SHA512:
6
+ metadata.gz: 439b74cb944e7f2090b1668f8479ec07e63dbcd26562d2ca236e3e1c230b7260e2da596a364346d109f089c2fb95e430ba19e4098c42d151f705a85bdf1731a5
7
+ data.tar.gz: d7f68102876347d491bcd08cfea7a4a85d886c5cb9455d99cd92d6f94d4ac1b0c0c9ed1fb58b53a95bee3cd65e15923b59c5f6c7c688423efaca97d8761cb649
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at susurrus.silent@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in totpc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 susurri
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Totpc
2
+
3
+ totpc is an application for Two-factor authentication (2FA) with Time-Based
4
+ One-Time Password (TOTP) like google or github.
5
+ It stores id/key pairs in the encrypted file.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'totpc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install totpc
22
+
23
+ ## Usage
24
+
25
+ Commands:
26
+ totpc add # add secret.
27
+ totpc chpass # change passphrase
28
+ totpc help [COMMAND] # Describe available commands or one specific command
29
+ totpc list # list IDs
30
+ totpc print # print totp codes.
31
+ totpc remove # remove secret.
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec totpc` to use the gem in this directory, ignoring other installed copies of this gem.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/susurri/totpc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "totpc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/totpc ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "totpc"
4
+
5
+ Totpc::CLI.start
data/lib/totpc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'totpc/version'
2
+ require 'totpc/secrets'
3
+ require 'totpc/cli'
4
+
5
+ # time based one time password
6
+ module Totpc
7
+ # Your code goes here...
8
+ end
data/lib/totpc/cli.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'thor'
2
+ require 'totpc/secrets'
3
+
4
+ module Totpc
5
+ # command line interpreter
6
+ class CLI < Thor
7
+ def initialize(args, local_options, config)
8
+ @secrets = Secrets.new(Dir.home + '/.totpc')
9
+ super(args, local_options, config)
10
+ end
11
+ desc 'print', 'print totp codes.'
12
+ def print
13
+ @secrets.print
14
+ end
15
+ desc 'add', 'add secret.'
16
+ def add
17
+ STDOUT.print 'id: '
18
+ id = STDIN.gets.chomp
19
+ STDOUT.print 'secret: '
20
+ secret = STDIN.gets.chomp
21
+ @secrets.add(id: id, secret: secret)
22
+ end
23
+ desc 'remove', 'remove secret.'
24
+ def remove
25
+ STDOUT.print 'id: '
26
+ id = STDIN.gets.chomp
27
+ STDOUT.print 'remove ' + id + '? y/[n] '
28
+ @secrets.remove(id) if /^[yY]/ =~ STDIN.gets
29
+ end
30
+ desc 'list', 'list IDs'
31
+ def list
32
+ @secrets.list
33
+ end
34
+ desc 'chpass', 'change passphrase'
35
+ def chpass
36
+ @secrets.chpass
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ module Totpc
2
+ # methods to ask passphrase
3
+ module Passphrase
4
+ def ask_noecho(prompt)
5
+ STDOUT.print prompt
6
+ input = STDIN.noecho(&:gets).chomp
7
+ puts
8
+ input
9
+ end
10
+
11
+ def passphrase
12
+ ask_noecho('Passphrase: ')
13
+ end
14
+
15
+ def confirm_passphrase(pass)
16
+ return pass if pass == ask_noecho('Passphrase(confirm): ')
17
+ nil
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,124 @@
1
+ require 'yaml'
2
+ require 'io/console'
3
+ require 'openssl'
4
+ require 'rotp'
5
+ require 'totpc/window'
6
+ require 'totpc/passphrase'
7
+
8
+ module Totpc
9
+ # handle encrypted secrets store
10
+ class Secrets
11
+ include Passphrase
12
+ def initialize(filename)
13
+ @filename = filename
14
+ @secrets = []
15
+ @totp = {}
16
+ @window = Window.new
17
+ end
18
+
19
+ def add(entry)
20
+ load
21
+ return if dup?(entry)
22
+ @secrets.reject! { |secret| secret[:id] == entry[:id] }
23
+ @secrets.push(entry)
24
+ save
25
+ end
26
+
27
+ def remove(id)
28
+ load
29
+ @secrets.reject! { |secret| secret[:id] == id }
30
+ save
31
+ end
32
+
33
+ def list
34
+ load
35
+ @secrets.each do |secret|
36
+ puts secret[:id]
37
+ end
38
+ end
39
+
40
+ def print
41
+ load
42
+ init_totp
43
+ @window.init_curses
44
+ loop do
45
+ @window.show_curses(@secrets, @totp)
46
+ break if @window.getch
47
+ end
48
+ ensure
49
+ @window.close
50
+ end
51
+
52
+ def chpass
53
+ load
54
+ new_passphrase = ask_noecho('New Passphrase: ')
55
+ new_passphrase2 = ask_noecho('New Passphrase(confirm): ')
56
+ abort 'Passphrase does not match' if new_passphrase != new_passphrase2
57
+ @passphrase = new_passphrase
58
+ save
59
+ end
60
+
61
+ private
62
+
63
+ def init_totp
64
+ @secrets.each do |secret|
65
+ @totp[secret[:id]] = ROTP::TOTP.new(secret[:secret])
66
+ end
67
+ end
68
+
69
+ def dup?(entry)
70
+ dup = @secrets.select { |secret| secret[:id] == entry[:id] }
71
+ return false if dup.empty?
72
+ STDOUT.print 'replace ' + entry[:id] + '? y/[n] '
73
+ return false if /^[yY]/ =~ STDIN.gets
74
+ true
75
+ end
76
+
77
+ def key_iv(passphrase, salt, cipher)
78
+ digest = OpenSSL::Digest.new('sha512')
79
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac(passphrase, salt, 2000,
80
+ cipher.key_len + cipher.iv_len,
81
+ digest)
82
+ key = key_iv[0, cipher.key_len]
83
+ iv = key_iv[cipher.key_len, cipher.iv_len]
84
+ [key, iv]
85
+ end
86
+
87
+ def encrypt(data)
88
+ enc = OpenSSL::Cipher::Cipher.new('AES-256-CBC')
89
+ salt = OpenSSL::Random.random_bytes(8)
90
+ enc.encrypt
91
+ enc.key, enc.iv = key_iv(@passphrase, salt, enc)
92
+ 'Salted__' + salt + enc.update(data) + enc.final
93
+ end
94
+
95
+ def decrypt(data)
96
+ salt = data[8, 8]
97
+ data = data[16..-1]
98
+ dec = OpenSSL::Cipher::Cipher.new('AES-256-CBC')
99
+ dec.decrypt
100
+ dec.key, dec.iv = key_iv(@passphrase, salt, dec)
101
+ dec.update(data) + dec.final
102
+ end
103
+
104
+ def load
105
+ return unless File.exist?(@filename)
106
+ @passphrase = passphrase unless @passphrase
107
+ f = File.open(@filename, 'rb')
108
+ @secrets = YAML.load(decrypt(f.read))
109
+ f.close
110
+ end
111
+
112
+ def save
113
+ unless File.exist?(@filename)
114
+ loop do
115
+ break if (@passphrase = confirm_passphrase(passphrase))
116
+ puts 'passphrase not match'
117
+ end
118
+ end
119
+ f = File.open(@filename, 'wb')
120
+ f.write(encrypt(YAML.dump(@secrets)))
121
+ f.close
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,3 @@
1
+ module Totpc
2
+ VERSION = '1.0.1'.freeze
3
+ end
@@ -0,0 +1,47 @@
1
+ require 'curses'
2
+
3
+ module Totpc
4
+ # curses window to show codes
5
+ class Window
6
+ include Curses
7
+ def init_curses
8
+ init_screen
9
+ Curses.timeout = 1000
10
+ crmode
11
+ end
12
+
13
+ def show_curses(secrets, totp)
14
+ show_header_footer
15
+ ypos = 2
16
+ secrets.each do |secret|
17
+ show_message(ypos, 0, secret[:id] + ' : ' +
18
+ totp[secret[:id]].now)
19
+ ypos += 1
20
+ end
21
+ refresh
22
+ end
23
+
24
+ def show_header_footer
25
+ show_message(lines - 1, cols - 20, 'Hit any key to quit')
26
+ show_remaining
27
+ end
28
+
29
+ def show_message(x, y, message)
30
+ setpos(x, y)
31
+ addstr(message)
32
+ end
33
+
34
+ def show_remaining
35
+ count = 30 - Time.now.to_i % 30
36
+ show_message(0, 0, 'remaining ' + format('%02d', count))
37
+ end
38
+
39
+ def getch
40
+ Curses.getch
41
+ end
42
+
43
+ def close
44
+ close_screen
45
+ end
46
+ end
47
+ end
data/totpc.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'totpc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "totpc"
8
+ spec.version = Totpc::VERSION
9
+ spec.authors = ["susurri"]
10
+ spec.email = ["susurrus.silent@gmail.com"]
11
+
12
+ spec.summary = %q{an application for 2FA using TOTP}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/susurri/totpc"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
23
+ spec.add_runtime_dependency 'curses', '~> 1.0', '>= 1.0.2'
24
+ spec.add_runtime_dependency 'rotp', '~> 3.3', '>= 3.3.0'
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: totpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - susurri
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: curses
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.0.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: rotp
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.3'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.3.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.3'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.3.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.11'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.11'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '10.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '10.0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '3.0'
109
+ description: ''
110
+ email:
111
+ - susurrus.silent@gmail.com
112
+ executables:
113
+ - totpc
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".travis.yml"
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - exe/totpc
128
+ - lib/totpc.rb
129
+ - lib/totpc/cli.rb
130
+ - lib/totpc/passphrase.rb
131
+ - lib/totpc/secrets.rb
132
+ - lib/totpc/version.rb
133
+ - lib/totpc/window.rb
134
+ - totpc.gemspec
135
+ homepage: https://github.com/susurri/totpc
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.5.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: an application for 2FA using TOTP
159
+ test_files: []