safedb 0.01.0001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.yardopts +3 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE +21 -0
  6. data/README.md +793 -0
  7. data/Rakefile +16 -0
  8. data/bin/safe +5 -0
  9. data/lib/configs/README.md +58 -0
  10. data/lib/extension/array.rb +162 -0
  11. data/lib/extension/dir.rb +35 -0
  12. data/lib/extension/file.rb +123 -0
  13. data/lib/extension/hash.rb +33 -0
  14. data/lib/extension/string.rb +572 -0
  15. data/lib/factbase/facts.safedb.net.ini +38 -0
  16. data/lib/interprete.rb +462 -0
  17. data/lib/keytools/PRODUCE_RAND_SEQ_USING_DEV_URANDOM.txt +0 -0
  18. data/lib/keytools/kdf.api.rb +243 -0
  19. data/lib/keytools/kdf.bcrypt.rb +265 -0
  20. data/lib/keytools/kdf.pbkdf2.rb +262 -0
  21. data/lib/keytools/kdf.scrypt.rb +190 -0
  22. data/lib/keytools/key.64.rb +326 -0
  23. data/lib/keytools/key.algo.rb +109 -0
  24. data/lib/keytools/key.api.rb +1391 -0
  25. data/lib/keytools/key.db.rb +330 -0
  26. data/lib/keytools/key.docs.rb +195 -0
  27. data/lib/keytools/key.error.rb +110 -0
  28. data/lib/keytools/key.id.rb +271 -0
  29. data/lib/keytools/key.ident.rb +243 -0
  30. data/lib/keytools/key.iv.rb +107 -0
  31. data/lib/keytools/key.local.rb +259 -0
  32. data/lib/keytools/key.now.rb +402 -0
  33. data/lib/keytools/key.pair.rb +259 -0
  34. data/lib/keytools/key.pass.rb +120 -0
  35. data/lib/keytools/key.rb +585 -0
  36. data/lib/logging/gem.logging.rb +132 -0
  37. data/lib/modules/README.md +43 -0
  38. data/lib/modules/cryptology/aes-256.rb +154 -0
  39. data/lib/modules/cryptology/amalgam.rb +70 -0
  40. data/lib/modules/cryptology/blowfish.rb +130 -0
  41. data/lib/modules/cryptology/cipher.rb +207 -0
  42. data/lib/modules/cryptology/collect.rb +138 -0
  43. data/lib/modules/cryptology/crypt.io.rb +225 -0
  44. data/lib/modules/cryptology/engineer.rb +99 -0
  45. data/lib/modules/mappers/dictionary.rb +288 -0
  46. data/lib/modules/storage/coldstore.rb +186 -0
  47. data/lib/modules/storage/git.store.rb +399 -0
  48. data/lib/session/fact.finder.rb +334 -0
  49. data/lib/session/require.gem.rb +112 -0
  50. data/lib/session/time.stamp.rb +340 -0
  51. data/lib/session/user.home.rb +49 -0
  52. data/lib/usecase/cmd.rb +487 -0
  53. data/lib/usecase/config/README.md +57 -0
  54. data/lib/usecase/docker/README.md +146 -0
  55. data/lib/usecase/docker/docker.rb +49 -0
  56. data/lib/usecase/edit/README.md +43 -0
  57. data/lib/usecase/edit/delete.rb +46 -0
  58. data/lib/usecase/export.rb +40 -0
  59. data/lib/usecase/files/README.md +37 -0
  60. data/lib/usecase/files/eject.rb +56 -0
  61. data/lib/usecase/files/file_me.rb +78 -0
  62. data/lib/usecase/files/read.rb +169 -0
  63. data/lib/usecase/files/write.rb +89 -0
  64. data/lib/usecase/goto.rb +57 -0
  65. data/lib/usecase/id.rb +36 -0
  66. data/lib/usecase/import.rb +157 -0
  67. data/lib/usecase/init.rb +63 -0
  68. data/lib/usecase/jenkins/README.md +146 -0
  69. data/lib/usecase/jenkins/jenkins.rb +208 -0
  70. data/lib/usecase/login.rb +71 -0
  71. data/lib/usecase/logout.rb +28 -0
  72. data/lib/usecase/open.rb +71 -0
  73. data/lib/usecase/print.rb +40 -0
  74. data/lib/usecase/put.rb +81 -0
  75. data/lib/usecase/set.rb +44 -0
  76. data/lib/usecase/show.rb +138 -0
  77. data/lib/usecase/terraform/README.md +91 -0
  78. data/lib/usecase/terraform/terraform.rb +121 -0
  79. data/lib/usecase/token.rb +35 -0
  80. data/lib/usecase/update/README.md +55 -0
  81. data/lib/usecase/update/rename.rb +180 -0
  82. data/lib/usecase/use.rb +41 -0
  83. data/lib/usecase/verse.rb +20 -0
  84. data/lib/usecase/view.rb +71 -0
  85. data/lib/usecase/vpn/README.md +150 -0
  86. data/lib/usecase/vpn/vpn.ini +31 -0
  87. data/lib/usecase/vpn/vpn.rb +54 -0
  88. data/lib/version.rb +3 -0
  89. data/safedb.gemspec +34 -0
  90. metadata +193 -0
data/lib/interprete.rb ADDED
@@ -0,0 +1,462 @@
1
+ require "thor"
2
+ require "fileutils"
3
+
4
+ require "session/time.stamp"
5
+ require "logging/gem.logging"
6
+ require "session/require.gem"
7
+
8
+
9
+ # Include the logger mixins so that every class can enjoy "import free"
10
+ # logging through pointers to the (extended) log behaviour.
11
+ include OpenLogger
12
+
13
+
14
+ # This standard out sync command flushes text destined for STDOUT immediately,
15
+ # without waiting either for a full cache or script completion.
16
+ $stdout.sync = true
17
+
18
+
19
+ # Recursively require all gems that are either in or under the directory
20
+ # that this code is executing from. Only use this tool if your library is
21
+ # relatively small but highly interconnected. In these instances it raises
22
+ # productivity and reduces pesky "not found" exceptions.
23
+ OpenSession::RecursivelyRequire.now( __FILE__ )
24
+
25
+
26
+ # This command line processor extends the Thor gem CLI tools in order to
27
+ #
28
+ # - read the posted commands, options and switches
29
+ # - maps the incoming string data to objects
30
+ # - assert that the mandatory options exist
31
+ # - assert the type of each parameter
32
+ # - ensure that the parameter values are in range
33
+ # - delegate processing to the registered handlers
34
+
35
+ class Interprete < Thor
36
+
37
+
38
+ log.info(x) { "request to interact with a safe book has been received." }
39
+
40
+
41
+ # With this class option every (and especially the log) use case has
42
+ # the option of modifying its behaviour based on the presence and state
43
+ # of the --debug switch.
44
+ class_option :debug, :type => :boolean
45
+
46
+ # The script class option is implemented in the parent {SafeDb::UseCase}
47
+ # use case enabling behaviour alteration based on the presence and state of
48
+ # the --script flag.
49
+ class_option :script, :type => :boolean
50
+
51
+
52
+
53
+ # Description of the init configuration call.
54
+ desc "init <book_name> <storage_dir>", "initialize the safe book on this device"
55
+
56
+ # If confident that command history cannot be exploited to gain the
57
+ # human password or if the agent running safe is itself a script,
58
+ # the <tt>with</tt> option can be used to convey the password.
59
+ option :with
60
+
61
+ # Initialize the credentials manager, collect the human password and
62
+ # manufacture the strong asymmetric public / private keypair.
63
+ #
64
+ # @param domain_name [String] the domain the software operates under
65
+ # @param base_path [String] the path to the base operating directory
66
+ def init( domain_name, base_path = nil )
67
+ log.info(x) { "initialize the safe book on this device." }
68
+ init_uc = SafeDb::Init.new
69
+ init_uc.master_p4ss = options[:with] if options[:with]
70
+ init_uc.domain_name = domain_name
71
+ init_uc.base_path = base_path unless base_path.nil?
72
+ init_uc.flow_of_events
73
+ end
74
+
75
+
76
+
77
+ # Description of the login use case command line call.
78
+ desc "login <book_name>", "login to the book before interacting with it"
79
+
80
+ # If confident that command history cannot be exploited to gain the
81
+ # human password or if the agent running safe is itself a script,
82
+ # the <tt>with</tt> option can be used to convey the password.
83
+ option :with
84
+
85
+ # Login in order to securely interact with your data.
86
+ # @param domain_name [String] the domain the software operates under
87
+ def login( domain_name = nil )
88
+ log.info(x) { "[usecase] ~> login to the book before interacting with it." }
89
+ login_uc = SafeDb::Login.new
90
+ login_uc.domain_name = domain_name unless domain_name.nil?
91
+ login_uc.master_p4ss = options[:with] if options[:with]
92
+ login_uc.flow_of_events
93
+ end
94
+
95
+
96
+
97
+ # Description of the print use case command line call.
98
+ desc "print <key_name>", "print the key value at the opened chapter and verse"
99
+
100
+ # Print the value of the specified key belonging to a dictionary at
101
+ # the opened chapter and verse of the currently logged in book.
102
+ #
103
+ # @param key_name [String] the key whose value is to be printed
104
+ def print key_name
105
+ log.info(x) { "[usecase] ~> print the key value at the opened chapter and verse." }
106
+ print_uc = SafeDb::Print.new
107
+ print_uc.key_name = key_name
108
+ print_uc.from_script = options[:script].nil? ? false : options[:script]
109
+ print_uc.flow_of_events
110
+ end
111
+
112
+
113
+
114
+ # Description of the verse use case command line call.
115
+ desc "verse", "print the verse name at the opened chapter and verse"
116
+
117
+ # Print the name of the verse at the opened chapter and verse location.
118
+ def verse
119
+ log.info(x) { "[usecase] ~> print the verse name at the opened chapter and verse." }
120
+ verse_uc = SafeDb::Verse.new
121
+ verse_uc.from_script = options[:script].nil? ? false : options[:script]
122
+ verse_uc.flow_of_events
123
+ end
124
+
125
+
126
+
127
+ # Description of the safe token use case.
128
+ desc "token", "generate and print out an encrypted (shell bound) session token"
129
+
130
+ # The<b>token</b> use cases prints out an encrypted session token tied
131
+ # to the workstation and shell environment.
132
+ def token
133
+ log.info(x) { "[usecase] ~> generate and print out an encrypted (shell bound) session token" }
134
+ SafeDb::Token.new.flow_of_events
135
+ end
136
+
137
+
138
+
139
+ # Description of the open use case command.
140
+ desc "open <chapter> <verse>", "open a chapter and verse to read from or write to"
141
+
142
+ # Open up a conduit (path) to the place where we can issue read, create, update,
143
+ # and destroy commands.
144
+ #
145
+ # The allowed characters that makeup chapter and verse aside from alphanumerics are
146
+ #
147
+ # - dollar signs
148
+ # - percent signs
149
+ # - ampersands
150
+ # - hyphens
151
+ # - underscores
152
+ # - plus signs
153
+ # - equal signs
154
+ # - @ signs
155
+ # - period characters and
156
+ # - question marks
157
+ #
158
+ # Notably whitespace including spaces and tabs are not allowed.
159
+ #
160
+ # @param chapter [String]
161
+ # the chapter of the logged in book to open
162
+ #
163
+ # @param verse [String]
164
+ # the verse of the logged in book and specified chapter to open
165
+ def open chapter, verse
166
+ log.info(x) { "[usecase] ~> open a chapter and verse to read from or write to." }
167
+ open_uc = SafeDb::Open.new
168
+ open_uc.env_path = chapter
169
+ open_uc.key_path = verse
170
+ open_uc.flow_of_events
171
+ end
172
+
173
+
174
+
175
+ # Description of the export use case command.
176
+ desc "export", "exports the book or chapter or the mini dictionary at verse."
177
+
178
+ # Export the entire book if no chapter and verse is specified (achieved with a safe close),
179
+ # or the chapter if only the chapter is open (safe shut or safe open <<chapter>>, or the
180
+ # mini-dictionary at the verse if both chapter and verse are open.
181
+ def export
182
+ log.info(x) { "[usecase] ~> export book chapter content or dictionary at verse in JSON format." }
183
+ SafeDb::Export.new.flow_of_events
184
+ end
185
+
186
+
187
+
188
+ # Description of the put secret command.
189
+ desc "put <key> <value>", "put key/value pair into dictionary at open chapter and verse"
190
+
191
+ # Put a secret with an id like login/username and a value like joebloggs into the
192
+ # context (eg work/laptop) that was opened with the open command.
193
+ #
194
+ # @param secret_id [String] the id of the secret to put into the opened context
195
+ # @param secret_value [String] the value of the secret to put into the opened context
196
+ def put secret_id, secret_value
197
+ log.info(x) { "[usecase] ~> put key/value pair into dictionary at open chapter and verse." }
198
+ put_uc = SafeDb::Put.new
199
+ put_uc.secret_id = secret_id
200
+ put_uc.secret_value = secret_value
201
+ put_uc.flow_of_events
202
+ end
203
+
204
+
205
+
206
+ # Description of the file command.
207
+ desc "file <file_key> <file_url>", "ingest a file into the safe from the filesystem (or S3, ssh, Google Drive)"
208
+
209
+ # The <b>file use case</b> pulls a read in from either an accessible readsystem
210
+ # or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
211
+ #
212
+ # @param file_key [String] keyname representing the file that is being read in
213
+ # @param file_url [String] url of file to ingest and assimilate into the safe
214
+ def file file_key, file_url
215
+ log.info(x) { "[usecase] ~> file read against key [[ #{file_key} ]]" }
216
+ log.info(x) { "[usecase] ~> file read from url [[ #{file_url} ]]" }
217
+ file_uc = SafeDb::FileMe.new
218
+ file_uc.file_key = file_key
219
+ file_uc.file_url = file_url
220
+ file_uc.flow_of_events
221
+ end
222
+
223
+
224
+
225
+ # Description of the eject command.
226
+ desc "eject <file_key>", "write out ingested file at chapter/verse with specified file key"
227
+
228
+ # The <b>eject use case</b> writes out a file that was previously ingested
229
+ # and coccooned inside the safe typically with the file command.
230
+ #
231
+ # @param file_key [String] the key that the file was ingested against
232
+ def eject file_key
233
+ log.info(x) { "[usecase] ~> eject file at chapter/verse against specified key." }
234
+ eject_uc = SafeDb::Eject.new
235
+ eject_uc.file_key = file_key
236
+ eject_uc.flow_of_events
237
+ end
238
+
239
+
240
+
241
+ # Description of the delete command.
242
+ desc "delete <entity_id>", "delete a line (key/value pair), or a verse, chapter and even a book"
243
+
244
+ # The <b>delete use case</b> can delete a single line (key/value pair), or
245
+ # a verse, chapter and even a book
246
+ #
247
+ # @param entity_id [String] the ID of the entity to delete (line, verse, chapter or book)
248
+ def delete entity_id
249
+ log.info(x) { "[usecase] ~> delete a safe entity with a key id [#{entity_id}]." }
250
+ delete_uc = SafeDb::DeleteMe.new
251
+ delete_uc.entity_id = entity_id
252
+ delete_uc.flow_of_events
253
+ end
254
+
255
+
256
+
257
+ # Description of the read command.
258
+ desc "read <file_url>", "read (reread) file either locally or via http, git or ssh"
259
+
260
+ # The <b>read use case</b> pulls a read in from either an accessible readsystem
261
+ # or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
262
+ #
263
+ # This use case expects a @file_url parameter. The actions it takes are to
264
+ #
265
+ # - register @in.url to mirror @file_url
266
+ # - register @out.url to mirror @file_url
267
+ # - check the location of @file_url
268
+ # - if no file exists it humbly finishes up
269
+ #
270
+ # @param file_url [String] url of file to ingest and assimilate into the safe
271
+ def read file_url
272
+ log.info(x) { "[usecase] ~> read (reread) file from optional url [[ #{file_url} ]]" }
273
+ read_uc = SafeDb::Read.new
274
+ read_uc.file_url = file_url
275
+ read_uc.flow_of_events
276
+ end
277
+
278
+
279
+
280
+ # Description of the write command.
281
+ desc "write <file_url>", "write out file at chapter/verse to (optional) file url"
282
+
283
+ # The <b>write use case</b> writes out a file that was previously ingested
284
+ # and coccooned inside the safe.
285
+ #
286
+ # @param file_url [String] optional file url marking where to write the file
287
+ def write( file_url = nil )
288
+ log.info(x) { "[usecase] ~> write out file at chapter/verse to (optional) file url." }
289
+ write_uc = SafeDb::Write.new
290
+ write_uc.from_script = options[:script].nil? ? false : options[:script]
291
+ write_uc.file_url = file_url if file_url
292
+ write_uc.flow_of_events
293
+ end
294
+
295
+
296
+
297
+ # Description of the show secret command.
298
+ desc "show", "show dictionary at the opened chapter and verse"
299
+
300
+ # Show the secrets at the opened path. These secrets
301
+ # are simply written out to the shell console.
302
+ def show
303
+ log.info(x) { "[usecase] ~> show dictionary at the opened chapter and verse." }
304
+ SafeDb::Show.new.flow_of_events
305
+ end
306
+
307
+
308
+
309
+ # Description of the view command.
310
+ desc "view", "print list of chapter and verse combos to console"
311
+
312
+ # Display a bird's eye view of the domain's database including
313
+ # its envelopes, their keys and imported objects such as files.
314
+ def view
315
+ log.info(x) { "[usecase] ~> print list of chapter and verse combos to console." }
316
+ view_uc = SafeDb::View.new
317
+ view_uc.flow_of_events
318
+ end
319
+
320
+
321
+
322
+ # Description of the goto use case command.
323
+ desc "goto <index>", "shortcut that opens chapter and verse at specified index"
324
+
325
+ # Goto is a shortcut (or alias even) for the open command that takes an integer
326
+ # index that effectively specifies which <envelope> and <key> to open.
327
+ #
328
+ # @param index [Number]
329
+ # the integer index chosen from the list procured by the view command.
330
+ def goto index
331
+ log.info(x) { "[usecase] ~> opens the chapter and verse at index [#{index}]." }
332
+ goto_uc = SafeDb::Goto.new
333
+ goto_uc.index = index
334
+ goto_uc.flow_of_events
335
+
336
+ end
337
+
338
+
339
+
340
+ # Description of the terraform integration use case command.
341
+ desc "terraform <command>", "runs terraform after exporting IAM credentials at opened location"
342
+
343
+ # This terraform use case exports the AWS IAM user access key, secret key and region key
344
+ # into (very safe) environment variables and then runs terraform plan, apply or destroy.
345
+ #
346
+ # This is both ultra secure and extremely convenient because the credentials do not leave
347
+ # the safe and exist within (environment variable) memory only for the duration of the
348
+ # terraform command.
349
+ #
350
+ # It is safe because you do not need to expose your AWS credentials in plain text.
351
+ # It is convenient because switching IAM users and AWS regions is as easy as typing the now
352
+ # ubiquitous safe open command.
353
+ #
354
+ # safe open <<chapter>> <<verse>>
355
+ #
356
+ # @param command [String]
357
+ # the terraform command to run which is currently limited to plan, apply and destroy.
358
+ # This parameter is optional and if nothing is given then "apply" is assumed.
359
+ def terraform( command = nil )
360
+ log.info(x) { "[usecase] ~> will export IAM credentials then invoke $ terraform #{command}" }
361
+ terraform_uc = SafeDb::Terraform.new
362
+ terraform_uc.command = command if command
363
+ terraform_uc.flow_of_events
364
+ end
365
+
366
+
367
+
368
+ # Description of the jenkins integration use case command.
369
+ desc "jenkins <<command>> <<what>> <<where>>", "sends credentials to the Jenkins 2 CI service."
370
+
371
+ # This Jenkins use case injects for example the AWS IAM user access key, secret key and region key
372
+ # into a running Jenkins CI (Continuous Integration) service at the specified (url) location.
373
+ #
374
+ # safe jenkins post aws http://localhost:8080
375
+ #
376
+ # @param command [String]
377
+ #
378
+ # the action to be taken which is currently limited to be [post].
379
+ #
380
+ # @param service [String]
381
+ #
382
+ # Which service do the credentials being posted originate from? The crrent list includes
383
+ #
384
+ # - aws ( the 3 IAM user credentials )
385
+ # - docker ( the username / password of docker repository )
386
+ # - git ( the username/password of Git repository )
387
+ # - rubygems ( the username / password of RubyGems package manager account )
388
+ #
389
+ # @param url [String]
390
+ #
391
+ # the full url of the jenkins service for example http://localhost:8080
392
+ # which includes the scheme (http|https) the hostname or ip address and
393
+ # the port jenkins is listening on (if not the default 80 or 443).
394
+ #
395
+ def jenkins( command, service, url )
396
+
397
+ log.info(x) { "[usecase] ~> request to #{command} #{service} credentials to Jenkins at #{url}" }
398
+ jenkins_uc = SafeDb::Jenkins.new
399
+
400
+ jenkins_uc.command = command if command
401
+ jenkins_uc.service = service if service
402
+ jenkins_uc.url = url if url
403
+
404
+ jenkins_uc.flow_of_events
405
+
406
+ end
407
+
408
+
409
+
410
+ # Description of the docker repository integration use case command.
411
+ desc "docker <<command>>", "logs into or out of the dockerhub repository."
412
+
413
+ # This docker use case ....
414
+ #
415
+ # safe docker login
416
+ # safe docker logout
417
+ #
418
+ # @param command [String]
419
+ # the action to be taken which is currently limited to either
420
+ # login or logout
421
+ def docker( command = "login" )
422
+
423
+ log.info(x) { "[usecase] ~> request to #{command} into or out of a docker repository." }
424
+ docker_uc = SafeDb::Docker.new
425
+ docker_uc.command = command
426
+ docker_uc.flow_of_events
427
+
428
+ end
429
+
430
+
431
+
432
+ # Description of the vpn use case command.
433
+ desc "vpn <command>", "runs vpn command typically safe vpn up or safe vpn down"
434
+
435
+ # This VPN use case connects to the VPN whose specifics are recorded within the vpn.ini
436
+ # factfile living in the same directory as the vpn.rb usecase class.
437
+ #
438
+ # @param command [String]
439
+ # the vpn command to run which is currently limited to up or down
440
+ # This parameter is optional and if nothing is given then "up" is assumed.
441
+ def vpn( command = nil )
442
+ log.info(x) { "[usecase] ~> VPN connection command #{command} has been issued." }
443
+ vpn_uc = SafeDb::Vpn.new
444
+ vpn_uc.command = command if command
445
+ vpn_uc.flow_of_events
446
+ end
447
+
448
+
449
+
450
+ # Description of the identifier command.
451
+ desc "id", "prints out the current timestamp identifiers"
452
+
453
+ # Put out the multiple formats of the current timestamp.
454
+ def id
455
+ log.info(x) { "[usecase] ~> prints out the current timestamp identifiers." }
456
+ id_uc = SafeDb::Id.new
457
+ id_uc.flow_of_events
458
+ end
459
+
460
+
461
+
462
+ end