keepasshttp 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8babaeef8f439832b4219ddf366386242ede64d42fd74b204e658dcd7c61d983
4
+ data.tar.gz: 4e9f8f1badad0824bb1ed6c67be75b03b31f0b3524be2287d89f7c794e572e93
5
+ SHA512:
6
+ metadata.gz: 339f9ac3d4e43896db11340e56aa021d4ce47044abcb8f573bb7028dfab6801a6f78a4c39ad4daed26c2c0863e6db394bed1f6471494371babfed9c7b1eca82a
7
+ data.tar.gz: cc40c75b8f751b11026cd1420c4486e5b56c8e294dbb41971cf18e470f3eea9022e0899f15e452b1606f84405eafab6ddad5613e815e48f8d7cc2d229342c0d2
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Naming/UncommunicativeMethodParamName:
5
+ AllowedNames: [ iv ]
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in keepasshttp.gemspec
8
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ keepasshttp (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ keepasshttp!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.4
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2018 Holger Arndt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # Keepasshttp
2
+
3
+ This is a simple client for https://github.com/pfn/keepasshttp to fetch credentials from your Keepass container from a ruby script.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'keepasshttp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install keepasshttp
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ require 'keepass'
25
+
26
+ keep = Keepass.connect
27
+
28
+ keep.password_for('http://example.com')
29
+ ```
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`.
36
+
37
+ To see if it works run
38
+
39
+ ```bash
40
+ $ keepasshttp URL_THAT_IS_IN_YOUR_KEEPASSDB
41
+ ```
42
+
43
+ If it works Keypass will prompt you for a label (which name you pick is irrelevant) and it should print you an json to the shell containing your data.
44
+
45
+ Example:
46
+
47
+ ```bash
48
+ $ keepasshttps http://example.com
49
+ [{"Login":"foo","Password":"secret","Uuid":"A3BE9660BC4BDC45B69806D212D933B4","Name":"example.com"}]
50
+ ```
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Kjarrigan/keepasshttp.
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'keepasshttp'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'keepasshttp'
6
+ require 'json'
7
+
8
+ puts Keepasshttp.connect.password_for(ARGV[0]).to_json
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'keepasshttp'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'keepasshttp'
9
+ spec.version = Keepasshttp::VERSION
10
+ spec.authors = ['Holger Arndt']
11
+ spec.email = ['holger.arndt@hetzner.com']
12
+
13
+ spec.licenses = ['MIT']
14
+ spec.summary = 'Ruby client for keepasshttp'
15
+ spec.description = 'A client for https://github.com/pfn/keepasshttp to ' \
16
+ 'fetch passwords'
17
+ spec.homepage = 'https://github.com/Kjarrigan/keepasshttp-ruby'
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Tried to only use stdlib gems for a minimal footprint
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'openssl'
7
+
8
+ # At the moment everything is in this one class as the "logic" is manageable
9
+ class Keepasshttp
10
+ # Provide String.to_base64 as refinement
11
+ module Base64Helper
12
+ refine String do
13
+ def to_base64
14
+ [self].pack('m*').chomp
15
+ end
16
+ end
17
+ end
18
+ using Base64Helper
19
+
20
+ VERSION = '0.1.1'
21
+
22
+ def self.connect(port: 19_455)
23
+ kee = new(port: port)
24
+ kee.login
25
+ kee
26
+ end
27
+
28
+ attr_accessor :port
29
+ attr_reader :session
30
+
31
+ def initialize(port: 19_455)
32
+ @port = port
33
+ @session = false
34
+ end
35
+
36
+ def password_for(url)
37
+ ping
38
+
39
+ enc_url = encrypt(url, iv: new_iv)
40
+ json = http('get-logins', Url: enc_url)
41
+ iv = json['Nonce']
42
+ json['Entries'].map do |dataset|
43
+ dataset.map do |key, val|
44
+ [key, decrypt(val, iv: iv)]
45
+ end.to_h
46
+ end
47
+ end
48
+
49
+ def login
50
+ return true if @session
51
+
52
+ @session = OpenSSL::Cipher.new('AES-256-CBC')
53
+ session.encrypt
54
+ @key = session.random_key
55
+ new_iv
56
+
57
+ json = http(:associate, Key: @key.to_base64)
58
+ return false unless json
59
+
60
+ @id = json['Id']
61
+ end
62
+
63
+ def ping
64
+ http 'test-associate'
65
+ end
66
+
67
+ private
68
+
69
+ def http(request_type, params = {})
70
+ params = { RequestType: request_type, TriggerUnlock: false }.merge(params)
71
+ params[:Id] ||= @id if @id
72
+ params[:Verifier] ||= @verifier if @verifier
73
+ params[:Nonce] ||= @nonce if @nonce
74
+
75
+ success?(
76
+ Net::HTTP.post(URI("http://localhost:#{port}/"), params.to_json,
77
+ 'Content-Type' => 'application/json')
78
+ )
79
+ end
80
+
81
+ def success?(resp)
82
+ json = JSON.parse(resp.body)
83
+ return json if resp.code =~ /^2..$/ && json['Success']
84
+
85
+ raise(json['Error'] || resp.body)
86
+ end
87
+
88
+ def new_iv
89
+ iv = session.random_iv
90
+ @nonce = iv.to_base64
91
+ @verifier = encrypt(iv.to_base64, iv: iv)
92
+ iv
93
+ end
94
+
95
+ def encrypt(val, iv:)
96
+ session.encrypt
97
+ session.key = @key
98
+ session.iv = iv
99
+
100
+ (session.update(val) + session.final).to_base64
101
+ end
102
+
103
+ def decrypt(string, iv:)
104
+ session.decrypt
105
+ session.key = @key
106
+ session.iv = iv.unpack1('m*')
107
+
108
+ session.update(string.unpack1('m*')) + session.final
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keepasshttp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Holger Arndt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-25 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A client for https://github.com/pfn/keepasshttp to fetch passwords
56
+ email:
57
+ - holger.arndt@hetzner.com
58
+ executables:
59
+ - keepasshttp
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - exe/keepasshttp
75
+ - keepasshttp.gemspec
76
+ - lib/keepasshttp.rb
77
+ homepage: https://github.com/Kjarrigan/keepasshttp-ruby
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.7
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ruby client for keepasshttp
101
+ test_files: []