git-svn-id: https://beef.googlecode.com/svn/trunk@1046 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
46 lines
1.4 KiB
Ruby
46 lines
1.4 KiB
Ruby
#
|
|
# Copyright 2011 Wade Alcorn wade@bindshell.net
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
module BeEF
|
|
module Core
|
|
#
|
|
# This module provides crypto functionality
|
|
#
|
|
module Crypto
|
|
|
|
# the minimum length of the security token
|
|
TOKEN_MINIMUM_LENGTH = 15
|
|
|
|
#
|
|
# Generate a secure random token
|
|
#
|
|
# @param: {Integer} the length of the secure token
|
|
#
|
|
def self.secure_token(len = nil)
|
|
# get default length from config
|
|
config = BeEF::Core::Configuration.instance
|
|
token_length = len || config.get('beef.crypto_default_value_length').to_i
|
|
|
|
# type checking
|
|
raise Exception::TypeError, "Token length is less than the minimum length enforced by the framework: #{TOKEN_MINIMUM_LENGTH}" if (token_length < TOKEN_MINIMUM_LENGTH)
|
|
|
|
# return random hex string
|
|
return OpenSSL::Random.random_bytes(token_length).unpack("H*")[0]
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|