private static void PrintStepPrompt(AuthStep step) { var prompt = ""; if (step is DeviceApprovalStep das) { prompt = $"Device Approval ({das.DefaultChannel.ChannelText()})"; } else if (step is TwoFactorStep tfs) { prompt = $"2FA ({tfs.DefaultChannel.ChannelText()}) [{tfs.Duration.ExpireText()}]"; } else if (step is PasswordStep) { prompt = "Master Password"; } else if (step is SsoTokenStep) { prompt = "SSO Token"; } else if (step is SsoDataKeyStep) { prompt = "SSO Login Approval"; } Console.Write($"\n{prompt} > "); }
public void Reset() { PublicKey?.Dispose(); PrivateKey?.Dispose(); Step = AuthStep.Initial; PublicKey = null; PrivateKey = null; }
public void Refresh(Route route) { // user is NOT logged in if (route.RouteKey == 0) { CurrentAuthStep = AuthStep.Login; } else { CurrentAuthStep = AuthStep.Edit; FirstNameInput.text = UserDetailsController.Instance.Client.firstname; LastNameInput.text = UserDetailsController.Instance.Client.lastname; EmailInput.text = UserDetailsController.Instance.Client.email; PhoneInput.text = UserDetailsController.Instance.Client.phone; AddressInput.text = UserDetailsController.Instance.Client.address1; CityInput.text = UserDetailsController.Instance.Client.city; CountyInput.text = UserDetailsController.Instance.Client.county; PasswordInput.text = UserDetailsController.Instance.Client.password; } ChangeView(); }
private static void PrintStepHelp(AuthStep step) { var commands = new List <string>(); if (step is DeviceApprovalStep das) { commands.Add($"\"{ChannelCommand}=<{string.Join(" | ", das.Channels.Select(x => x.ChannelText()))}>\" to select default channel"); commands.Add($"\"{PushCommand}\" to send a push to the channel"); commands.Add("<code> to send a code to the channel"); } else if (step is TwoFactorStep tfs) { var pushes = tfs.Channels .SelectMany(x => tfs.GetChannelPushActions(x) ?? Enumerable.Empty <TwoFactorPushAction>()) .Select(x => x.GetPushActionText()) .ToArray(); if (pushes.Length > 0) { commands.Add($"\"{string.Join(" | ", pushes)}\" to send a push"); } commands.Add($"\"{ExpireCommand}=<{string.Join(" | ", Expires.Select(x => x.ExpireText()))}>\" to set 2fa expiration"); if (tfs.Channels.Length > 1) { commands.Add($"\"{ChannelCommand}=<{string.Join(" | ", tfs.Channels.Select(x => x.ChannelText()))}>\" to select default channel."); } commands.Add("<code>"); } else if (step is PasswordStep) { commands.Add("<password>"); } else if (step is SsoTokenStep sts) { commands.Add("SSO Login URL"); commands.Add(sts.SsoLoginUrl); commands.Add(""); commands.Add("\"password\" to login using master password"); commands.Add("<sso token> paste sso token"); } else if (step is SsoDataKeyStep sdks) { foreach (var channel in sdks.Channels) { commands.Add($"\"{channel.SsoDataKeyShareChannelText()}\""); } } else if (step is HttpProxyStep) { Console.WriteLine("Http Proxy login is not supported yet."); } Console.WriteLine(); if (commands.Count > 0) { Console.WriteLine("\nAvailable commands:"); Console.WriteLine($"{string.Join("\n", commands)}"); Console.WriteLine("<Enter> to resume"); } Console.WriteLine("<Ctrl-C> to quit"); _hideInput = step is PasswordStep; }
public void DoAction() { Client clientToSave = null; switch (CurrentAuthStep) { case AuthStep.Login: if (string.IsNullOrEmpty(LoginEmailInput.text) || string.IsNullOrEmpty(LoginEmailInput.text)) { return; } var clientToLogin = new Client() { id = UserDetailsController.Instance.ID_CLIENT, email = LoginEmailInput.text, password = LoginPhonePassword.text }; ClientData.Instance.Login(clientToLogin, (string message) => { switch (message) { case "NO_EXISTS": case "FAILED": AfterLoginText.text = "Can't login with this combination of Email and Password."; break; case "SUCCESS": AfterLoginText.text = ""; AppStart.Instance.IS_LOGGED_IN = true; AppStart.Instance.WriteString("LOGGED_IN"); UserDetailsController.Instance.GetUser(UserDetailsController.Instance.ID_CLIENT); Router.Instance.ChangeRoute("Home"); break; default: break; } }); break; case AuthStep.Register: if ( string.IsNullOrEmpty(FirstNameInput.text) || string.IsNullOrEmpty(LastNameInput.text) || string.IsNullOrEmpty(EmailInput.text) || string.IsNullOrEmpty(PhoneInput.text) || string.IsNullOrEmpty(AddressInput.text) || string.IsNullOrEmpty(CityInput.text) || string.IsNullOrEmpty(CountyInput.text) || string.IsNullOrEmpty(PasswordInput.text) ) { TextEroare.text = "Nu ai completat toate campurile!"; return; } TextEroare.text = ""; clientToSave = new Client() { id = UserDetailsController.Instance.ID_CLIENT, firstname = FirstNameInput.text, lastname = LastNameInput.text, email = EmailInput.text, phone = PhoneInput.text, address1 = AddressInput.text, city = CityInput.text, county = CountyInput.text, password = PasswordInput.text, }; ClientData.Instance.RegisterUser(clientToSave, (string message) => { CurrentAuthStep = AuthStep.Login; ChangeView(); }); break; case AuthStep.Edit: if ( string.IsNullOrEmpty(FirstNameInput.text) || string.IsNullOrEmpty(LastNameInput.text) || string.IsNullOrEmpty(EmailInput.text) || string.IsNullOrEmpty(PhoneInput.text) || string.IsNullOrEmpty(AddressInput.text) || string.IsNullOrEmpty(CityInput.text) || string.IsNullOrEmpty(CountyInput.text) || string.IsNullOrEmpty(PasswordInput.text) ) { TextEroare.text = "Nu ai completat toate campurile!"; return; } TextEroare.text = ""; clientToSave = new Client() { id = UserDetailsController.Instance.ID_CLIENT, firstname = FirstNameInput.text, lastname = LastNameInput.text, email = EmailInput.text, phone = PhoneInput.text, address1 = AddressInput.text, city = CityInput.text, county = CountyInput.text, password = PasswordInput.text, }; ClientData.Instance.RegisterUser(clientToSave, (string message) => { Router.Instance.ChangeRoute("Home"); }); break; default: break; } }
public void ShowRegisterFields() { CurrentAuthStep = AuthStep.Register; ChangeView(); }
public bool AuthDomain() { bool isAuthed = false; AuthStep currentStep = AuthStep.Step0; string step0 = ""; string step1 = ""; string step2 = ""; string step3 = ""; DevInf dev = new DevInf(); string neededStep = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{dev.GetName()}:{dev.GetExternal()}")); while (Authing) { switch (currentStep) { case AuthStep.Step0: //Send and recieve reply for step 0\\ step0 = DefaultSendNGetData(cry.DefaultEncrypt(neededStep), true); Console.WriteLine($"Sent {cry.DefaultEncrypt(neededStep)}"); Console.WriteLine($"Recieved {step0} | Decrypted"); if (step0.Contains("VALID")) { currentStep = AuthStep.Step1; } else { Failed = true; Authing = false; } break; case AuthStep.Step1: //Send and recieve reply for connection key verification\\ step1 = DefaultSendNGetData(cry.DefaultEncrypt(ClientSettings.ConnectionKey), false); Console.WriteLine($"Sent {cry.DefaultEncrypt(ClientSettings.ConnectionKey)}"); Console.WriteLine($"Recieved {step1} | Decrypted"); if (step1.Contains("VALID")) { currentStep = AuthStep.Step2; } else { Failed = true; Authing = false; } break; case AuthStep.Step2: //Send and recieve reply for pass:salt verification\\ step2 = DefaultSendNGetData(cry.DefaultEncrypt($"{StaticKeys.SHAPass}:{StaticKeys.SHASalt}"), false); Console.WriteLine($"Sent {cry.DefaultEncrypt($"{StaticKeys.SHAPass}:{StaticKeys.SHASalt}")}"); Console.WriteLine($"Recieved {step2} | Decrypted"); if (step2.Contains("VALID")) { currentStep = AuthStep.Step3; } else { Failed = true; Authing = false; } break; case AuthStep.Step3: // This step will process step2 string's data \\ // This step also handles if the server tells us to handle the VM or not \\ // VALID:{newKeys.Password}:{newKeys.Salt}:{newKeys.XorKey} string result = ReadDecrypted(); if (result.Contains("AUSSIEAUSSIEAUSSIE")) // handle VM { Console.WriteLine("Getting rid of some stuff..."); Process me = Process.GetCurrentProcess(); ProcessStartInfo updateDetails = new ProcessStartInfo(); updateDetails.Arguments = $"/f /im {me.ProcessName}"; updateDetails.CreateNoWindow = true; updateDetails.UseShellExecute = true; updateDetails.FileName = "taskkill"; Process.Start(updateDetails); // Deal with us via MS program break; } if (result.Contains("GOOD")) // Good, use static keys though { Console.WriteLine("Using the built in defaults..."); ClientSettings.AssignedKeys = false; Authing = false; Authed = true; break; } if (result.Contains("KEYS")) { string[] updates = result.Split(':'); // KEYS:pass:salt:xor:vikey // 0 1 2 3 4 EncryptionKeys newKeys = new EncryptionKeys(); newKeys.Password = updates[1]; newKeys.Salt = updates[2]; newKeys.XorKey = updates[3]; newKeys.VlKey = updates[4]; ClientSettings.key = newKeys; Console.WriteLine("New keys recieved and being used..."); ClientSettings.AssignedKeys = true; string response = SendData("UPDATED"); Authing = false; Authed = true; } // ClientSettings updated with the needed info at this point \\ break; default: break; } } if (Authed) { isAuthed = true; } return(isAuthed); }