on master help sign in
4 files changed+43−5
since splitsnapshots
unifiedsplit
backend/BW/Logic.purs+32−2 backend/Storage.purs+7−1 packages.dhall+2−2 spago.dhall+2
backend/BW/Logic.purs+32−2
@@ -15,6 +15,7 @@ import Data.JNullable as JNullable
1515import Data.JOpt (JOpt(..), fromJOpt)
1616import Data.Maybe (Maybe(..), fromMaybe, maybe)
1717import Data.Newtype (class Newtype, unwrap, wrap)
18+import Data.Number.Format as Number
1819import Data.String as String
1920import Data.SymmetricCryptoKey (SymmetricCryptoKey)
2021import Data.SymmetricCryptoKey as SymmetricCryptoKey
@@ -26,10 +27,14 @@ import Effect.Aff.Class (class MonadAff, liftAff)
2627import Effect.Class (liftEffect)
2728import Effect.Exception (error)
2829import Effect.Exception as Exc
30+import Effect.Random (random)
31+import Localstorage as Storage
2932import Run (Run)
3033import Run.Reader (Reader, askAt)
34+import Storage (DeviceIDKey(..))
3135import Type.Prelude (Proxy(..))
3236import Untagged.Union (type (|+|))
37+import Web.Storage.Storage (Storage)
3338
3439-- | Creates the master key
3540makePreloginKey
@@ -96,6 +101,7 @@ getLogInRequestToken
96101 , crypto :: Reader CryptoService
97102 , effect :: Effect
98103 , aff :: Aff
104+ , storage :: Reader Storage
99105 | r
100106 )
101107 (IdentityCaptchaResponse |+| IdentityTwoFactorResponse |+| IdentityTokenResponse)
@@ -106,6 +112,8 @@ getLogInRequestToken
106112 , captchaResponse
107113 , secondFactor: Bridge.Cmd_Login_secondFactor_Maybe secondFactor
108114 } = do
115+ key <- makePreloginKey prelogin email password
116+ crypto <- askAt (Proxy :: _ "crypto")
109117 let
110118 twoFactor =
111119 maybe
@@ -117,7 +125,11 @@ getLogInRequestToken
117125 x { provider = bridgeToSecondFactorType provider }
118126 )
119127 secondFactor
120− StringHash hashedPassword <- bwPasswordStringHash prelogin email password
128+ _localHashedPassword <-
129+ liftPromise
130+ $ runFn3 crypto.hashPassword password key (nullify hashPurposeLocalAuthorization)
131+ StringHash hashedPassword <- liftPromise $ runFn3 crypto.hashPassword password key jnull
132+ deviceId <- getDeviceID
121133 api :: ApiService <- askAt (Proxy :: _ "api")
122134 liftPromise
123135 $ api.postIdentityToken
@@ -128,7 +140,7 @@ getLogInRequestToken
128140 , device:
129141 { type: deviceTypeUnknownBrowser
130142 , name: "Ubuntu Touch"
131− , identifier: "42"
143+ , identifier: deviceId
132144 , pushToken: jnull
133145 }
134146 }
@@ -480,3 +492,21 @@ encryptNullable
480492encryptNullable x = case unwrap x of
481493 Nothing -> pure jnull
482494 Just y -> nullify <$> encrypt y
495+
496+getDeviceID ::
497+ forall r.
498+ Run
499+ ( effect :: Effect
500+ , storage :: Reader Storage
501+ | r
502+ )
503+ String
504+getDeviceID = do
505+ storage <- askAt (Proxy :: _ "storage")
506+ maybeId <- liftEffect $ Storage.get storage DeviceIDKey
507+ case maybeId of
508+ Just id -> pure id
509+ Nothing -> do
510+ id <- map Number.toString $ liftEffect $ random
511+ liftEffect $ Storage.store storage DeviceIDKey id
512+ pure id
backend/Storage.purs+7−1
@@ -2,7 +2,7 @@ module Storage where
22
33import Prelude
44
5−import BW (Hash(..))
5+import BW (Hash)
66import BW.Types (IdentityTokenResponse, SyncResponse, PreloginResponse)
77import Localstorage (class StorageKey)
88
@@ -35,3 +35,9 @@ data MasterPasswordHashKey
3535
3636instance StorageKey MasterPasswordHashKey Hash where
3737 storageKey MasterPasswordHashKey = "master-password-hash"
38+
39+data DeviceIDKey
40+ = DeviceIDKey
41+
42+instance StorageKey DeviceIDKey String where
43+ storageKey DeviceIDKey = "device-uuid"
packages.dhall+2−2
@@ -99,8 +99,8 @@ in upstream
9999-------------------------------
100100-}
101101let upstream =
102− https://github.com/purescript/package-sets/releases/download/psc-0.15.2-20220706/packages.dhall
103− sha256:7a24ebdbacb2bfa27b2fc6ce3da96f048093d64e54369965a2a7b5d9892b6031
102+ https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220808/packages.dhall
103+ sha256:60eee64b04ca0013fae3e02a69fc3b176105c6baa2f31865c67cd5f881a412fd
104104
105105in upstream
106106 with argonaut-aeson-generic =
spago.dhall+2
@@ -35,8 +35,10 @@ to generate this file without the comments in this block.
3535 , "maybe"
3636 , "newtype"
3737 , "nullable"
38+ , "numbers"
3839 , "orders"
3940 , "prelude"
41+ , "random"
4042 , "refs"
4143 , "run"
4244 , "strings"