lib/client.rb in navi_client-1.2.3 vs lib/client.rb in navi_client-1.2.4
- old
+ new
@@ -8,10 +8,11 @@
require "logger"
require "httparty"
require "http_service/naviai"
+require 'openssl'
module Client
def logger
@logger
end
@@ -113,10 +114,34 @@
save(meta, "meta/#{custom_uid}")
end
def encrypt(data)
- Base64.encode64(data)
+ cipher = OpenSSL::Cipher::AES.new(256, :CFB)
+ cipher.encrypt
+
+ yml_config = config
+
+ key_iv_exists = (yml_config['key'] && yml_config['iv']) ? (!yml_config['key'].empty? && !yml_config['iv'].empty? ) : false
+
+ if key_iv_exists
+ # this condition must be true for cloud version
+ cipher.key = Base64.decode64(File.read(yml_config['key']))
+ cipher.iv = Base64.decode64(File.read(yml_config['iv']))
+ else
+ cipher.key = key = cipher.random_key
+ cipher.iv = iv = cipher.random_iv
+
+ key_path, iv_path = save_aes_key_iv(key, iv)
+
+ yml_config['key'] = key_path
+ yml_config['iv'] = iv_path
+
+ update_config(yml_config)
+ end
+
+ encrypted = cipher.update(data)
+ Base64.encode64(encrypted)
end
def time_now
Time.now.utc.iso8601(3)
end