vault-tree 0.3.4 → 0.6.0
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.
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/CHANGE_LOG.md +27 -0
- data/README.md +15 -73
- data/features/contracts/asymmetric_vault.feature +69 -2
- data/features/contracts/block_chain_key_transfer.feature +59 -0
- data/features/contracts/one_two_three.feature +109 -1
- data/features/contracts/readme.md +5 -6
- data/features/contracts_and_vaults.md +19 -24
- data/features/decision_tree.md +1 -1
- data/features/exceptions.feature +54 -43
- data/features/install_and_usage.md +38 -33
- data/features/keywords/assembled_shamir_key.feature +17 -17
- data/features/keywords/dh_key.feature +5 -5
- data/features/keywords/external_input.feature +35 -0
- data/features/keywords/external_key.feature +24 -0
- data/features/keywords/key.feature +3 -3
- data/features/keywords/random_number.feature +3 -3
- data/features/keywords/shamir_key_shares.feature +29 -0
- data/features/keywords/shamir_share.feature +40 -0
- data/features/keywords/split_key.feature +10 -9
- data/features/keywords/unlocked.feature +3 -3
- data/features/readme.md +1 -1
- data/features/steps/asymmetric_vault.steps.rb +14 -21
- data/features/steps/block_chain_key_transfer.steps.rb +17 -22
- data/features/steps/core.steps.rb +60 -71
- data/features/steps/exceptions.steps.rb +27 -64
- data/features/steps/external_input.steps.rb +17 -0
- data/features/steps/one_two_three.steps.rb +21 -27
- data/features/steps/secret_sharing.steps.rb +36 -19
- data/lib/vault-tree.rb +1 -1
- data/lib/vault-tree/contract/content_ciphertext.rb +33 -0
- data/lib/vault-tree/contract/content_plaintext.rb +33 -0
- data/lib/vault-tree/contract/contract.rb +15 -72
- data/lib/vault-tree/contract/contract_header.rb +11 -0
- data/lib/vault-tree/contract/vault.rb +24 -74
- data/lib/vault-tree/contract/vault_key.rb +21 -0
- data/lib/vault-tree/contract/vault_list.rb +56 -0
- data/lib/vault-tree/exceptions/empty_vault.rb +18 -3
- data/lib/vault-tree/exceptions/failed_lock_attempt.rb +18 -0
- data/lib/vault-tree/exceptions/failed_unlock_attempt.rb +23 -1
- data/lib/vault-tree/exceptions/invalid_external_input.rb +16 -0
- data/lib/vault-tree/exceptions/{missing_passphrase.rb → invalid_shamir_split.rb} +2 -1
- data/lib/vault-tree/exceptions/library_exception.rb +64 -0
- data/lib/vault-tree/exceptions/missing_partner_decryption_key.rb +11 -1
- data/lib/vault-tree/exceptions/unsupported_keyword.rb +17 -1
- data/lib/vault-tree/exceptions/vault_does_not_exist.rb +8 -1
- data/lib/vault-tree/keywords/assembled_shamir_key.rb +1 -1
- data/lib/vault-tree/keywords/contents.rb +1 -1
- data/lib/vault-tree/keywords/dh_key.rb +2 -2
- data/lib/vault-tree/keywords/external_input.rb +58 -0
- data/lib/vault-tree/keywords/external_key.rb +20 -0
- data/lib/vault-tree/keywords/key.rb +7 -1
- data/lib/vault-tree/keywords/keyword_interpreter.rb +5 -3
- data/lib/vault-tree/keywords/public_encryption_key.rb +1 -5
- data/lib/vault-tree/keywords/shamir_key_shares.rb +18 -0
- data/lib/vault-tree/keywords/shamir_share.rb +18 -0
- data/lib/vault-tree/keywords/split_key.rb +1 -1
- data/lib/vault-tree/lock_smith.rb +7 -8
- data/lib/vault-tree/lock_smith/{generated_shamir_key.rb → shamir_key_shares.rb} +22 -21
- data/lib/vault-tree/lock_smith/{split_key.rb → split_key_crypto.rb} +0 -0
- data/lib/vault-tree/version.rb +1 -1
- data/spec/assembled_shamir_key_spec.rb +0 -1
- data/spec/custom_exception_spec.rb +81 -0
- data/spec/lock_smith_spec.rb +0 -48
- data/spec/secret_sharing_spec.rb +0 -1
- data/spec/shamir_key_shares_spec.rb +27 -0
- data/vault-tree.gemspec +1 -1
- metadata +33 -139
- data/Gemfile.lock +0 -53
- data/VagrantFile +0 -30
- data/features/keywords/external_data.feature +0 -11
- data/features/keywords/generated_shamir_key.feature +0 -55
- data/features/keywords/master_passphrase.feature +0 -68
- data/features/manipulating_contracts.md +0 -84
- data/features/support/contract_fixtures/asymmetric_vault.0.1.0.json +0 -69
- data/features/support/contract_fixtures/blank_simple_test_contract.json +0 -14
- data/features/support/contract_fixtures/block_chain_key_transfer.0.1.0.json +0 -59
- data/features/support/contract_fixtures/broken_contract.json +0 -55
- data/features/support/contract_fixtures/one_two_three.0.7.0.json +0 -108
- data/features/support/contract_fixtures/simple_test_contract.json +0 -14
- data/features/support/contract_fixtures/template.json +0 -33
- data/lib/vault-tree/contract/close_validator.rb +0 -28
- data/lib/vault-tree/contract/doorman.rb +0 -113
- data/lib/vault-tree/contract/open_validator.rb +0 -20
- data/lib/vault-tree/exceptions/exception_template.erb +0 -0
- data/lib/vault-tree/exceptions/fill_attempt_master_password.rb +0 -6
- data/lib/vault-tree/exceptions/missing_external_data.rb +0 -6
- data/lib/vault-tree/exceptions/vault_tree_exception.rb +0 -25
- data/lib/vault-tree/keywords/external_data.rb +0 -32
- data/lib/vault-tree/keywords/generated_shamir_key.rb +0 -57
- data/lib/vault-tree/keywords/master_passphrase.rb +0 -9
- data/spec/generated_shamir_key_spec.rb +0 -52
- data/support/cookbooks/ark/.gitignore +0 -12
- data/support/cookbooks/ark/.kitchen.yml +0 -34
- data/support/cookbooks/ark/.travis.yml +0 -6
- data/support/cookbooks/ark/Berksfile +0 -9
- data/support/cookbooks/ark/CHANGELOG.md +0 -87
- data/support/cookbooks/ark/CONTRIBUTING.md +0 -257
- data/support/cookbooks/ark/README.md +0 -301
- data/support/cookbooks/ark/Rakefile +0 -36
- data/support/cookbooks/ark/TESTING.md +0 -25
- data/support/cookbooks/ark/Toftfile +0 -15
- data/support/cookbooks/ark/attributes/default.rb +0 -6
- data/support/cookbooks/ark/chefignore +0 -96
- data/support/cookbooks/ark/files/default/foo.tar.gz +0 -0
- data/support/cookbooks/ark/files/default/foo.tbz +0 -0
- data/support/cookbooks/ark/files/default/foo.tgz +0 -0
- data/support/cookbooks/ark/files/default/foo.zip +0 -0
- data/support/cookbooks/ark/files/default/tests/minitest/default_test.rb +0 -0
- data/support/cookbooks/ark/files/default/tests/minitest/support/helpers.rb +0 -0
- data/support/cookbooks/ark/files/default/tests/minitest/test_test.rb +0 -94
- data/support/cookbooks/ark/libraries/default.rb +0 -167
- data/support/cookbooks/ark/metadata.rb +0 -13
- data/support/cookbooks/ark/providers/default.rb +0 -370
- data/support/cookbooks/ark/recipes/default.rb +0 -31
- data/support/cookbooks/ark/recipes/test.rb +0 -138
- data/support/cookbooks/ark/resources/default.rb +0 -54
- data/support/cookbooks/ark/templates/default/add_to_path.sh.erb +0 -1
- data/support/cookbooks/ark/test/support/Gemfile +0 -4
- data/support/cookbooks/build-essential/README.md +0 -24
- data/support/cookbooks/build-essential/metadata.rb +0 -10
- data/support/cookbooks/build-essential/recipes/default.rb +0 -45
- data/support/cookbooks/chruby/.gitignore +0 -15
- data/support/cookbooks/chruby/.kitchen.yml +0 -26
- data/support/cookbooks/chruby/.ruby_version +0 -1
- data/support/cookbooks/chruby/Berksfile +0 -3
- data/support/cookbooks/chruby/Gemfile +0 -7
- data/support/cookbooks/chruby/LICENSE +0 -14
- data/support/cookbooks/chruby/README.md +0 -92
- data/support/cookbooks/chruby/Rakefile +0 -7
- data/support/cookbooks/chruby/Thorfile +0 -6
- data/support/cookbooks/chruby/Vagrantfile +0 -86
- data/support/cookbooks/chruby/attributes/default.rb +0 -10
- data/support/cookbooks/chruby/chefignore +0 -96
- data/support/cookbooks/chruby/metadata.rb +0 -11
- data/support/cookbooks/chruby/recipes/default.rb +0 -43
- data/support/cookbooks/chruby/recipes/system.rb +0 -25
- data/support/cookbooks/chruby/templates/default/chruby.sh.erb +0 -22
- data/support/cookbooks/chruby/test/integration/default/bash/embedded_test.sh +0 -1
- data/support/cookbooks/git/.gitignore +0 -14
- data/support/cookbooks/git/.kitchen.yml +0 -46
- data/support/cookbooks/git/Berksfile +0 -8
- data/support/cookbooks/git/CHANGELOG.md +0 -87
- data/support/cookbooks/git/CONTRIBUTING +0 -29
- data/support/cookbooks/git/Gemfile +0 -3
- data/support/cookbooks/git/LICENSE +0 -201
- data/support/cookbooks/git/README.md +0 -115
- data/support/cookbooks/git/TESTING.md +0 -25
- data/support/cookbooks/git/attributes/default.rb +0 -40
- data/support/cookbooks/git/metadata.rb +0 -35
- data/support/cookbooks/git/recipes/default.rb +0 -53
- data/support/cookbooks/git/recipes/server.rb +0 -58
- data/support/cookbooks/git/recipes/source.rb +0 -49
- data/support/cookbooks/git/recipes/windows.rb +0 -37
- data/support/cookbooks/git/templates/default/git-xinetd.d.erb +0 -10
- data/support/cookbooks/git/templates/default/sv-git-daemon-log-run.erb +0 -2
- data/support/cookbooks/git/templates/default/sv-git-daemon-run.erb +0 -3
- data/support/cookbooks/install_ruby/README.md +0 -3
- data/support/cookbooks/install_ruby/metadata.rb +0 -10
- data/support/cookbooks/install_ruby/recipes/default.rb +0 -14
- data/support/cookbooks/ruby_build/.gitignore +0 -6
- data/support/cookbooks/ruby_build/.kitchen.yml +0 -31
- data/support/cookbooks/ruby_build/.travis.yml +0 -4
- data/support/cookbooks/ruby_build/Berksfile +0 -10
- data/support/cookbooks/ruby_build/CHANGELOG.md +0 -72
- data/support/cookbooks/ruby_build/Gemfile +0 -14
- data/support/cookbooks/ruby_build/README.md +0 -338
- data/support/cookbooks/ruby_build/Rakefile +0 -21
- data/support/cookbooks/ruby_build/attributes/default.rb +0 -67
- data/support/cookbooks/ruby_build/chefignore +0 -53
- data/support/cookbooks/ruby_build/libraries/ruby_build_recipe_helpers.rb +0 -40
- data/support/cookbooks/ruby_build/metadata.rb +0 -18
- data/support/cookbooks/ruby_build/providers/ruby.rb +0 -88
- data/support/cookbooks/ruby_build/recipes/default.rb +0 -69
- data/support/cookbooks/ruby_build/resources/ruby.rb +0 -33
- data/support/cookbooks/ruby_build/test/cookbooks/alltherubies/metadata.rb +0 -10
- data/support/cookbooks/ruby_build/test/cookbooks/alltherubies/recipes/default.rb +0 -59
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/_verify_tests.bash +0 -33
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_1.8.7.bats +0 -29
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_1.9.2.bats +0 -18
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_1.9.3.bats +0 -18
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_2.0.0.bats +0 -18
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_jruby.bats +0 -20
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_rbx.bats +0 -18
- data/support/cookbooks/ruby_build/test/integration/alltherubies/bats/verify_ree.bats +0 -19
- data/support/cookbooks/ruby_build/test/integration/installation/bats/installation.bats +0 -6
- data/support/scripts/libsodium_ubuntu.sh +0 -80
- data/support/tasks/.gitkeep +0 -0
- data/support/tasks/libsodium_install.rb +0 -57
|
@@ -14,11 +14,11 @@ module VaultTree
|
|
|
14
14
|
private
|
|
15
15
|
|
|
16
16
|
def public_key_vault_contents
|
|
17
|
-
contract.
|
|
17
|
+
contract.open_vault(public_key_vault_id)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def secret_key_vault_contents
|
|
21
|
-
contract.
|
|
21
|
+
contract.open_vault(secret_key_vault_id)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module VaultTree
|
|
2
|
+
class ExternalInput < Keyword
|
|
3
|
+
attr_reader :input_name
|
|
4
|
+
|
|
5
|
+
def post_initialize(arg_array)
|
|
6
|
+
@input_name = arg_array[0]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def evaluate
|
|
10
|
+
validate_external_input
|
|
11
|
+
contract.external_input[input_name_symbol]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def id
|
|
17
|
+
vault.id
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def input_name_symbol
|
|
21
|
+
input_name.to_sym
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def validate_external_input
|
|
25
|
+
input_hash_present
|
|
26
|
+
input_value_not_nil
|
|
27
|
+
input_value_not_empty
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def input_hash_present
|
|
31
|
+
raise_error unless contract.external_input.kind_of?(Hash)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def input_value_not_nil
|
|
35
|
+
raise_error if (input_key_present? && nil_input_value?)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def input_value_not_empty
|
|
39
|
+
raise_error if (input_key_present? && empty_input_value?)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def input_key_present?
|
|
43
|
+
contract.external_input.has_key?(input_name_symbol)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def nil_input_value?
|
|
47
|
+
contract.external_input[input_name_symbol].nil?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def empty_input_value?
|
|
51
|
+
contract.external_input[input_name_symbol].empty?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def raise_error
|
|
55
|
+
raise Exceptions::InvalidExternalInput.new(nil, vault_id: id)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module VaultTree
|
|
2
|
+
class ExternalKey < Keyword
|
|
3
|
+
attr_reader :input_name
|
|
4
|
+
|
|
5
|
+
def post_initialize(arg_array)
|
|
6
|
+
@input_name = arg_array[0]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def evaluate
|
|
10
|
+
LockSmith.new(message: raw_external_input).secure_hash
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def raw_external_input
|
|
16
|
+
KeywordInterpreter.new("EXTERNAL_INPUT['#{input_name}']", vault).evaluate
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -3,15 +3,17 @@ module VaultTree
|
|
|
3
3
|
attr_reader :word, :vault
|
|
4
4
|
|
|
5
5
|
def initialize(word,vault)
|
|
6
|
-
@word = word
|
|
6
|
+
@word = word
|
|
7
7
|
@vault = vault
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def evaluate # start here
|
|
11
11
|
begin
|
|
12
12
|
keyword_class_name.new(vault, arg_array).evaluate
|
|
13
|
-
rescue NameError
|
|
14
|
-
raise Exceptions::UnsupportedKeyword
|
|
13
|
+
rescue NameError => e
|
|
14
|
+
raise Exceptions::UnsupportedKeyword.new(e,
|
|
15
|
+
vault_id: vault.id,
|
|
16
|
+
keyword: word)
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module VaultTree
|
|
2
|
+
class ShamirKeyShares < Keyword
|
|
3
|
+
attr_reader :outstanding_shares, :recovery_threshold
|
|
4
|
+
|
|
5
|
+
def post_initialize(arg_array)
|
|
6
|
+
@outstanding_shares = arg_array[0]
|
|
7
|
+
@recovery_threshold = arg_array[1]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def evaluate
|
|
11
|
+
Crypto::ShamirKeyShares.new(
|
|
12
|
+
outstanding_shares: outstanding_shares,
|
|
13
|
+
recovery_threshold: recovery_threshold
|
|
14
|
+
).generate
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module VaultTree
|
|
2
|
+
class ShamirShare < Keyword
|
|
3
|
+
attr_reader :share_collection_vault, :collection_index
|
|
4
|
+
|
|
5
|
+
def post_initialize(arg_array)
|
|
6
|
+
@share_collection_vault = arg_array[0]
|
|
7
|
+
@collection_index = arg_array[1]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def evaluate
|
|
11
|
+
share_collection[collection_index]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def share_collection
|
|
15
|
+
JSON.parse contract.open_vault(share_collection_vault)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'rbnacl'
|
|
2
|
+
require_relative 'lock_smith/assembled_shamir_key'
|
|
2
3
|
|
|
3
4
|
module VaultTree
|
|
4
5
|
# VaultTree::LockSmith Interface to Crypto Primatives
|
|
@@ -135,19 +136,17 @@ module VaultTree
|
|
|
135
136
|
# Recovers the shared secret from the shares provided
|
|
136
137
|
# in the initializer.
|
|
137
138
|
#
|
|
138
|
-
# @return [String]
|
|
139
|
-
def
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# Secret Shares associated with the split message
|
|
143
|
-
#
|
|
144
|
-
# @return [Array] Array of strings
|
|
145
|
-
def split_secret
|
|
139
|
+
# @return [String] assembled secret key
|
|
140
|
+
def assemble_shamir_key
|
|
141
|
+
VaultTree::Crypto::AssembledShamirKey.new( key_shares: secret_shares).assemble
|
|
146
142
|
end
|
|
147
143
|
|
|
148
144
|
private
|
|
149
145
|
|
|
150
146
|
def message; @message end
|
|
147
|
+
def outstanding_secret_shares; @outstanding_secret_shares end
|
|
148
|
+
def secret_recovery_threshold; @secret_recovery_threshold end
|
|
149
|
+
def secret_shares; @secret_shares end
|
|
151
150
|
|
|
152
151
|
# Locksmith always expects hex representations
|
|
153
152
|
# of keys and ciphertext. Convert to binary to
|
|
@@ -2,27 +2,17 @@ require 'secretsharing'
|
|
|
2
2
|
|
|
3
3
|
module VaultTree
|
|
4
4
|
module Crypto
|
|
5
|
-
class
|
|
5
|
+
class ShamirKeyShares
|
|
6
6
|
|
|
7
7
|
def initialize(params)
|
|
8
8
|
@outstanding_shares = params[:outstanding_shares]
|
|
9
9
|
@recovery_threshold = params[:recovery_threshold]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# JSON representation of a collection of secret shares
|
|
13
13
|
#
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
create_secret
|
|
17
|
-
LockSmith.new(message: secret_string).secure_hash
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Shares associated with the newly generated Sharmir key
|
|
21
|
-
#
|
|
22
|
-
# @return [Array] Array of strings
|
|
23
|
-
def shares
|
|
24
|
-
create_secret
|
|
25
|
-
shares_array.map{|s| s.to_s}
|
|
14
|
+
def generate
|
|
15
|
+
json_shares_mapping
|
|
26
16
|
end
|
|
27
17
|
|
|
28
18
|
# Fixnum representation if string value given
|
|
@@ -39,20 +29,26 @@ module VaultTree
|
|
|
39
29
|
@recovery_threshold.to_i
|
|
40
30
|
end
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def secret_string
|
|
45
|
-
shamir_object.secret.to_s
|
|
46
|
-
end
|
|
32
|
+
protected
|
|
47
33
|
|
|
48
|
-
def
|
|
49
|
-
|
|
34
|
+
def json_shares_mapping
|
|
35
|
+
sh = {}
|
|
36
|
+
i = 1; shares.each{ |s| sh[i.to_s] = s; i = i + 1;}
|
|
37
|
+
JSON.generate(sh)
|
|
50
38
|
end
|
|
51
39
|
|
|
52
40
|
def shamir_object
|
|
53
41
|
@shamir_object ||= SecretSharing::Shamir.new(outstanding_shares, recovery_threshold)
|
|
54
42
|
end
|
|
55
43
|
|
|
44
|
+
# Shares associated with the newly generated Sharmir key
|
|
45
|
+
#
|
|
46
|
+
# @return [Array] Array of strings
|
|
47
|
+
def shares
|
|
48
|
+
create_secret
|
|
49
|
+
shares_array.map{|s| s.to_s}
|
|
50
|
+
end
|
|
51
|
+
|
|
56
52
|
def create_secret
|
|
57
53
|
shamir_object.create_random_secret unless secret_set?
|
|
58
54
|
end
|
|
@@ -60,6 +56,11 @@ module VaultTree
|
|
|
60
56
|
def secret_set?
|
|
61
57
|
shamir_object.secret_set?
|
|
62
58
|
end
|
|
59
|
+
|
|
60
|
+
def shares_array
|
|
61
|
+
shamir_object.shares
|
|
62
|
+
end
|
|
63
|
+
|
|
63
64
|
end
|
|
64
65
|
end
|
|
65
66
|
end
|
|
File without changes
|
data/lib/vault-tree/version.rb
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
require_relative '../lib/vault-tree'
|
|
3
|
+
|
|
4
|
+
module VaultTree
|
|
5
|
+
module Exceptions
|
|
6
|
+
describe 'Raising a Custom Exception' do
|
|
7
|
+
|
|
8
|
+
def example_code
|
|
9
|
+
begin
|
|
10
|
+
raise 'Some Random Runtime Error'
|
|
11
|
+
rescue => e
|
|
12
|
+
raise FailedUnlockAttempt.new(e,
|
|
13
|
+
vault_id: 'a_specific_vault',
|
|
14
|
+
unlocking_key: 'EXTERNAL_DATA')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'can catch an exception and reraise a custom exception' do
|
|
19
|
+
expect{example_code}.to raise_error(FailedUnlockAttempt)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'Outputs message nicely to standard out' do
|
|
23
|
+
begin
|
|
24
|
+
example_code
|
|
25
|
+
rescue
|
|
26
|
+
STDOUT.write('Hopefully this looks good.')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'Output of various custom exceptions' do
|
|
32
|
+
|
|
33
|
+
it 'Failed Unlock Attempt' do
|
|
34
|
+
begin
|
|
35
|
+
raise 'Some Random Runtime Error'
|
|
36
|
+
rescue => e
|
|
37
|
+
begin
|
|
38
|
+
raise FailedUnlockAttempt.new(e,
|
|
39
|
+
vault_id: 'a_specific_vault',
|
|
40
|
+
unlocking_key: 'EXTERNAL_DATA')
|
|
41
|
+
rescue
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'Empty Vault' do
|
|
47
|
+
begin
|
|
48
|
+
raise 'Some Random Runtime Error'
|
|
49
|
+
rescue => e
|
|
50
|
+
begin
|
|
51
|
+
raise EmptyVault.new(e, vault_id: 'a_specific_vault')
|
|
52
|
+
rescue
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'Vault Does Not Exist' do
|
|
58
|
+
begin
|
|
59
|
+
raise 'Some Random Runtime Error'
|
|
60
|
+
rescue => e
|
|
61
|
+
begin
|
|
62
|
+
raise VaultDoesNotExist.new(e, vault_id: 'some_none_existant_vault')
|
|
63
|
+
rescue
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'Unsupported Keyword' do
|
|
69
|
+
begin
|
|
70
|
+
raise 'Some Random Runtime Error'
|
|
71
|
+
rescue => e
|
|
72
|
+
begin
|
|
73
|
+
raise UnsupportedKeyword.new(e, vault_id: 'some_vault', keyword: 'some_keyword')
|
|
74
|
+
rescue
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
data/spec/lock_smith_spec.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'rspec'
|
|
2
|
-
RSpec.configure{ |config| config.color_enabled = true }
|
|
3
2
|
|
|
4
3
|
require_relative '../lib/vault-tree/lock_smith'
|
|
5
4
|
|
|
@@ -39,52 +38,5 @@ module VaultTree
|
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
|
|
42
|
-
describe '#split_secret | #combine_secret_shares' do
|
|
43
|
-
|
|
44
|
-
context 'with 3 out of 5 secrets' do
|
|
45
|
-
it 'recovers the shared secret' do
|
|
46
|
-
pending
|
|
47
|
-
secret_key = LockSmith.new().generate_secret_key
|
|
48
|
-
secret_shares = LockSmith.new(message: secret_key, outstanding_secret_shares: 5, secret_recovery_threshold: 3).split_secret
|
|
49
|
-
combined_secret = LockSmith.new(message: secret_key, secret_shares: secret_shares).combine_secret_shares
|
|
50
|
-
combined_secret.should == secret_key
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context 'with 5 out of 5 secrets' do
|
|
55
|
-
it 'recovers the shared secret' do
|
|
56
|
-
pending
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context 'with 2 out of 2 secrets' do
|
|
61
|
-
it 'recovers the shared secret' do
|
|
62
|
-
pending
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context 'in exceptional situations' do
|
|
67
|
-
|
|
68
|
-
it 'throws an exception on init if one of the shares is not a string' do
|
|
69
|
-
pending
|
|
70
|
-
s = SecretSharing::Shamir.new(5,3)
|
|
71
|
-
s.create_random_secret
|
|
72
|
-
@established_secret = s.secret.to_s
|
|
73
|
-
@expected_digest = LockSmith.new(message: @established_secret).secure_hash
|
|
74
|
-
@key_shares = s.shares[0..2].map{|s| s.to_s}
|
|
75
|
-
|
|
76
|
-
# Replace the last string with just an object
|
|
77
|
-
@key_shares[2] = Object.new
|
|
78
|
-
expect{AssembledShamirKey.new(key_shares: @key_shares)}.to raise_error(TypeError)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it 'throws an exception if the key shares are nil' do
|
|
82
|
-
pending
|
|
83
|
-
@key_shares = nil
|
|
84
|
-
expect{AssembledShamirKey.new(key_shares: @key_shares)}.to raise_error(TypeError)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
41
|
end
|
|
90
42
|
end
|