Skip to content

Commit

Permalink
do not initialize new MbedTLS objects at each authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored and Keno committed Jan 27, 2018
1 parent 42ef052 commit 38eb5f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/GitHub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ import HTTP,
MbedTLS,
HttpCommon # for deprecations

########
# init #
########

const ENTROPY = Ref{MbedTLS.Entropy}()
const RNG = Ref{MbedTLS.CtrDrbg}()

function __init__()
ENTROPY[] = MbedTLS.Entropy()
RNG[] = MbedTLS.CtrDrbg()
MbedTLS.seed!(RNG[], ENTROPY[])
end

#############
# Utilities #
#############
Expand Down
5 changes: 1 addition & 4 deletions src/utils/auth.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ function JWTAuth(app_id::Int, key::MbedTLS.PKContext; iat = now(Dates.UTC), exp_
"exp" => trunc(Int64, Dates.datetime2unix(iat+Dates.Minute(exp_mins))),
"iss" => app_id
))))
entropy = MbedTLS.Entropy()
rng = MbedTLS.CtrDrbg()
MbedTLS.seed!(rng, entropy)
signature = base64_to_base64url(base64encode(MbedTLS.sign(key, MbedTLS.MD_SHA256,
MbedTLS.digest(MbedTLS.MD_SHA256, string(algo,'.',data)), rng)))
MbedTLS.digest(MbedTLS.MD_SHA256, string(algo,'.',data)), RNG[])))
JWTAuth(string(algo,'.',data,'.',signature))
end

Expand Down

0 comments on commit 38eb5f9

Please sign in to comment.