dmp 0.1.5 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46a098dc9f8eb855a74af2e91abdf35b13885bf41be8ca89c5a94ec813878726
4
- data.tar.gz: 4d5d03eedb5193dc8f6fe279b684cab8c51be07062028db3ce73679d57f3f337
3
+ metadata.gz: 865f8aedf90a4845b1d04cd7343874c142d7241742844afe889d91fac254f78f
4
+ data.tar.gz: ec33e3320f9784754bc753a9fbd93c86169bfae4819b2fdefad85cddde726601
5
5
  SHA512:
6
- metadata.gz: 61892dda3dc33a8241225b9bb04753871c4947bc07b93724af38af01c0dd217775923de8dd8d0ef2c533894090b564fc55dac875c8356ccd09ef4ed839a4ecf5
7
- data.tar.gz: be47c2b049fdbabfee69f2fc4d77918280917abd7a7c9f8e0cdcdbd4a3c40fd97e4d1f4134a727f6e7cb64eebf4f9cc3bc4a89bec1f5d8b8e23737864ed2c78c
6
+ metadata.gz: f99340d8d3aa4a21a2d2f3d4a16eb169917afc23bceb4b687d581bd5ce23d875123d4bb89050ed13b56327a9cb4a809e98dc823dbbdf273fdab1f3674713406a
7
+ data.tar.gz: d4ce23d7523c434d1715ae5db14d2b5efd12f6d1f45052b8479592ee9a0a55aa5e406c538897e539cdd111a895a76fc73c08254420fdfb148fe8b03753165218
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dmp (0.1.5)
4
+ dmp (0.2.1)
5
5
  clipboard (~> 1.1)
6
6
  colorize (~> 0.8)
7
7
  thor (~> 0)
data/lib/dmp.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'dmp/version'
2
+ require 'net/http'
3
+ require 'digest/sha1'
2
4
 
3
5
  # Module to manage DMP operations
4
6
  module Dmp
@@ -14,4 +16,23 @@ module Dmp
14
16
  random_pass = pass_list.shuffle[0...pass_length]
15
17
  random_pass
16
18
  end
19
+
20
+ def self.check_pwned(passphrase)
21
+ if passphrase.kind_of?(Array)
22
+ passphrase = passphrase.join(' ')
23
+ end
24
+
25
+ hex_pass = Digest::SHA1.hexdigest(passphrase)
26
+ hex_pass_sample = hex_pass[0...5]
27
+ hex_pass_rest = hex_pass[5..-1]
28
+
29
+ # request a sample to HIBP to avoid disclosing the full pwd
30
+ uri = URI("https://api.pwnedpasswords.com/range/#{hex_pass_sample}")
31
+ req = Net::HTTP.get(uri)
32
+
33
+ clean_list = req.split("\r\n")
34
+ pass_list = clean_list.map { |hash| hash.split(':') }
35
+ pass_hash = Hash[*pass_list.flatten!]
36
+ pass_hash[hex_pass_rest.upcase]
37
+ end
17
38
  end
@@ -12,11 +12,23 @@ module Dmp
12
12
  aliases: '-c',
13
13
  type: :boolean,
14
14
  desc: 'Copy passphrase to clipboard.'
15
+ method_option :hibp,
16
+ aliases: '-H',
17
+ type: :boolean,
18
+ desc: 'Check if passphrase is vulnerable in HIBP database.'
15
19
  def gen_pass(pass_length = 7)
16
20
  # Generate colored passphrase
17
21
  passphrase = Dmp.gen_passphrase(pass_length.to_i)
18
22
 
19
23
  # if flag clipboard is 'true' then copy passphrase to clipboard
24
+ if options[:clipboard]
25
+ Clipboard.copy(passphrase.join(' '))
26
+ end
27
+
28
+ # if flag hibp is 'true' then alert the user
29
+ if options[:hibp]
30
+ vuln_count = Dmp.check_pwned(passphrase)
31
+ end
20
32
 
21
33
  # colors array will be used to pick a randomized sample
22
34
  # removing black cause it looks ugly in terminals
@@ -28,9 +40,23 @@ module Dmp
28
40
  phrase.colorize(rand_color)
29
41
  end
30
42
  puts '- Passphrase: '.bold + passphrase.join(' ')
31
- if options[:clipboard]
32
- Clipboard.copy(passphrase.join(' '))
33
- puts '- Copied to clipboard.'.bold.green
43
+ puts '- Copied to clipboard.'.bold.green if options[:clipboard]
44
+ if vuln_count
45
+ puts "- WARNING: Passphrase vulnerable #{vuln_count} times!".red.bold
46
+ elsif options[:hibp]
47
+ puts '- Password is safe to use.'.green.bold
48
+ end
49
+ end
50
+
51
+ desc 'check', 'Check if a password/passphrase is vulnerable.'
52
+ def check_pass
53
+ puts 'Enter your password, press ENTER when you\'re done.'
54
+ password = ask('Password (hidden):'.yellow, echo: false)
55
+ vuln_count = Dmp.check_pwned(password)
56
+ if vuln_count
57
+ puts " Your password appears in #{vuln_count} data sets!".red.bold
58
+ else
59
+ puts " Your password/passphrase is safe to use.".green.bold
34
60
  end
35
61
  end
36
62
 
@@ -1,5 +1,5 @@
1
1
  module Dmp
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.1"
3
3
  BANNER = '''
4
4
  ____ __ __ ____
5
5
  | _ \ | \/ | | _ \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franccesco Orozco