From 7d728d02dea1430005ec9a24c20dd48ffa2c8efa Mon Sep 17 00:00:00 2001 From: icebaker Date: Sat, 3 Jun 2023 20:33:53 -0300 Subject: security --- controllers/interfaces/cli.rb | 6 +++--- controllers/interfaces/eval.rb | 4 ---- controllers/security.rb | 10 +++++++++- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'controllers') diff --git a/controllers/interfaces/cli.rb b/controllers/interfaces/cli.rb index 5967c75..ae066cd 100644 --- a/controllers/interfaces/cli.rb +++ b/controllers/interfaces/cli.rb @@ -13,11 +13,11 @@ module NanoBot puts NanoBot::GEM[:version] exit when 'security' - result = NanoBot.security + result = NanoBot.security.check if result[:encryption] puts "\n✅ Encryption is enabled and properly working." - puts ' It means that your data is cyrptographed stored in your disk.' + puts ' This means that your data is stored in an encrypted format on your disk.' else puts "\n❌ Encryption is not being utilized to store your content." puts ' This means that your data can be easily read because it is stored in plaintext.' @@ -27,7 +27,7 @@ module NanoBot puts "\n✅ A password is being used for the encrypted content." puts ' This means that only those who possess the password can decrypt your data.' else - puts "\n❌ No password is being used for the encrypted content." + puts "\n❌ No custom password is being used for the encrypted content." puts ' This means that anyone can easily decrypt your data.' end diff --git a/controllers/interfaces/eval.rb b/controllers/interfaces/eval.rb index 5f472ad..9613b28 100644 --- a/controllers/interfaces/eval.rb +++ b/controllers/interfaces/eval.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require 'pry' -require 'rainbow' - -require_relative '../../logic/helpers/hash' require_relative '../../logic/cartridge/affixes' module NanoBot diff --git a/controllers/security.rb b/controllers/security.rb index 94cc9ff..8f066a5 100644 --- a/controllers/security.rb +++ b/controllers/security.rb @@ -5,12 +5,20 @@ require_relative '../components/crypto' module NanoBot module Controllers module Security + def self.decrypt(content) + Components::Crypto.decrypt(content) + end + def self.check password = ENV.fetch('NANO_BOTS_ENCRYPTION_PASSWORD', nil) password = 'UNSAFE' unless password && password != '' { - encryption: Components::Crypto.encrypt('SAFE') != 'SAFE', + encryption: ( + Components::Crypto.encrypt('SAFE') != 'SAFE' && + Components::Crypto.encrypt('SAFE') != Components::Crypto.encrypt('SAFE') && + Components::Crypto.decrypt(Components::Crypto.encrypt('SAFE')) == 'SAFE' + ), password: password != 'UNSAFE' } end -- cgit v1.2.3