public override int Run(string[] remainingArguments) { try { if (!string.IsNullOrEmpty(_privKeyPass)) { Console.Out.Write(" *** Enter password for the private key *** : "); _privKeyPass = StandardInput.GetHiddenInput(); } else { _privKeyPass = AlphaNumeric.CreateString(32); Console.Out.WriteLine($" *** The password for the private key *** : {_privKeyPass}"); } var privKey = KeyHelper.CreatePrivKey(_conf, _uow, _keyAlgo, _privKeySize, _privKeyPass, SignatureHashAlgorithm.SHA256); var pubKey = _uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.PrivateKeyId == privKey.Id).ToLambda()) .Single(); Console.Out.WriteLine($"{privKey.KeyValue}"); Console.Out.WriteLine($"{pubKey.KeyValue}"); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { Console.Out.Write($" *** Enter password for user '{_user.UserName}' *** : "); var decryptedPass = StandardInput.GetHiddenInput(); Console.Out.WriteLine(); _ = _service.User_SetPasswordV1(_user.Id, new PasswordAddV1() { EntityId = _user.Id, NewPassword = decryptedPass, NewPasswordConfirm = decryptedPass, }).Result; var user = _service.User_GetV1(_user.Id.ToString()) .Result; FormatOutput.Users(_uow, new List <E_User> { _map.Map <E_User>(user) }); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { var license = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>() .Where(x => x.ConfigKey == "RebexLicense").ToLambda()).OrderBy(x => x.Created) .Last(); Rebex.Licensing.Key = license.ConfigValue; AsymmetricKeyAlgorithm.Register(Curve25519.Create); AsymmetricKeyAlgorithm.Register(Ed25519.Create); AsymmetricKeyAlgorithm.Register(EllipticCurveAlgorithm.Create); try { if (string.IsNullOrEmpty(_privKeyPass)) { Console.Out.Write(" *** Enter password for the private key *** : "); _privKeyPass = StandardInput.GetHiddenInput(); } Console.Out.WriteLine(); Console.Out.WriteLine("Opened " + _path.FullName); KeyHelper.ImportPrivKey(_conf, _uow, _privKeyPass, SignatureHashAlgorithm.SHA256, new FileInfo(_path.FullName)); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var license = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>() .Where(x => x.ConfigKey == "RebexLicense").ToLambda()).OrderBy(x => x.Created) .Last(); Rebex.Licensing.Key = license.ConfigValue; AsymmetricKeyAlgorithm.Register(Curve25519.Create); AsymmetricKeyAlgorithm.Register(Ed25519.Create); AsymmetricKeyAlgorithm.Register(EllipticCurveAlgorithm.Create); if (string.IsNullOrEmpty(_secretCurrent)) { Console.Out.Write(" *** Enter current secret to encrypt passwords *** : "); _secretCurrent = StandardInput.GetHiddenInput(); } if (string.IsNullOrEmpty(_secretNew)) { Console.Out.Write(" *** Enter new secret to encrypt passwords *** : "); _secretNew = StandardInput.GetHiddenInput(); } else { _secretNew = AlphaNumeric.CreateString(32); Console.Out.WriteLine($" *** The new secret to encrypt passwords is *** : {_secretNew}"); } var keys = _uow.PrivateKeys.Get().ToList(); var creds = _uow.Credentials.Get().ToList(); Console.Out.WriteLine(); Console.Out.WriteLine(" *** Current private key pass ciphertexts *** "); ConsoleHelper.StdOutKeyPairSecrets(keys); Console.Out.WriteLine(); Console.Out.WriteLine(" *** Current credential password ciphertexts *** "); ConsoleHelper.StdOutCredentialSecrets(creds); keys = KeyHelper.EditPrivKeySecrets(_uow, keys, _secretCurrent, _secretNew).ToList(); creds = UserHelper.EditCredentialSecrets(_uow, creds, _secretCurrent, _secretNew).ToList(); Console.Out.WriteLine(); Console.Out.WriteLine(" *** New private key pass ciphertexts *** "); ConsoleHelper.StdOutKeyPairSecrets(keys); Console.Out.WriteLine(); Console.Out.WriteLine(" *** New credential password ciphertexts *** "); ConsoleHelper.StdOutCredentialSecrets(creds); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var credentials = _uow.Credentials.Get(); if (credentials.Where(x => x.Domain == _credDomain && x.UserName == _credLogin).Any()) { Console.Out.WriteLine(" *** The credential entered already exists ***"); Console.Out.WriteLine(); ConsoleHelper.StdOutCredentials(credentials); return(StandardOutput.FondFarewell()); } if (string.IsNullOrEmpty(_credPass)) { Console.Out.Write(" *** Enter credential password to use *** : "); _credPass = StandardInput.GetHiddenInput(); Console.Out.WriteLine(); } var secret = _conf["Databases:AuroraSecret"]; var cipherText = AES.EncryptString(_credPass, secret); var plainText = AES.DecryptString(cipherText, secret); if (_credPass != plainText) { throw new ArithmeticException(); } var credential = _uow.Credentials.Create( new tbl_Credential { Id = Guid.NewGuid(), Domain = _credDomain, UserName = _credLogin, Password = cipherText, Created = DateTime.Now, Enabled = true, Deletable = true, }); _uow.Commit(); Console.Out.WriteLine(); ConsoleHelper.StdOutCredentials(credentials); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var credential = _uow.Credentials.Get(QueryExpressionFactory.GetQueryExpression <tbl_Credential>() .Where(x => x.Domain == _credDomain && x.UserName == _credLogin).ToLambda()) .SingleOrDefault(); if (credential == null) { throw new ConsoleHelpAsException($" *** Invalid credential '{_credDomain}\\{_credLogin}' ***"); } if (string.IsNullOrEmpty(_credPass)) { Console.Out.Write(" *** Enter credential password to use *** : "); _credPass = StandardInput.GetHiddenInput(); Console.Out.WriteLine(); } var secret = _conf["Databases:AuroraSecret"]; var cipherText = AES.EncryptString(_credPass, secret); var plainText = AES.DecryptString(cipherText, secret); if (_credPass != plainText) { throw new ArithmeticException(); } credential.Password = cipherText; credential.LastUpdated = DateTime.Now; _uow.Credentials.Update(credential); _uow.Commit(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { if (string.IsNullOrEmpty(_credPass)) { Console.Out.Write(" *** Enter credential password to use *** : "); _credPass = StandardInput.GetHiddenInput(); Console.Out.WriteLine(); } /* * Get the user token for the specified user, domain, and password using the unmanaged LogonUser method. * The local machine name can be used for the domain name to impersonate a user on this machine. */ var safeAccessTokenHandle = UserHelper.GetSafeAccessTokenHandle(_credDomain, _credLogin, _credPass); Console.Out.WriteLine("Beginning user is " + WindowsIdentity.GetCurrent().Name); Console.Out.WriteLine(); /* * to run as unimpersonated, pass 'SafeAccessTokenHandle.InvalidHandle' instead of variable 'safeAccessTokenHandle' */ WindowsIdentity.RunImpersonated(safeAccessTokenHandle, () => { Console.Out.WriteLine("Impersonated user is " + WindowsIdentity.GetCurrent().Name); Console.Out.WriteLine(); }); Console.Out.WriteLine("Ending user is " + WindowsIdentity.GetCurrent().Name); Console.Out.WriteLine(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { if (_hashType == HashTypes.PBKDF2) { Console.Write("Enter plain text value: "); var clearText = StandardInput.GetHiddenInput(); var hashText = PBKDF2.Create(clearText); if (!PBKDF2.Validate(hashText, clearText)) { Console.WriteLine("Failed to generate hash. Please try again."); } else { Console.WriteLine(); Console.WriteLine(" Hash value: " + hashText); } } if (_hashType == HashTypes.SHA256) { Console.Write("Enter plain text value: "); var clearText = StandardInput.GetHiddenInput(); var hashText = SHA256.Create(clearText); Console.WriteLine(); Console.WriteLine(" Hash value: " + hashText); } return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }