lorj 1.0.14 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lorj_account_import.rb +7 -33
- data/lib/core/core.rb +36 -13
- data/lib/core/core_import_export.rb +76 -23
- data/lib/core/core_internal.rb +12 -3
- data/lib/core/core_object_params.rb +2 -1
- data/lib/core/core_setup_encrypt.rb +58 -54
- data/lib/core/definition.rb +0 -2
- data/lib/core/process.rb +5 -1
- data/lib/lorj/version.rb +2 -2
- data/lib/lorj.rb +1 -1
- data/lib/prc.rb +16 -1
- data/spec/21_lorj_processes_spec.rb +12 -6
- data/spec/22_lorj_core_spec.rb +2 -1
- data/spec/30_lorj_basedefinition_spec.rb +9 -12
- data/spec/31_lorj_importexport_spec.rb +53 -30
- data/spec/spec_helper.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0501318f36deb3f6d31fdce4d63f148d91a818
|
4
|
+
data.tar.gz: 6800e36135d9decb469b1d9dc87e1f3be7385980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b14d5a49cfe34e91495e412e1c64041ecad1c38927dda2c555e4b57d2589182863a1bbe6e49492639638d6ecdc8121895f667878d77f91ca5ef32a944b20f87b
|
7
|
+
data.tar.gz: 61d2970cecf4ba70bb01135ecfcc6813bf43ff89c708aa0e29c716975881562cca13b611d533414f263a9d289ddaada7bea8a6fdb83ea43d1abd0ea4b60b6592
|
data/bin/lorj_account_import.rb
CHANGED
@@ -39,7 +39,6 @@ class Test < Lorj::BaseDefinition
|
|
39
39
|
|
40
40
|
# Internal function to test.
|
41
41
|
def_internal '_get_encrypt_key'
|
42
|
-
def_internal '_get_encrypted_value'
|
43
42
|
|
44
43
|
def run
|
45
44
|
puts 'Checking imported account...'
|
@@ -53,7 +52,8 @@ class Test < Lorj::BaseDefinition
|
|
53
52
|
entr = _get_encrypt_key
|
54
53
|
data = @core.config['credentials#account_key']
|
55
54
|
|
56
|
-
res =
|
55
|
+
res = Lorj::SSLCrypt.get_encrypted_value(data, entr,
|
56
|
+
'credentials#account_key')
|
57
57
|
|
58
58
|
test_state(!res.nil?, 'Account key', data)
|
59
59
|
end
|
@@ -69,20 +69,15 @@ class Test < Lorj::BaseDefinition
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# TODO: Implement Thor instead of ARGV use.
|
72
|
+
# TODO: Support to load local process.
|
72
73
|
if ARGV.length <= 3
|
73
74
|
puts "Syntax is 'ruby #{__FILE__}' <LorjRef> <key> <CloudDataFile> "\
|
74
|
-
"[<AccountName
|
75
|
+
"[<AccountName>]\n"\
|
75
76
|
"where:\n"\
|
76
77
|
"LorjRef : Lorj application struture to use. \n"\
|
77
|
-
|
78
|
-
"<process>[@<libToLoad]\n"\
|
78
|
+
" Format: <datapath[|<pdatapath>]>\n"\
|
79
79
|
" datapath : Path where Lorj store data.\n"\
|
80
80
|
" pdatapath : Path where Lorj store private data.\n"\
|
81
|
-
" process : Lorj process name to load. It can be a path to a\n"\
|
82
|
-
" process file.\n"\
|
83
|
-
" libToLoad : Optional. Ruby library containing The Lorj process.\n"\
|
84
|
-
" If missing, it will try to load a lib named \n"\
|
85
|
-
" lorj_<process>\n"\
|
86
81
|
'key : Base64 encoded key. Used to decrypt the <CloudDataFi'\
|
87
82
|
"le>\n"\
|
88
83
|
"CloudDataFile : File containing the Lorj cloud data to import.\n"\
|
@@ -94,7 +89,7 @@ end
|
|
94
89
|
|
95
90
|
ref, key_encoded, data_file, account = ARGV
|
96
91
|
|
97
|
-
ref_found = ref.match(/^(.*(\|(.*))?)
|
92
|
+
ref_found = ref.match(/^(.*(\|(.*))?)$/)
|
98
93
|
|
99
94
|
unless ref_found
|
100
95
|
puts 'LorjRef must be formatted as : <datapath[|<pdatapath>]>='\
|
@@ -105,13 +100,6 @@ end
|
|
105
100
|
datapath = ref_found[1]
|
106
101
|
pdatapath = datapath
|
107
102
|
pdatapath = ref_found[3] unless ref_found[3].nil?
|
108
|
-
process = ref_found[4]
|
109
|
-
|
110
|
-
if ref_found[6].nil?
|
111
|
-
lib_name = "lorj_#{process}"
|
112
|
-
else
|
113
|
-
lib_name = ref_found[6]
|
114
|
-
end
|
115
103
|
|
116
104
|
unless File.exist?(data_file)
|
117
105
|
puts "#{data_file} doesn't exist. Please check and retry."
|
@@ -123,12 +111,6 @@ if key_encoded == ''
|
|
123
111
|
exit 1
|
124
112
|
end
|
125
113
|
|
126
|
-
begin
|
127
|
-
require lib_name
|
128
|
-
rescue => e
|
129
|
-
puts "Warning! Unable to load RubyGem '#{lib_name}'.\n#{e}"
|
130
|
-
end
|
131
|
-
|
132
114
|
if key_encoded.length % 4 > 0
|
133
115
|
key_encoded += '=' * (4 - (key_encoded.length % 4))
|
134
116
|
end
|
@@ -154,20 +136,12 @@ else
|
|
154
136
|
end
|
155
137
|
end
|
156
138
|
|
157
|
-
name, controller = account.split('@') unless account.nil?
|
158
|
-
|
159
139
|
PrcLib.data_path = datapath
|
160
140
|
PrcLib.pdata_path = pdatapath
|
161
141
|
|
162
|
-
keypath = Lorj::KeyPath.new(process)
|
163
|
-
|
164
|
-
processes = [{ :process_module => keypath.key_tree }]
|
165
|
-
|
166
|
-
core = Lorj::Core.new(Lorj::Account.new, processes)
|
167
|
-
|
168
142
|
data = File.read(data_file).strip
|
169
143
|
|
170
|
-
core.account_import(entr, data,
|
144
|
+
core = Lorj.account_import(entr, data, account)
|
171
145
|
|
172
146
|
puts 'Import done.'
|
173
147
|
|
data/lib/core/core.rb
CHANGED
@@ -15,8 +15,6 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
# rubocop: disable Metrics/AbcSize
|
19
|
-
|
20
18
|
# Module Lorj which contains several classes.
|
21
19
|
#
|
22
20
|
# Those classes describes :
|
@@ -317,17 +315,21 @@ module Lorj
|
|
317
315
|
|
318
316
|
# Function to import an encrypted Hash as a Lorj Account.
|
319
317
|
#
|
320
|
-
# For details about this functions,
|
318
|
+
# For details about this functions,
|
319
|
+
# see #Lorj::BaseDefinition.account_data_import
|
320
|
+
#
|
321
|
+
# To import an exported data, consider calling Lorj.account_import.
|
321
322
|
#
|
322
323
|
# * *Args* :
|
323
|
-
# - +
|
324
|
-
# - +
|
324
|
+
# - +data+ : Hash. data to import.
|
325
|
+
# - +name+ : By default, it import in the same name described in the data.
|
326
|
+
# But we can change it with this parameter.
|
325
327
|
#
|
326
328
|
# * *Raises* :
|
327
329
|
# No exceptions
|
328
|
-
def account_import(
|
330
|
+
def account_import(data, name = nil)
|
329
331
|
return nil if @core_object.nil?
|
330
|
-
@core_object.
|
332
|
+
@core_object.account_data_import(data, name)
|
331
333
|
end
|
332
334
|
|
333
335
|
# Function to export a Lorj Account in an encrypted Hash.
|
@@ -402,6 +404,7 @@ module Lorj
|
|
402
404
|
# (processes & controller)
|
403
405
|
initialize_core_object(model)
|
404
406
|
PrcLib.model.clear_heap
|
407
|
+
PrcLib.processes model[:processes]
|
405
408
|
end
|
406
409
|
|
407
410
|
private
|
@@ -470,20 +473,40 @@ module Lorj
|
|
470
473
|
# It must be controllers/<controller_name>/<controller_name>.rb
|
471
474
|
# You can change 'controllers' by any name, with :controllers_dir
|
472
475
|
#
|
473
|
-
# - +properties :
|
476
|
+
# - +properties : required.
|
474
477
|
# - :controllers_dir : Name of the controllers directory.
|
475
478
|
# By default 'controllers'
|
479
|
+
# - :lib_name : name of the gem library declaring the process.
|
476
480
|
#
|
477
481
|
# The process will be added in Lorj.processes Hash
|
478
482
|
#
|
479
483
|
def declare_process(process_name, path, properties = {})
|
484
|
+
unless properties.is_a?(Hash) && properties[:lib_name].is_a?(String)
|
485
|
+
puts("Lorj: process module error: '#{__method__}"\
|
486
|
+
"('#{process_name}', '#{path}', #{properties})' requires :lib_name"\
|
487
|
+
"\nat line #{caller[0]}")
|
488
|
+
return nil
|
489
|
+
end
|
480
490
|
process_data = Lorj::ProcessResource.new(process_name, path, properties)
|
481
491
|
|
482
|
-
|
492
|
+
if process_data.nil?
|
493
|
+
puts("Lorj: process module error: '#{process_name}' fails to be "\
|
494
|
+
"declared:\n"\
|
495
|
+
"process_name: '#{process_name}'\n"\
|
496
|
+
"path : '#{path}'\n"\
|
497
|
+
"properties : #{properties.to_yaml}")
|
498
|
+
return nil
|
499
|
+
end
|
483
500
|
|
484
501
|
@processes = {} if @processes.nil?
|
485
502
|
|
486
|
-
|
503
|
+
if process_data.process.nil?
|
504
|
+
puts("Lorj: process module error: process failure:\n"\
|
505
|
+
"process_name: '#{process_name}'\n"\
|
506
|
+
"path : '#{path}'\n"\
|
507
|
+
"properties : #{properties.to_yaml}")
|
508
|
+
return nil
|
509
|
+
end
|
487
510
|
|
488
511
|
process_name = process_data.name
|
489
512
|
|
@@ -492,8 +515,8 @@ module Lorj
|
|
492
515
|
process_data
|
493
516
|
end
|
494
517
|
|
495
|
-
|
496
|
-
|
497
|
-
|
518
|
+
def processes
|
519
|
+
@processes = {} if @processes.nil?
|
520
|
+
@processes
|
498
521
|
end
|
499
522
|
end
|
@@ -17,14 +17,57 @@
|
|
17
17
|
|
18
18
|
#
|
19
19
|
module Lorj
|
20
|
+
# Function to import an encrypted Hash as a Lorj Account.
|
21
|
+
#
|
22
|
+
# The encrypted Hash will be decrypted by the key provided.
|
23
|
+
# The content of the hash will be stored in the 'account' layer
|
24
|
+
# of config.
|
25
|
+
#
|
26
|
+
# For details on how import work, look in #account_data_import
|
27
|
+
#
|
28
|
+
# * *Args* :
|
29
|
+
# - +key+ : key to use to decrypt the 'enc_hash'.
|
30
|
+
# - +import_data+ : import data. This data is structured as follow:
|
31
|
+
# - :enc_data : The encrypted account data.
|
32
|
+
# - :processes: Array or models + controllers to load.
|
33
|
+
# - +name+ : Optional. Name of the account.
|
34
|
+
#
|
35
|
+
# * *returns*:
|
36
|
+
# - +core+ : Core object, with loaded model, created during the import.
|
37
|
+
#
|
38
|
+
# * *Raises* :
|
39
|
+
# No exceptions
|
40
|
+
def self.account_import(key, import_data, name = nil)
|
41
|
+
import_data = YAML.load(import_data)
|
42
|
+
hash = Lorj::SSLCrypt.get_encrypted_value(import_data[:enc_data], key,
|
43
|
+
'Encrypted account data')
|
44
|
+
|
45
|
+
data = YAML.load(hash)
|
46
|
+
|
47
|
+
processes = import_data[:processes]
|
48
|
+
|
49
|
+
processes.each do |p|
|
50
|
+
next unless p.key?(:process_module)
|
51
|
+
|
52
|
+
PrcLib.debug("Loading module '#{p[:process_module]}' from GEM lib '%s'",
|
53
|
+
p[:lib_name])
|
54
|
+
begin
|
55
|
+
require "#{p[:lib_name]}"
|
56
|
+
rescue => e
|
57
|
+
PrcLib.error("Unable to load module '#{p[:process_module]}'\n%s", e)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
core = Lorj::Core.new(Lorj::Account.new, processes)
|
62
|
+
core.account_import(data, name)
|
63
|
+
|
64
|
+
core
|
65
|
+
end
|
66
|
+
|
20
67
|
# Implements account_import and account_export
|
21
68
|
# exposed by core.
|
22
69
|
class BaseDefinition
|
23
|
-
# Function to import an
|
24
|
-
#
|
25
|
-
# The encrypted Hash will be decrypted by the key provided.
|
26
|
-
# The content of the hash will be stored in the 'account' layer
|
27
|
-
# of config.
|
70
|
+
# Function to import an account data in Lorj::Account.
|
28
71
|
#
|
29
72
|
# The 'account' layer is not cleaned before. If you need to
|
30
73
|
# clean it up, do:
|
@@ -39,7 +82,7 @@ module Lorj
|
|
39
82
|
# If you pass 'name' and 'controller', ac_update will be used to update the
|
40
83
|
# account data
|
41
84
|
# If the imported data contains name and controller data, by default, it
|
42
|
-
# will call ac_update
|
85
|
+
# will call ac_update.
|
43
86
|
#
|
44
87
|
# The location used comes from PrcLib.data_path
|
45
88
|
# Passwords will be encrypted by the internal .key file stored in
|
@@ -49,19 +92,13 @@ module Lorj
|
|
49
92
|
# verify if some data are missed for any object action (create/delete/...)
|
50
93
|
#
|
51
94
|
# * *Args* :
|
52
|
-
# - +
|
53
|
-
# - +enc_hash+ : Encrypted Hash.
|
95
|
+
# - +data+ : Account data to import.
|
54
96
|
# - +name+ : Optional. Name of the account.
|
55
|
-
# - +controller+ : Optional. Name of the controller.
|
56
97
|
#
|
57
98
|
# * *Raises* :
|
58
99
|
# No exceptions
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
data = YAML.load(hash)
|
63
|
-
|
64
|
-
_update_account_meta(data, name, controller)
|
100
|
+
def account_data_import(data, name = nil)
|
101
|
+
_update_account_meta(data, name)
|
65
102
|
|
66
103
|
entr = _get_encrypt_key
|
67
104
|
|
@@ -70,7 +107,7 @@ module Lorj
|
|
70
107
|
key = "#{s}##{k}"
|
71
108
|
data_def = Lorj.data.auto_section_data(key)
|
72
109
|
if data_def && data_def[:encrypted].is_a?(TrueClass)
|
73
|
-
v =
|
110
|
+
v = Lorj::SSLCrypt.encrypt_value(v, entr)
|
74
111
|
end
|
75
112
|
config.set(key, v, :name => 'account')
|
76
113
|
end
|
@@ -127,26 +164,42 @@ module Lorj
|
|
127
164
|
rhash_tree = Lorj.data.first_section(k)
|
128
165
|
rhash_tree = v[:keys] if v.key?(:keys)
|
129
166
|
if !data_def.nil? && data_def[:encrypted].is_a?(TrueClass)
|
130
|
-
data =
|
167
|
+
data = Lorj::SSLCrypt.get_encrypted_value(data, entr, data_def[:desc])
|
131
168
|
end
|
132
169
|
rhash.rh_set(data, *rhash_tree)
|
133
170
|
end
|
134
171
|
|
135
|
-
entr =
|
136
|
-
|
172
|
+
entr = Lorj::SSLCrypt.new_encrypt_key
|
173
|
+
export_data = { :enc_data => Lorj::SSLCrypt.encrypt_value(rhash.to_yaml,
|
174
|
+
entr) }
|
175
|
+
export_data[:processes] = _export_processes
|
176
|
+
[entr, export_data.to_yaml]
|
137
177
|
end
|
138
178
|
|
139
179
|
private
|
140
180
|
|
141
|
-
def
|
181
|
+
def _export_processes
|
182
|
+
export_data = []
|
183
|
+
PrcLib.processes.each do |p|
|
184
|
+
next unless p.key?(:process_name) && p.key?(:lib_name)
|
185
|
+
|
186
|
+
process = {}
|
187
|
+
process[:process_module] = p[:process_name]
|
188
|
+
process[:lib_name] = p[:lib_name]
|
189
|
+
process[:controller] = p[:controller_name] if p.key?(:controller_name)
|
190
|
+
export_data << process if process.length > 0
|
191
|
+
end
|
192
|
+
export_data
|
193
|
+
end
|
194
|
+
|
195
|
+
def _update_account_meta(data, name)
|
142
196
|
if name.nil? && data.rh_exist?(:account, :name)
|
143
197
|
name = data.rh_get(:account, :name)
|
144
198
|
end
|
145
|
-
|
146
|
-
controller = data.rh_get(:account, :provider)
|
147
|
-
end
|
199
|
+
controller = data.rh_get(:account, :provider)
|
148
200
|
|
149
201
|
name = nil if name == ''
|
202
|
+
controller = nil if controller == ''
|
150
203
|
|
151
204
|
config.ac_update(name, controller) unless name.nil? || controller.nil?
|
152
205
|
end
|
data/lib/core/core_internal.rb
CHANGED
@@ -14,8 +14,6 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
# rubocop: disable Metrics/AbcSize
|
18
|
-
|
19
17
|
# - Lorj::Core : Lorj exposed interface.
|
20
18
|
# - Initialization functions
|
21
19
|
module Lorj
|
@@ -331,6 +329,7 @@ module Lorj
|
|
331
329
|
module_process = Lorj.processes[name]
|
332
330
|
my_process[:process_name] = name
|
333
331
|
my_process[:process_path] = module_process.process
|
332
|
+
my_process[:lib_name] = module_process.lib_name
|
334
333
|
|
335
334
|
if a_process[:controller_path]
|
336
335
|
my_process[:controller_path] = a_process[:controller_path]
|
@@ -391,15 +390,20 @@ module Lorj
|
|
391
390
|
def _process_module_set_ctr(my_process, controllers, controller_name)
|
392
391
|
return if controller_name.nil?
|
393
392
|
|
393
|
+
unless controller_name.is_a?(String)
|
394
|
+
controller_name = controller_name.to_s
|
395
|
+
end
|
394
396
|
controller_path = controllers[controller_name]
|
395
397
|
|
396
398
|
if controller_path.nil?
|
397
399
|
PrcLib.warning("Controller '%s' was not found. Please check. The "\
|
398
|
-
|
400
|
+
"process may not work. \nValid one are '%s'",
|
401
|
+
controller_name, controllers.keys)
|
399
402
|
return
|
400
403
|
end
|
401
404
|
|
402
405
|
my_process[:controller_path] = controller_path
|
406
|
+
my_process[:controller_name] = controller_name
|
403
407
|
end
|
404
408
|
|
405
409
|
# Function analyzing the process class parameter
|
@@ -474,6 +478,11 @@ module Lorj
|
|
474
478
|
|
475
479
|
the_process_class
|
476
480
|
end
|
481
|
+
end
|
482
|
+
|
483
|
+
# Define private Initialize functions for controllers
|
484
|
+
class Core
|
485
|
+
private
|
477
486
|
|
478
487
|
# Determine the process file path from the single name.
|
479
488
|
# Uses PrcLib.process_path as path to load this process.
|
@@ -112,7 +112,8 @@ module Lorj
|
|
112
112
|
end
|
113
113
|
|
114
114
|
if param_options[:decrypt].is_a?(TrueClass)
|
115
|
-
value =
|
115
|
+
value = Lorj::SSLCrypt.get_encrypted_value(value, _get_encrypt_key,
|
116
|
+
attr_name)
|
116
117
|
end
|
117
118
|
|
118
119
|
return unless param_options[:mapping]
|
@@ -26,10 +26,8 @@ require 'base64'
|
|
26
26
|
# and setup
|
27
27
|
# this task to make it to work.
|
28
28
|
module Lorj
|
29
|
-
#
|
30
|
-
|
31
|
-
private
|
32
|
-
|
29
|
+
# SSL Encryption feature for Lorj.
|
30
|
+
module SSLCrypt
|
33
31
|
# internal runtime function to create a new key
|
34
32
|
# *parameters*:
|
35
33
|
# - +new+ : true to create a new key.
|
@@ -40,7 +38,7 @@ module Lorj
|
|
40
38
|
# - :key: password
|
41
39
|
# - :salt : String current time number
|
42
40
|
# - :iv: Base64 random iv
|
43
|
-
def
|
41
|
+
def self.new_encrypt_key(key = rand(36**10).to_s(36))
|
44
42
|
random_iv = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv
|
45
43
|
{
|
46
44
|
:key => key,
|
@@ -49,6 +47,57 @@ module Lorj
|
|
49
47
|
}
|
50
48
|
end
|
51
49
|
|
50
|
+
# internal runtime function for process call #_build_hdata and
|
51
|
+
# #_get_encrypted_value_hidden
|
52
|
+
# Get encrypted value
|
53
|
+
#
|
54
|
+
# *parameters*:
|
55
|
+
# - +default+ : encrypted default value
|
56
|
+
# - +entropy+ : Entropy Hash
|
57
|
+
# - +sDesc+ : data description
|
58
|
+
#
|
59
|
+
# *return*:
|
60
|
+
# - value : decrypted value.
|
61
|
+
#
|
62
|
+
# *raise*:
|
63
|
+
#
|
64
|
+
def self.get_encrypted_value(enc_value, entr, sDesc)
|
65
|
+
return '' if enc_value.nil?
|
66
|
+
begin
|
67
|
+
Encryptor.decrypt(
|
68
|
+
:value => Base64.strict_decode64(enc_value),
|
69
|
+
:key => entr[:key],
|
70
|
+
:iv => Base64.strict_decode64(entr[:iv]),
|
71
|
+
:salt => entr[:salt]
|
72
|
+
)
|
73
|
+
rescue => e
|
74
|
+
PrcLib.error("Unable to decrypt your %s.\n"\
|
75
|
+
"%s\n"\
|
76
|
+
' You will need to re-enter it.',
|
77
|
+
sDesc, e)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Function to encrypt a data with a entr key.
|
82
|
+
#
|
83
|
+
# *return*:
|
84
|
+
# - value : encrypted value in Base64 encoded data.
|
85
|
+
def self.encrypt_value(value, entr)
|
86
|
+
Base64.strict_encode64(
|
87
|
+
Encryptor.encrypt(
|
88
|
+
:value => value,
|
89
|
+
:key => entr[:key],
|
90
|
+
:iv => Base64.strict_decode64(entr[:iv]),
|
91
|
+
:salt => entr[:salt]
|
92
|
+
)
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Adding encrypt core functions.
|
98
|
+
class BaseDefinition
|
99
|
+
private
|
100
|
+
|
52
101
|
# internal runtime function for process call
|
53
102
|
# Get encrypted value hidden by *
|
54
103
|
#
|
@@ -67,7 +116,7 @@ module Lorj
|
|
67
116
|
key_file = File.join(PrcLib.pdata_path, '.key')
|
68
117
|
if !File.exist?(key_file)
|
69
118
|
# Need to create a random key.
|
70
|
-
entr =
|
119
|
+
entr = Lorj::SSLCrypt.new_encrypt_key
|
71
120
|
|
72
121
|
Lorj.debug(2, "Writing '%s' key file", key_file)
|
73
122
|
unless PrcLib.dir_exists?(PrcLib.pdata_path)
|
@@ -101,7 +150,8 @@ module Lorj
|
|
101
150
|
return '' if enc_value.nil?
|
102
151
|
value_hidden = ''
|
103
152
|
begin
|
104
|
-
value_hidden = '*' *
|
153
|
+
value_hidden = '*' * Lorj::SSLCrypt.get_encrypted_value(enc_value, entr,
|
154
|
+
sDesc).length
|
105
155
|
rescue => e
|
106
156
|
PrcLib.error('Unable to decrypt your %s. You will need to re-enter it.'\
|
107
157
|
'\n%s', sDesc, e.message)
|
@@ -112,52 +162,6 @@ module Lorj
|
|
112
162
|
value_hidden
|
113
163
|
end
|
114
164
|
|
115
|
-
# internal runtime function for process call #_build_hdata and
|
116
|
-
# #_get_encrypted_value_hidden
|
117
|
-
# Get encrypted value
|
118
|
-
#
|
119
|
-
# *parameters*:
|
120
|
-
# - +default+ : encrypted default value
|
121
|
-
# - +entropy+ : Entropy Hash
|
122
|
-
# - +sDesc+ : data description
|
123
|
-
#
|
124
|
-
# *return*:
|
125
|
-
# - value : decrypted value.
|
126
|
-
#
|
127
|
-
# *raise*:
|
128
|
-
#
|
129
|
-
def _get_encrypted_value(enc_value, entr, sDesc)
|
130
|
-
return '' if enc_value.nil?
|
131
|
-
begin
|
132
|
-
Encryptor.decrypt(
|
133
|
-
:value => Base64.strict_decode64(enc_value),
|
134
|
-
:key => entr[:key],
|
135
|
-
:iv => Base64.strict_decode64(entr[:iv]),
|
136
|
-
:salt => entr[:salt]
|
137
|
-
)
|
138
|
-
rescue => e
|
139
|
-
PrcLib.error("Unable to decrypt your %s.\n"\
|
140
|
-
"%s\n"\
|
141
|
-
' You will need to re-enter it.',
|
142
|
-
sDesc, e)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
# Function to encrypt a data with a entr key.
|
147
|
-
#
|
148
|
-
# *return*:
|
149
|
-
# - value : encrypted value in Base64 encoded data.
|
150
|
-
def _encrypt_value(value, entr)
|
151
|
-
Base64.strict_encode64(
|
152
|
-
Encryptor.encrypt(
|
153
|
-
:value => value,
|
154
|
-
:key => entr[:key],
|
155
|
-
:iv => Base64.strict_decode64(entr[:iv]),
|
156
|
-
:salt => entr[:salt]
|
157
|
-
)
|
158
|
-
)
|
159
|
-
end
|
160
|
-
|
161
165
|
# internal runtime function for process call
|
162
166
|
# Ask encrypted function executed by _ask
|
163
167
|
#
|
@@ -194,7 +198,7 @@ module Lorj
|
|
194
198
|
PrcLib.message('%s cannot be empty.', sDesc) if value_free == ''
|
195
199
|
end
|
196
200
|
end
|
197
|
-
|
201
|
+
Lorj::SSLCrypt.encrypt_value(value_free, entr)
|
198
202
|
end
|
199
203
|
end
|
200
204
|
end
|
data/lib/core/definition.rb
CHANGED
data/lib/core/process.rb
CHANGED
@@ -22,7 +22,8 @@ module Lorj
|
|
22
22
|
#
|
23
23
|
#
|
24
24
|
class ProcessResource
|
25
|
-
attr_reader :defaults_file, :data_file, :process, :name, :controllers
|
25
|
+
attr_reader :defaults_file, :data_file, :process, :name, :controllers,
|
26
|
+
:lib_name
|
26
27
|
|
27
28
|
# ProcessResource initialization
|
28
29
|
#
|
@@ -49,6 +50,7 @@ module Lorj
|
|
49
50
|
# By default is `<name>/defaults.yaml`
|
50
51
|
# - :data_file : Use a different file as process data definition.
|
51
52
|
# By default is `<name>/data.yaml`
|
53
|
+
# - :lib_name : Is the name of the library declaring the process.
|
52
54
|
#
|
53
55
|
# * *return*:
|
54
56
|
# - self with at least a process name and a path to it.
|
@@ -82,6 +84,8 @@ module Lorj
|
|
82
84
|
name, 'data.yaml'))
|
83
85
|
@data_file = data_file if data_file
|
84
86
|
|
87
|
+
@lib_name = props[:lib_name] if props.key?(:lib_name)
|
88
|
+
|
85
89
|
self
|
86
90
|
end
|
87
91
|
|
data/lib/lorj/version.rb
CHANGED
data/lib/lorj.rb
CHANGED
@@ -82,7 +82,7 @@ module Lorj
|
|
82
82
|
# Internally used with raise.
|
83
83
|
# Used to identify the error origin, while an error is thrown.
|
84
84
|
class PrcError < RuntimeError
|
85
|
-
attr_reader :
|
85
|
+
attr_reader :lorj_message
|
86
86
|
|
87
87
|
def initialize(message = nil)
|
88
88
|
@lorj_message = message
|
data/lib/prc.rb
CHANGED
@@ -97,6 +97,10 @@ require 'logger'
|
|
97
97
|
#
|
98
98
|
# Model loaded.
|
99
99
|
#
|
100
|
+
# - PrcLib.processes
|
101
|
+
#
|
102
|
+
# Processes loaded.
|
103
|
+
#
|
100
104
|
# - PrcLib.log_file
|
101
105
|
#
|
102
106
|
# Initialize a log file name (relative or absolute path) instead of default
|
@@ -148,7 +152,10 @@ module PrcLib
|
|
148
152
|
rescue => e
|
149
153
|
fatal_error(1, e.message)
|
150
154
|
end
|
155
|
+
end
|
151
156
|
|
157
|
+
# Defines module parameters.
|
158
|
+
module PrcLib
|
152
159
|
# Define module data for lorj library configuration
|
153
160
|
class << self
|
154
161
|
attr_accessor :log, :core_level
|
@@ -226,7 +233,7 @@ module PrcLib
|
|
226
233
|
end
|
227
234
|
end
|
228
235
|
|
229
|
-
# TODO: Low. Be able to support multiple model.
|
236
|
+
# TODO: Low. Be able to support multiple model loaded.
|
230
237
|
|
231
238
|
# Lorj::Model object access.
|
232
239
|
# If the object doesn't exist, it will be created
|
@@ -235,6 +242,14 @@ module PrcLib
|
|
235
242
|
@model
|
236
243
|
end
|
237
244
|
|
245
|
+
# TODO: Low. Be able to support multiple processes loaded.
|
246
|
+
|
247
|
+
# PrcLib.processes
|
248
|
+
def processes(p = nil)
|
249
|
+
@processes = p unless p.nil?
|
250
|
+
@processes
|
251
|
+
end
|
252
|
+
|
238
253
|
# TODO: Support for several defaults, depending on controllers loaded.
|
239
254
|
|
240
255
|
# Attribute app_defaults
|
@@ -129,7 +129,8 @@ describe 'Lorj::Process,' do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'can declare a module process' do
|
132
|
-
expect(Lorj.declare_process('mock', @process_path
|
132
|
+
expect(Lorj.declare_process('mock', @process_path,
|
133
|
+
:lib_name => 'lorj')).to be
|
133
134
|
end
|
134
135
|
|
135
136
|
it 'kept module in Lorj.processes' do
|
@@ -138,14 +139,19 @@ describe 'Lorj::Process,' do
|
|
138
139
|
end
|
139
140
|
|
140
141
|
it 'Lorj.declare_process, can declare several module processes' do
|
141
|
-
expect(Lorj.declare_process('mock', @process_path
|
142
|
-
|
143
|
-
expect(Lorj.declare_process(
|
142
|
+
expect(Lorj.declare_process('mock', @process_path,
|
143
|
+
:lib_name => 'lorj')).to be
|
144
|
+
expect(Lorj.declare_process(:mock2, @process_path,
|
145
|
+
:lib_name => 'lorj')).to be
|
146
|
+
expect(Lorj.declare_process('mock3', @process_path,
|
147
|
+
:lib_name => 'lorj')).to equal(nil)
|
144
148
|
end
|
145
149
|
|
146
150
|
it 'become empty, if name or process_path are incorrect' do
|
147
|
-
expect(Lorj.declare_process(nil, @process_path
|
148
|
-
|
151
|
+
expect(Lorj.declare_process(nil, @process_path,
|
152
|
+
:lib_name => 'lorj')).to equal(nil)
|
153
|
+
expect(Lorj.declare_process('mock', nil,
|
154
|
+
:lib_name => 'lorj')).to equal(nil)
|
149
155
|
end
|
150
156
|
|
151
157
|
it 'all kept module processes in Lorj.processes not duplicated.' do
|
data/spec/22_lorj_core_spec.rb
CHANGED
@@ -39,8 +39,9 @@ require 'spec_helper'
|
|
39
39
|
describe 'Lorj::Core,' do
|
40
40
|
context 'Using lorj-spec process, ' do
|
41
41
|
process_path = File.expand_path(File.join(app_path, '..', 'lorj-spec'))
|
42
|
-
Lorj.declare_process('mock', process_path)
|
42
|
+
Lorj.declare_process('mock', process_path, :lib_name => 'lorj')
|
43
43
|
Lorj.declare_process('mock2', process_path,
|
44
|
+
:lib_name => 'lorj',
|
44
45
|
:controllers_path => File.join(process_path,
|
45
46
|
'providers_extra'))
|
46
47
|
end
|
@@ -54,11 +54,8 @@ describe 'Internal BaseDefinition features' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# Internal function to test.
|
57
|
-
def_internal '_new_encrypt_key'
|
58
57
|
def_internal '_get_encrypt_key'
|
59
58
|
def_internal '_get_encrypted_value_hidden'
|
60
|
-
def_internal '_get_encrypted_value'
|
61
|
-
def_internal '_encrypt_value'
|
62
59
|
def_internal '_account_map'
|
63
60
|
end
|
64
61
|
|
@@ -73,8 +70,8 @@ describe 'Internal BaseDefinition features' do
|
|
73
70
|
File.delete(@key_file) if File.exist?(@key_file)
|
74
71
|
end
|
75
72
|
|
76
|
-
it '
|
77
|
-
ret =
|
73
|
+
it 'Lorj::SSLCrypt.new_encrypt_key return a new entr hash' do
|
74
|
+
ret = Lorj::SSLCrypt.new_encrypt_key
|
78
75
|
expect(ret.class).to equal(Hash)
|
79
76
|
expect(ret.keys.sort).to eq([:key, :salt, :iv].sort)
|
80
77
|
expect(ret[:key].class).to equal(String)
|
@@ -93,21 +90,21 @@ describe 'Internal BaseDefinition features' do
|
|
93
90
|
expect(@spec_obj.spec_get_encrypt_key).to eq(ret)
|
94
91
|
end
|
95
92
|
|
96
|
-
it '
|
93
|
+
it 'Lorj::SSLCrypt.encrypt_value return a strict base64 data' do
|
97
94
|
to_enc = 'Data to encrypt'
|
98
95
|
entr = @spec_obj.spec_get_encrypt_key
|
99
|
-
ret =
|
96
|
+
ret = Lorj::SSLCrypt.encrypt_value(to_enc, entr)
|
100
97
|
|
101
98
|
expect(Base64.strict_decode64(ret).class).to eq(String)
|
102
|
-
expect(ret).to eq(
|
99
|
+
expect(ret).to eq(Lorj::SSLCrypt.encrypt_value(to_enc, entr))
|
103
100
|
end
|
104
101
|
|
105
|
-
it '
|
102
|
+
it 'Lorj::SSLCrypt.get_encrypted_value return is decryptable' do
|
106
103
|
to_enc = 'Data to encrypt'
|
107
104
|
entr = @spec_obj.spec_get_encrypt_key
|
108
|
-
ret =
|
105
|
+
ret = Lorj::SSLCrypt.encrypt_value(to_enc, entr)
|
109
106
|
|
110
|
-
expect(
|
107
|
+
expect(Lorj::SSLCrypt.get_encrypted_value(ret, entr,
|
111
108
|
'value')).to eq(to_enc)
|
112
109
|
end
|
113
110
|
|
@@ -115,7 +112,7 @@ describe 'Internal BaseDefinition features' do
|
|
115
112
|
'original value' do
|
116
113
|
to_enc = 'Data to encrypt'
|
117
114
|
entr = @spec_obj.spec_get_encrypt_key
|
118
|
-
ret =
|
115
|
+
ret = Lorj::SSLCrypt.encrypt_value(to_enc, entr)
|
119
116
|
hidden = @spec_obj.spec_get_encrypted_value_hidden('value', ret, entr)
|
120
117
|
|
121
118
|
expect(hidden.include?('*')).to equal(true)
|
@@ -55,8 +55,6 @@ describe 'Internal BaseDefinition features' do
|
|
55
55
|
|
56
56
|
# Internal function to test.
|
57
57
|
def_internal '_get_encrypt_key'
|
58
|
-
def_internal '_get_encrypted_value'
|
59
|
-
def_internal '_encrypt_value'
|
60
58
|
end
|
61
59
|
|
62
60
|
# Spec class for ImportExport feature spec
|
@@ -89,9 +87,10 @@ describe 'Internal BaseDefinition features' do
|
|
89
87
|
@spec_obj = ImportExportSpec.new(@config)
|
90
88
|
|
91
89
|
process_path = File.expand_path(File.join(app_path, '..', 'lorj-spec'))
|
92
|
-
Lorj.declare_process('mock', process_path)
|
90
|
+
Lorj.declare_process('mock', process_path, :lib_name => 'lorj')
|
93
91
|
|
94
|
-
@core = Lorj::Core.new(@config, [{ :process_module => :mock
|
92
|
+
@core = Lorj::Core.new(@config, [{ :process_module => :mock,
|
93
|
+
:controller_name => :mock }])
|
95
94
|
|
96
95
|
@key_file = File.join(PrcLib.pdata_path, '.key')
|
97
96
|
@crypt = BaseDefinitionSpec.new
|
@@ -110,14 +109,20 @@ describe 'Internal BaseDefinition features' do
|
|
110
109
|
expect(@spec_obj.spec_account_map['credentials#key']).to eq({})
|
111
110
|
end
|
112
111
|
|
113
|
-
it 'account_export() returns valid [entr,
|
112
|
+
it 'account_export() returns valid [entr, export_dat]' do
|
114
113
|
export = @spec_obj.account_export
|
115
114
|
expect(export.class).to equal(Array)
|
116
|
-
entr,
|
117
|
-
|
118
|
-
|
119
|
-
expect(
|
120
|
-
|
115
|
+
entr, export_dat = export
|
116
|
+
export_dat = YAML.load(export_dat)
|
117
|
+
expect(export_dat.key?(:enc_data)).to equal(true)
|
118
|
+
expect(export_dat.key?(:processes)).to equal(true)
|
119
|
+
expect(export_dat[:processes].class).to equal(Array)
|
120
|
+
expect(export_dat[:processes][0].key?(:process_module)).to equal(true)
|
121
|
+
expect(export_dat[:processes][0].key?(:lib_name)).to equal(true)
|
122
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
123
|
+
entr, 'data encrypted')
|
124
|
+
expect(dat_decrypted.class).to equal(String)
|
125
|
+
data = YAML.load(dat_decrypted)
|
121
126
|
expect(data.rh_exist?(:account, :name)).to equal(true)
|
122
127
|
expect(data.rh_get(:account, :name)).to eq('test')
|
123
128
|
expect(data.rh_exist?(:credentials, :keypair_name)).to equal(true)
|
@@ -127,30 +132,33 @@ describe 'Internal BaseDefinition features' do
|
|
127
132
|
end
|
128
133
|
|
129
134
|
it 'account_export(nil, false) returns account@name and credentials#key' do
|
130
|
-
entr,
|
131
|
-
|
132
|
-
|
133
|
-
|
135
|
+
entr, export_dat = @spec_obj.account_export(nil, false)
|
136
|
+
export_dat = YAML.load(export_dat)
|
137
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
138
|
+
entr, 'data encrypted')
|
139
|
+
data = YAML.load(dat_decrypted)
|
134
140
|
expect(data.rh_exist?(:account, :name)).to equal(false)
|
135
141
|
expect(data.rh_exist?(:credentials, :key)).to equal(true)
|
136
142
|
end
|
137
143
|
|
138
144
|
it 'account_export(nil, false, false) returns "runtime" keypair_name'\
|
139
145
|
' value' do
|
140
|
-
entr,
|
141
|
-
|
142
|
-
|
143
|
-
|
146
|
+
entr, export_dat = @spec_obj.account_export(nil, false, false)
|
147
|
+
export_dat = YAML.load(export_dat)
|
148
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
149
|
+
entr, 'data encrypted')
|
150
|
+
data = YAML.load(dat_decrypted)
|
144
151
|
expect(data.rh_exist?(:credentials, :keypair_name)).to equal(true)
|
145
152
|
expect(data.rh_get(:credentials, :keypair_name)).to eq('another_key')
|
146
153
|
end
|
147
154
|
|
148
155
|
it 'account_export({"credentials#key" => {}}) returns key, '\
|
149
156
|
'name & provider' do
|
150
|
-
entr,
|
151
|
-
|
152
|
-
|
153
|
-
|
157
|
+
entr, export_dat = @spec_obj.account_export('credentials#key' => {})
|
158
|
+
export_dat = YAML.load(export_dat)
|
159
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
160
|
+
entr, 'data encrypted')
|
161
|
+
data = YAML.load(dat_decrypted)
|
154
162
|
expect(data.rh_exist?(:credentials, :keypair_name)).to equal(false)
|
155
163
|
expect(data.rh_exist?(:credentials, :key)).to equal(true)
|
156
164
|
expect(data.rh_exist?(:account, :name)).to equal(true)
|
@@ -159,24 +167,39 @@ describe 'Internal BaseDefinition features' do
|
|
159
167
|
it 'account_export({"credentials#key" => {:keys => [:server, :key]}})'\
|
160
168
|
' returns ' do
|
161
169
|
map = { 'credentials#key' => { :keys => [:server, :key] } }
|
162
|
-
entr,
|
163
|
-
|
164
|
-
|
165
|
-
|
170
|
+
entr, export_dat = @spec_obj.account_export(map)
|
171
|
+
export_dat = YAML.load(export_dat)
|
172
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
173
|
+
entr, 'data encrypted')
|
174
|
+
data = YAML.load(dat_decrypted)
|
166
175
|
expect(data.rh_exist?(:credentials, :key)).to equal(false)
|
167
176
|
expect(data.rh_exist?(:server, :key)).to equal(true)
|
168
177
|
expect(data.rh_exist?(:account, :name)).to equal(true)
|
169
178
|
end
|
170
179
|
|
171
|
-
it '
|
172
|
-
entr,
|
180
|
+
it 'account_data_import(data) update the "account layer"' do
|
181
|
+
entr, export_dat = @spec_obj.account_export
|
182
|
+
export_dat = YAML.load(export_dat)
|
173
183
|
@config.ac_erase
|
174
|
-
|
175
|
-
|
184
|
+
dat_decrypted = Lorj::SSLCrypt.get_encrypted_value(export_dat[:enc_data],
|
185
|
+
entr, 'data encrypted')
|
186
|
+
data = YAML.load(dat_decrypted)
|
187
|
+
res = @spec_obj.account_data_import(data)
|
188
|
+
expect(res.class).to equal(Hash)
|
176
189
|
expect(@config['account#name']).to eq('test')
|
177
190
|
expect(@config[:keypair_name]).to eq('another_key')
|
178
191
|
expect(@config.get(:keypair_name, nil,
|
179
192
|
:name => 'account')).to eq('mykey')
|
180
193
|
end
|
194
|
+
|
195
|
+
it 'Lorj.account_import(entr, enc_hash) update the "account layer"' do
|
196
|
+
entr, export_dat = @spec_obj.account_export
|
197
|
+
core = Lorj.account_import(entr, export_dat)
|
198
|
+
expect(core).to be
|
199
|
+
expect(core.config['account#name']).to eq('test')
|
200
|
+
expect(core.config[:keypair_name]).to eq('mykey')
|
201
|
+
expect(core.config.get(:keypair_name, nil,
|
202
|
+
:name => 'account')).to eq('mykey')
|
203
|
+
end
|
181
204
|
end
|
182
205
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -86,3 +86,29 @@ module Lorj
|
|
86
86
|
a
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
RSpec.configure do |config|
|
91
|
+
config.before(:all, &:silence_output)
|
92
|
+
config.after(:all, &:enable_output)
|
93
|
+
end
|
94
|
+
|
95
|
+
public
|
96
|
+
|
97
|
+
# Redirects stderr and stout to /dev/null.txt
|
98
|
+
def silence_output
|
99
|
+
# Store the original stderr and stdout in order to restore them later
|
100
|
+
@original_stderr = $stderr
|
101
|
+
@original_stdout = $stdout
|
102
|
+
|
103
|
+
# Redirect stderr and stdout
|
104
|
+
$stderr = File.open(File.join('', 'dev', 'null'), 'w')
|
105
|
+
$stdout = File.open(File.join('', 'dev', 'null'), 'w')
|
106
|
+
end
|
107
|
+
|
108
|
+
# Replace stderr and stdout so anything else is output correctly
|
109
|
+
def enable_output
|
110
|
+
$stderr = @original_stderr
|
111
|
+
$stdout = @original_stdout
|
112
|
+
@original_stderr = nil
|
113
|
+
@original_stdout = nil
|
114
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- forj team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|