opensecret 0.0.9925 → 0.0.9949
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/README.md +656 -40
- data/lib/configs/README.md +58 -0
- data/lib/extension/file.rb +67 -0
- data/lib/extension/string.rb +10 -0
- data/lib/factbase/facts.opensecret.io.ini +1 -0
- data/lib/interprete.rb +334 -61
- data/lib/keytools/PRODUCE_RAND_SEQ_USING_DEV_URANDOM.txt +0 -0
- data/lib/keytools/kdf.api.rb +9 -15
- data/lib/keytools/kdf.bcrypt.rb +69 -19
- data/lib/keytools/kdf.pbkdf2.rb +112 -23
- data/lib/keytools/key.api.rb +146 -36
- data/lib/keytools/key.db.rb +94 -29
- data/lib/keytools/key.id.rb +1 -1
- data/lib/keytools/key.ident.rb +243 -0
- data/lib/keytools/key.local.rb +62 -68
- data/lib/keytools/key.pass.rb +2 -2
- data/lib/keytools/key.rb +2 -28
- data/lib/modules/{cryptology.md → README.md} +0 -0
- data/lib/session/fact.finder.rb +65 -428
- data/lib/session/time.stamp.rb +1 -28
- data/lib/usecase/cmd.rb +127 -54
- data/lib/usecase/config/README.md +57 -0
- data/lib/usecase/docker/README.md +146 -0
- data/lib/usecase/docker/docker.rb +49 -0
- data/lib/usecase/edit/README.md +43 -0
- data/lib/usecase/edit/delete.rb +46 -0
- data/lib/usecase/export.rb +40 -0
- data/lib/usecase/files/README.md +37 -0
- data/lib/usecase/files/eject.rb +56 -0
- data/lib/usecase/files/file_me.rb +78 -0
- data/lib/usecase/files/read.rb +169 -0
- data/lib/usecase/files/write.rb +89 -0
- data/lib/usecase/goto.rb +57 -0
- data/lib/usecase/id.rb +1 -1
- data/lib/usecase/import.rb +13 -30
- data/lib/usecase/init.rb +2 -17
- data/lib/usecase/jenkins/README.md +146 -0
- data/lib/usecase/jenkins/crazy_ruby_post_attempt.OLD +234 -0
- data/lib/usecase/jenkins/jenkins.rb +208 -0
- data/lib/usecase/login.rb +6 -5
- data/lib/usecase/logout.rb +1 -3
- data/lib/usecase/open.rb +11 -66
- data/lib/usecase/print.rb +40 -0
- data/lib/usecase/put.rb +34 -156
- data/lib/usecase/set.rb +2 -4
- data/lib/usecase/show.rb +138 -0
- data/lib/usecase/terraform/README.md +91 -0
- data/lib/usecase/terraform/terraform.rb +121 -0
- data/lib/usecase/token.rb +4 -80
- data/lib/usecase/update/README.md +55 -0
- data/lib/usecase/update/rename.rb +180 -0
- data/lib/usecase/use.rb +1 -3
- data/lib/usecase/verse.rb +20 -0
- data/lib/usecase/view.rb +71 -0
- data/lib/usecase/vpn/README.md +150 -0
- data/lib/usecase/vpn/vpn.ini +31 -0
- data/lib/usecase/vpn/vpn.rb +54 -0
- data/lib/version.rb +1 -1
- data/opensecret.gemspec +3 -4
- metadata +34 -35
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/LICENSE.txt +0 -21
- data/bin/ops +0 -20
- data/lib/keytools/binary.map.rb +0 -294
- data/lib/keytools/doc.conversion.to.ones.and.zeroes.ruby +0 -179
- data/lib/keytools/doc.rsa.radix.binary-mapping.ruby +0 -190
- data/lib/keytools/doc.star.schema.strategy.txt +0 -77
- data/lib/keytools/doc.using.pbkdf2.kdf.ruby +0 -95
- data/lib/keytools/doc.using.pbkdf2.pkcs.ruby +0 -266
- data/lib/keytools/key.mach.rb +0 -248
- data/lib/keytools/keydebug.txt +0 -295
- data/lib/modules/cryptology/open.bcrypt.rb +0 -170
- data/lib/usecase/read.rb +0 -89
- data/lib/usecase/safe.rb +0 -92
@@ -1,170 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
|
5
|
-
=begin
|
6
|
-
|
7
|
-
Using BCrypt for password hashing has several advantages over the builtin Digest classes. First of all it has a decent interface:
|
8
|
-
|
9
|
-
gem "bcrypt-ruby"
|
10
|
-
require "bcrypt"
|
11
|
-
hashed_password = BCrypt::Password.create "my password"
|
12
|
-
hashed_password is now an instance of BCrypt::Password. You can check the password now with ==:
|
13
|
-
|
14
|
-
hashed_password == "my password" # => true
|
15
|
-
The second nice point is the built-in security. Passwords are automatically salted. Furthermore, BCrypt has a parameter cost which exponentially scales the computation time.
|
16
|
-
|
17
|
-
hashed_password1 = BCrypt::Password.create( "my password", cost: 1 )
|
18
|
-
hashed_password10 = BCrypt::Password.create( "my password", cost: 10 )
|
19
|
-
Computing hashedpassword10 is 2^9 times as expessive as computing hashedpassword1. This way you can adjust the hashing algorithm to your available resources and always use the most-expensive-to-crack hashing you can afford.
|
20
|
-
|
21
|
-
Last but definitly not least storing and restoring BCrypt::Passwords is simple as hell:
|
22
|
-
|
23
|
-
storable_string = hashed_password.to_s
|
24
|
-
restored_hash = BCrypt::Password.new storable_string
|
25
|
-
NICE!
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
bcrypt-ruby
|
34
|
-
An easy way to keep your users' passwords secure.
|
35
|
-
|
36
|
-
http://github.com/codahale/bcrypt-ruby/tree/master
|
37
|
-
Build Status
|
38
|
-
|
39
|
-
Why you should use bcrypt()
|
40
|
-
If you store user passwords in the clear, then an attacker who steals a copy of your database has a giant list of emails and passwords. Some of your users will only have one password -- for their email account, for their banking account, for your application. A simple hack could escalate into massive identity theft.
|
41
|
-
|
42
|
-
It's your responsibility as a web developer to make your web application secure -- blaming your users for not being security experts is not a professional response to risk.
|
43
|
-
|
44
|
-
bcrypt() allows you to easily harden your application against these kinds of attacks.
|
45
|
-
|
46
|
-
Note: JRuby versions of the bcrypt gem <= 2.1.3 had a security vulnerability that was fixed in >= 2.1.4. If you used a vulnerable version to hash passwords with international characters in them, you will need to re-hash those passwords. This vulnerability only affected the JRuby gem.
|
47
|
-
|
48
|
-
How to install bcrypt
|
49
|
-
gem install bcrypt
|
50
|
-
The bcrypt gem is available on the following ruby platforms:
|
51
|
-
|
52
|
-
JRuby
|
53
|
-
RubyInstaller 1.8, 1.9, 2.0, 2.1, and 2.2 builds on win32
|
54
|
-
Any 1.8, 1.9, 2.0, 2.1, 2.2, or 2.3 Ruby on a BSD/OS X/Linux system with a compiler
|
55
|
-
How to use bcrypt() in your Rails application
|
56
|
-
Note: Rails versions >= 3 ship with ActiveModel::SecurePassword which uses bcrypt-ruby. has_secure_password docs implements a similar authentication strategy to the code below.
|
57
|
-
|
58
|
-
The User model
|
59
|
-
require 'bcrypt'
|
60
|
-
|
61
|
-
class User < ActiveRecord::Base
|
62
|
-
# users.password_hash in the database is a :string
|
63
|
-
include BCrypt
|
64
|
-
|
65
|
-
def password
|
66
|
-
@password ||= Password.new(password_hash)
|
67
|
-
end
|
68
|
-
|
69
|
-
def password=(new_password)
|
70
|
-
@password = Password.create(new_password)
|
71
|
-
self.password_hash = @password
|
72
|
-
end
|
73
|
-
end
|
74
|
-
Creating an account
|
75
|
-
def create
|
76
|
-
@user = User.new(params[:user])
|
77
|
-
@user.password = params[:password]
|
78
|
-
@user.save!
|
79
|
-
end
|
80
|
-
Authenticating a user
|
81
|
-
def login
|
82
|
-
@user = User.find_by_email(params[:email])
|
83
|
-
if @user.password == params[:password]
|
84
|
-
give_token
|
85
|
-
else
|
86
|
-
redirect_to home_url
|
87
|
-
end
|
88
|
-
end
|
89
|
-
How to use bcrypt-ruby in general
|
90
|
-
require 'bcrypt'
|
91
|
-
|
92
|
-
my_password = BCrypt::Password.create("my password")
|
93
|
-
#=> "$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"
|
94
|
-
|
95
|
-
my_password.version #=> "2a"
|
96
|
-
my_password.cost #=> 10
|
97
|
-
my_password == "my password" #=> true
|
98
|
-
my_password == "not my password" #=> false
|
99
|
-
|
100
|
-
my_password = BCrypt::Password.new("$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa")
|
101
|
-
my_password == "my password" #=> true
|
102
|
-
my_password == "not my password" #=> false
|
103
|
-
Check the rdocs for more details -- BCrypt, BCrypt::Password.
|
104
|
-
|
105
|
-
How bcrypt() works
|
106
|
-
bcrypt() is a hashing algorithm designed by Niels Provos and David Mazières of the OpenBSD Project.
|
107
|
-
|
108
|
-
Background
|
109
|
-
Hash algorithms take a chunk of data (e.g., your user's password) and create a "digital fingerprint," or hash, of it. Because this process is not reversible, there's no way to go from the hash back to the password.
|
110
|
-
|
111
|
-
In other words:
|
112
|
-
|
113
|
-
hash(p) #=> <unique gibberish>
|
114
|
-
You can store the hash and check it against a hash made of a potentially valid password:
|
115
|
-
|
116
|
-
<unique gibberish> =? hash(just_entered_password)
|
117
|
-
Rainbow Tables
|
118
|
-
But even this has weaknesses -- attackers can just run lists of possible passwords through the same algorithm, store the results in a big database, and then look up the passwords by their hash:
|
119
|
-
|
120
|
-
PrecomputedPassword.find_by_hash(<unique gibberish>).password #=> "secret1"
|
121
|
-
Salts
|
122
|
-
The solution to this is to add a small chunk of random data -- called a salt -- to the password before it's hashed:
|
123
|
-
|
124
|
-
hash(salt + p) #=> <really unique gibberish>
|
125
|
-
The salt is then stored along with the hash in the database, and used to check potentially valid passwords:
|
126
|
-
|
127
|
-
<really unique gibberish> =? hash(salt + just_entered_password)
|
128
|
-
bcrypt-ruby automatically handles the storage and generation of these salts for you.
|
129
|
-
|
130
|
-
Adding a salt means that an attacker has to have a gigantic database for each unique salt -- for a salt made of 4 letters, that's 456,976 different databases. Pretty much no one has that much storage space, so attackers try a different, slower method -- throw a list of potential passwords at each individual password:
|
131
|
-
|
132
|
-
hash(salt + "aadvark") =? <really unique gibberish>
|
133
|
-
hash(salt + "abacus") =? <really unique gibberish>
|
134
|
-
etc.
|
135
|
-
This is much slower than the big database approach, but most hash algorithms are pretty quick -- and therein lies the problem. Hash algorithms aren't usually designed to be slow, they're designed to turn gigabytes of data into secure fingerprints as quickly as possible. bcrypt(), though, is designed to be computationally expensive:
|
136
|
-
|
137
|
-
Ten thousand iterations:
|
138
|
-
user system total real
|
139
|
-
md5 0.070000 0.000000 0.070000 ( 0.070415)
|
140
|
-
bcrypt 22.230000 0.080000 22.310000 ( 22.493822)
|
141
|
-
If an attacker was using Ruby to check each password, they could check ~140,000 passwords a second with MD5 but only ~450 passwords a second with bcrypt().
|
142
|
-
|
143
|
-
Cost Factors
|
144
|
-
In addition, bcrypt() allows you to increase the amount of work required to hash a password as computers get faster. Old passwords will still work fine, but new passwords can keep up with the times.
|
145
|
-
|
146
|
-
The default cost factor used by bcrypt-ruby is 10, which is fine for session-based authentication. If you are using a stateless authentication architecture (e.g., HTTP Basic Auth), you will want to lower the cost factor to reduce your server load and keep your request times down. This will lower the security provided you, but there are few alternatives.
|
147
|
-
|
148
|
-
To change the default cost factor used by bcrypt-ruby, use BCrypt::Engine.cost = new_value:
|
149
|
-
|
150
|
-
BCrypt::Password.create('secret').cost
|
151
|
-
#=> 10, the default provided by bcrypt-ruby
|
152
|
-
|
153
|
-
# set a new default cost
|
154
|
-
BCrypt::Engine.cost = 8
|
155
|
-
BCrypt::Password.create('secret').cost
|
156
|
-
#=> 8
|
157
|
-
The default cost can be overridden as needed by passing an options hash with a different cost:
|
158
|
-
|
159
|
-
BCrypt::Password.create('secret', :cost => 6).cost #=> 6
|
160
|
-
More Information
|
161
|
-
bcrypt() is currently used as the default password storage hash in OpenBSD, widely regarded as the most secure operating system available.
|
162
|
-
|
163
|
-
For a more technical explanation of the algorithm and its design criteria, please read Niels Provos and David Mazières' Usenix99 paper: http://www.usenix.org/events/usenix99/provos.html
|
164
|
-
|
165
|
-
If you'd like more down-to-earth advice regarding cryptography, I suggest reading Practical Cryptography by Niels Ferguson and Bruce Schneier: http://www.schneier.com/book-practical.html
|
166
|
-
|
167
|
-
Etc
|
168
|
-
|
169
|
-
=end
|
170
|
-
|
data/lib/usecase/read.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
module OpenSecret
|
4
|
-
|
5
|
-
|
6
|
-
class Read < Command
|
7
|
-
|
8
|
-
|
9
|
-
def execute
|
10
|
-
|
11
|
-
return unless ops_key_exists?
|
12
|
-
appdb_content = OpenKey::KeyApi.read_app_content()
|
13
|
-
|
14
|
-
## @todo - rename appdb_content as master_db
|
15
|
-
## @todo - rename appdb_content as master_db
|
16
|
-
## @todo - rename appdb_content as master_db
|
17
|
-
## @todo - rename appdb_content as master_db
|
18
|
-
## @todo - rename appdb_content as master_db
|
19
|
-
## @todo - rename appdb_content as master_db
|
20
|
-
## @todo - rename appdb_content as master_db
|
21
|
-
## @todo - rename appdb_content as master_db
|
22
|
-
## @todo - rename appdb_content as master_db
|
23
|
-
## @todo - rename appdb_content as master_db
|
24
|
-
## @todo - rename appdb_content as master_db
|
25
|
-
## @todo - rename appdb_content as master_db
|
26
|
-
## @todo - rename appdb_content as master_db
|
27
|
-
## @todo - rename appdb_content as master_db
|
28
|
-
## @todo - rename appdb_content as master_db
|
29
|
-
|
30
|
-
return if unopened_envelope?( appdb_content )
|
31
|
-
|
32
|
-
envelope_id = ENVELOPE_KEY_PREFIX + appdb_content[ ENV_PATH ]
|
33
|
-
has_content = OpenKey::KeyApi.content_exists?( appdb_content[ envelope_id ] )
|
34
|
-
|
35
|
-
# --
|
36
|
-
# -- To get hold of the content we must either
|
37
|
-
# --
|
38
|
-
# -- a) unlock it using the breadcrumbs or
|
39
|
-
# -- b) start afresh with a new content db
|
40
|
-
# --
|
41
|
-
content_box = OpenKey::KeyApi.content_unlock( appdb_content[ envelope_id ] ) if has_content
|
42
|
-
content_box = content_box.fast_forward( appdb_content[ KEY_PATH ] )
|
43
|
-
content_box = OpenKey::KeyDb.new() unless has_content
|
44
|
-
|
45
|
-
puts ""
|
46
|
-
puts "--- ----------------------------------\n"
|
47
|
-
puts "--- envelope => #{appdb_content[ ENV_PATH ]}\n"
|
48
|
-
puts "--- key path => #{appdb_content[ KEY_PATH ]}\n"
|
49
|
-
puts "--- ----------------------------------\n"
|
50
|
-
puts JSON.pretty_generate( content_box )
|
51
|
-
puts "--- ----------------------------------\n"
|
52
|
-
puts ""
|
53
|
-
|
54
|
-
return
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
|
62
|
-
def print_put_success
|
63
|
-
|
64
|
-
puts ""
|
65
|
-
puts "Success putting a key/value pair into the open envelope."
|
66
|
-
puts "You can put more in and then close the envelope."
|
67
|
-
puts ""
|
68
|
-
puts " ops close"
|
69
|
-
puts ""
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
# Perform pre-conditional validations in preparation to executing the main flow
|
75
|
-
# of events for this use case. This method may throw the below exceptions.
|
76
|
-
#
|
77
|
-
# @raise [SafeDirNotConfigured] if the safe's url has not been configured
|
78
|
-
# @raise [EmailAddrNotConfigured] if the email address has not been configured
|
79
|
-
# @raise [StoreUrlNotConfigured] if the crypt store url is not configured
|
80
|
-
def pre_validation
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
end
|
data/lib/usecase/safe.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
module OpenSecret
|
4
|
-
|
5
|
-
# This is the [On] usecase that is triggered when a user would like
|
6
|
-
# to start a locking (encryption) session.
|
7
|
-
#
|
8
|
-
# Pre-Conditions
|
9
|
-
#
|
10
|
-
# - [session.config.file] exists with domain,user,email,store_id => store_url
|
11
|
-
#
|
12
|
-
# Main Flow of Events
|
13
|
-
#
|
14
|
-
# Stash the path into the host machine's configuration file and proceed
|
15
|
-
# to create the path directory chain if it does not already exist.
|
16
|
-
#
|
17
|
-
class Safe < Command
|
18
|
-
|
19
|
-
attr_writer :safe_path
|
20
|
-
@@context_name = "opensecret"
|
21
|
-
@@prime_name = "opensecret.safe"
|
22
|
-
|
23
|
-
# The safe use case simply validates the presented path and when the
|
24
|
-
# execute method is called it stashes the path within the host machine's
|
25
|
-
# configuration file and proceeds to create the path directory chain
|
26
|
-
# if it does not already exist.
|
27
|
-
def execute
|
28
|
-
|
29
|
-
OpenSession::Attributes.stash @@context_name, @@context_name, "safe", @safe_path
|
30
|
-
FileUtils.mkdir_p @safe_path unless File.exists? @safe_path
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def pre_validation
|
36
|
-
|
37
|
-
needs_chopping = @safe_path.end_with?("/") || @safe_path.end_with?("\\")
|
38
|
-
@safe_path = @safe_path.chop if needs_chopping
|
39
|
-
|
40
|
-
index_1st = @safe_path.index @@prime_name
|
41
|
-
index_2nd = @safe_path.rindex @@prime_name
|
42
|
-
|
43
|
-
xtra_msg = "Text [ #{@@prime_name} ] can only appear once in [ #{@safe_path} ]."
|
44
|
-
raise SafePrimeNameRepeated.new xtra_msg, @safe_path unless index_1st == index_2nd
|
45
|
-
|
46
|
-
unless @safe_path.end_with? @@prime_name
|
47
|
-
|
48
|
-
if @safe_path.include? @@prime_name
|
49
|
-
prime_name_end_index = @safe_path.index(@@prime_name) + @@prime_name.length
|
50
|
-
@safe_path = @safe_path[0..prime_name_end_index]
|
51
|
-
else
|
52
|
-
@safe_path = File.join @safe_path, @@prime_name
|
53
|
-
end
|
54
|
-
|
55
|
-
ends_with_prime = @safe_path.end_with? @@prime_name
|
56
|
-
not_at_end_msg = "Text [#{@@prime_name} ] is not at end of [ #{@safe_path} ]."
|
57
|
-
raise SafePrimeNameNotAtEnd.new not_at_end_msg, @safe_path unless ends_with_prime
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
if( File.exists?( @safe_path ) && !(File.directory? @safe_path) )
|
62
|
-
raise SafeDirectoryIsFile.new "the [safe] directory path points to a file", @safe_path
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
# The safe_path instance attribute must be configured within
|
69
|
-
# the context configuration file using a keyname of "safe".
|
70
|
-
#
|
71
|
-
# @raise ArgumentError for any one of a long list of reasons that
|
72
|
-
# cause the key value to not be retrieved. This can range from
|
73
|
-
# non-existent directories and files, non readable files, incorrect
|
74
|
-
# configurations right down to missing keys or even missing values.
|
75
|
-
def post_validation
|
76
|
-
|
77
|
-
configured_path = OpenSession::Attributes.instance.get_value @@context_name, @@context_name, "safe"
|
78
|
-
path_string_1 = " path 1 => #{configured_path}"
|
79
|
-
path_string_2 = " path 2 => #{@safe_path}"
|
80
|
-
mismatch_path = "Path mismatch to opensecret [safe] detected."
|
81
|
-
err_msg = "\n" + mismatch_path + "\n" + path_string_1 + "\n" + path_string_2 + "\n"
|
82
|
-
|
83
|
-
raise RuntimeError, err_msg unless @safe_path.eql? configured_path
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
end
|