public override int Run(string[] remainingArguments) { try { var keys = _uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == null && x.Deletable == false).ToLambda(), new List <Expression <Func <tbl_PublicKey, object> > >() { x => x.PrivateKey, }); if (_delete) { ConsoleHelper.StdOutKeyPairs(keys.OrderBy(x => x.Created)); Console.Out.Write(" *** Enter GUID of public key to delete *** : "); var input = Guid.Parse(StandardInput.GetInput()); var pubKey = _uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.Id == input).ToLambda(), new List <Expression <Func <tbl_PublicKey, object> > >() { x => x.PrivateKey, }).SingleOrDefault(); if (pubKey != null) { _uow.PublicKeys.Delete(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.Id == pubKey.Id).ToLambda()); _uow.PrivateKeys.Delete(QueryExpressionFactory.GetQueryExpression <tbl_PrivateKey>() .Where(x => x.Id == pubKey.PrivateKeyId).ToLambda()); _uow.Commit(); } } else if (_deleteAll) { ConsoleHelper.StdOutKeyPairs(keys.OrderBy(x => x.Created)); _uow.PublicKeys.Delete(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == null && x.Deletable == false).ToLambda()); _uow.PrivateKeys.Delete(QueryExpressionFactory.GetQueryExpression <tbl_PrivateKey>() .Where(x => x.IdentityId == null && x.Deletable == false).ToLambda()); _uow.Commit(); } else { ConsoleHelper.StdOutKeyPairs(keys.OrderBy(x => x.Created)); } return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { if (!string.IsNullOrEmpty(_pubKeyComment)) { Console.Out.Write(" *** Enter user@hostname or a comment for the public key *** : "); _pubKeyComment = StandardInput.GetInput(); } Console.Out.WriteLine("Opened " + _path.FullName); Console.Out.WriteLine(); if (_base64) { KeyHelper.ImportPubKeyBase64(_uow, _user, SignatureHashAlgorithm.SHA256, new FileInfo(_path.FullName)); } else { KeyHelper.ImportPubKey(_uow, _user, SignatureHashAlgorithm.SHA256, _pubKeyComment, new FileInfo(_path.FullName)); } return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var configs = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>() .Where(x => x.Deletable == true).ToLambda()); ConsoleHelper.StdOutSettings(configs); if (_configID == Guid.Empty) { Console.Out.Write(" *** Enter GUID of config to delete *** : "); _configID = Guid.Parse(StandardInput.GetInput()); } _uow.Settings.Delete(QueryExpressionFactory.GetQueryExpression <tbl_Setting>() .Where(x => x.Id == _configID && x.Deletable == true).ToLambda()); _uow.Commit(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { FormatOutput.Logins(_uow, new List <E_Login> { _login }); Console.Out.WriteLine(); Console.Out.Write(" *** Enter 'yes' to delete login *** : "); var input = StandardInput.GetInput(); Console.Out.WriteLine(); if (input.ToLower() == "yes") { _ = _service.Login_DeleteV1(_login.Id) .Result; } return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { if (_user.tbl_UserMount != null) { Console.Out.WriteLine(" *** The user already has a mount ***"); Console.Out.WriteLine(); ConsoleHelper.StdOutUserMounts(new List <tbl_UserMount> { _user.tbl_UserMount }); return(StandardOutput.FondFarewell()); } var credentials = _uow.Credentials.Get(); ConsoleHelper.StdOutCredentials(credentials); Console.Out.WriteLine(); Console.Out.Write(" *** Enter GUID of credential to use for mount *** : "); var input = StandardInput.GetInput(); _user.tbl_UserMount.CredentialId = Guid.Parse(input); _uow.Users.Update(_user); _uow.Commit(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var admin = new AdminService(_conf); admin.Grant = new ResourceOwnerGrantV2(_conf); var users = admin.User_GetV1(new DataStateV1() { Sort = new List <IDataStateSort>() { new DataStateV1Sort() { Field = "userName", Dir = "asc" } }, Skip = 0, Take = 100, }).Result; foreach (var entry in users.Data) { Console.Out.WriteLine($" User '{entry.UserName}' with GUID '{entry.Id}'"); } Console.Out.WriteLine(); Console.Out.Write(" *** Enter GUID of (identity) user to use *** : "); var input = StandardInput.GetInput(); var user = _uow.Users.Create( new tbl_User { IdentityId = Guid.Parse(input), IdentityAlias = _userName, RequirePassword = true, RequirePublicKey = false, FileSystemType = _fileSystem.ToString(), Enabled = true, Deletable = false, Created = DateTime.Now, }); _uow.Commit(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var credentials = _uow.Credentials.Get(QueryExpressionFactory.GetQueryExpression <tbl_Credential>() .Where(x => x.Deletable == true).ToLambda()); ConsoleHelper.StdOutCredentials(credentials); if (_credID == Guid.Empty) { Console.Out.WriteLine(); Console.Out.Write(" *** Enter GUID of credential to delete *** : "); _credID = Guid.Parse(StandardInput.GetInput()); } var mounts = _uow.UserMounts.Get(QueryExpressionFactory.GetQueryExpression <tbl_UserMount>() .Where(x => x.CredentialId == _credID).ToLambda()); if (mounts.Any()) { Console.Out.WriteLine(); Console.Out.WriteLine(" *** The credential can not be deleted while in use ***"); Console.Out.WriteLine(); ConsoleHelper.StdOutUserMounts(mounts); return(StandardOutput.FondFarewell()); } _uow.Credentials.Delete(QueryExpressionFactory.GetQueryExpression <tbl_Credential>() .Where(x => x.Id == _credID && x.Deletable == true).ToLambda()); _uow.Commit(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var nets = _uow.Networks.Get(QueryExpressionFactory.GetQueryExpression <tbl_Network>() .Where(x => x.IdentityId == _user.IdentityId).ToLambda()); ConsoleHelper.StdOutNetworks(nets); if (_delete) { Console.Out.Write(" *** Enter GUID of network to delete *** : "); var input = Guid.Parse(StandardInput.GetInput()); var key = _uow.Networks.Get(QueryExpressionFactory.GetQueryExpression <tbl_Network>() .Where(x => x.IdentityId == _user.IdentityId && x.Id == input).ToLambda()) .SingleOrDefault(); if (key != null) { _uow.Networks.Delete(QueryExpressionFactory.GetQueryExpression <tbl_Network>() .Where(x => x.IdentityId == _user.IdentityId && x.Id == key.Id).ToLambda()); _uow.Commit(); } } else if (_deleteAll) { _uow.Networks.Delete(QueryExpressionFactory.GetQueryExpression <tbl_Network>() .Where(x => x.IdentityId == _user.IdentityId).ToLambda()); _uow.Commit(); } 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(_privKeyPass)) { Console.Out.Write(" *** Enter password for the private key *** : "); _privKeyPass = StandardInput.GetHiddenInput(); } if (string.IsNullOrEmpty(_pubKeyComment)) { Console.Out.Write(" *** Enter user@hostname or a comment for the public key *** : "); _pubKeyComment = StandardInput.GetInput(); } Console.Out.WriteLine(); Console.Out.WriteLine("Opened " + _path.FullName); KeyHelper.ImportPrivKey(_conf, _uow, _user, _privKeyPass, SignatureHashAlgorithm.SHA256, _pubKeyComment, new FileInfo(_path.FullName)); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { var dir = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}.system"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var keys = _uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == null && x.Deletable == false).ToLambda(), new List <Expression <Func <tbl_PublicKey, object> > >() { x => x.PrivateKey, }); ConsoleHelper.StdOutKeyPairs(keys); Console.Out.Write(" *** Enter GUID of public key to export *** : "); var input = Guid.Parse(StandardInput.GetInput()); var pubKey = keys.Where(x => x.Id == input).SingleOrDefault(); if (pubKey != null) { //public pkcs8 key format var pubPkcs8File = new FileInfo(dir + Path.DirectorySeparatorChar + "pub." + SshPublicKeyFormat.Pkcs8.ToString().ToLower() + ".txt"); var pubPkcs8Bytes = KeyHelper.ExportPubKey(pubKey, SshPublicKeyFormat.Pkcs8); File.WriteAllBytes(pubPkcs8File.FullName, pubPkcs8Bytes); Console.Out.WriteLine("Created " + pubPkcs8File); //public ssh2base64 key format var pubSsh2Base64File = new FileInfo(dir + Path.DirectorySeparatorChar + "pub." + SshPublicKeyFormat.Ssh2Base64.ToString().ToLower() + ".txt"); var pubSsh2Base64Bytes = KeyHelper.ExportPubKey(pubKey, SshPublicKeyFormat.Ssh2Base64); File.WriteAllBytes(pubSsh2Base64File.FullName, pubSsh2Base64Bytes); Console.Out.WriteLine("Created " + pubSsh2Base64File); //public ssh2raw key format var pubSsh2RawFile = new FileInfo(dir + Path.DirectorySeparatorChar + "pub." + SshPublicKeyFormat.Ssh2Raw.ToString().ToLower()); var pubSsh2RawBytes = KeyHelper.ExportPubKey(pubKey, SshPublicKeyFormat.Ssh2Raw); File.WriteAllBytes(pubSsh2RawFile.FullName, pubSsh2RawBytes); Console.Out.WriteLine("Created " + pubSsh2Base64File); if (pubKey.PrivateKey != null) { var privKey = pubKey.PrivateKey; //private key password in cleartext var privKeyPassFile = new FileInfo(dir + Path.DirectorySeparatorChar + "cleartext_passowrd.txt"); File.WriteAllText(privKeyPassFile.FullName, AES.DecryptString(privKey.KeyPass, _conf["Databases:AuroraSecret"])); Console.Out.WriteLine("Created " + privKeyPassFile); //private newopenssh key format var privNewOpenSshFile = new FileInfo(dir + Path.DirectorySeparatorChar + "priv." + SshPrivateKeyFormat.NewOpenSsh.ToString().ToLower() + ".txt"); var privNewOpenSshBytes = KeyHelper.ExportPrivKey(_conf, privKey, SshPrivateKeyFormat.NewOpenSsh, privKey.KeyPass); File.WriteAllBytes(privNewOpenSshFile.FullName, privNewOpenSshBytes); Console.Out.WriteLine("Created " + privNewOpenSshFile); //private openssh key format var privOpenSshFile = new FileInfo(dir + Path.DirectorySeparatorChar + "priv." + SshPrivateKeyFormat.OpenSsh.ToString().ToLower() + ".txt"); var privOpenSshBytes = KeyHelper.ExportPrivKey(_conf, privKey, SshPrivateKeyFormat.OpenSsh, privKey.KeyPass); File.WriteAllBytes(privOpenSshFile.FullName, privOpenSshBytes); Console.Out.WriteLine("Created " + privOpenSshFile); //private pkcs8 key format var privPcks8File = new FileInfo(dir + Path.DirectorySeparatorChar + "priv." + SshPrivateKeyFormat.Pkcs8.ToString().ToLower() + ".txt"); var privPcks8Bytes = KeyHelper.ExportPrivKey(_conf, privKey, SshPrivateKeyFormat.Pkcs8, privKey.KeyPass); File.WriteAllBytes(privPcks8File.FullName, privPcks8Bytes); Console.Out.WriteLine("Created " + privPcks8File); //private putty key format var privPuttyFile = new FileInfo(dir + Path.DirectorySeparatorChar + "priv." + SshPrivateKeyFormat.Putty.ToString().ToLower() + ".txt"); var privPuttyBytes = KeyHelper.ExportPrivKey(_conf, privKey, SshPrivateKeyFormat.Putty, privKey.KeyPass); File.WriteAllBytes(privPuttyFile.FullName, privPuttyBytes); Console.Out.WriteLine("Created " + privPuttyFile); } } else { throw new ConsoleHelpAsException($" *** Public key with GUID {input} not found ***"); } return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }
public override int Run(string[] remainingArguments) { try { if (_user.tbl_UserMount != null) { Console.Out.WriteLine(" *** The user already has a mount ***"); ConsoleHelper.StdOutUserMounts(new List <tbl_UserMount> { _user.tbl_UserMount }); return(StandardOutput.FondFarewell()); } if (_alternateCredential) { var credentials = _uow.Credentials.Get(); ConsoleHelper.StdOutCredentials(credentials); Console.Out.WriteLine(); Console.Out.Write(" *** Enter GUID of credential to use for mount *** : "); var input = StandardInput.GetInput(); _uow.UserMounts.Create( new tbl_UserMount { IdentityId = _user.IdentityId, CredentialId = Guid.Parse(input), AuthType = _authType.ToString(), ServerAddress = _serverAddress, ServerShare = _serverShare, Enabled = true, Deletable = false, Created = DateTime.Now, }); } else { _uow.UserMounts.Create( new tbl_UserMount { IdentityId = _user.IdentityId, CredentialId = null, AuthType = _authType.ToString(), ServerAddress = _serverAddress, ServerShare = _serverShare, Enabled = true, Deletable = false, Created = DateTime.Now, }); } _uow.Commit(); return(StandardOutput.FondFarewell()); } catch (Exception ex) { return(StandardOutput.AngryFarewell(ex)); } }