safedb 0.3.1011 → 0.4.1002

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +56 -19
  3. data/README.md +15 -15
  4. data/Rakefile +7 -0
  5. data/bin/safe +2 -2
  6. data/lib/{interprete.rb → cli.rb} +168 -121
  7. data/lib/controller/admin/README.md +47 -0
  8. data/lib/controller/admin/access.rb +47 -0
  9. data/lib/controller/admin/checkin.rb +83 -0
  10. data/lib/controller/admin/checkout.rb +57 -0
  11. data/lib/controller/admin/diff.rb +75 -0
  12. data/lib/{usecase → controller/admin}/export.rb +15 -14
  13. data/lib/controller/admin/goto.rb +52 -0
  14. data/lib/controller/admin/import.rb +54 -0
  15. data/lib/controller/admin/init.rb +113 -0
  16. data/lib/controller/admin/login.rb +88 -0
  17. data/lib/{usecase → controller/admin}/logout.rb +0 -0
  18. data/lib/controller/admin/open.rb +39 -0
  19. data/lib/{usecase → controller/admin}/token.rb +2 -2
  20. data/lib/controller/admin/tree.md +54 -0
  21. data/lib/{usecase → controller/admin}/use.rb +0 -0
  22. data/lib/controller/admin/view.rb +61 -0
  23. data/lib/{usecase → controller/api}/docker/README.md +0 -0
  24. data/lib/{usecase → controller/api}/docker/docker.rb +1 -1
  25. data/lib/{usecase → controller/api}/jenkins/README.md +0 -0
  26. data/lib/{usecase → controller/api}/jenkins/jenkins.rb +1 -1
  27. data/lib/{usecase → controller/api}/terraform/README.md +1 -1
  28. data/lib/{usecase → controller/api}/terraform/terraform.rb +1 -1
  29. data/lib/{usecase → controller/api}/vpn/README.md +1 -1
  30. data/lib/{usecase → controller/api}/vpn/vpn.ini +0 -0
  31. data/lib/{usecase → controller/api}/vpn/vpn.rb +0 -0
  32. data/lib/{usecase → controller}/config/README.md +0 -0
  33. data/lib/{usecase → controller}/edit/README.md +0 -0
  34. data/lib/controller/edit/editverse.rb +48 -0
  35. data/lib/controller/edit/put.rb +35 -0
  36. data/lib/controller/edit/remove.rb +29 -0
  37. data/lib/{usecase/update/README.md → controller/edit/rename.md} +0 -0
  38. data/lib/{usecase → controller}/files/README.md +1 -1
  39. data/lib/controller/files/read.rb +36 -0
  40. data/lib/{usecase/files/eject.rb → controller/files/write.rb} +15 -20
  41. data/lib/{usecase → controller}/id.rb +0 -0
  42. data/lib/controller/query/print.rb +26 -0
  43. data/lib/controller/query/queryverse.rb +39 -0
  44. data/lib/controller/query/show.rb +50 -0
  45. data/lib/{session/require.gem.rb → controller/requirer.rb} +13 -9
  46. data/lib/{usecase → controller}/set.rb +4 -4
  47. data/lib/controller/usecase.rb +244 -0
  48. data/lib/{usecase → controller}/verse.rb +0 -0
  49. data/lib/{usecase → controller}/visit/README.md +0 -0
  50. data/lib/{usecase → controller}/visit/visit.rb +0 -0
  51. data/lib/factbase/facts.safedb.net.ini +7 -7
  52. data/lib/{keytools/key.docs.rb → model/README.md} +102 -66
  53. data/lib/model/book.rb +484 -0
  54. data/lib/model/branch.rb +48 -0
  55. data/lib/model/checkin.feature +33 -0
  56. data/lib/{configs/README.md → model/configs.md} +4 -4
  57. data/lib/model/content.rb +214 -0
  58. data/lib/model/indices.rb +132 -0
  59. data/lib/model/safe_tree.rb +51 -0
  60. data/lib/model/state.inspect.rb +221 -0
  61. data/lib/model/state.migrate.rb +334 -0
  62. data/lib/model/text_chunk.rb +68 -0
  63. data/lib/{extension → utils/extend}/array.rb +0 -0
  64. data/lib/{extension → utils/extend}/dir.rb +0 -0
  65. data/lib/{extension → utils/extend}/file.rb +0 -0
  66. data/lib/utils/extend/hash.rb +76 -0
  67. data/lib/{extension → utils/extend}/string.rb +6 -6
  68. data/lib/{session/fact.finder.rb → utils/facts/fact.rb} +0 -0
  69. data/lib/utils/identity/identifier.rb +356 -0
  70. data/lib/{keytools/key.ident.rb → utils/identity/machine.id.rb} +67 -4
  71. data/lib/utils/inspect/inspector.rb +81 -0
  72. data/lib/{keytools/kdf.bcrypt.rb → utils/kdfs/bcrypt.rb} +0 -0
  73. data/lib/{keytools → utils/kdfs}/kdf.api.rb +16 -16
  74. data/lib/{keytools/key.local.rb → utils/kdfs/kdfs.rb} +40 -40
  75. data/lib/{keytools/kdf.pbkdf2.rb → utils/kdfs/pbkdf2.rb} +0 -0
  76. data/lib/{keytools/kdf.scrypt.rb → utils/kdfs/scrypt.rb} +0 -0
  77. data/lib/{keytools → utils}/key.error.rb +2 -2
  78. data/lib/{keytools → utils}/key.pass.rb +2 -2
  79. data/lib/{keytools → utils/keys}/key.64.rb +0 -0
  80. data/lib/{keytools → utils/keys}/key.rb +6 -2
  81. data/lib/{keytools/key.iv.rb → utils/keys/random.iv.rb} +0 -0
  82. data/lib/{logging/gem.logging.rb → utils/logs/logger.rb} +6 -5
  83. data/lib/{keytools/key.pair.rb → utils/store/datamap.rb} +48 -30
  84. data/lib/{keytools/key.db.rb → utils/store/datastore.rb} +38 -104
  85. data/lib/utils/store/merge-boys-school.json +40 -0
  86. data/lib/utils/store/merge-girls-school.json +48 -0
  87. data/lib/utils/store/merge-merged-data.json +56 -0
  88. data/lib/utils/store/struct.rb +75 -0
  89. data/lib/utils/store/test-commands.sh +24 -0
  90. data/lib/{keytools/key.now.rb → utils/time/timestamp.rb} +32 -21
  91. data/lib/version.rb +1 -1
  92. metadata +86 -73
  93. data/lib/extension/hash.rb +0 -33
  94. data/lib/keytools/key.algo.rb +0 -109
  95. data/lib/keytools/key.api.rb +0 -1326
  96. data/lib/keytools/key.id.rb +0 -322
  97. data/lib/modules/cryptology/amalgam.rb +0 -70
  98. data/lib/modules/cryptology/engineer.rb +0 -99
  99. data/lib/modules/mappers/dictionary.rb +0 -288
  100. data/lib/session/time.stamp.rb +0 -340
  101. data/lib/session/user.home.rb +0 -49
  102. data/lib/usecase/cmd.rb +0 -471
  103. data/lib/usecase/edit/delete.rb +0 -46
  104. data/lib/usecase/files/file_me.rb +0 -78
  105. data/lib/usecase/files/read.rb +0 -169
  106. data/lib/usecase/files/write.rb +0 -89
  107. data/lib/usecase/goto.rb +0 -57
  108. data/lib/usecase/import.rb +0 -157
  109. data/lib/usecase/init.rb +0 -61
  110. data/lib/usecase/login.rb +0 -72
  111. data/lib/usecase/open.rb +0 -71
  112. data/lib/usecase/print.rb +0 -40
  113. data/lib/usecase/put.rb +0 -81
  114. data/lib/usecase/show.rb +0 -138
  115. data/lib/usecase/update/rename.rb +0 -180
  116. data/lib/usecase/view.rb +0 -71
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/ruby
2
+
3
+ module SafeDb
4
+
5
+ # This idempotent <b>init use case</b> promises that a password-protected
6
+ # book with the given name will exist within the safe's directory tree, along
7
+ # with key derivation salts, ciphertext and other paraphernalia.
8
+ #
9
+ # After successful execution, the following state is observable
10
+ #
11
+ # - folder **`~/.safedb.net/safedb-master-crypts/safedb.book.<BOOK_ID>`** exists
12
+ # - book content file **`safedb.chapter.<CONTENT_ID>.txt`** exists
13
+ # - **`safedb-user-configuration.ini`** links the branch and book ids
14
+ # - **`safedb-master-index-local.ini`** has section with [<BOOK_ID>]
15
+ #
16
+ # Within the master index file in the [<BOOK_ID>] section will be
17
+ #
18
+ # - the book initialiize time
19
+ # - the salts and ciphertext from the key derivation functions
20
+ # - the ID and initialization vector (iv) of the contents file
21
+ #
22
+ # == init use case <b>pre-conditions</b>
23
+ #
24
+ # Warning or error messages must result unless these pre-conditions are met
25
+ #
26
+ # - a secret (if required) is prompted or in --password or SAFE_BOOK_PASSWORD
27
+ # - the strength of the human sourced password is adequate
28
+ # - the book name ( maybe from SAFE_BOOK_NAME ) follows convention
29
+ # - the shell must have a SAFE_TTY_TOKEN environment variable
30
+ #
31
+ class Init < AccessUc
32
+
33
+
34
+ def execute
35
+
36
+ # @todo => in parent class Auth validate the book name
37
+
38
+
39
+ @book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH )
40
+
41
+ if is_book_initialized?()
42
+ print_already_initialized
43
+ return
44
+ end
45
+
46
+ StateMigrate.create_book( @book_id )
47
+
48
+ # @todo => search for password in environment variable
49
+
50
+ book_secret = KeyPass.password_from_shell( true ) if @password.nil?
51
+ book_secret = @password unless @password.nil?
52
+
53
+ master_keys = DataMap.new( Indices::MASTER_INDICES_FILEPATH )
54
+ master_keys.use( @book_id )
55
+
56
+ StateMigrate.recycle_both_keys(
57
+ @book_id,
58
+ book_secret,
59
+ master_keys,
60
+ virginal_book()
61
+ )
62
+
63
+ print_success_initializing
64
+
65
+ end
66
+
67
+
68
+ private
69
+
70
+
71
+ def virginal_book()
72
+
73
+ initial_db = DataStore.new()
74
+ initial_db.store( Indices::SAFE_BOOK_INITIALIZE_TIME, KeyNow.readable() )
75
+ initial_db.store( Indices::SAFE_BOOK_NAME, @book_name )
76
+ initial_db.store( Indices::SAFE_BOOK_INIT_VERSION, Indices::SAFE_VERSION_STRING )
77
+ initial_db.store( Indices::SAFE_BOOK_CHAPTER_KEYS, {} )
78
+
79
+ return initial_db.to_json
80
+
81
+ end
82
+
83
+
84
+ def print_already_initialized
85
+
86
+ puts ""
87
+ puts "You can go ahead and login."
88
+ puts "Your domain [#{@book_name}] is already setup."
89
+ puts "You should already know the password."
90
+ puts ""
91
+ puts " #{COMMANDMENT} login #{@book_name}"
92
+ puts ""
93
+
94
+ end
95
+
96
+
97
+ def print_success_initializing
98
+
99
+ puts ""
100
+ puts "Success! You can now login."
101
+ puts "Your book #{@book_name} with id #{@book_id} is up."
102
+ puts "From now on you simply login like this."
103
+ puts ""
104
+ puts " #{COMMANDMENT} login #{@book_name}"
105
+ puts ""
106
+
107
+ end
108
+
109
+
110
+ end
111
+
112
+
113
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/ruby
2
+
3
+ module SafeDb
4
+
5
+ # The <b>login use case</b> is given the domain name and if needs be
6
+ # it collects the password then (if correct) logs the user in.
7
+ #
8
+ # Here are some key facts about the login command
9
+ #
10
+ # - its domain name parameter is mandatory
11
+ # - it is called at the start of every branch
12
+ # - it is undone by the logout command
13
+ # - it requires the shell token environment variable to be set
14
+ # - you can nest login commands thus using multiple domains
15
+ # - you can call it with a --with=password switch
16
+ # - a space before the command prevents it being logged in .bash_history
17
+ # - you can deliver the password in multiple ways
18
+ class Login < AccessUc
19
+
20
+ def execute
21
+
22
+ # @todo => in parent class Auth validate the book name
23
+
24
+ @book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH )
25
+
26
+ unless ( is_book_initialized?() )
27
+ print_not_initialized
28
+ return
29
+ end
30
+
31
+ if( StateInspect.is_logged_in?( @book_id ) )
32
+ StateMigrate.use_book( @book_id )
33
+ View.new().flow()
34
+ return
35
+ end
36
+
37
+ # @todo => search for password in environment variable
38
+
39
+ book_password = KeyPass.password_from_shell( false ) if @password.nil?
40
+ book_password = @password unless @password.nil?
41
+
42
+ # @todo => if password is correct - if not print out an error.
43
+
44
+ book_keys = DataMap.new( Indices::MASTER_INDICES_FILEPATH )
45
+ book_keys.use( @book_id )
46
+
47
+ StateMigrate.login( book_keys, book_password )
48
+ View.new().flow()
49
+
50
+ end
51
+
52
+
53
+ private
54
+
55
+
56
+ def print_already_logged_in
57
+
58
+ puts ""
59
+ puts "We are already logged in. Open a secret envelope, put, then seal."
60
+ puts ""
61
+ puts " #{COMMANDMENT} open aws.credentials:s3reader"
62
+ puts " #{COMMANDMENT} put access_key ABCD1234"
63
+ puts " #{COMMANDMENT} put secret_key FGHIJ56789"
64
+ puts " #{COMMANDMENT} put region_key eu-central-1"
65
+ puts " #{COMMANDMENT} seal"
66
+ puts ""
67
+
68
+ end
69
+
70
+
71
+ def print_not_initialized
72
+
73
+ puts ""
74
+ puts "This book [ #{@book_name} ] has not yet been initialized."
75
+ puts "Please initialize it with this command."
76
+ puts ""
77
+ puts " #{COMMANDMENT} init #{@book_name}"
78
+ puts ""
79
+
80
+ end
81
+
82
+
83
+ end
84
+
85
+
86
+ end
87
+
88
+
File without changes
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/ruby
2
+
3
+ module SafeDb
4
+
5
+ # The <tt>open use case</tt> allows us to add (put), subtract (remove), change
6
+ # (update) and list the credential within first a chapter (outer) and then within
7
+ # a verse (inner), of the logged in book.
8
+ #
9
+ # == safe reopen <<chapter>> <<verse>>
10
+ #
11
+ # If you need to be sure that you are re-opening a chapter and verse that already
12
+ # exists you use the <tt>safe reopen</tt> command. This command produces an error
13
+ # if it cannot find specified chapter and verse.
14
+ #
15
+ class Open < UseCase
16
+
17
+ # The chapter and verse of this book that are to be opened.
18
+ attr_writer :chapter, :verse
19
+
20
+ def execute
21
+
22
+ book = Book.new()
23
+ book.set_open_chapter_name( @chapter )
24
+ book.set_open_verse_name( @verse )
25
+ book.write()
26
+
27
+ # Show the mini dictionary at the opened chapter and verse location
28
+ # More work is needed when for when only the chapter is opened in
29
+ # which case we should show the list of verses and perhaps the count
30
+ # of key value pairs each verse contains.
31
+ Show.new.flow()
32
+
33
+ end
34
+
35
+
36
+ end
37
+
38
+
39
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SafeDb
4
4
 
5
- # The <tt>token use case</tt> prints out an encrypted session token tied
5
+ # The <tt>token use case</tt> prints out an encrypted shell token tied
6
6
  # to the workstation and shell environment. See the root README.md on how
7
7
  # to export it and create a simple command alias for it in the ~/.bash_aliases
8
8
  # script which is executed when the shell starts.
@@ -11,7 +11,7 @@ module SafeDb
11
11
 
12
12
  def execute
13
13
 
14
- print KeyLocal.generate_shell_key_and_token()
14
+ print KeyDerivation.generate_shell_key_and_token()
15
15
 
16
16
  end
17
17
 
@@ -0,0 +1,54 @@
1
+
2
+ # the safedb directory tree
3
+
4
+ On disk, the safe database is largely just **crypt files** and **indices** which contain salts and possibly remote repository urls. You'll also find a safe **user configuration file** plus activity logs.
5
+
6
+ ```
7
+ ~/.safedb.net
8
+ |
9
+ |--- safedb-master-index-local.ini
10
+ |--- safedb-user-configuration.ini
11
+ |--- safedb-activity-journal.log
12
+ |
13
+ |--- safedb-master-crypts
14
+ |
15
+ |--- .git
16
+ |--- safedb.book.ababab-ababab
17
+ |
18
+ |--- safedb.chapter.8d04ldabcd.txt
19
+ |--- safedb.chapter.fl3456asdf.txt
20
+ |--- safedb.chapter.pw9521pqwo.txt
21
+
22
+ |
23
+ |--- safedb.book.cdcdcd-cdcdcd
24
+ |
25
+ |--- safedb.chapter.o3wertpoiu.txt
26
+ |--- safedb.chapter.xcvbrt2345.txt
27
+ |
28
+ |
29
+ |--- safedb-branch-crypts
30
+ |
31
+ |--- safedb-branch-ababab-ababab-xxxxxx-xxxxxx-xxxxxx
32
+ |
33
+ |--- safedb.chapter.8d04ldabcd.txt
34
+ |--- safedb.chapter.fl3456asdf.txt
35
+ |--- safedb.chapter.pw9521pqwo.txt
36
+ |
37
+ |
38
+ |--- safedb-branch-ababab-ababab-xxxxxx-zzzzzz-zzzzzz
39
+ |
40
+ |--- safedb.chapter.id1234abcd.txt
41
+ |--- safedb.chapter.id3456asdf.txt
42
+ |--- safedb.chapter.id9521pqwo.txt
43
+
44
+ |
45
+ |
46
+ |--- safedb-branch-cdcdcd-cdcdcd-ghighi-ghighi-ghighi
47
+ |
48
+ |--- safedb.chapter.o3wertpoiu.txt
49
+ |--- safedb.chapter.xcvbrt2345.txt
50
+
51
+ |--- safedb-branch-indices
52
+ |
53
+ |--- safedb-indices-xxxxxx-xxxxxx-xxxxxx.ini
54
+ ```
File without changes
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby
2
+
3
+ module SafeDb
4
+
5
+ # View provides a bird's eye view of the book's content and links well with
6
+ # the <b>goto</b>, <b>show</b> and <b>tell</b> commands.
7
+ #
8
+ # View maps out and numbers each chapter/verse combination.
9
+ # Goto with the number effectively shortcuts the open pinpointer.
10
+ # Show prints out the verse lines at the opened path but masks any secrets.
11
+ # Tell also prints out the verse lines but unabashedly displays secrets.
12
+ class View < UseCase
13
+
14
+ def execute
15
+
16
+ book = Book.new()
17
+
18
+ puts ""
19
+ puts " == Birth Day := #{book.init_time()}\n"
20
+ puts " == Book Name := #{book.book_name()} [#{book.book_id}]\n"
21
+ puts " == Book Mark := #{book.get_open_chapter_name()}/#{book.get_open_verse_name()}\n" if book.is_opened?()
22
+ puts ""
23
+
24
+ verse_count = 0
25
+ chapter_index = 0
26
+ book.branch_chapter_keys().each_pair do | chapter_name, chapter_keys |
27
+
28
+ chapter_index += 1
29
+ verse_index = 0
30
+ chapter_data = Content.unlock_branch_chapter( chapter_keys )
31
+ chapter_data.each_key do | verse_name |
32
+
33
+ verse_index += 1
34
+ verse_count += 1
35
+ is_open = book.is_open?( chapter_name, verse_name )
36
+ isnt_first = verse_count != 1
37
+ isnt_last = ( chapter_index != book.branch_chapter_keys().length() ) || ( verse_index != chapter_data.length() )
38
+ mark_open = is_open ? "<< " : ""
39
+ mark_close = is_open ? " >>" : ""
40
+ fixdint = format( "%02d", verse_count )
41
+ puts " -- ---- --------------------------------------" if( is_open && isnt_first )
42
+ puts " -- [#{fixdint}] #{mark_open}#{chapter_name} :~~ #{verse_name}#{mark_close}\n"
43
+ puts " -- ---- --------------------------------------" if( is_open && isnt_last )
44
+
45
+ end
46
+
47
+ end
48
+
49
+ puts ""
50
+ puts " == There are #{book.branch_chapter_keys().length()} chapters and #{verse_count} verses."
51
+ puts ""
52
+
53
+ return
54
+
55
+ end
56
+
57
+
58
+ end
59
+
60
+
61
+ end
File without changes
@@ -30,7 +30,7 @@ module SafeDb
30
30
  # key/value mini-dictionary breadcrumbs sitting
31
31
  # within the master database at the section labelled
32
32
  # envelope@<<actual_chapter_id>>.
33
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) )
33
+ chapter_data = DataStore.from_json( Lock.content_unlock( master_db[ chapter_id ] ) )
34
34
 
35
35
  key_value_dictionary = chapter_data[ verse_id ]
36
36
  docker_username = key_value_dictionary[ "docker.username" ]
File without changes
@@ -169,7 +169,7 @@ module SafeDb
169
169
  # key/value mini-dictionary breadcrumbs sitting
170
170
  # within the master database at the section labelled
171
171
  # envelope@<<actual_chapter_id>>.
172
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) )
172
+ chapter_data = DataStore.from_json( Lock.content_unlock( master_db[ chapter_id ] ) )
173
173
 
174
174
  key_value_dictionary = chapter_data[ verse_id ]
175
175
 
@@ -44,7 +44,7 @@ Now and forever you can return to the chapter and verse and enjoy a secure crede
44
44
 
45
45
  You can even change directories and run other terraform projects against the opened IAM user. You can also open an IAM user, run commands, open another run commands and then reopen the first and run commands.
46
46
 
47
- As long as you stay within your shell window - your safe login will persist. Once your session is finished you either logout or exit the shell.
47
+ As long as you stay within your shell window - your safe login will persist. Once your branch is finished you either logout or exit the shell.
48
48
 
49
49
  ### Shortcut Alert
50
50
 
@@ -46,7 +46,7 @@ module SafeDb
46
46
  # key/value mini-dictionary breadcrumbs sitting
47
47
  # within the master database at the section labelled
48
48
  # envelope@<<actual_chapter_id>>.
49
- chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) )
49
+ chapter_data = DataStore.from_json( Lock.content_unlock( master_db[ chapter_id ] ) )
50
50
 
51
51
  # Now read the three AWS IAM credentials @access.key, @secret.key and region.key
52
52
  # into the 3 environment variables terraform expects to find.
@@ -103,7 +103,7 @@ Now and forever you can return to the chapter and verse and enjoy a secure crede
103
103
 
104
104
  You can even change directories and run other terraform projects against the opened IAM user. You can also open an IAM user, run commands, open another run commands and then reopen the first and run commands.
105
105
 
106
- As long as you stay within your shell window - your safe login will persist. Once your session is finished you either logout or exit the shell.
106
+ As long as you stay within your shell window - your safe login will persist. Once your branch is finished you either logout or exit the shell.
107
107
 
108
108
  ### Shortcut Alert
109
109
 
File without changes
File without changes
File without changes