public CallResult KeyExchange_server(string publicKey, string iv) { //Initialize a new key provides this.keyProvider = AuthenticationComponent.getNewKeyProvider(); ECDiffieHellmanPublicKey otherKey = ECDiffieHellmanCngPublicKey.FromByteArray(publicKey.GetBytesBase64(), CngKeyBlobFormat.EccPublicBlob); //derive connection key from target's public key var key = keyProvider.DeriveKeyMaterial(otherKey); ClientConnection.WtlpClient.EncryptionKey = key; var initVector = iv.GetBytesBase64(); ClientConnection.WtlpClient.EncryptionIV = iv.GetBytesBase64(); //Increase Trust level (connection is now encrypted) this.ClientConnection.TrustLevel = 2; this.ClientConnection.MyTrustLevel = 2; //Send back our own public key so target can derive connection key, too CallResult result = new ResponseResult(keyProvider.PublicKey.ToByteArray().ToStringBase64()); //once the response has been sent, enable encryption for all following messages result.PostProcessingAction += delegate { this.ClientConnection.WtlpClient.EncryptMessages = true; }; //Reset key provider keyProvider = null; return(result); }
public Session(string target, IConnectionManager connectionManager) { this.connectionManager = connectionManager; this.Target = target; this.Name = target; this.connection = connectionManager.GetClientConnection(target); if (connection == null) { connection = connectionManager.AddClientConnection(target); connection.ConnectionReset += connection_ConnectionReset; connection.ConnectionTimedOut += connection_ConnectionTimedOut; connection.RemoteErrorOccurred += connection_RemoteErrorOccurred; } //authComponent = (AuthenticationComponent)connection.GetClientComponent(ComponentNamesExtended.Authentication); //clientInfoComponent = (ClientInfoClientComponent)connection.GetClientComponent(ComponentNamesExtended.ClientInfoProvider); //loggingConfigurator = (XmppLoggingConfiguratorComponent)connection.GetClientComponent(ComponentNamesExtended.XmppLoggingConfigurator); //fileShareComponent = (FileShareClientComponent)connection.GetClientComponent(ComponentNamesExtended.FileShare); authComponent = new AuthenticationComponent() { ClientConnection = connection }; clientInfoComponent = new ClientInfoClientComponent() { ClientConnection = connection }; loggingConfigurator = new XmppLoggingConfiguratorComponent() { ClientConnection = connection }; fileShareComponent = new FileShareClientComponent() { ClientConnection = connection }; //CommandInfo info = new CommandInfo(); commands.Add("get-status", new CommandInfo() { ParameterCount = 0, CommandMethod = getStatusCommand, CheckConnection = false}); commands.Add("connect", new CommandInfo() { ParameterCount = 0, CommandMethod = connectCommand, CheckConnection = false }); commands.Add("disconnect", new CommandInfo() { ParameterCount = 0, CommandMethod = disconnectCommand }); commands.Add("userauth", new CommandInfo() { ParameterCount = 1, CommandMethod = userauthCommand }); commands.Add("get-info", new CommandInfo() { ParameterCount = 0, CommandMethod = getInfoCommand }); commands.Add("exit-session", new CommandInfo() { CheckConnection=false, ParameterCount = 0, CommandMethod = exitSessionCommand }); commands.Add("logger.get-enabled", new CommandInfo() { ParameterCount = 0, CommandMethod = loggerGetEnabledCommand }); commands.Add("logger.set-enabled", new CommandInfo() { ParameterCount = 1, CommandMethod = loggerSetEnabledCommand }); commands.Add("logger.get-loglevel", new CommandInfo() { ParameterCount = 0, CommandMethod = loggerGetLogLevelCommand }); commands.Add("logger.set-loglevel", new CommandInfo() { ParameterCount = 1, CommandMethod = loggerSetLogLevelCommand }); commands.Add("logger.get-recipient", new CommandInfo() { ParameterCount = 0, CommandMethod = loggerGetRecipientCommand }); commands.Add("logger.set-recipient", new CommandInfo() { ParameterCount = 1, CommandMethod = loggerSetRecipientCommand }); commands.Add("logger.get-debuglogging", new CommandInfo() { ParameterCount = 0, CommandMethod = loggerGetDebugLoggingCommand }); commands.Add("logger.set-debuglogging", new CommandInfo() { ParameterCount = 1, CommandMethod = loggerSetDebugLoggingCommand }); commands.Add("logger.test-logging", new CommandInfo() { ParameterCount = 1, CommandMethod = loggerTestLoggingCommand }); commands.Add("fileshare.add-directory", new CommandInfo() { ParameterCount = 2, CommandMethod = fileshareAddDirectoryCommand }); commands.Add("fileshare.remove-directory", new CommandInfo() { ParameterCount = 1, CommandMethod = fileshareRemoveDirectoryCommand }); commands.Add("fileshare.get-directory", new CommandInfo() { ParameterCount = 1, CommandMethod = fileshareGetDirectoryCommand }); commands.Add("fileshare.get-file", new CommandInfo() { ParameterCount = 1, CommandMethod = fileshareGetFileCommand }); commands.Add("fileshare.add-permission", new CommandInfo() { ParameterCount = -2, CommandMethod = fileshareAddPermissionCommand }); commands.Add("fileshare.remove-permission", new CommandInfo() { ParameterCount = 1, CommandMethod = fileshareRemovePermissionCommand }); commands.Add("fileshare.get-mounts", new CommandInfo() { ParameterCount = 0, CommandMethod = fileshareGetMountsCommand }); commands.Add("fileshare.check-permission", new CommandInfo() { ParameterCount = 1, CommandMethod = fileshareCheckPermissionCommand }); commands.Add("fileshare.get-permissions", new CommandInfo() { ParameterCount = 0, CommandMethod = fileshareGetPermissionsCommand }); commands.Add("fileshare.get-rootdirectory", new CommandInfo() { ParameterCount = 0, CommandMethod = fileshareGetRootDirectoryCommand }); commands.Add("fileshare.set-rootdirectory", new CommandInfo() { ParameterCount = 1, CommandMethod = fileshareSetRootDirectoryCommand }); commands.Add("fileshare.create-snapshot", new CommandInfo() { ParameterCount = 0, CommandMethod = fileshareCreateSnapshotCommand }); commands.Add("fileshare.get-snapshots", new CommandInfo() { ParameterCount = 0, CommandMethod = fileshareGetSnapshotsCommand }); }
static void Main(string[] args) { //Display general Info printLogo(); Console.Title = "Wolpertinger Fileserver"; Console.WriteLine(); ConsoleHelper.WriteLine(ConsoleColor.Red, " Wolpertinger.FileServer {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()); ConsoleHelper.WriteLine(ConsoleColor.Red, " Wolpertinger.Core {0}", Assembly.GetAssembly(typeof(DefaultConnectionManager)).GetName().Version.ToString()); Console.WriteLine(); //Set up XmlSerializer XmlSerializer.RegisterType(typeof(ClientInfo), "clientInfo"); XmlSerializer.RegisterType(typeof(DirectoryObject), "directoryObject"); XmlSerializer.RegisterType(typeof(FileObject), "fileObject"); XmlSerializer.RegisterType(typeof(Permission), "permission"); XmlSerializer.RegisterType(typeof(MountInfo), "mountInfo"); XmlSerializer.RegisterType(typeof(SnapshotInfo), "snapshotInfo"); XmlSerializer.RegisterType(typeof(RemoteMethodCall), "remoteMethodCall"); XmlSerializer.RegisterType(typeof(RemoteMethodResponse), "remoteMethodResponse"); XmlSerializer.RegisterType(typeof(RemoteError), "remoteError"); //Set up logger LoggerService.SetLogger(new CompositeLogger(new Wolpertinger.Core.ConsoleLogger(), new XmppLogger())); logger = LoggerService.GetLogger("Wolpertinger.Fileserver"); FileObject.HashingService = HashingService.GetHashingService(); AuthenticationComponent foo = new AuthenticationComponent(); if (!Directory.Exists(Path.GetDirectoryName(folder))) { Directory.CreateDirectory(Path.GetDirectoryName(folder)); } //Set up AppData directory if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } //Set up databasefolder if (!Directory.Exists(DatabaseFolder)) { Directory.CreateDirectory(DatabaseFolder); } //Initalize ConnectionManager //TODO manager.AddProfile(Profile.FileServer); //manager.AddComponent(typeof(ClientInfoProvider), typeof(XmppLoggingConfigurator), typeof(FileShare)); connectionManager = new DefaultConnectionManager(); //connectionManager.ComponentFactory = new DefaultComponentFactory(); connectionManager.LoadSettings(folder); //connectionManager.Connect(); connectionManager.AcceptIncomingConnections = true; XmppLogger.ConnectionManager = connectionManager; XmppLogger.LoadSettings(); //Load setting specific to this role connectionManager.WolpertingerUsername = settingsFile.GetItem<string>("AdminUsername"); connectionManager.WolpertingerPassword = settingsFile.GetItem<string>("AdminPassword").ToSecureString(); FileShareServerComponent.Init(); //Console.WriteLine("Account: " + connectionManager.XmppUsername + "@" + connectionManager.XmppServer); Console.ReadLine(); }