public async Task <ISecretKey> Generate(IMasterKey masterKey, IPublicKey publicKey, IAttributes attributes) { try { var masterKeyFile = await LocalHost.WriteFileAsync(masterKey.Value); var publicKeyFile = await LocalHost.WriteFileAsync(publicKey.Value); var privateKeyFile = LocalHost.GetRandomFilename(); await LocalHost.RunProcessAsync("cpabe-keygen", $"-o {privateKeyFile} {publicKeyFile} {masterKeyFile} {attributes.Get()}"); var privateKeyBytes = await LocalHost.ReadFileAsync(privateKeyFile); var privateKey = new MockSecretKey() { Value = privateKeyBytes }; File.Delete(masterKeyFile); File.Delete(publicKeyFile); File.Delete(privateKeyFile); return(privateKey); } catch (Exception exception) { throw new ABESchemeException($"Error has occured during secret key generation: {attributes.Get()}", exception); } }
public async Task <ICipherText> Encrypt(byte[] data, IPublicKey publicKey, IAccessPolicy accessPolicy) { try { var publicKeyFile = await LocalHost.WriteFileAsync(publicKey.Value); var messageFile = await LocalHost.WriteFileAsync(data); var encodedDataFile = LocalHost.GetRandomFilename(); await LocalHost.RunProcessAsync("cpabe-enc", $"-o {encodedDataFile} {publicKeyFile} {messageFile} \"{accessPolicy.AndGate()}\""); var encodedDataBytes = await LocalHost.ReadFileAsync(encodedDataFile); var encodedData = new MockCipherText() { Value = encodedDataBytes }; File.Delete(publicKeyFile); File.Delete(messageFile); File.Delete(encodedDataFile); return(encodedData); } catch (Exception exception) { throw new ABESchemeException($"Error has occured during encryption: {accessPolicy.AndGate()}", exception); } }
public async Task <byte[]> DecryptToBytes(ICipherText cipherText, IPublicKey publicKey, ISecretKey secretKey) { try { var cipherTextFile = await LocalHost.WriteFileAsync(cipherText.Value); var publicKeyFile = await LocalHost.WriteFileAsync(publicKey.Value); var secretKeyFile = await LocalHost.WriteFileAsync(secretKey.Value); var messageFile = LocalHost.GetRandomFilename(); await LocalHost.RunProcessAsync("cpabe-dec", $"-o {messageFile} {publicKeyFile} {secretKeyFile} {cipherTextFile}"); var messageBytes = await LocalHost.ReadFileAsync(messageFile); File.Delete(publicKeyFile); File.Delete(secretKeyFile); return(messageBytes); } catch (Exception exception) { if (exception.Message.Contains("cannot decrypt")) { throw new UnathorizedAttributesAccessException(); } throw new ABESchemeException("Error has occured during decryption", exception); } }
public async Task <SetupResult> Setup() { try { var masterKeyFile = LocalHost.GetRandomFilename(); var publicKeyFile = LocalHost.GetRandomFilename(); await LocalHost.RunProcessAsync("cpabe-setup", $"-p {publicKeyFile} -m {masterKeyFile}"); var masterKeyBytes = await LocalHost.ReadFileAsync(masterKeyFile); var publicKeyBytes = await LocalHost.ReadFileAsync(publicKeyFile); var setupResult = new SetupResult() { MasterKey = new MockMasterKey() { Value = masterKeyBytes }, PublicKey = new MockPublicKey() { Value = publicKeyBytes } }; File.Delete(masterKeyFile); File.Delete(publicKeyFile); return(setupResult); } catch (Exception exception) { throw new ABESchemeException("Error has occured during initialization", exception); } }
/** * [EN] * Has to be called outside the constructor to not to bug the visual designer (because of the call to LocalHost.listInstalledNodeVersions) */ public void init() { foreach (String v in LocalHost.listInstalledNodeVersions()) { nodeVersionChooser.DropDownItems.Add(v); } }
public bool Load() { JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> json; try { json = serializer.Deserialize <dynamic>(File.ReadAllText("proxy.txt")); bool ssl = false; bool.TryParse(json["ssl"].ToString(), out ssl); IsSSL = ssl; // Local server LocalHost = json["local_host"].ToString(); try { string[] localHost = LocalHost.Split(':'); LocalHostEndPoint = new IPEndPoint(Dns.GetHostEntry(localHost[0]).AddressList[0], int.Parse(localHost[1])); } catch (Exception e) { Console.WriteLine("\"local_host\" value is invalid!"); Console.WriteLine($" Exception: {e}"); } // Remote pool PoolAddress = json["pool_address"].ToString(); try { string[] remoteHost = PoolAddress.Split(':'); PoolEndPoint = new IPEndPoint(Dns.GetHostEntry(remoteHost[0]).AddressList[0], int.Parse(remoteHost[1])); } catch (Exception e) { Console.WriteLine("\"pool_address\" value is invalid!"); Console.WriteLine($" Exception: {e}"); } // Set wallet Wallet = json["wallet"].ToString().Trim(); // Worker name if (json.ContainsKey("worker") && json["worker"] != null) { Worker = json["worker"].ToString(); } else { Worker = null; } return(true); } catch { return(false); } }
public FullHost(bool interactive) { _interactive = interactive; LocalHost = new LocalHost(true); _currentRunspace = RunspaceFactory.CreateRunspace(LocalHost); _currentRunspace.Open(); LoadProfiles(); }
public FullHost(bool interactive) { _interactive = interactive; LocalHost = new LocalHost(true); _currentRunspace = RunspaceFactory.CreateRunspace(LocalHost); _currentRunspace.Open(); _ctrlStmtKeywordLength = Parser.ControlStatementKeywords.Max(s => s.Length); LoadProfiles(); }
public void load() { if (!_isLoaded) { // // Do we have the profiles directory ? // if (!Directory.Exists("Profiles")) { Directory.CreateDirectory("Profiles"); } // // Creating profile if file does not exist // if (!File.Exists(_profilePath)) { save(); } // // ...Or read it, if it exist, and load everything // else { // String str = File.ReadAllText(_profilePath, Encoding.UTF8); System.Xml.XmlDocument doc = new XmlDocument(); doc.LoadXml(str); // foreach (System.Xml.XmlNode i in doc.GetElementsByTagName("NodeInstance")) { if (File.Exists(i.Attributes.GetNamedItem("mainFile").InnerText)) { NodeInstance ni = NodePool.getInstance().createNodeInstance( LocalHost.getLatestInstalledNodeVersion(), i.Attributes.GetNamedItem("name").InnerText, i.Attributes.GetNamedItem("mainFile").InnerText ); ni.restartOnMainJsFileChange = i.Attributes.GetNamedItem("restartOnFileChange").InnerText == "true" ? true : false; ni.restartOnCrash = i.Attributes.GetNamedItem("restartOnCrash").InnerText == "true" ? true : false; if (i.FirstChild != null && i.FirstChild.Name == "RestartOnFileChangePatternsString") { ni.restartOnFileChangePatternsString = i.FirstChild.InnerText; } } } } // _isLoaded = true; } }
public FullHost() { myHost = new LocalHost(); myRunSpace = RunspaceFactory.CreateRunspace(myHost); myRunSpace.Open(); string exePath = Assembly.GetCallingAssembly().Location; string configPath = Path.Combine(Path.GetDirectoryName(exePath), "config.ps1"); Execute(configPath); }
/** * [EN] * Gets new web debug port */ public void regenerateWebDebugPort() { if (_webDebugPort == -1) { _webDebugPort = LocalHost.getOpenedPort(8282); } else { _webDebugPort = LocalHost.getOpenedPort(_webDebugPort); } }
/** * [EN] * Gets new debug port */ public void regenerateDebugPort() { if (_debugPort == -1) { _debugPort = LocalHost.getOpenedPort(8081); } else { _debugPort = LocalHost.getOpenedPort(_debugPort); } }
private void button_startServer_Click(object sender, RoutedEventArgs e) { Console.WriteLine("server starting"); // initialise serverside endpoint - the address of this machine serverEndPoint = new IPEndPoint(IPAddress.Any, Int32.Parse(GyroMouseServer.Properties.Settings.Default.preferredUDPPort)); // start listening for incoming commands at this port listeningPort = new UdpClient(serverEndPoint); // update UI elements textBlock_ip.Text = LocalHost.getLocalHost(); textBlock_port.Text = serverEndPoint.ToString().Substring(serverEndPoint.ToString().LastIndexOf(':') + 1); textBlock_notifications.Text = "Waiting for a client..."; // setup client endpoint to accept any incoming address this is the address of the phone clientEndpoint = new IPEndPoint(IPAddress.Any, 0); // initialise a barrier sync = new Barrier(2); // start the thread which handles client requests. The request parser thread waits till a client is available Console.WriteLine("starting thread which listends on the udp port"); clientRequestParser = new ClientRequestParser(blockingCollections, serverEndPoint, clientEndpoint, listeningPort, UIThread, ref sync); clientRequestParser.SetUIElements(textBlock_notifications, textBlock_ip); clientRequestParserThreadStart = new ThreadStart(clientRequestParser.ParseRequests); clientRequestHandleThread = new Thread(clientRequestParserThreadStart); clientRequestHandleThread.Name = "clientRequestHandleThread"; clientRequestHandleThread.Start(); Console.WriteLine("starting thread which listends on the udp port complete"); // start the tcpConnectionHandler Thread. This thread is responsible for connecting new clients Console.WriteLine("starting thread which listends for incoming connections"); tcpPort = Int32.Parse(GyroMouseServer.Properties.Settings.Default.preferredTCPPort); tCPConnectionHandler = new TCPConnectionHandler(serverIPAddr, tcpServer, tcpPort); ts = new ThreadStart(tCPConnectionHandler.Run); TCPConnectionHandlerThread = new Thread(ts); TCPConnectionHandlerThread.Name = "TCPConnectionHandlerThread"; TCPConnectionHandlerThread.Start(); Console.WriteLine("starting thread which listends for incoming connections complete"); // toggle UI elements button_startServer.IsEnabled = false; button_stopServer.IsEnabled = true; // generate a toast Toast.generateToastInfo(5000, "Server Started", LocalHost.getLocalHost() + " : " + serverEndPoint.ToString().Substring(serverEndPoint.ToString().LastIndexOf(':') + 1)); ServerState.serverRunning = true; Console.WriteLine("Server started"); }
public FullHost(bool interactive) { _interactive = interactive; LocalHost = new LocalHost(); _currentRunspace = RunspaceFactory.CreateRunspace(LocalHost); _currentRunspace.Open(); // TODO: check user directory for a config script and fall back to the default one of the installation // need to use .CodeBase property, as .Location gets the wrong path if the assembly was shadow-copied var localAssemblyPath = new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath; Execute(FormatConfigCommand(localAssemblyPath)); }
public AddNodeForm() { InitializeComponent(); nodeJsComboBox.DropDownStyle = ComboBoxStyle.DropDownList; //nodeJsComboBox.Items.Add("node0.4.0-on-cygwin"); //nodeJsComboBox.Items.Add("node0.5.8"); //nodeJsComboBox.Items.Add("node0.6.6"); foreach (string v in LocalHost.listInstalledNodeVersions()) { nodeJsComboBox.Items.Add(v); } nodeJsComboBox.SelectedIndex = nodeJsComboBox.Items.Count - 1; LocalHost.listInstalledNodeVersions(); }
private static void Server() { LocalHost host = new LocalHost(new NetConfiguration(5001) { Port = 5000, AllowConnectors = true, MaxConnections = 5, Name = "Server", Timeout = 1, NetworkRate = 500 }); host.Start(); while (isPooling) { host.Tick(); Thread.Sleep(50); } }
private static void Client() { LocalHost host = new LocalHost(new NetConfiguration(5001) { Port = 8080, AllowConnectors = false, MaxConnections = 5, Name = "Client", Timeout = 1, NetworkRate = 50 }); host.Start(); while (isPooling) { host.Tick(); Thread.Sleep(50); } }
public static Runspace CreateRunspace(InitialSessionState initialSessionState) { PSHost host = new LocalHost(); // DefaultHost(Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture); return(RunspaceFactory.CreateRunspace(host, initialSessionState)); }
public void Update(GameTime gameTime) { while (LocalHost.IsDataAvailable) { NetworkGamer sender; LocalHost.ReceiveData(_reader, out sender); string type = _reader.ReadString(); int id; if (type == "Player") { id = _reader.ReadInt32(); NetworkBehavior net = _behaviors.OfType <NetPlayerBehavior>().FirstOrDefault((b) => b.Id == id); if (net != null) { net.ReceiveData(_reader); } } if (type == "Fireball") { id = _reader.ReadInt32(); NetworkBehavior net = _behaviors.OfType <NetFireballBehavior>().FirstOrDefault((b) => b.Id == id); if (net != null) { net.ReceiveData(_reader); } } if (type == "CreatePlayer") { id = _reader.ReadInt32(); string name = _reader.ReadString(); Vector2 position = _reader.ReadVector2(); int health = _reader.ReadInt32(); Color color = _reader.ReadColor(); if (id != _session.LocalGamers[0].Id) { Player player = new Player(GameMain.CurrentLevel, position, color, new GenericInput(), name) { Health = health }; player.Behaviors.Add(new NetPlayerBehavior(player, id)); GameMain.CurrentLevel.AddEntity(player); } } if (type == "CreateFireball") { id = _reader.ReadInt32(); Vector2 position = _reader.ReadVector2(); Direction direction = (Direction)_reader.ReadInt32(); Color color = _reader.ReadColor(); Fireball fireball = new Fireball(GameMain.CurrentLevel, position, color, direction); fireball.Behaviors.Add(new NetFireballBehavior(fireball, id)); GameMain.CurrentLevel.AddEntity(fireball); } if (type == "RequestFireball") { Vector2 position = _reader.ReadVector2(); Direction direction = (Direction)_reader.ReadInt32(); Color color = _reader.ReadColor(); Fireball fireball = new Fireball(GameMain.CurrentLevel, position, color, direction); fireball.Behaviors.Add(new NetFireballBehavior(fireball, 0)); //GameMain.CurrentLevel.AddEntity(fireball); CreateFireball(fireball); } } _session.Update(); }
public FullHost() { myHost = new LocalHost(); myRunSpace = RunspaceFactory.CreateRunspace(myHost); myRunSpace.Open(); }
public static void SetConfigPath(string path) { LocalHost = new ConfigFileReader(path).ReadConfig(); _localTaskRunner = new LocalComponent <TJob>(LocalHost.MachineId, LocalHost.MachineNumber); }
private static VAL functions(string func, VAL parameters, Memory DS) { const string _FUNC_LOCAL_IP = "localip"; string conn; switch (func) { case _FUNC_CONFIG: conn = ConnectionString.SearchXmlConnectionString(parameters); if (conn != null) { return(new VAL(conn)); } else { return(new VAL()); } case _FUNC_CFG: conn = ConnectionString.SearchTieConnectionString(parameters, DS); if (conn != null) { return(new VAL(conn)); } else { return(new VAL()); } case "include": include(parameters, DS); return(new VAL()); case "mydoc": return(new VAL(ConfigurationEnvironment.MyDocuments)); case _FUNC_LOCAL_IP: if (parameters.Size > 2) { cerr.WriteLine($"function {_FUNC_LOCAL_IP} requires 0, 1 or 2 parameters"); return(new VAL()); } if (parameters.Size >= 1 && parameters[0].VALTYPE != VALTYPE.intcon) { cerr.WriteLine($"function {_FUNC_LOCAL_IP}(nic) requires integer parameter"); return(new VAL()); } if (parameters.Size >= 2 && parameters[1].VALTYPE != VALTYPE.intcon) { cerr.WriteLine($"function {_FUNC_LOCAL_IP}(nic, port) requires integer parameter"); return(new VAL()); } int index = 0; if (parameters.Size >= 1) { index = (int)parameters[0]; } int port = 0; if (parameters.Size >= 2) { port = (int)parameters[1]; } string address = LocalHost.GetLocalIP(index); if (port > 0) { return(new VAL($"{address}:{port}")); } else { return(new VAL(address)); } } return(null); }
internal static byte[] GetNetBytes(Match match) { if (match == null) { throw new ArgumentNullException("match"); } if (!match.Success) { throw new ArgumentException("Regular exception didn't match!", "match"); } Group group = match.get_Groups().get_Item("AmsNetId"); Group group2 = match.get_Groups().get_Item("First"); if (group2.Value != string.Empty) { return(new byte[] { byte.Parse(group2.Value), byte.Parse(match.get_Groups().get_Item("Second").Value), byte.Parse(match.get_Groups().get_Item("Third").Value), byte.Parse(match.get_Groups().get_Item("Fourth").Value), byte.Parse(match.get_Groups().get_Item("Fifth").Value), byte.Parse(match.get_Groups().get_Item("Sixth").Value) }); } StringComparer ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase; return((ordinalIgnoreCase.Compare(group.Value, "Local") != 0) ? ((ordinalIgnoreCase.Compare(group.Value, "LocalHost") != 0) ? ((ordinalIgnoreCase.Compare(group.Value, "Empty") != 0) ? null : Empty.ToBytes()) : LocalHost.ToBytes()) : Local.ToBytes()); }
public NodeInstanceStandardOutputForm(NodeInstance n) { // InitializeComponent(); // // Title // Text = n.name; // // NodePool events // NodePool.getInstance().NodeInstanceRemoved += new NodeInstanceRemovedEventHandler(_NodeInstanceRemoved); // // APP instance // _nodeInstance = n; nodeInstanceMainMenu1.init(); nodeInstanceMainMenu1.nodeInstance = _nodeInstance; nodeTerminal.nodeInstance = _nodeInstance; //_nodeInstance.run(); // // NPM instance // /* * _npmInstance = new NodeInstance(_nodeInstance.nodeVersion); * _npmInstance.name = "______NPM______"; * _npmInstance.mainJsFilePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @"Resources\nodejs\node0.6.6\node_modules\npm\cli.js"); */ _npmInstance = NodePool.getInstance("npm").createNodeInstance(_nodeInstance.nodeVersion, _nodeInstance.name + "______NPM______" + RuntimeUniqueId.getAsString(), Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @"Resources\nodejs\" + LocalHost.getLatestInstalledNodeVersion() + @"\node_modules\npm\cli.js")); _npmInstance.restartOnCrash = false; _npmInstance.restartOnMainJsFileChange = false; _npmInstance.workingDirectory = Path.GetDirectoryName(_nodeInstance.mainJsFilePath);// set working directory for local npm npmTerminal.nodeInstance = _npmInstance; _npmInstance.run(); // nodeTerminal.focusStdIn(); }