internal SmbReadWriteFileSystem(FileSystemProviderSettings settings, IServiceScopeFactory factory, tbl_User userEntity, string identityUser, string identityPass) : base(settings) { /* * this file-system is functional only when the daemon is running a on windows platform. there is * an interop call required to obtain a user credential outside the context of what the daemon runs as. */ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { throw new NotImplementedException(); } _factory = factory; _userEntity = userEntity; using (var scope = factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); var conf = scope.ServiceProvider.GetRequiredService <IConfiguration>(); var userMount = uow.UserMounts.Get(QueryExpressionFactory.GetQueryExpression <tbl_UserMount>() .Where(x => x.IdentityId == _userEntity.IdentityId).ToLambda()) .Single(); if (userMount.CredentialId.HasValue) { var userCred = uow.Credentials.Get(QueryExpressionFactory.GetQueryExpression <tbl_Credential>() .Where(x => x.Id == userMount.CredentialId).ToLambda()) .Single(); var secret = conf["Databases:AuroraSecret"]; var plainText = AES.DecryptString(userCred.Password, secret); var cipherText = AES.EncryptString(plainText, secret); if (userCred.Password != cipherText) { throw new UnauthorizedAccessException(); } _userToken = UserHelper.GetSafeAccessTokenHandle(userCred.Domain, userCred.UserName, plainText); } else { _userToken = UserHelper.GetSafeAccessTokenHandle(null, identityUser, identityPass); } _userMount = userMount.ServerAddress + userMount.ServerShare; var pubKeys = uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == _userEntity.IdentityId).ToLambda()).ToList(); var pubKeysContent = KeyHelper.ExportPubKeyBase64(_userEntity, pubKeys); } }
internal CompositeReadOnlyFileSystem(FileSystemProviderSettings settings, IServiceScopeFactory factory, tbl_User userEntity) : base(settings) { _factory = factory; _userEntity = userEntity; using (var scope = _factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); var pubKeys = uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == _userEntity.IdentityId).ToLambda()).ToList(); var pubKeysContent = KeyHelper.ExportPubKeyBase64(_userEntity, pubKeys); CompositeFileSystemHelper.EnsureRootExists(uow, userEntity); } }
internal MemoryReadWriteFileSystem(FileSystemProviderSettings settings, IServiceScopeFactory factory, tbl_User userEntity) : base(settings) { _factory = factory; _userEntity = userEntity; _path = new Dictionary <NodePath, NodeBase>(); _store = new Dictionary <NodeBase, MemoryNodeData>(); using (var scope = _factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); var pubKeys = uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == _userEntity.IdentityId).ToLambda()).ToList(); var pubKeysContent = KeyHelper.ExportPubKeyBase64(_userEntity, pubKeys); MemoryFileSystemHelper.EnsureRootExists(Root, _path, _store); MemoryFileSystemHelper.CreatePubKeysFile(Root, _path, _store, _userEntity, pubKeysContent); } }
public override int Run(string[] remainingArguments) { try { var dir = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}.{_user.IdentityAlias}"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var keys = _uow.PublicKeys.Get(QueryExpressionFactory.GetQueryExpression <tbl_PublicKey>() .Where(x => x.IdentityId == _user.IdentityId).ToLambda(), new List <Expression <Func <tbl_PublicKey, object> > >() { x => x.PrivateKey, }); ConsoleHelper.StdOutKeyPairs(keys.OrderBy(x => x.Created)); 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 opensshbase64 key format in "authorized_keys" var pubOpenSshBase64File = new FileInfo(dir + Path.DirectorySeparatorChar + "authorized_keys.txt"); var pubOpenSshBase64Str = KeyHelper.ExportPubKeyBase64(_user, new List <tbl_PublicKey>() { pubKey }); File.WriteAllText(pubOpenSshBase64File.FullName, pubOpenSshBase64Str.ToString()); Console.Out.WriteLine("Created " + pubOpenSshBase64File); //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)); } }