Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5-internal/PR-3727
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed client ID conversion round trip
39 changes: 18 additions & 21 deletions services/brig/src/Brig/Effects/JwtTools.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Data.Nonce (Nonce)
import Data.PEMKeys
import Imports
import Network.HTTP.Types (StdMethod (..))
import Numeric (readHex)
import Polysemy
import Wire.API.MLS.Credential (ClientIdentity (..))
import Wire.API.MLS.Epoch (Epoch (..))
Expand Down Expand Up @@ -46,23 +45,21 @@ data JwtTools m a where
makeSem ''JwtTools

interpretJwtTools :: Member (Embed IO) r => Sem (JwtTools ': r) a -> Sem r a
interpretJwtTools = interpret $ \(GenerateDPoPAccessToken pr ci n uri method skew ex now pem) -> do
case readHex @Word64 (cs $ clientToText $ ciClient ci) of
[(parsedClientId, "")] ->
mapLeft RustError
<$> runExceptT
( DPoPAccessToken
<$> Jwt.generateDpopToken
(Jwt.Proof (toByteString' pr))
(Jwt.UserId (toByteString' (ciUser ci)))
(Jwt.ClientId parsedClientId)
(Jwt.Domain (toByteString' (ciDomain ci)))
(Jwt.Nonce (toByteString' n))
(Jwt.Uri (toByteString' uri))
method
(Jwt.MaxSkewSecs skew)
(Jwt.ExpiryEpoch (epochNumber ex))
(Jwt.NowEpoch (epochNumber now))
(Jwt.PemBundle (toByteString' pem))
)
_ -> pure $ Left ClientIdSyntaxError
interpretJwtTools = interpret $ \case
GenerateDPoPAccessToken pr ci n uri method skew ex now pem ->
mapLeft RustError
<$> runExceptT
( DPoPAccessToken
<$> Jwt.generateDpopToken
(Jwt.Proof (toByteString' pr))
(Jwt.UserId (toByteString' (ciUser ci)))
(Jwt.ClientId (clientToWord64 (ciClient ci)))
(Jwt.Domain (toByteString' (ciDomain ci)))
(Jwt.Nonce (toByteString' n))
(Jwt.Uri (toByteString' uri))
method
(Jwt.MaxSkewSecs skew)
(Jwt.ExpiryEpoch (epochNumber ex))
(Jwt.NowEpoch (epochNumber now))
(Jwt.PemBundle (toByteString' pem))
)