Re-implemented #generate_id in Core::Main::Crypto.

This is a better home for it since that is where other OpenSSL
crypto/token generator methods reside.
This commit is contained in:
soh_cah_toa
2014-04-23 11:41:11 -04:00
parent 861d66207d
commit 007f6302df
2 changed files with 18 additions and 8 deletions

View File

@@ -39,6 +39,23 @@ module Core
config.set('beef.api_token', token)
token
end
# Generates a unique identifier for DNS rules.
#
# @return [String] 8-character hex identifier
def self.dns_rule_id
id = nil
length = 4
begin
id = OpenSSL::Random.random_bytes(length).unpack('H*')[0]
BeEF::Core::Models::Dns::Rule.each { |rule| throw StandardError if id == rule.id }
rescue StandardError
retry
end
id.to_s
end
end
end

View File

@@ -23,7 +23,7 @@ module BeEF
# Hooks the model's "save" event. Generates a rule identifier and callback.
before :save do |rule|
rule.callback = validate_response(rule.resource, rule.response)
rule.id = generate_id
rule.id = BeEF::Core::Crypto.dns_rule_id
end
private
@@ -37,13 +37,6 @@ module BeEF
"t.respond!('1.1.1.1')"
end
# Generates a unique identifier for use as a primary key.
#
# @return [String] 8-character hex identifier
def generate_id
'42'
end
end
end