licensing

This commit is contained in:
Yan
2017-11-15 12:01:35 +06:30
parent 5ec45593de
commit 7c6153f16f
4 changed files with 58 additions and 95 deletions

View File

@@ -1,38 +0,0 @@
class AesCrypt
@cipher = ""
def initialize
@cipher = OpenSSL::Cipher::Cipher.new(ENV["cipher_type"])
end
private
def export_key(passphrase)
# We want a 256 bit key symetric key based on passphrase
digest = Digest::SHA256.new
key = digest.update(passphrase)
# key = digest.digest
ENV['aes_key'] = @cipher.key = key # stores the key in key, and also sets the generated key on the @cipher
ENV['aes_iv'] = @cipher.iv = @cipher.random_iv # stores the iv in iv, and also sets the generated iv on the @cipher
return @cipher.key, @cipher.iv
end
def encrypt(data)
cipher.encrypt
cipher.key = ENV["aes_key"]
cipher.iv = ENV["aes_iv"]
encrypted = cipher.update(data) + cipher.final
encrypted = Base64.encode64(encrypted)
return encrypted
end
def decrypt(data)
cipher.decrypt
cipher.key = ENV["aes_key"]
cipher.iv = ENV["aes_iv"]
# Start the decryption
decoded = Base64.decode64(data)
decrypted = cipher.update(decoded) + cipher.final
return decrypted
end
end

View File

@@ -13,7 +13,7 @@ class License
def initialize(server = "", lookup = "")
#this code is hard-code to reflect server mode - Very important.
self.server_mode = ENV["server_mode"]
self.server_mode = ENV["SERVER_MODE"]
if (server != "")
self.class.base_uri server
@@ -50,7 +50,6 @@ class License
##change the d/e key
# @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
@params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
response = self.class.get("/subdomain", @params)
@license = response.parsed_response
@@ -75,49 +74,49 @@ class License
end
def detail_with_local_file(lookup)
has_license = verify_license()
def detail_with_local_file()
has_license = true #verify_license()
if has_license
puts "VERIFIED"
end
if cache_license.nil?
##change the d/e key
@params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
# if cache_license.nil?
# ##change the d/e key
# @params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
response = self.class.get("/request_license", @params)
@license = response.parsed_response
# response = self.class.get("/request_license", @params)
# @license = response.parsed_response
if (@license["status"] == true)
# if (@license["status"] == true)
assign()
# assign()
Rails.logger.info "License - " + response.parsed_response.to_s
# Rails.logger.info "License - " + response.parsed_response.to_s
Redis.current do |conn|
##Remote - store the remote response in local redis cache
conn.set(cache_key, Marshal.dump(@license))
##ADD to List to remove later
conn.sadd("License:cache:keys", cache_key)
end
# Redis.current do |conn|
# ##Remote - store the remote response in local redis cache
# conn.set(cache_key, Marshal.dump(@license))
# ##ADD to List to remove later
# conn.sadd("License:cache:keys", cache_key)
# end
return true
end
# return true
# end
Rails.logger.info 'API License'
# Rails.logger.info 'API License'
else
@license = Marshal.load(cache_license) if cache_license
# else
# @license = Marshal.load(cache_license) if cache_license
Rails.logger.info 'Cache License'
# Rails.logger.info 'Cache License'
if (@license["status"] == true)
assign()
return true
end
end
return false
# if (@license["status"] == true)
# assign()
# return true
# end
# end
# return false
end
def detail
@@ -144,10 +143,13 @@ class License
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
if (@varified["status"])
check_expire_date
if (!check_expired(@varified["plan_next_renewal_date"]))
return true
end
else
delete_license_file
end
end
return false
end
def check_remote_license(license_key)
@@ -181,32 +183,32 @@ class License
#Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file.
def expired?
if (self.plan_next_renewal_date < Date.today)
def check_expired(renewal_date)
if (renewal_date < Date.today)
return true
else
return false
end
end
def self.check_license_file
return File.exist?("config/license.yml")
end
private
def check_license_file
return File.exist?("config/license.yml")
end
# read line by key for license file
def read_license(key)
decrypted_line = ""
if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line|
if line.include? (key)
decrypted_line_array = line.split(":")
decrypted_line = AESEncDec.decrypt(decrypted_line_array[1])
end
# read line by key for license file
def read_license(key)
decrypted_line = ""
if File.exist?("config/license.yml")
File.open("config/license.yml").each do |line|
if line.include? (key)
decrypted_line_array = line.split(":")
decrypted_line = AESCrypt.decrypt(decrypted_line_array[1])
end
end
end
end
private
def assign
# self.name = @license["name"]
# self.address_1 = @license["address_1"]