public async Task InitAsync(Context context) { _userId = await _userService.GetUserIdAsync(); _appId = await _appIdService.GetAppIdAsync(); CrashManager.Register(context, HockeyAppId, this); }
public async Task InitAsync(BITHockeyManager manager) { _userId = await _userService.GetUserIdAsync(); _appId = await _appIdService.GetAppIdAsync(); manager.UserId = _userId; }
public async Task InitAsync() { _userId = await _userService.GetUserIdAsync(); _appId = await _appIdService.GetAppIdAsync(); var manager = BITHockeyManager.SharedHockeyManager; manager.Configure(HockeyAppId, this); manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend; manager.UserId = _userId; manager.Authenticator.AuthenticateInstallation(); manager.DisableMetricsManager = manager.DisableFeedbackManager = manager.DisableUpdateManager = true; manager.StartManager(); }
public async Task InitAsync() { _userId = await _stateService.GetActiveUserIdAsync(); _appId = await _appIdService.GetAppIdAsync(); AppCenter.Start(AppSecret, typeof(Crashes)); AppCenter.SetUserId(_userId); Crashes.GetErrorAttachments = (ErrorReport report) => { return(new ErrorAttachmentLog[] { ErrorAttachmentLog.AttachmentWithText(Description, "crshdesc.txt"), }); }; }
public async Task OnMessageAsync(JObject value, string deviceType) { Debug.WriteLine($"{TAG} OnMessageAsync called"); Resolve(); if (value == null) { return; } _showNotification = false; Debug.WriteLine($"{TAG} Message Arrived: {JsonConvert.SerializeObject(value)}"); NotificationResponse notification = null; if (deviceType == Device.Android) { notification = value.ToObject <NotificationResponse>(); } else { if (!value.TryGetValue("data", StringComparison.OrdinalIgnoreCase, out JToken dataToken) || dataToken == null) { return; } notification = dataToken.ToObject <NotificationResponse>(); } Debug.WriteLine($"{TAG} - Notification object created: t:{notification?.Type} - p:{notification?.Payload}"); var appId = await _appIdService.GetAppIdAsync(); if (notification?.Payload == null || notification.ContextId == appId) { return; } var myUserId = await _stateService.GetActiveUserIdAsync(); var isAuthenticated = await _stateService.IsAuthenticatedAsync(); switch (notification.Type) { case NotificationType.SyncCipherUpdate: case NotificationType.SyncCipherCreate: var cipherCreateUpdateMessage = JsonConvert.DeserializeObject <SyncCipherNotification>( notification.Payload); if (isAuthenticated && cipherCreateUpdateMessage.UserId == myUserId) { await _syncService.SyncUpsertCipherAsync(cipherCreateUpdateMessage, notification.Type == NotificationType.SyncCipherUpdate); } break; case NotificationType.SyncFolderUpdate: case NotificationType.SyncFolderCreate: var folderCreateUpdateMessage = JsonConvert.DeserializeObject <SyncFolderNotification>( notification.Payload); if (isAuthenticated && folderCreateUpdateMessage.UserId == myUserId) { await _syncService.SyncUpsertFolderAsync(folderCreateUpdateMessage, notification.Type == NotificationType.SyncFolderUpdate); } break; case NotificationType.SyncLoginDelete: case NotificationType.SyncCipherDelete: var loginDeleteMessage = JsonConvert.DeserializeObject <SyncCipherNotification>( notification.Payload); if (isAuthenticated && loginDeleteMessage.UserId == myUserId) { await _syncService.SyncDeleteCipherAsync(loginDeleteMessage); } break; case NotificationType.SyncFolderDelete: var folderDeleteMessage = JsonConvert.DeserializeObject <SyncFolderNotification>( notification.Payload); if (isAuthenticated && folderDeleteMessage.UserId == myUserId) { await _syncService.SyncDeleteFolderAsync(folderDeleteMessage); } break; case NotificationType.SyncCiphers: case NotificationType.SyncVault: case NotificationType.SyncSettings: if (isAuthenticated) { await _syncService.FullSyncAsync(false); } break; case NotificationType.SyncOrgKeys: if (isAuthenticated) { await _apiService.RefreshIdentityTokenAsync(); await _syncService.FullSyncAsync(true); } break; case NotificationType.LogOut: if (isAuthenticated) { _messagingService.Send("logout"); } break; default: break; } }
private async Task <AuthResult> LogInHelperAsync(string email, string hashedPassword, SymmetricCryptoKey key, TwoFactorProviderType?twoFactorProvider = null, string twoFactorToken = null, bool?remember = null) { var storedTwoFactorToken = await _tokenService.GetTwoFactorTokenAsync(email); var appId = await _appIdService.GetAppIdAsync(); var deviceRequest = new DeviceRequest(appId, _platformUtilsService); var request = new TokenRequest { Email = email, MasterPasswordHash = hashedPassword, Device = deviceRequest, Remember = false }; if (twoFactorToken != null && twoFactorProvider != null) { request.Provider = twoFactorProvider; request.Token = twoFactorToken; request.Remember = remember.GetValueOrDefault(); } else if (storedTwoFactorToken != null) { request.Provider = TwoFactorProviderType.Remember; request.Token = storedTwoFactorToken; } var response = await _apiService.PostIdentityTokenAsync(request); ClearState(); var result = new AuthResult { TwoFactor = response.Item2 != null }; if (result.TwoFactor) { // Two factor required. var twoFactorResponse = response.Item2; Email = email; MasterPasswordHash = hashedPassword; _key = _setCryptoKeys ? key : null; TwoFactorProvidersData = twoFactorResponse.TwoFactorProviders2; result.TwoFactorProviders = twoFactorResponse.TwoFactorProviders2; return(result); } var tokenResponse = response.Item1; if (tokenResponse.TwoFactorToken != null) { await _tokenService.SetTwoFactorTokenAsync(tokenResponse.TwoFactorToken, email); } #region cozy _tokenService.SetClientInfos(tokenResponse.ClientId, tokenResponse.RegistrationAccessToken); #endregion await _tokenService.SetTokensAsync(tokenResponse.AccessToken, tokenResponse.RefreshToken); await _userService.SetInformationAsync(_tokenService.GetUserId(), _tokenService.GetEmail(), _kdf.Value, _kdfIterations.Value); if (_setCryptoKeys) { await _cryptoService.SetKeyAsync(key); await _cryptoService.SetKeyHashAsync(hashedPassword); await _cryptoService.SetEncKeyAsync(tokenResponse.Key); // User doesn't have a key pair yet (old account), let's generate one for them. if (tokenResponse.PrivateKey == null) { try { var keyPair = await _cryptoService.MakeKeyPairAsync(); await _apiService.PostAccountKeysAsync(new KeysRequest { PublicKey = keyPair.Item1, EncryptedPrivateKey = keyPair.Item2.EncryptedString }); tokenResponse.PrivateKey = keyPair.Item2.EncryptedString; } catch { } } await _cryptoService.SetEncPrivateKeyAsync(tokenResponse.PrivateKey); } _lockService.FingerprintLocked = false; _messagingService.Send("loggedIn"); return(result); }
private async Task <AuthResult> LogInHelperAsync(string email, string hashedPassword, string localHashedPassword, string code, string codeVerifier, string redirectUrl, SymmetricCryptoKey key, TwoFactorProviderType?twoFactorProvider = null, string twoFactorToken = null, bool?remember = null, string captchaToken = null, string orgId = null) { var storedTwoFactorToken = await _tokenService.GetTwoFactorTokenAsync(email); var appId = await _appIdService.GetAppIdAsync(); var deviceRequest = new DeviceRequest(appId, _platformUtilsService); string[] emailPassword; string[] codeCodeVerifier; if (email != null && hashedPassword != null) { emailPassword = new[] { email, hashedPassword }; } else { emailPassword = null; } if (code != null && codeVerifier != null && redirectUrl != null) { codeCodeVerifier = new[] { code, codeVerifier, redirectUrl }; } else { codeCodeVerifier = null; } TokenRequest request; if (twoFactorToken != null && twoFactorProvider != null) { request = new TokenRequest(emailPassword, codeCodeVerifier, twoFactorProvider, twoFactorToken, remember, captchaToken, deviceRequest); } else if (storedTwoFactorToken != null) { request = new TokenRequest(emailPassword, codeCodeVerifier, TwoFactorProviderType.Remember, storedTwoFactorToken, false, captchaToken, deviceRequest); } else { request = new TokenRequest(emailPassword, codeCodeVerifier, null, null, false, captchaToken, deviceRequest); } var response = await _apiService.PostIdentityTokenAsync(request); ClearState(); var result = new AuthResult { TwoFactor = response.TwoFactorNeeded, CaptchaSiteKey = response.CaptchaResponse?.SiteKey }; if (result.CaptchaNeeded) { return(result); } if (result.TwoFactor) { // Two factor required. Email = email; MasterPasswordHash = hashedPassword; LocalMasterPasswordHash = localHashedPassword; Code = code; CodeVerifier = codeVerifier; SsoRedirectUrl = redirectUrl; _key = _setCryptoKeys ? key : null; TwoFactorProvidersData = response.TwoFactorResponse.TwoFactorProviders2; result.TwoFactorProviders = response.TwoFactorResponse.TwoFactorProviders2; CaptchaToken = response.TwoFactorResponse.CaptchaToken; return(result); } var tokenResponse = response.TokenResponse; result.ResetMasterPassword = tokenResponse.ResetMasterPassword; result.ForcePasswordReset = tokenResponse.ForcePasswordReset; if (tokenResponse.TwoFactorToken != null) { await _tokenService.SetTwoFactorTokenAsync(tokenResponse.TwoFactorToken, email); } await _tokenService.SetAccessTokenAsync(tokenResponse.AccessToken, true); await _stateService.AddAccountAsync( new Account( new Account.AccountProfile() { UserId = _tokenService.GetUserId(), Email = _tokenService.GetEmail(), Name = _tokenService.GetName(), KdfType = tokenResponse.Kdf, KdfIterations = tokenResponse.KdfIterations, HasPremiumPersonally = _tokenService.GetPremium(), }, new Account.AccountTokens() { AccessToken = tokenResponse.AccessToken, RefreshToken = tokenResponse.RefreshToken, } ) ); _messagingService.Send("accountAdded"); if (_setCryptoKeys) { if (key != null) { await _cryptoService.SetKeyAsync(key); } if (localHashedPassword != null) { await _cryptoService.SetKeyHashAsync(localHashedPassword); } if (code == null || tokenResponse.Key != null) { if (tokenResponse.KeyConnectorUrl != null) { await _keyConnectorService.GetAndSetKey(tokenResponse.KeyConnectorUrl); } await _cryptoService.SetEncKeyAsync(tokenResponse.Key); // User doesn't have a key pair yet (old account), let's generate one for them. if (tokenResponse.PrivateKey == null) { try { var keyPair = await _cryptoService.MakeKeyPairAsync(); await _apiService.PostAccountKeysAsync(new KeysRequest { PublicKey = keyPair.Item1, EncryptedPrivateKey = keyPair.Item2.EncryptedString }); tokenResponse.PrivateKey = keyPair.Item2.EncryptedString; } catch { } } await _cryptoService.SetEncPrivateKeyAsync(tokenResponse.PrivateKey); } else if (tokenResponse.KeyConnectorUrl != null) { // SSO Key Connector Onboarding var password = await _cryptoFunctionService.RandomBytesAsync(64); var k = await _cryptoService.MakeKeyAsync(Convert.ToBase64String(password), _tokenService.GetEmail(), tokenResponse.Kdf, tokenResponse.KdfIterations); var keyConnectorRequest = new KeyConnectorUserKeyRequest(k.EncKeyB64); await _cryptoService.SetKeyAsync(k); var encKey = await _cryptoService.MakeEncKeyAsync(k); await _cryptoService.SetEncKeyAsync(encKey.Item2.EncryptedString); var keyPair = await _cryptoService.MakeKeyPairAsync(); try { await _apiService.PostUserKeyToKeyConnector(tokenResponse.KeyConnectorUrl, keyConnectorRequest); } catch (Exception e) { throw new Exception("Unable to reach Key Connector", e); } var keys = new KeysRequest { PublicKey = keyPair.Item1, EncryptedPrivateKey = keyPair.Item2.EncryptedString }; var setPasswordRequest = new SetKeyConnectorKeyRequest( encKey.Item2.EncryptedString, keys, tokenResponse.Kdf, tokenResponse.KdfIterations, orgId ); await _apiService.PostSetKeyConnectorKey(setPasswordRequest); } } await _stateService.SetBiometricLockedAsync(false); _messagingService.Send("loggedIn"); return(result); }
private async Task <AuthResult> LogInHelperAsync(string email, string hashedPassword, string code, string codeVerifier, string redirectUrl, SymmetricCryptoKey key, TwoFactorProviderType?twoFactorProvider = null, string twoFactorToken = null, bool?remember = null) { var storedTwoFactorToken = await _tokenService.GetTwoFactorTokenAsync(email); var appId = await _appIdService.GetAppIdAsync(); var deviceRequest = new DeviceRequest(appId, _platformUtilsService); string[] emailPassword; string[] codeCodeVerifier; if (email != null && hashedPassword != null) { emailPassword = new[] { email, hashedPassword }; } else { emailPassword = null; } if (code != null && codeVerifier != null && redirectUrl != null) { codeCodeVerifier = new[] { code, codeVerifier, redirectUrl }; } else { codeCodeVerifier = null; } TokenRequest request; if (twoFactorToken != null && twoFactorProvider != null) { request = new TokenRequest(emailPassword, codeCodeVerifier, twoFactorProvider, twoFactorToken, remember, deviceRequest); } else if (storedTwoFactorToken != null) { request = new TokenRequest(emailPassword, codeCodeVerifier, TwoFactorProviderType.Remember, storedTwoFactorToken, false, deviceRequest); } else { request = new TokenRequest(emailPassword, codeCodeVerifier, null, null, false, deviceRequest); } var response = await _apiService.PostIdentityTokenAsync(request); ClearState(); var result = new AuthResult { TwoFactor = response.Item2 != null }; if (result.TwoFactor) { // Two factor required. var twoFactorResponse = response.Item2; Email = email; MasterPasswordHash = hashedPassword; Code = code; CodeVerifier = codeVerifier; SsoRedirectUrl = redirectUrl; _key = _setCryptoKeys ? key : null; TwoFactorProvidersData = twoFactorResponse.TwoFactorProviders2; result.TwoFactorProviders = twoFactorResponse.TwoFactorProviders2; return(result); } var tokenResponse = response.Item1; result.ResetMasterPassword = tokenResponse.ResetMasterPassword; if (tokenResponse.TwoFactorToken != null) { await _tokenService.SetTwoFactorTokenAsync(tokenResponse.TwoFactorToken, email); } await _tokenService.SetTokensAsync(tokenResponse.AccessToken, tokenResponse.RefreshToken); await _userService.SetInformationAsync(_tokenService.GetUserId(), _tokenService.GetEmail(), tokenResponse.Kdf, tokenResponse.KdfIterations); if (_setCryptoKeys) { await _cryptoService.SetKeyAsync(key); await _cryptoService.SetKeyHashAsync(hashedPassword); await _cryptoService.SetEncKeyAsync(tokenResponse.Key); // User doesn't have a key pair yet (old account), let's generate one for them. if (tokenResponse.PrivateKey == null) { try { var keyPair = await _cryptoService.MakeKeyPairAsync(); await _apiService.PostAccountKeysAsync(new KeysRequest { PublicKey = keyPair.Item1, EncryptedPrivateKey = keyPair.Item2.EncryptedString }); tokenResponse.PrivateKey = keyPair.Item2.EncryptedString; } catch { } } await _cryptoService.SetEncPrivateKeyAsync(tokenResponse.PrivateKey); } _vaultTimeoutService.BiometricLocked = false; _messagingService.Send("loggedIn"); return(result); }
public async Task InitAsync() { _userId = await _userService.GetUserIdAsync(); _appId = await _appIdService.GetAppIdAsync(); }