public ChapterUnorderer(IUi ui, string sourceDir, string dstFile, bool?mode) { _ui = ui; _sourceDir = sourceDir; _dstFile = dstFile; _mode = mode; }
public static Account[] OpenVaultBrowser(string username, string password, string deviceId, string baseUrl, IUi ui, ISecureStorage storage, IRestTransport transport) { // Reset to default. Let the user simply pass a null or "" and not bother with an overload. if (baseUrl.IsNullOrEmpty()) { baseUrl = DefaultBaseUrl; } var rest = new RestClient(transport, baseUrl, defaultHeaders: DefaultRestHeaders); // 1. Request the number of KDF iterations needed to derive the key var iterations = RequestKdfIterationCount(username, rest); // 2. Derive the master encryption key or KEK (key encryption key) var key = Util.DeriveKey(username, password, iterations); // 3. Hash the password that is going to be sent to the server var hash = Util.HashPassword(password, key); // 4. Authenticate with the server and get the token var token = Login(username, hash, deviceId, ui, storage, rest); // 5. Fetch the vault var encryptedVault = DownloadVault(rest, token); // 6. Decrypt and parse the vault. Done! return(DecryptVault(encryptedVault, key)); }
public Game() { _ui = new DirectXUi(this, _worldContainer); GenerateWorldEvent = new AutoResetEvent(false); _dayTimer = new DayTimer(); _ais = new List <IAi>(); }
public static Account[] OpenVault(string username, string password, ClientInfo clientInfo, IUi ui, IRestTransport transport) { var rest = new RestClient(transport, "https://lastpass.com"); var session = Login(username, password, clientInfo, ui, rest); try { var blob = DownloadVault(session, rest); var key = Util.DeriveKey(username, password, session.KeyIterationCount); var privateKey = new RSAParameters(); if (!session.EncryptedPrivateKey.IsNullOrEmpty()) { privateKey = Parser.ParseEncryptedPrivateKey(session.EncryptedPrivateKey, key); } return(ParseVault(blob, key, privateKey)); } finally { Logout(session, rest); } }
public Game() { _ui = new DirectXUi(this, _worldContainer); GenerateWorldEvent = new AutoResetEvent(false); _dayTimer = new DayTimer(); _ais = new List<IAi>(); }
// TODO: It's impossible to test this function because of the S3.* static calls. public static byte[] OpenVaultDb(string username, string password, string deviceId, string deviceName, IUi ui, IRestTransport transport) { var rest = new RestClient(transport, "https://spcb.stickypassword.com/SPCClient/"); // Request the token that is encrypted with the master password and get the one-time PIN // when a new device is registered for the first time. var(encryptedToken, passcode) = GetEncryptedTokenAndPasscode(username, deviceId, ui, rest); // Decrypt the token. This token is now used to authenticate with the server. var token = Util.DecryptToken(username, password, encryptedToken); // The device must be registered first. AuthorizeDevice(username, token, deviceId, deviceName, passcode, DateTime.Now, rest); // Get the S3 credentials to access the database on AWS. var s3Token = GetS3Token(username, token, deviceId, DateTime.Now, rest); // Download the database. return(DownloadLatestDb(s3Token, transport)); }
//private IUi i_UI = new IUi(); internal GarageManager(IGarageHandler handler, IUi ui) { this.handler = handler; this.ui = ui; Run(); }
// // Internal // internal static Vault Open(string username, string password, string passphrase, IUi ui, ISecureStorage storage, IRestTransport transport) { return(new Vault(Client.OpenVault(username, password, passphrase, ui, storage, transport))); }
public Game( IUi ui, ITimer timer, Dictionary <string, LinkedList <string> > qustions) { mUi = ui; mTimer = timer; this.qustions = qustions; }
// This version allows custom base URL. baseUrl could be set to null or "" for a default value. public static Vault Open(string username, string password, string deviceId, string baseUrl, IUi ui, ISecureStorage storage) { using var transport = new RestTransport(); return(new Vault(Client.OpenVault(username, password, deviceId, baseUrl, ui, storage, transport))); }
public Integration(string remoteRepoPath) { _remoteRepoPath = remoteRepoPath; _ui = new Ui(); var factory = new Factory(remoteRepoPath); _remoteSyncTable = factory.Build_remote_sync_table(); _remoteFileStore = factory.Build_remote_file_store(); }
// Public entries point to the library: Login, Logout, ListAllVaults, OpenVault // We try to mimic the remote structure, that's why there's an array of vaults. // We open all the ones we can. public static Session LogIn(string username, string password, string accountKey, string uuid, Region region, IUi ui, ISecureStorage storage) { return(LogIn(username, password, accountKey, uuid, GetDomain(region), ui, storage)); }
// This version allows custom base URL. baseUrl could be set to null or "" for the default value. public static Vault Open(ClientInfoBrowser clientInfo, string baseUrl, IUi ui, ISecureStorage storage) { using var transport = new RestTransport(); return(new Vault(Client.OpenVaultBrowser(username: clientInfo.Username, password: clientInfo.Password, deviceId: clientInfo.DeviceId, baseUrl: baseUrl, ui: ui, storage: storage, transport: transport))); }
public Game(IUi ui, ITimer timer) { mUi = ui; mTimer = timer; for (var i = 0; i < 50; i++) { mPopQuestions.AddLast("Pop Question " + i); mScienceQuestions.AddLast("Science Question " + i); mSportsQuestions.AddLast("Sports Question " + i); mRockQuestions.AddLast("Rock Question " + i); } }
public static Vault Open(string username, string password, string deviceId, string baseUrl, IUi ui, ISecureStorage storage) { return(Open(new ClientInfoBrowser(username: username, password: password, deviceId: deviceId), baseUrl, ui, storage)); }
internal static OobResult ApproveOob(string username, Dictionary <string, string> parameters, IUi ui, RestClient rest) { if (!parameters.TryGetValue("outofbandtype", out var method)) { throw new InternalErrorException("Out of band method is not specified"); } return(method switch { "lastpassauth" => ui.ApproveLastPassAuth(), "duo" => ApproveDuo(username, parameters, ui, rest), _ => throw new UnsupportedFeatureException($"Out of band method '{method}' is not supported") });
internal static HttpCookies LogInMfa(UserInfo userInfo, R.LogInResult logInResult, string token, IUi ui, ISecureStorage storage, RestClient rest) { void CheckCancel(Ui.Passcode passcode) { if (passcode == Ui.Passcode.Cancel) { throw new CanceledMultiFactorException("Second factor step is canceled by the user"); } } var methods = logInResult.MfaMethods?.AllowedMethods; if (methods == null) { throw MakeInvalidResponseError("allowed MFA methods not found"); } Ui.Passcode code; if (methods.Contains("totp")) { code = ui.ProvideGoogleAuthPasscode(); CheckCancel(code); SubmitTotp(userInfo, code, token, logInResult.MfaToken, rest); } else if (methods.Contains("yubikey")) { throw new UnsupportedFeatureException( $"Zoho removed support for the classic YubiKey. FIDO U2F is not supported yet."); } else { var unsupportedMethods = methods.JoinToString(", "); throw new UnsupportedFeatureException($"MFA methods '{unsupportedMethods}' are not supported"); } // Has to be done regardless of the "remember me" setting return(MarkDeviceTrusted(userInfo, code.RememberMe, token, logInResult.MfaToken, rest)); }
// Returns a valid session or throws internal static Session LoginWithOtp(string username, string password, int keyIterationCount, OtpMethod method, ClientInfo clientInfo, IUi ui, RestClient rest) { var passcode = method switch { OtpMethod.GoogleAuth => ui.ProvideGoogleAuthPasscode(), OtpMethod.MicrosoftAuth => ui.ProvideMicrosoftAuthPasscode(), OtpMethod.Yubikey => ui.ProvideYubikeyPasscode(), _ => throw new InternalErrorException("Invalid OTP method") }; if (passcode == OtpResult.Cancel) { throw new CanceledMultiFactorException("Second factor step is canceled by the user"); } var response = PerformSingleLoginRequest(username, password, keyIterationCount, new Dictionary <string, object> { ["otp"] = passcode.Passcode }, clientInfo, rest); var session = ExtractSessionFromLoginResponse(response, keyIterationCount, clientInfo); if (session == null) { throw MakeLoginError(response); } if (passcode.RememberMe) { MarkDeviceAsTrusted(session, clientInfo, rest); } return(session); }
// Valid domains are: my.1password.com, my.1password.eu, my.1password.ca public static Session LogIn(string username, string password, string accountKey, string uuid, string domain, IUi ui, ISecureStorage storage) { var transport = new RestTransport(); try { return(LogIn(new ClientInfo(username, password, accountKey, uuid, domain), ui, storage, transport)); } catch (Exception) { transport.Dispose(); throw; } }
// The deviceId should be generated via Vault.GenerateRandomDeviceId on the first call and reused // later on for the same device. This allows to bypass the email verification on every connection and // prevents the pollution of the server side list of known devices. public static Vault Open(string username, string password, string deviceId, string deviceName, IUi ui, ISqliteProvider sqliteProvider) { // Download the database. using var transport = new RestTransport(); var db = Client.OpenVaultDb(username: username, password: password, deviceId: deviceId, deviceName: deviceName, ui: ui, transport: transport); // Parse the database, extract and decrypt all the account information. var accounts = Parser.ParseAccounts(db, password, sqliteProvider); return(new Vault(accounts)); }
public static Account[] OpenVault(string username, string password, string passphrase, IUi ui, ISecureStorage storage, IRestTransport transport) { var rest = new RestClient(transport); // This token is needed to access other pages of the login flow. It's sent via headers, // cookies and in the request data. var token = RequestToken(rest); // TLD is determined by the region/data center. Each user is associated with a specific region. var userInfo = RequestUserInfo(username, token, DataCenterToTld(DefaultDataCenter), rest); // Perform the login dance that possibly involves the MFA steps. The cookies are later // used by the subsequent requests. // // TODO: It would be ideal to figure out which cookies are needed for general // cleanliness. It was too many of them and so they are now passed altogether a bundle // between the requests. var cookies = LogIn(userInfo, password, token, ui, storage, rest); try { var vaultKey = Authenticate(passphrase, cookies, userInfo.Tld, rest); var vaultResponse = DownloadVault(cookies, userInfo.Tld, rest); var sharingKey = DecryptSharingKey(vaultResponse, vaultKey); return(ParseAccounts(vaultResponse, vaultKey, sharingKey)); } finally { LogOut(cookies, userInfo.Tld, rest); } }
public Battle(IUi u, IEnvironment env) { ui = u; gameEnvironment = env; var i = 0; while (i < PlayersNumber) { var player = new Player(i, $"Player{i + 1}"); player.Die += PlayerDie; player.Damaged += PlayerDamaged; players.Add(player); i++; } CurrentPlayerIndex = new Random().Next(PlayersNumber); ui.StartGame(players[CurrentPlayerIndex].Name); if (!ui.IsTestActions()) { PlayTurn(players[CurrentPlayerIndex].NextTurn()); } }
internal static Passcode AskU2fPasscode(JObject u2fParams, IUi ui) { // TODO: Decide what to do on other platforms // TODO: See how to get rid of the #if in favor of some cleaner way (partial classes?) #if NETFRAMEWORK var appId = (string)u2fParams["appId"]; var challenge = (string)u2fParams["challenge"]; var keyHandle = (string)u2fParams["keys"][0]["keyHandle"]; // TODO: Support multiple keys // The challenge that is received from the server is not the actual U2F challenge, it's // just a part of it. The actual challenge is a SHA-256 hash of the "client data" that // is formed from various bits of information. The client data is sent back to the // server in a follow up request. The U2f library calculates the SHA-256 for us, so no // need to hash it here. var clientData = $"{{\"challenge\":\"{challenge}\",\"origin\":\"{appId}\",\"typ\":\"navigator.id.getAssertion\"}}"; var signature = U2fWin10.U2f.Sign(appId, clientData.ToBytes(), keyHandle.Decode64Loose()); if (signature.IsNullOrEmpty()) { throw MakeCancelledMfaError(); } // This is the 2FA token that is expected by the BW server var token = JsonConvert.SerializeObject(new { keyHandle = keyHandle, clientData = clientData.ToBytes().ToUrlSafeBase64NoPadding(), signatureData = signature.ToUrlSafeBase64NoPadding(), }); // TODO: Add support for remember-me. return(new Passcode(token, false)); #else throw new UnsupportedFeatureException("U2f is not supported on this platform"); #endif }
internal static string Login(string username, byte[] passwordHash, string deviceId, IUi ui, ISecureStorage storage, RestClient rest) { // Try simple password login, potentially with a stored second factor token if // "remember me" was used before. var rememberMeOptions = GetRememberMeOptions(storage); var response = RequestAuthToken(username, passwordHash, deviceId, rememberMeOptions, rest); // Simple password login (no 2FA) succeeded if (response.AuthToken != null) { return(response.AuthToken); } var secondFactor = response.SecondFactor; if (secondFactor.Methods == null || secondFactor.Methods.Count == 0) { throw new InternalErrorException("Expected a non empty list of available 2FA methods"); } // We had a "remember me" token saved, but the login failed anyway. This token is not valid anymore. if (rememberMeOptions != null) { EraseRememberMeToken(storage); } var method = ChooseSecondFactorMethod(secondFactor, ui); var extra = secondFactor.Methods[method]; Passcode passcode = null; switch (method) { case Response.SecondFactorMethod.GoogleAuth: passcode = ui.ProvideGoogleAuthPasscode(); break; case Response.SecondFactorMethod.Email: // When only the email 2FA present, the email is sent by the server right away. // Trigger only when other methods are present. if (secondFactor.Methods.Count != 1) { TriggerEmailMfaPasscode(username, passwordHash, rest); } passcode = ui.ProvideEmailPasscode((string)extra["Email"] ?? ""); break; case Response.SecondFactorMethod.Duo: case Response.SecondFactorMethod.DuoOrg: { var duo = Duo.Authenticate((string)extra["Host"] ?? "", (string)extra["Signature"] ?? "", ui, rest.Transport); if (duo != null) { passcode = new Passcode(duo.Passcode, duo.RememberMe); } break; } case Response.SecondFactorMethod.YubiKey: passcode = ui.ProvideYubiKeyPasscode(); break; case Response.SecondFactorMethod.U2f: passcode = AskU2fPasscode(JObject.Parse((string)extra["Challenge"]), ui); break; default: throw new UnsupportedFeatureException($"2FA method {method} is not supported"); } // We're done interacting with the UI ui.Close(); if (passcode == null) { throw MakeCancelledMfaError(); } var secondFactorResponse = RequestAuthToken(username, passwordHash, deviceId, new SecondFactorOptions(method, passcode.Code, passcode.RememberMe), rest); // Password + 2FA is successful if (secondFactorResponse.AuthToken != null) { SaveRememberMeToken(secondFactorResponse, storage); return(secondFactorResponse.AuthToken); } throw new BadMultiFactorException("Second factor code is not correct"); }
public static Vault Open(string username, string password, string deviceId, IUi ui, ISecureStorage storage) { return(Open(username, password, deviceId, null, ui, storage)); }
// C1.Location, C1.Size public MidiPianoViewSettings(IUi iui) { this.uiComponent = iui; ClientPadding = new Padding(64, 60, 18, 0); }
// The main entry point. Use this function to open the vault in the browser mode. In // this the login process is interactive when 2FA is enabled. This is an old mode // that might potentially trigger a captcha. Captcha solving is not supported. // There's no way to complete a login and get the vault if the captcha is triggered. // Use the CLI/API mode. This mode requires a different type of credentials. // The device ID should be unique to each installation, but it should not be new on // every run. A new random device ID should be generated with GenerateRandomDeviceId // on the first run and reused later on. public static Vault Open(ClientInfoBrowser clientInfo, IUi ui, ISecureStorage storage) { return(Open(clientInfo, null, ui, storage)); }
public Cat(IUi ui, ITextdatei textdatei, IKommandozeile kommandozeile) { this.ui = ui; this.textdatei = textdatei; this.kommandozeile = kommandozeile; }
internal static Response.SecondFactorMethod ChooseSecondFactorMethod(Response.SecondFactor secondFactor, IUi ui) { var methods = secondFactor.Methods; if (methods == null || methods.Count == 0) { throw new InternalErrorException("Logical error: should be called with non empty list of methods"); } var availableMethods = new List <MfaMethod>(); foreach (var m in methods.Keys) { switch (m) { case Response.SecondFactorMethod.GoogleAuth: availableMethods.Add(MfaMethod.GoogleAuth); break; case Response.SecondFactorMethod.Email: availableMethods.Add(MfaMethod.Email); break; case Response.SecondFactorMethod.Duo: availableMethods.Add(MfaMethod.Duo); break; case Response.SecondFactorMethod.YubiKey: availableMethods.Add(MfaMethod.YubiKey); break; case Response.SecondFactorMethod.U2f: #if NETFRAMEWORK availableMethods.Add(MfaMethod.U2f); #endif break; case Response.SecondFactorMethod.RememberMe: break; case Response.SecondFactorMethod.DuoOrg: availableMethods.Add(MfaMethod.DuoOrg); break; } } // Only unsupported methods were found if (availableMethods.Count == 0) { var unsupported = string.Join(", ", methods.Keys); throw new UnsupportedFeatureException($"Seconds factor methods [{unsupported}] are not supported"); } // Cancel is always available availableMethods.Add(MfaMethod.Cancel); return(ui.ChooseMfaMethod(availableMethods.ToArray()) switch { MfaMethod.Cancel => throw MakeCancelledMfaError(), MfaMethod.GoogleAuth => Response.SecondFactorMethod.GoogleAuth, MfaMethod.Email => Response.SecondFactorMethod.Email, MfaMethod.Duo => Response.SecondFactorMethod.Duo, MfaMethod.YubiKey => Response.SecondFactorMethod.YubiKey, MfaMethod.U2f => Response.SecondFactorMethod.U2f, MfaMethod.DuoOrg => Response.SecondFactorMethod.DuoOrg, _ => throw new InternalErrorException("The user responded with invalid input") });
public Player(string name, IUi ui) { Name = name; mUi = ui; }
public static void SetCurrent(IUi ui) { _implementation = ui; }
static Ui() { Current = new Ui(); }
/// <summary> /// Execute one or more SQL statements as a transaction. Roll back the transaction if any of them fail. /// </summary> public async Task Execute( IUi ui, int rowLimit, string connectionString) { List <string> statements = SqlQuery.SplitIntoStatements(Query); if (statements.Count == 0) { return; } var sw = new System.Diagnostics.Stopwatch(); var currentStatement = ""; try { using (var cn = new OdbcConnection(connectionString)) { // START CONNECT ui.SetStatusLabel(ExecuteStatus.Connecting.Description()); sw.Restart(); cn.Open(); Duration_Connect = sw.Elapsed; // END CONNECT using (var cmd = new OdbcCommand()) { cmd.Connection = cn; // START EXECUTE ui.SetStatusLabel(ExecuteStatus.Executing.Description()); sw.Restart(); using (var t = cn.BeginTransaction()) { cmd.Transaction = t; // Assign transaction object for a pending local transaction. foreach (var statement in statements) { if (string.IsNullOrEmpty(statement)) { continue; } currentStatement = statement.Trim(); cmd.CommandText = currentStatement; var statementResult = new StatementResult(); if (!currentStatement.StartsWith("select", StringComparison.OrdinalIgnoreCase)) { statementResult.RowsAffected = await cmd.ExecuteNonQueryAsync(); statementResult.Duration_Execute = sw.Elapsed; // END EXECUTE } else { using (var reader = await cmd.ExecuteReaderAsync()) { statementResult.Duration_Execute = sw.Elapsed; // END EXECUTE // BEGIN STREAM ui.SetStatusLabel(ExecuteStatus.Streaming.Description()); sw.Restart(); statementResult.Data.Add(GetColumns(reader)); int readCount = 1; while (readCount <= rowLimit && reader.Read()) { statementResult.Data.Add(GetData(reader)); readCount += 1; } statementResult.Duration_Stream = sw.Elapsed; // END STREAM ui.SetStatusLabel(""); statementResult.RowsAffected = reader.RecordsAffected; } } Results.Add(statementResult); } try { t.Commit(); } catch { t.Rollback(); throw; } } } } } catch (ArgumentOutOfRangeException ex) { if (ex.Message == "Year, Month, and Day parameters describe an un-representable DateTime.") { // filemaker allows importing incorrect data into fields, so we need to catch these errors! Error = ExecuteError.UnrepresentableDateTimeValue.Description(); } else { Error = ex.Message; } Error += Environment.NewLine + Environment.NewLine + currentStatement; } catch (Exception ex) { Error = ex.Message + Environment.NewLine + Environment.NewLine + currentStatement; } }
public static Vault Open(string username, string password, ClientInfo clientInfo, IUi ui) { using var transport = new RestTransport(); return(new Vault(Client.OpenVault(username, password, clientInfo, ui, transport))); }