class Pnthr::Security
Everything lives in the security class for now
Attributes
cipher[RW]
request[RW]
Public Class Methods
new(id, secret, options = {})
click to toggle source
# File lib/pnthr.rb, line 20 def initialize(id, secret, options = {}) @cipher = OpenSSL::Cipher::AES.new(secret.length * 8, :CFB) options[:url] ||= 'https://pnthr-api.herokuapp.com/' options[:ssl] = options[:ssl].nil? ? true : options[:ssl] options[:iv] ||= Base64.encode64(rand.to_s)[0..15] @request = { url: options[:url], uri: URI.parse(options[:url]), id: id, iv: options[:iv], secret: secret, ssl: options[:ssl] } end
Public Instance Methods
cage(payload)
click to toggle source
Cage - Will make our payload without sending
# File lib/pnthr.rb, line 49 def cage(payload) Base64.encode64(encrypt(payload)).strip! + "-" + @request[:iv] end
decrypt(data, key = nil, iv = nil)
click to toggle source
Decrypt - Simple AES decryption
# File lib/pnthr.rb, line 85 def decrypt(data, key = nil, iv = nil) key ||= @request[:secret] iv ||= @request[:iv] @cipher.decrypt @cipher.key = key @cipher.iv = iv @cipher.update(data) end
encrypt(data, key = nil, iv = nil)
click to toggle source
Encrypt - Simple AES encryption
-
a variable length key is used for greatest flexibility
-
CFB is used
+ Needs HMAC
# File lib/pnthr.rb, line 71 def encrypt(data, key = nil, iv = nil) key ||= @request[:secret] iv ||= @request[:iv] @cipher.encrypt @cipher.key = key @cipher.iv = iv @cipher.update(data) end
release(payload, password)
click to toggle source
Release - Will fully decrypt a payload to raw text
# File lib/pnthr.rb, line 56 def release(payload, password) part = payload.split('-') level1 = decrypt(Base64.decode64(part[0]), @request[:secret], part[1]) decrypt(level1, Digest::MD5.hexdigest(password), part[1]) end
roar(payload)
click to toggle source
Encrypt the payload, makes the request and returns the response
# File lib/pnthr.rb, line 40 def roar(payload) https = Net::HTTP.new(@request[:uri].host, @request[:uri].port) https.use_ssl = @request[:ssl] https.post(@request[:uri].path, cage(payload), { 'pnthr' => @request[:id] }) end