dmp 0.1.5 → 0.2.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dmp.rb +21 -0
- data/lib/dmp/cli.rb +29 -3
- data/lib/dmp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 865f8aedf90a4845b1d04cd7343874c142d7241742844afe889d91fac254f78f
|
4
|
+
data.tar.gz: ec33e3320f9784754bc753a9fbd93c86169bfae4819b2fdefad85cddde726601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f99340d8d3aa4a21a2d2f3d4a16eb169917afc23bceb4b687d581bd5ce23d875123d4bb89050ed13b56327a9cb4a809e98dc823dbbdf273fdab1f3674713406a
|
7
|
+
data.tar.gz: d4ce23d7523c434d1715ae5db14d2b5efd12f6d1f45052b8479592ee9a0a55aa5e406c538897e539cdd111a895a76fc73c08254420fdfb148fe8b03753165218
|
data/Gemfile.lock
CHANGED
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
|
data/lib/dmp/cli.rb
CHANGED
@@ -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
|
-
|
33
|
-
puts
|
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
|
|
data/lib/dmp/version.rb
CHANGED