totp-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d87f424948f2e94cccb1c3210df1a78e681052f
4
+ data.tar.gz: 3cfeb55c751318342bf16ae5cc9343582886c197
5
+ SHA512:
6
+ metadata.gz: 6003be10f8151863b4ae87676040e5415e618acc1844b687e4d1b335fb5775efd742cc45758b3ca2acf4fe8ffa7d40471cfeb78345b58cf2b03730a4b228608c
7
+ data.tar.gz: 9f07d82f959dce2dbb5a6014ec7588e9617ee9da9cb997a4b1a6f53ad2731a89bd9ddea184a475ed8de87e75ffb5d4c6f1e53dc40b227b6f5d90df59235804d0
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ html/
3
+ pkg/
4
+ vendor/cache/*.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Brady Love
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ # TOTP CLI
2
+ ======================================
3
+
4
+ TOTP CLI is a command line application for storing and generating OTP (One Time Password)
5
+ tokens. This is a quick rushed through version that doesn't have any tests.
6
+
7
+ I plan to do a complete rewrite with tests and a few more features. Until then
8
+ feel free to fork and add or tweak.
9
+
10
+ ## Installation
11
+
12
+ gem install totp-cli
13
+
14
+ For clipboard functionality to work on OSX you need to install reattach-to-user-namespace
15
+
16
+ brew install reattach-to-user-namespace
17
+
18
+ For clipboard funcationality to work on Linux you need to install xsel
19
+
20
+ sudo apt-get install xsel # Debian/Ubuntu
21
+ sudo yum install xsel # Fedora, Red Hat, CentOS
22
+ sudo pacman -S xsel # Arch Linux
23
+
24
+ ## Usage
25
+
26
+ Getting help:
27
+
28
+ totp --help
29
+
30
+ Adding a token:
31
+
32
+ totp add -l <label> -s <secret>
33
+
34
+ Listing tokens:
35
+
36
+ totp list
37
+
38
+ Showing a single token:
39
+
40
+ totp now -i <id>
41
+ totp now -l <label>
42
+
43
+ Show single token and copy OTP to clipboard
44
+
45
+ totp now -i <id> -c
46
+ totp now -l <label> -c
47
+
48
+ Remove a token
49
+
50
+ totp remove -i <id>
51
+ totp remove -l <label>
52
+
53
+ ## License
54
+
55
+ Copyright (c) 2014 Brady Love
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ "Software"), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
71
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
72
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
73
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
74
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler'
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler."
10
+ exit -1
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems."
18
+ exit e.status_code
19
+ end
20
+
21
+ require 'rake'
22
+
23
+ require 'rubygems/tasks'
24
+ Gem::Tasks.new
25
+
26
+ require 'rdoc/task'
27
+ RDoc::Task.new do |rdoc|
28
+ rdoc.title = "totp-cli"
29
+ end
30
+ task :doc => :rdoc
31
+
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new
34
+
35
+ task :test => :spec
36
+ task :default => :spec
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path(File.join(File.dirname(__FILE__),'..'))
4
+ if File.directory?(File.join(root,'.git'))
5
+ Dir.chdir(root) do
6
+ begin
7
+ require 'bundler/setup'
8
+ rescue LoadError => e
9
+ warn e.message
10
+ warn "Run `gem install bundler` to install Bundler"
11
+ exit -1
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'slop'
17
+ require 'totp/cli'
18
+
19
+ opts = Slop.parse(help: true) do
20
+ banner = 'Usage: totp (action) [options]'
21
+
22
+ on :v, :version, 'Print the version' do
23
+ run do
24
+ puts TOTP::CLI::VERSION
25
+ end
26
+ end
27
+
28
+ command 'list' do
29
+ run do |opts, args|
30
+ store =
31
+ tokens = TOTP::CLI::Token.all
32
+
33
+ tokens.each do |token|
34
+ puts "#{token.id}\t| #{token.label}\t | #{token.now}"
35
+ end
36
+ end
37
+ end
38
+
39
+ command 'add' do
40
+ on :s=, :secret=, 'Secret for the TOTP token', :string
41
+ on :l=, :label=, 'Label for the TOTP token', :string
42
+
43
+ run do |opts, args|
44
+ raise "secret is required" unless opts[:secret]
45
+ raise "label is required" unless opts[:label]
46
+
47
+ token = TOTP::CLI::Token.create(opts[:label], opts[:secret])
48
+
49
+ puts "#{token.id}\t| #{token.label}\t | #{token.now}"
50
+ end
51
+ end
52
+
53
+ command 'now' do
54
+ on :i=, :id=, 'ID of TOTP from list', :string
55
+ on :l=, :label=, 'Label for the TOTP token', :string
56
+ on :c, :clipboard, "Copy to clipboard?"
57
+
58
+ run do |opts, args|
59
+ token = nil
60
+
61
+ if opts[:id]
62
+ token = TOTP::CLI::Token.find_by_id(opts[:id].to_i)
63
+
64
+ if !token
65
+ puts "Unable to find token with id #{opts[:id]}"
66
+ exit -1
67
+ end
68
+ elsif opts[:label]
69
+ token = TOTP::CLI::Token.find_by_label(opts[:label].strip)
70
+
71
+ if !token
72
+ puts "Unable to find token with id #{opts[:id]}"
73
+ exit -1
74
+ end
75
+ end
76
+
77
+ puts "#{token.id}\t| #{token.label}\t | #{token.now}"
78
+
79
+ if opts[:clipboard]
80
+ TOTP::CLI::Clipboard.set(token.now)
81
+ end
82
+ end
83
+ end
84
+
85
+ command 'remove' do
86
+ on :i=, :id=, 'ID of TOTP from list', :string
87
+ on :l=, :label=, 'Label for the TOTP token', :string
88
+
89
+ run do |opts, args|
90
+ if opts[:id]
91
+ token = TOTP::CLI::Token.find_by_id(opts[:id].to_i)
92
+
93
+ if !token
94
+ puts "Unable to find token with id #{opts[:id]}"
95
+ exit -1
96
+ end
97
+ elsif opts[:label]
98
+ token = TOTP::CLI::Token.find_by_label(opts[:label].strip)
99
+
100
+ if !token
101
+ puts "Unable to find token with id #{opts[:id]}"
102
+ exit -1
103
+ end
104
+ end
105
+
106
+ token.delete!
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,11 @@
1
+ require 'totp/cli/os'
2
+ require 'totp/cli/clipboard'
3
+ require 'totp/cli/store'
4
+ require 'totp/cli/token'
5
+ require 'totp/cli/version'
6
+
7
+ module TOTP
8
+ module CLI
9
+
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ module TOTP
2
+ module CLI
3
+ class Clipboard
4
+ class << self
5
+ def set(text)
6
+ if OS.mac?
7
+ osx_copy(text)
8
+ elsif OS.linux?
9
+ linux_copy(text)
10
+ else
11
+ puts "Platform clipboard not supported"
12
+ return
13
+ end
14
+
15
+ puts "Copied #{text} to clipboard"
16
+ end
17
+
18
+ private
19
+
20
+ def osx_copy(text)
21
+ IO.popen('reattach-to-user-namespace pbcopy', 'w') { |i| i << text }
22
+ end
23
+
24
+ def linux_copy(text)
25
+ IO.popen('xsel -b', 'w') do |i|
26
+ i << text
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module TOTP
2
+ module CLI
3
+ module OS
4
+ def OS.windows?
5
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
6
+ end
7
+
8
+ def OS.mac?
9
+ (/darwin/ =~ RUBY_PLATFORM) != nil
10
+ end
11
+
12
+ def OS.unix?
13
+ !OS.windows?
14
+ end
15
+
16
+ def OS.linux?
17
+ OS.unix? and not OS.mac?
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'pstore'
2
+
3
+ module TOTP
4
+ module CLI
5
+ class Store
6
+ attr_accessor :store
7
+
8
+ def initialize(file)
9
+ @store = PStore.new(file)
10
+ end
11
+
12
+ def read_all
13
+ tokens = []
14
+
15
+ store.transaction(true) do
16
+ store.roots.each_with_index do |label, index|
17
+ tokens << Token.new(id: index,
18
+ label: label,
19
+ secret: store[label])
20
+ end
21
+ end
22
+
23
+ tokens
24
+ end
25
+
26
+ def save(label, secret)
27
+ store.transaction do
28
+ store[label] = secret
29
+ end
30
+ end
31
+
32
+ def remove(label)
33
+ store.transaction do
34
+ store.delete(label)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,69 @@
1
+ require 'rotp'
2
+ require 'etc'
3
+
4
+ module TOTP
5
+ module CLI
6
+ class Token
7
+ class << self
8
+ def all
9
+ store.read_all
10
+ end
11
+
12
+ def find_by_id(id)
13
+ all.each do |token|
14
+ return token if token.id == id
15
+ end
16
+
17
+ nil
18
+ end
19
+
20
+ def find_by_label(label)
21
+ all.each do |token|
22
+ return token if token.label == label
23
+ end
24
+
25
+ nil
26
+ end
27
+
28
+ def create(label, secret)
29
+ store.save(label, secret)
30
+
31
+ find_by_label(label)
32
+ end
33
+
34
+ def store
35
+ filepath = File.join(Etc.getpwuid.dir, ".totp-cli")
36
+ Store.new(filepath)
37
+ end
38
+ end
39
+
40
+ attr_accessor :id, :label, :secret
41
+
42
+ def initialize(options = {})
43
+ @id = options[:id]
44
+ @label = options[:label]
45
+ @secret = options[:secret]
46
+ end
47
+
48
+ def now
49
+ otp = totp.now.to_s
50
+
51
+ while otp.length < 6
52
+ otp = "0" + otp
53
+ end
54
+
55
+ otp
56
+ end
57
+
58
+ def delete!
59
+ self.class.store.remove(label)
60
+ end
61
+
62
+ private
63
+
64
+ def totp
65
+ @totp ||= ROTP::TOTP.new(secret)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ module TOTP
2
+ module CLI
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'totp/cli'
3
+
4
+ describe Totp::Cli do
5
+ it "should have a VERSION constant" do
6
+ subject.const_get('VERSION').should_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'totp/cli/version'
3
+
4
+ include Totp::Cli
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/totp/cli/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "totp-cli"
7
+ gem.version = TOTP::CLI::VERSION
8
+ gem.summary = %q{TOTP application with a command line interface}
9
+ gem.description = %q{Stores TOTP seeds and generates one time passwords all using a loveley command line interface}
10
+ gem.license = "MIT"
11
+ gem.authors = ["Brady Love"]
12
+ gem.email = "love.brady@gmail.com"
13
+ gem.homepage = "https://rubygems.org/gems/totp-cli"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'slop', '~> 3.5'
21
+ gem.add_dependency 'rotp', '~> 1.6'
22
+
23
+ gem.add_development_dependency 'bundler', '~> 1.0'
24
+ gem.add_development_dependency 'rake', '~> 0.8'
25
+ gem.add_development_dependency 'rdoc', '~> 3.0'
26
+ gem.add_development_dependency 'rspec', '~> 2.4'
27
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
28
+ gem.add_development_dependency 'pry'
29
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: totp-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brady Love
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rotp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubygems-tasks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Stores TOTP seeds and generates one time passwords all using a loveley
126
+ command line interface
127
+ email: love.brady@gmail.com
128
+ executables:
129
+ - totp
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .ruby-version
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/totp
141
+ - lib/totp/cli.rb
142
+ - lib/totp/cli/clipboard.rb
143
+ - lib/totp/cli/os.rb
144
+ - lib/totp/cli/store.rb
145
+ - lib/totp/cli/token.rb
146
+ - lib/totp/cli/version.rb
147
+ - spec/cli_spec.rb
148
+ - spec/spec_helper.rb
149
+ - totp-cli.gemspec
150
+ homepage: https://rubygems.org/gems/totp-cli
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.2.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: TOTP application with a command line interface
174
+ test_files:
175
+ - spec/cli_spec.rb
176
+ - spec/spec_helper.rb