"ddos challenge" style script #4
1 changed files with 3 additions and 9 deletions
|
|
@ -7,11 +7,8 @@ local resty_string = require "resty.string"
|
|||
|
||||
local function generateToken()
|
||||
-- Generate a cryptographically strong random token
|
||||
local strong_random = resty_random.bytes(16, true)
|
||||
while strong_random == nil do
|
||||
strong_random = resty_random.bytes(16, true)
|
||||
end
|
||||
return resty_string.to_hex(strong_random)
|
||||
-- Uses RAND_pseudo_bytes which is secure and won't fail
|
||||
return resty_string.to_hex(resty_random.bytes(16))
|
||||
end
|
||||
|
||||
local function getCookieValue(cookie_header, cookie_name)
|
||||
|
|
@ -159,10 +156,7 @@ end
|
|||
|
||||
local function serveQuestionChallenge(original_uri, state)
|
||||
-- Select a random question
|
||||
local random_byte = resty_random.bytes(1, true)
|
||||
while random_byte == nil do
|
||||
random_byte = resty_random.bytes(1, true)
|
||||
end
|
||||
local random_byte = resty_random.bytes(1)
|
||||
local q_idx = (string.byte(random_byte) % #QUESTIONS) + 1
|
||||
local question = QUESTIONS[q_idx]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue