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-3572
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`rusty-jwt-tools` is upgraded to version 0.5.0
22 changes: 15 additions & 7 deletions libs/jwt-tools/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ main :: IO ()
main = hspec $ do
describe "generateDpopToken FFI when passing valid inputs" $ do
it "should return an access token" $ do
-- FUTUREWORK(leif): fix this test, we need new valid test data,
-- this test exists mainly for debugging purposes
-- a functionality test is also coverd in the integration tests in services/brig/test/integration/API/User/Client.hs (`testCreateAccessToken`)
pending
actual <- runExceptT $ generateDpopToken proof uid cid domain nonce uri method maxSkewSecs expires now pem
print actual
isRight actual `shouldBe` True
describe "generateDpopToken FFI when passing a wrong nonce value" $ do
it "should return BackendNonceMismatchError" $ do
-- FUTUREWORK(leif): fix this test, we need new valid test data,
-- this test exists mainly for debugging purposes
-- a functionality test is also coverd in the integration tests in services/brig/test/integration/API/User/Client.hs (`testCreateAccessToken`)
pending
actual <- runExceptT $ generateDpopToken proof uid cid domain (Nonce "foobar") uri method maxSkewSecs expires now pem
actual `shouldBe` Left BackendNonceMismatchError
describe "toResult" $ do
Expand Down Expand Up @@ -73,16 +81,16 @@ main = hspec $ do
toResult Nothing Nothing `shouldBe` Left UnknownError
where
token = ""
proof = Proof "eyJhbGciOiJFZERTQSIsInR5cCI6ImRwb3Arand0IiwiandrIjp7Imt0eSI6Ik9LUCIsImNydiI6IkVkMjU1MTkiLCJ4IjoidUhNR0paWllUbU9zOEdiaTdaRUJLT255TnJYYnJzNTI1dE1QQUZoYjBzbyJ9fQ.eyJpYXQiOjE2Nzg4MDUyNTgsImV4cCI6MjA4ODc3MzI1OCwibmJmIjoxNjc4ODA1MjU4LCJzdWIiOiJp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xODk2MjZlYWUwMTExZC9hY2Nlc3MtdG9rZW4iLCJjaGFsIjoiMkxLbEFWMjR2VGtIMHlaaFdacEZrT01mSEE1d3lGQkgifQ.FW5i40CvndSSo3wQdA1DMUkGRmxk86cORAllwC2PCejVuk7TsdZuIKuJZFVa1VTJKWwNCPqPZ05Gsxxeh1DiDA"
uid = UserId "206f58bf-3b96-4082-9469-1935d85e4221"
cid = ClientId 10239098846720299293
domain = Domain "wire.com"
nonce = Nonce "c0tEcm9CT0M4MzJSN3F4d0FHWExLb1RnZ045SzlHWnM"
uri = Uri "https://wire.example.com/clients/8963027069877103526/access-token"
nonce = Nonce "GAq4nRj9RYSsRxh9Xu1amA"
uri = Uri "https://elna.wire.link/clients/10239098846720299293/access-token"
method = POST
maxSkewSecs = MaxSkewSecs 5
now = NowEpoch 5435234232
expires = ExpiryEpoch $ 2136351646
now = NowEpoch 360
expires = ExpiryEpoch 2136351646
pem =
PemBundle $
"-----BEGIN PRIVATE KEY-----\n\
Expand Down
7 changes: 6 additions & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,20 @@ let
'';
};

sources = import ./sources.nix;
pkgsCargo = import sources.nixpkgs-cargo {};
in

self: super: {

cryptobox = self.callPackage ./pkgs/cryptobox { };
zauth = self.callPackage ./pkgs/zauth { };
mls-test-cli = self.callPackage ./pkgs/mls-test-cli { };

# Named like this so cabal2nix can find it
rusty_jwt_tools_ffi = self.callPackage ./pkgs/rusty_jwt_tools_ffi { };
rusty_jwt_tools_ffi = self.callPackage ./pkgs/rusty_jwt_tools_ffi {
inherit (pkgsCargo) rustPlatform;
};

nginxModules = super.nginxModules // {
zauth = {
Expand Down
6 changes: 3 additions & 3 deletions nix/pkgs/rusty_jwt_tools_ffi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
}:

let
version = "0.3.4";
version = "0.5.0";
src = fetchFromGitHub {
owner = "wireapp";
repo = "rusty-jwt-tools";
rev = "fc4569c5b84d00a5cc8fc77b450714a5261cd3d9";
sha256 = "sha256-cZffVKfH0FzA4Eo7YVxivT3JWTwz9uu1HWhPVlvbYqM=";
rev = "6704e08376bb49168133d8f4ce66155adeb6bfb0";
sha256 = "sha256-ocmeFXjU3psCO+hpDuEAIzYIm4QzP+jHJR/V8yyw6Lw=";
};
cargoLockFile = builtins.toFile "cargo.lock" (builtins.readFile "${src}/ffi/Cargo.lock");

Expand Down
12 changes: 12 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,17 @@
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/402cc3633cc60dfc50378197305c984518b30773.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-cargo": {
"branch": "nixpkgs-unstable",
"description": "Nix Packages collection",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "efd23a1c9ae8c574e2ca923c2b2dc336797f4cc4",
"sha256": "0pb1dgdgfsnsngw2ci807wln2jnlsha4zkm1y14x497qbw4izir3",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/efd23a1c9ae8c574e2ca923c2b2dc336797f4cc4.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
1 change: 0 additions & 1 deletion services/brig/brig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ executable brig-integration
, attoparsec
, base
, base16-bytestring
, base64-bytestring
, bilge
, bloodhound
, brig
Expand Down
1 change: 0 additions & 1 deletion services/brig/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ mkDerivation {
attoparsec
base
base16-bytestring
base64-bytestring
bilge
bloodhound
brig-types
Expand Down
14 changes: 8 additions & 6 deletions services/brig/test/integration/API/User/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Data.Aeson hiding (json)
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as M
import Data.Aeson.Lens
import Data.ByteString.Base64.URL qualified as B64
import Data.ByteString.Conversion
import Data.Coerce (coerce)
import Data.Default
Expand All @@ -52,10 +51,10 @@ import Data.Nonce (isValidBase64UrlEncodedUUID)
import Data.Qualified (Qualified (..))
import Data.Range (unsafeRange)
import Data.Set qualified as Set
import Data.Text (replace)
import Data.Text.Ascii (AsciiChars (validate))
import Data.Text.Ascii (AsciiChars (validate), encodeBase64UrlUnpadded, toText)
import Data.Time (addUTCTime)
import Data.Time.Clock.POSIX
import Data.UUID (toByteString)
import Data.Vector qualified as Vec
import Imports
import Network.Wai.Utilities.Error qualified as Error
Expand Down Expand Up @@ -1424,22 +1423,25 @@ testCreateAccessToken opts n brig = do
let localDomain = opts ^. Opt.optionSettings & Opt.setFederationDomain
u <- randomUser brig
let uid = userId u
-- convert the user Id into 16 octets of binary and then base64url
let uidBS = Data.UUID.toByteString (toUUID uid)
let uidB64 = encodeBase64UrlUnpadded (cs uidBS)
let email = fromMaybe (error "invalid email") $ userEmail u
rs <-
login n (defEmailLogin email) PersistentCookie
<!! const 200 === statusCode
let t = decodeToken rs
let uidb64 = B64.encodeUnpadded $ cs $ replace "-" "" $ cs (toByteString' uid)
cid <- createClientForUser brig uid
nonceResponse <- Util.headNonce brig uid cid <!! const 200 === statusCode
let nonceBs = cs $ fromMaybe (error "invalid nonce") $ getHeader "Replay-Nonce" nonceResponse
now <- liftIO $ posixSecondsToUTCTime . fromInteger <$> (floor <$> getPOSIXTime)
let clientIdentity = cs $ "im:wireapp=" <> uidb64 <> "/" <> toByteString' cid <> "@" <> toByteString' localDomain
let clientIdentity = cs $ "im:wireapp=" <> cs (toText uidB64) <> "/" <> toByteString' cid <> "@" <> toByteString' localDomain
let httpsUrl = cs $ "https://" <> toByteString' localDomain <> "/clients/" <> toByteString' cid <> "/access-token"
let expClaim = NumericDate (addUTCTime 10 now)
let claimsSet' =
emptyClaimsSet
& claimIat ?~ NumericDate now
& claimExp ?~ NumericDate (addUTCTime 10 now)
& claimExp ?~ expClaim
& claimNbf ?~ NumericDate now
& claimSub ?~ fromMaybe (error "invalid sub claim") ((clientIdentity :: Text) ^? stringOrUri)
& claimJti ?~ "6fc59e7f-b666-4ffc-b738-4f4760c884ca"
Expand Down