bloomed 1.0.0

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: c2789813aea4f66b7a6433a8694d60b50d1e7cc5
4
+ data.tar.gz: be4191d94d992dfddefb9b512461c0a5b6c1f04b
5
+ SHA512:
6
+ metadata.gz: e8d4bfa81e430496d308a159d8ec513204be4fb2f7939f7e1ff846ee994cae6b7bcf1394b5b6e7a7361e823ef8d0d58f7f92b40818440552f5579400cd90997e
7
+ data.tar.gz: b136f1cb1b084fb08b3c74e06ee1799de781a7de964f71d3afd2ea91af66d698f8c4f16869c21c368b9a68f66aa58a42de430a438ec3e997b91bb28e71b92c97
@@ -0,0 +1,59 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.5.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # Database setup
40
+ # - run: bundle exec rake db:create
41
+ # - run: bundle exec rake db:schema:load
42
+
43
+ # run tests!
44
+ - run:
45
+ name: run tests
46
+ command: |
47
+ mkdir /tmp/test-results
48
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
49
+
50
+ bundle exec rspec --format progress \
51
+ --out /tmp/test-results/rspec.xml \
52
+ $TEST_FILES
53
+
54
+ # collect reports
55
+ - store_test_results:
56
+ path: /tmp/test-results
57
+ - store_artifacts:
58
+ path: /tmp/test-results
59
+ destination: test-results
data/.gitignore ADDED
@@ -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
data/.ruby-version ADDED
@@ -0,0 +1,2 @@
1
+
2
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.16.3
@@ -0,0 +1 @@
1
+ Do as you like
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bloomed.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bloomed (1.0.0)
5
+ bloomer
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ bitarray (1.1.0)
11
+ bloomer (0.0.5)
12
+ bitarray
13
+ diff-lcs (1.3)
14
+ rake (10.5.0)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bloomed!
34
+ bundler (~> 1.16)
35
+ rake (~> 10.0)
36
+ rspec (~> 3.0)
37
+
38
+ BUNDLED WITH
39
+ 1.16.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Søren Skovsbøll
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,89 @@
1
+ # Bloomed
2
+
3
+ Troy Hunt's brilliant haveibeenpwned.com let's you download SHA1s of 517,238,891 real world passwords previously exposed in data breaches. This list is comprehensive but huge in size: 11GB compressed.
4
+ Using a bloom filter we can reduce the size down to files measured in MBs.
5
+
6
+ You can even keep a the bloom filter in memory in your web app or api. This is great if you're afraid to send the passwords that your users enter, to an external service for lookup.
7
+
8
+ This gem will let you control the trade off between memory size and precision. False positives will occur (that's the nature of bloom filters), but you control the frequency and how many of the pwned passwords you want in your filter, starting from the most pwned at the top.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'bloomed'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install bloomed
25
+
26
+ ## Usage
27
+
28
+ ### Quick start
29
+
30
+ ```ruby
31
+ require 'bloomed'
32
+ pw=Bloomed::PW.new
33
+ pw.pwned? "password123"
34
+ => true
35
+ ```
36
+
37
+ ### Using lower precision / lower memory consumption
38
+
39
+ There are two parameters that can be varied: `top` and `false_positive_probability`.
40
+
41
+
42
+ ```ruby
43
+ require 'bloomed'
44
+ pw=Bloomed::PW.new(top: 100000, false_positive_probability: 0.01) # 136 kb memory
45
+ pw.pwned? "password123"
46
+ => true
47
+ ```
48
+
49
+ ### Using higher precision / higher memory consumption
50
+
51
+ To keep the gem size small, it only ships with dumps up to 253 kb in size.
52
+
53
+ To generate a larger, optimized bloom filter for pwned passwords, please download pwned-passwords-ordered-by-count.7z from https://haveibeenpwned.com and extract `pwned-passwords-ordered-by-count.txt` to the current dir.
54
+
55
+ Once you have the `pwned-passwords-ordered-by-count.txt` file in place, you can run the following to generate the filter and cache it for later (on your machine.)
56
+
57
+ ```ruby
58
+ require 'bloomed'
59
+ pw=Bloomed::PW.new(top: 1E8, false_positive_probability: 0.0001) # 247 Mb! memory
60
+ pw.pwned? "password123"
61
+ => true
62
+ ```
63
+
64
+ ### The cache
65
+
66
+ The cache is stored in the `dumps` dir inside `dirname $(gem which bloomed)`.
67
+
68
+ ### Size of the in memory bloom filter
69
+
70
+ The filter can vary much in size. Use `Bloomed:PW#memory_size_bytes` to get the exact size.
71
+
72
+
73
+ ## Development
74
+
75
+ 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.
76
+
77
+ 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).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/skovsboll/bloomed. 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.
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
+
87
+ ## Code of Conduct
88
+
89
+ Everyone interacting in the Bloomed project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bloomed/blob/master/CODE_OF_CONDUCT.md).
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 "bloomed"
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(__FILE__)
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/bloomed.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bloomed/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bloomed"
8
+ spec.version = Bloomed::VERSION
9
+ spec.authors = ["Søren Skovsbøll"]
10
+ spec.email = ["soren@wero.es"]
11
+
12
+ spec.summary = "Bloom filter check for pwned passwords"
13
+ spec.description = "Check your users' passwords using a fraction of the memory of the full pwned passwords list."
14
+ spec.homepage = "https://github.com/skovsboll/bloomed"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "bloomer"
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
data/lib/bloomed.rb ADDED
@@ -0,0 +1,69 @@
1
+ require_relative 'bloomed/version'
2
+ require 'bloomer'
3
+
4
+ module Bloomed
5
+ class PW
6
+ attr_reader :false_positive_probability, :top
7
+
8
+ def initialize(top: 100_000, false_positive_probability: 0.001)
9
+ @top = top
10
+ @false_positive_probability = false_positive_probability
11
+ @bloom = prepare
12
+ end
13
+
14
+ def pwned?(pw)
15
+ @bloom.include?(Digest::SHA1.hexdigest(pw).upcase)
16
+ end
17
+
18
+ def memory_size_bytes
19
+ require 'objspace'
20
+ ObjectSpace.memsize_of(@bloom)
21
+ end
22
+
23
+ private
24
+
25
+ def prepare
26
+ if File.exist? file_name
27
+ load_cache
28
+ else
29
+ bloom_filter = generate
30
+ write_cache bloom_filter
31
+ bloom_filter
32
+ end
33
+ end
34
+
35
+ def file_name
36
+ inverse_probaility = 1.0 / false_positive_probability
37
+ File.join(
38
+ File.dirname(__FILE__),
39
+ 'dump',
40
+ "pwned_top_#{top.to_i}_one_in_#{inverse_probaility.to_i}.dump"
41
+ )
42
+ end
43
+
44
+ def load_cache
45
+ Marshal.load(File.read(file_name))
46
+ end
47
+
48
+ PWNED_PASSWORDS_FILENAME = 'pwned-passwords-ordered-by-count.txt'.freeze
49
+ def generate
50
+ unless File.exist? PWNED_PASSWORDS_FILENAME
51
+ raise "In order to generate new, optimized bloom filter for
52
+ pwned passwords, please download pwned-passwords-ordered-by-count.7z from
53
+ https://haveibeenpwned.com and extract pwned-passwords-ordered-by-count.txt
54
+ to the current dir."
55
+ end
56
+
57
+ bloom_filter = Bloomer::Scalable.new(top, false_positive_probability)
58
+ File.open(PWNED_PASSWORDS_FILENAME, 'r').first(top).each do |line|
59
+ bloom_filter.add line[0...40]
60
+ end
61
+ bloom_filter
62
+ end
63
+
64
+ def write_cache(b)
65
+ File.write(file_name, Marshal.dump(b))
66
+ b
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Bloomed
2
+ VERSION = "1.0.0"
3
+ end
data/lib/seed.rb ADDED
@@ -0,0 +1,8 @@
1
+ require './lib/bloomed'
2
+
3
+ ps = [0.01, 0.001, 0.0001]
4
+ cs = [1E4, 1E5, 1E6, 1E7, 1E8]
5
+
6
+ cs.product(ps).each do |c, p|
7
+ b = Bloomed::PW.new(first: c, false_positive_probability: p)
8
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bloomed
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Søren Skovsbøll
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bloomer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.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
+ description: Check your users' passwords using a fraction of the memory of the full
70
+ pwned passwords list.
71
+ email:
72
+ - soren@wero.es
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".circleci/config.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - bloomed.gemspec
91
+ - lib/bloomed.rb
92
+ - lib/bloomed/version.rb
93
+ - lib/dump/pwned_top_100000_one_in_100.dump
94
+ - lib/dump/pwned_top_100000_one_in_1000.dump
95
+ - lib/dump/pwned_top_100000_one_in_10000.dump
96
+ - lib/dump/pwned_top_10000_one_in_100.dump
97
+ - lib/dump/pwned_top_10000_one_in_1000.dump
98
+ - lib/dump/pwned_top_10000_one_in_10000.dump
99
+ - lib/seed.rb
100
+ homepage: https://github.com/skovsboll/bloomed
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.2.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Bloom filter check for pwned passwords
124
+ test_files: []