Skip to content

Commit

Permalink
mutex for mbedtls
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolau Leal Werneck committed Jul 8, 2022
1 parent 035a5ff commit 6bbc07b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/session.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module session
export GoogleSession, authorize

import Base: string, print, show
using Dates, Base64
using Dates, Base64

#using Requests
using HTTP, HTTP.Messages
using HTTP, HTTP.Messages

import JSON
import MbedTLS
Expand All @@ -18,14 +18,20 @@ using ..error
using ..credentials
using ..root

global mbedtlslock = ReentrantLock()
"""
SHA256withRSA(message, key)
Sign message using private key with RSASSA-PKCS1-V1_5-SIGN algorithm.
"""
SHA256withRSA(message, key::MbedTLS.PKContext) = MbedTLS.sign(key, MbedTLS.MD_SHA256,
MbedTLS.digest(MbedTLS.MD_SHA256, message), MbedTLS.MersenneTwister(0)
)
function SHA256withRSA(message, key::MbedTLS.PKContext)
lock(mbedtlslock)
output = MbedTLS.sign(key, MbedTLS.MD_SHA256,
MbedTLS.digest(MbedTLS.MD_SHA256, message), MbedTLS.MersenneTwister(0)
)
unlock(mbedtlslock)
output
end

"""
GoogleSession(...)
Expand Down Expand Up @@ -141,7 +147,7 @@ function JWS(credentials::JSONCredentials, claimset::JWTClaimSet, header::JWTHea
"$payload.$signature"
end

function token(credentials::JSONCredentials,
function token(credentials::JSONCredentials,
scopes::AbstractVector{<: AbstractString})
# construct claim-set from service account email and requested scopes
claimset = JWTClaimSet(credentials.client_email, scopes)
Expand Down

0 comments on commit 6bbc07b

Please sign in to comment.