lita-rotp 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e5387dc8524149b9b612b9220445db748f77698
4
+ data.tar.gz: 2262e56347f47d53144a9382ca88a6daeb3fb770
5
+ SHA512:
6
+ metadata.gz: 0b9124f25431db291cbb868c1581ea52c36545835f001ccf8360db9080ec28a0376a9a7c21dfcb539d0a83a6366e7358b7ee1bd7db21d1f7ab2901d5cfc6363b
7
+ data.tar.gz: 74d5b4a26b288ea4abccbdda6cba8ef06750e580addabd8ee57396365d051a8a097308e3d9b7544d8bb6773314e8a2be0b6ad19d0647908774a003d0a2f32d3f
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format Fuubar
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ FileName:
2
+ Exclude:
3
+ - Rakefile
4
+ - Gemfile
5
+ - lib/lita-rotp.rb
6
+ - lita-rotp.gemspec
7
+ Metrics/ClassLength:
8
+ Enabled: false
9
+ Style/ClassVars:
10
+ Enabled: false
11
+ Metrics/LineLength:
12
+ Max: 120
13
+ Metrics/MethodLength:
14
+ Max: 30
15
+
16
+ # pending: https://github.com/bbatsov/rubocop/issues/1332
17
+ Style/GuardClause:
18
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ branches:
2
+ only:
3
+ - master
4
+ env: CODECLIMATE_REPO_TOKEN=020fdb8a8da6518502f36d94bb21c2ce52da61d3c778cba8d4b35e9328c64502
5
+ services:
6
+ - redis-server
7
+ language: ruby
8
+ rvm:
9
+ - 2.1.2
10
+ - 2.1.1
11
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ source 'https://rubygems.org'
18
+
19
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ lita-rotp
2
+ ===========
3
+ [![Build Status](https://img.shields.io/travis/PagerDuty/lita-rotp/master.svg)](https://travis-ci.org/PagerDuty/lita-rotp)
4
+ [![Code Climate Coverage](http://img.shields.io/codeclimate/coverage/github/PagerDuty/lita-rotp.svg)](https://codeclimate.com/github/PagerDuty/lita-rotp)
5
+ [![RubyGems :: lita-rotp Gem Version](http://img.shields.io/gem/v/lita-rotp.svg)](https://rubygems.org/gems/lita-rotp)
6
+ [![Apache 2.0 License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
7
+
8
+ Copyright 2014 PagerDuty, Inc.
9
+
10
+ Lita handler for TOTP & HOTP token generation; uses Ruby One-Time Password (ROTP) library
11
+
12
+ INSTALLATION
13
+ ------------
14
+
15
+ Add `lita-rotp` to your Lita instance's Gemfile:
16
+
17
+ ``` ruby
18
+ gem 'lita-rotp', '~> 0.1'
19
+ ```
20
+
21
+ LICENSE
22
+ -------
23
+ **lita-rotp** is released under the
24
+ [Apache License 2.0](http://opensource.org/licenses/Apache-2.0).
25
+ The full text of the license can be found in the `LICENSE` file. The summary
26
+ can be found [here](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) courtesy
27
+ of tldrlegal.
28
+
29
+ CONFIGURATION
30
+ -------------
31
+ `lita-rotp` uses a Hash of key pairs to get the secrets:
32
+
33
+ ```Ruby
34
+ config.handlers.rotp.secret_pairs = { tim: '4QGNYPZ7OSBHCWWL', heckman: 'IR5IYN4G5HB66BOA' }
35
+ ```
36
+
37
+ You then use the name `heckman` to use the secret for heckman.
38
+
39
+ USAGE
40
+ -----
41
+ ```
42
+ > totp heckman
43
+ 596049
44
+
45
+ # or
46
+
47
+ > hotp tim 42
48
+ 368274
49
+
50
+ # or
51
+
52
+ > token heckman
53
+ 386015
54
+
55
+ > token tim 42
56
+ 549634
57
+ ```
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # -*- coding: UTF-8 -*_
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'rspec/core/rake_task'
18
+ require 'rubocop/rake_task'
19
+
20
+ RSpec::Core::RakeTask.new(:spec)
21
+
22
+ RuboCop::RakeTask.new(:rubocop) do |t|
23
+ t.patterns =
24
+ %w( Rakefile Gemfile lita-rotp.gemspec lib/**/*.rb spec/*_spec.rb )
25
+ t.fail_on_error = true
26
+ end
27
+
28
+ task default: [:rubocop, :spec]
data/lib/lita-rotp.rb ADDED
@@ -0,0 +1,24 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'lita'
18
+
19
+ Lita.load_locales Dir[File.expand_path(
20
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
21
+ )]
22
+
23
+ require 'lita-rotp/version'
24
+ require 'lita/handlers/rotp'
@@ -0,0 +1,27 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Generate your secure tokens with Lita!
18
+ #
19
+ # The namespace for LitaROTP
20
+ #
21
+ # @author Tim Heckman <tim@pagerduty.com>
22
+ module LitaROTP
23
+ # lita-rotp version
24
+ #
25
+ # @author Tim Heckman <tim@pagerduty.com>
26
+ VERSION = '0.1.0'
27
+ end
@@ -0,0 +1,117 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'rotp'
18
+
19
+ module Lita
20
+ # Lita Handler
21
+ module Handlers
22
+ # The ROTP wrapper for Lita
23
+ #
24
+ # @author Tim Heckman <tim@pagerduty.com>
25
+ class ROTP < Handler
26
+ route(
27
+ /^(?:token|otp)\s+?(?<name>[a-zA-Z0-9_\-]+)(?<counter>\s+?\d+)?.*$/,
28
+ :otp,
29
+ command: true,
30
+ help: {
31
+ 'otp tim' => 'generate a TOTP with the name "tim"',
32
+ 'otp doug 1401' => 'generate an HTOP with the name "doug" and a counter of 1401'
33
+ }
34
+ )
35
+
36
+ route(
37
+ /^totp\s+?(?<name>[a-zA-Z0-9_]+).*$/,
38
+ :totp,
39
+ command: true,
40
+ help: {
41
+ 'totp tim' => 'generate a TOTP with the name "tim"'
42
+ }
43
+ )
44
+
45
+ route(
46
+ /^hotp\s+?(?<name>[a-zA-Z0-9_]+)(?<counter>\s+?\d+)?.*$/,
47
+ :hotp,
48
+ command: true,
49
+ help: {
50
+ 'hotp doug 1401' => 'generate an HTOP with the name "doug" and a counter of 1401'
51
+ }
52
+ )
53
+
54
+ def self.default_config(config)
55
+ config.secret_pairs = {}
56
+ end
57
+
58
+ def otp(response)
59
+ md = response.match_data
60
+ name, counter = [md['name'], md['counter']]
61
+ counter = counter.strip.to_i if counter.is_a?(String)
62
+
63
+ reply = ''
64
+
65
+ if counter.nil?
66
+ secret = config.secret_pairs[name.to_sym]
67
+ return response.reply(t('not_found', n: name)) if secret.nil?
68
+ reply = totp_generate(secret)
69
+ else
70
+ secret = config.secret_pairs[name.to_sym]
71
+ return response.reply(t('not_found', n: name)) if secret.nil?
72
+ reply = hotp_generate(secret, counter)
73
+ end
74
+
75
+ response.reply(reply)
76
+ end
77
+
78
+ def totp(response)
79
+ name = response.match_data['name']
80
+ secret = config.secret_pairs[name.to_sym]
81
+
82
+ return response.reply(t('not_found', n: name)) if secret.nil?
83
+
84
+ response.reply(totp_generate(secret))
85
+ end
86
+
87
+ def hotp(response)
88
+ md = response.match_data
89
+ name, counter = [md['name'], md['counter']]
90
+
91
+ counter = counter.strip.to_i if counter.is_a?(String)
92
+
93
+ secret = config.secret_pairs[name.to_sym]
94
+
95
+ return response.reply(t('not_found', n: name)) if secret.nil?
96
+
97
+ response.reply(hotp_generate(secret, counter))
98
+ end
99
+
100
+ private
101
+
102
+ def totp_generate(secret)
103
+ t('token', t: ::ROTP::TOTP.new(secret).now)
104
+ rescue StandardError => e
105
+ t('boom', m: e.message)
106
+ end
107
+
108
+ def hotp_generate(secret, counter)
109
+ t('token', t: ::ROTP::HOTP.new(secret).at(counter.to_i))
110
+ rescue StandardError => e
111
+ t('boom', m: e.message)
112
+ end
113
+ end
114
+
115
+ Lita.register_handler(ROTP)
116
+ end
117
+ end
data/lita-rotp.gemspec ADDED
@@ -0,0 +1,50 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
18
+
19
+ require 'lita-rotp/version'
20
+
21
+ Gem::Specification.new do |s|
22
+ s.name = 'lita-rotp'
23
+ s.summary = 'TOTP & HOTP token generator using ROTP'
24
+ s.author = 'Tim Heckman'
25
+ s.email = 'tim@pagerduty.com'
26
+ s.license = 'Apache 2.0'
27
+ s.version = LitaROTP::VERSION
28
+ s.date = Time.now.strftime('%Y-%m-%d')
29
+ s.homepage = 'https://github.com/PagerDuty/lita-rotp'
30
+ s.description = 'Lita handler for TOTP & HOTP token generation; uses Ruby One-Time Password (ROTP) library'
31
+
32
+ s.test_files = `git ls-files spec/*`.split
33
+ s.files = `git ls-files`.split
34
+
35
+ s.required_ruby_version = '>= 2.1.0'
36
+ s.metadata = { 'lita_plugin_type' => 'handler' }
37
+
38
+ s.add_development_dependency 'bundler', '~> 1.5'
39
+ s.add_development_dependency 'rake', '~> 10.2'
40
+ s.add_development_dependency 'rubocop', '~> 0.26.0'
41
+ s.add_development_dependency 'rspec', '~> 3.0'
42
+ s.add_development_dependency 'fuubar', '~> 2.0'
43
+ s.add_development_dependency 'pry', '~> 0.10', '>= 0.10.1'
44
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4', '>= 0.4.0'
45
+ s.add_development_dependency 'yard', '~> 0.8.7'
46
+
47
+ s.add_runtime_dependency 'lita', '~> 3.3'
48
+ s.add_runtime_dependency 'rotp', '~> 2.0'
49
+ s.add_runtime_dependency 'lita-confirmation'
50
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,7 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ rotp:
5
+ token: "%{t}"
6
+ not_found: "No secret was found for: %{n}"
7
+ boom: "I had a problem :( ... %{m}"
@@ -0,0 +1,176 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe Lita::Handlers::ROTP, lita_handler: true do
20
+ # otp routing
21
+ it { routes_command('otp tim 1401').to(:otp) }
22
+ it { routes_command('otp tim').to(:otp) }
23
+ it { routes_command('token tim 1401').to(:otp) }
24
+ it { routes_command('token tim').to(:otp) }
25
+
26
+ # totp routing
27
+ it { routes_command('totp tim').to(:totp) }
28
+
29
+ # hotp routing
30
+ it { routes_command('hotp tim 1401').to(:hotp) }
31
+
32
+ let(:tim_secret) { '4QGNYPZ7OSBHCWWL' }
33
+ let(:heckman_secret) { 'IR5IYN4G5HB66BOA' }
34
+ let(:config) { { tim: tim_secret, heckman: heckman_secret } }
35
+ let(:rotph) { Lita::Handlers::ROTP.new('robot') }
36
+
37
+ before do
38
+ conf = double('Lita::Config', secret_pairs: config)
39
+ allow(rotph).to receive(:config).and_return(conf)
40
+ end
41
+
42
+ describe '.default_config' do
43
+ it 'should set secret_pairs to an empty Hash' do
44
+ expect(Lita.config.handlers.rotp.secret_pairs).to eql Hash.new
45
+ end
46
+ end
47
+
48
+ describe '.hotp_generate' do
49
+ context 'when generation succeeds' do
50
+ it 'should return the token template' do
51
+ func = rotph.send(:hotp_generate, tim_secret, 1687)
52
+ test = ROTP::HOTP.new(tim_secret).at(1687)
53
+ expect(func).to eql test
54
+
55
+ func = rotph.send(:hotp_generate, heckman_secret, 776)
56
+ test = ROTP::HOTP.new(heckman_secret).at(776)
57
+ expect(func).to eql test
58
+ end
59
+ end
60
+
61
+ context 'when generation fails' do
62
+ before { allow_any_instance_of(ROTP::HOTP).to receive(:at).and_raise(ROTP::Base32::Base32Error.new) }
63
+
64
+ it 'should respond with the error' do
65
+ expect(rotph.send(:hotp_generate, tim_secret, 1)).to eql 'I had a problem :( ... ROTP::Base32::Base32Error'
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '.totp_generate' do
71
+ context 'when generation succeeds' do
72
+ it 'should return the token template' do
73
+ func = rotph.send(:totp_generate, tim_secret)
74
+ test = ROTP::TOTP.new(tim_secret).now
75
+ expect(func).to eql test
76
+
77
+ func = rotph.send(:totp_generate, heckman_secret)
78
+ test = ROTP::TOTP.new(heckman_secret).now
79
+ expect(func).to eql test
80
+ end
81
+ end
82
+
83
+ context 'when generation fails' do
84
+ before { allow_any_instance_of(ROTP::TOTP).to receive(:now).and_raise(ROTP::Base32::Base32Error.new) }
85
+
86
+ it 'should respond with the error' do
87
+ expect(rotph.send(:totp_generate, tim_secret)).to eql 'I had a problem :( ... ROTP::Base32::Base32Error'
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '.hotp' do
93
+ context 'when secret found' do
94
+ it 'should respond with the token' do
95
+ send_command('hotp tim 42')
96
+ t = ROTP::HOTP.new(tim_secret).at(42)
97
+ expect(replies.last).to eql t
98
+ end
99
+ end
100
+
101
+ context 'when secret not found' do
102
+ before do
103
+ conf = double('Lita::Config', secret_pairs: {})
104
+ allow(rotph).to receive(:config).and_return(conf)
105
+ end
106
+
107
+ it 'should respond saying it could not find that secret' do
108
+ send_command('hotp tim 42')
109
+ expect(replies.last).to eql 'No secret was found for: tim'
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '.totp' do
115
+ context 'when secret found' do
116
+ it 'should respond with the token' do
117
+ send_command('totp heckman')
118
+ t = ROTP::TOTP.new(heckman_secret).now
119
+ expect(replies.last).to eql t
120
+ end
121
+ end
122
+
123
+ context 'when secret not found' do
124
+ before do
125
+ conf = double('Lita::Config', secret_pairs: {})
126
+ allow(rotph).to receive(:config).and_return(conf)
127
+ end
128
+
129
+ it 'should respond saying it could not find that secret' do
130
+ send_command('totp heckman')
131
+ expect(replies.last).to eql 'No secret was found for: heckman'
132
+ end
133
+ end
134
+ end
135
+
136
+ describe '.otp' do
137
+ context 'when secret found' do
138
+ context 'when requesting a totp' do
139
+ it 'should respond with the token' do
140
+ send_command('otp heckman 42')
141
+ t = ROTP::HOTP.new(heckman_secret).at(42)
142
+ expect(replies.last).to eql t
143
+ end
144
+ end
145
+
146
+ context 'when requesting an hotp' do
147
+ it 'should respond with the token' do
148
+ send_command('otp tim')
149
+ t = ROTP::TOTP.new(tim_secret).now
150
+ expect(replies.last).to eql t
151
+ end
152
+ end
153
+ end
154
+
155
+ context 'when secret not found' do
156
+ before do
157
+ conf = double('Lita::Config', secret_pairs: {})
158
+ allow(rotph).to receive(:config).and_return(conf)
159
+ end
160
+
161
+ context 'when requesting a totp' do
162
+ it 'should respond with the token' do
163
+ send_command('otp heckman 42')
164
+ expect(replies.last).to eql 'No secret was found for: heckman'
165
+ end
166
+ end
167
+
168
+ context 'when requesting an hotp' do
169
+ it 'should respond with the token' do
170
+ send_command('otp tim')
171
+ expect(replies.last).to eql 'No secret was found for: tim'
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'rspec'
18
+ require 'lita/rspec'
19
+ require 'codeclimate-test-reporter'
20
+
21
+ CodeClimate::TestReporter.start
22
+
23
+ require 'lita-rotp'
metadata ADDED
@@ -0,0 +1,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-rotp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Heckman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.26.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.26.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fuubar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.10.1
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.10'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.10.1
103
+ - !ruby/object:Gem::Dependency
104
+ name: codeclimate-test-reporter
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.4'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.4.0
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '0.4'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.4.0
123
+ - !ruby/object:Gem::Dependency
124
+ name: yard
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.8.7
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 0.8.7
137
+ - !ruby/object:Gem::Dependency
138
+ name: lita
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '3.3'
144
+ type: :runtime
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '3.3'
151
+ - !ruby/object:Gem::Dependency
152
+ name: rotp
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '2.0'
158
+ type: :runtime
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '2.0'
165
+ - !ruby/object:Gem::Dependency
166
+ name: lita-confirmation
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ type: :runtime
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ description: Lita handler for TOTP & HOTP token generation; uses Ruby One-Time Password
180
+ (ROTP) library
181
+ email: tim@pagerduty.com
182
+ executables: []
183
+ extensions: []
184
+ extra_rdoc_files: []
185
+ files:
186
+ - ".gitignore"
187
+ - ".rspec"
188
+ - ".rubocop.yml"
189
+ - ".travis.yml"
190
+ - Gemfile
191
+ - LICENSE
192
+ - README.md
193
+ - Rakefile
194
+ - lib/lita-rotp.rb
195
+ - lib/lita-rotp/version.rb
196
+ - lib/lita/handlers/rotp.rb
197
+ - lita-rotp.gemspec
198
+ - locales/en.yml
199
+ - spec/lita/handlers/rotp_spec.rb
200
+ - spec/spec_helper.rb
201
+ homepage: https://github.com/PagerDuty/lita-rotp
202
+ licenses:
203
+ - Apache 2.0
204
+ metadata:
205
+ lita_plugin_type: handler
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: 2.1.0
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 2.2.2
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: TOTP & HOTP token generator using ROTP
226
+ test_files:
227
+ - spec/lita/handlers/rotp_spec.rb
228
+ - spec/spec_helper.rb
229
+ has_rdoc: