public async Task GenerateCredentialsAsync( IWin32Window owner, InstanceLocator instanceLocator, ConnectionSettingsBase settings, bool silent) { // Prompt for username to use. string username; if (silent) { username = string.IsNullOrEmpty(settings.Username.StringValue) ? this.serviceProvider .GetService <IAuthorizationAdapter>() .Authorization .SuggestWindowsUsername() : settings.Username.StringValue; } else { username = this.serviceProvider .GetService <IGenerateCredentialsDialog>() .PromptForUsername( owner, string.IsNullOrEmpty(settings.Username.StringValue) ? this.serviceProvider .GetService <IAuthorizationAdapter>() .Authorization .SuggestWindowsUsername() : settings.Username.StringValue); if (username == null) { // Aborted. throw new OperationCanceledException(); } } var credentials = await this.serviceProvider.GetService <IJobService>().RunInBackground( new JobDescription("Generating Windows logon credentials..."), token => this.serviceProvider .GetService <IComputeEngineAdapter>() .ResetWindowsUserAsync( instanceLocator, username, token)) .ConfigureAwait(true); if (!silent) { this.serviceProvider.GetService <IShowCredentialsDialog>().ShowDialog( owner, credentials.UserName, credentials.Password); } // Save credentials. settings.Username.StringValue = credentials.UserName; settings.Password.ClearTextValue = credentials.Password; settings.Domain.StringValue = null; }
public FullNodeTumblerClientConfiguration(TumblingState tumblingState, bool onlyMonitor, bool connectionTest = false, bool useProxy = true) { this.tumblingState = tumblingState ?? throw new ArgumentNullException(nameof(tumblingState)); Network = tumblingState.TumblerNetwork ?? throw new ArgumentNullException(nameof(tumblingState.TumblerNetwork)); Logs.LogDir = this.tumblingState.NodeSettings.DataDir; if (!onlyMonitor || connectionTest) { TorPath = "tor"; Cooperative = true; AllowInsecure = true; if (tumblingState.TumblerUri != null) { TumblerServer = new TumblerUrlBuilder(this.tumblingState.TumblerUri); if (TumblerServer == null) { throw new ConfigException("Tumbler server is not configured"); } } if (useProxy) { AliceConnectionSettings = new SocksConnectionSettings() { Proxy = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050) }; BobConnectionSettings = new SocksConnectionSettings() { Proxy = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050) }; } else { // This mode is only for unit/integration tests, as it allows testing with latency introduced by Tor AliceConnectionSettings = new ConnectionSettingsBase(); BobConnectionSettings = new ConnectionSettingsBase(); } if (connectionTest) { return; } } OnlyMonitor = onlyMonitor; Logs.Configuration.LogInformation("Network: " + Network); DataDir = GetTumbleBitDataDir(this.tumblingState.NodeSettings.DataDir); Logs.Configuration.LogInformation("Data directory set to " + DataDir); DBreezeRepository = new DBreezeRepository(Path.Combine(DataDir, "db2")); Tracker = new Tracker(DBreezeRepository, Network); // Need to use our own ExternalServices implementations to remove RPC dependency Services = ExternalServices.CreateFromFullNode(DBreezeRepository, Tracker, this.tumblingState); }
public ConnectionSettingsEditor( ConnectionSettingsBase settings, Action <ConnectionSettingsBase> saveSettings, ConnectionSettingsEditor parent) { this.settings = settings; this.saveSettings = saveSettings; this.parent = parent; }
private async Task SetupTorAsync(ClientInteraction interaction, ConnectionSettingsBase settings, string torPath) { var tor = settings as ITorConnectionSettings; if (tor == null) { throw new ConfigException("TOR Settings not properly configured"); } _Disposables.Add(await tor.SetupAsync(interaction, torPath).ConfigureAwait(false)); }
private async Task SetupTorAsync(ClientInteraction interaction, ConnectionSettingsBase settings, string torPath) { var tor = settings as ITorConnectionSettings; if (tor == null) { return; } _Disposables.Add(await tor.SetupAsync(interaction, torPath).ConfigureAwait(false)); }
protected InventoryNode( string name, int iconIndex, ConnectionSettingsBase settings, Action <ConnectionSettingsBase> saveSettings, InventoryNode parent) : base(name, iconIndex, iconIndex) { this.settings = settings; this.saveSettings = saveSettings; this.parent = parent; }
private TumblerClient CreateTumblerClient(int cycleId, ConnectionSettingsBase settings) { if (!AllowInsecure && DateTimeOffset.UtcNow - previousHandlerCreationDate < CircuitRenewInterval) { throw new PrematureRequestException(); } previousHandlerCreationDate = DateTime.UtcNow; var client = new TumblerClient(Network, TumblerServer, cycleId); var handler = settings.CreateHttpHandler(); if (handler != null) { client.SetHttpHandler(handler); } return(client); }
private async Task SetupTorAsync(ClientInteraction interaction, ConnectionSettingsBase settings, string torPath) { var tor = settings as ITorConnectionSettings; if (tor == null) { throw new ConfigException("TOR Settings not properly configured"); } try { var torSettings = await tor.SetupAsync(interaction, torPath).ConfigureAwait(false); _Disposables.Add(torSettings); } catch (ConfigException cex) { throw new PrivacyProtocolConfigException(PrivacyProtocolType.Tor, cex); } }
public TumblerClientConfiguration LoadArgs(String[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest : null; if (ConfigurationFile != null) { AssetConfigFileExists(); var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); Network = Network ?? (configTemp.GetOrDefault <bool>("testnet", false) ? Network.TestNet : configTemp.GetOrDefault <bool>("regtest", false) ? Network.RegTest : null); } Network = Network ?? Network.Main; if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBit", Network); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(DataDir, Network); } Logs.Configuration.LogInformation("Network: " + Network); Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigurationException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); config.AddAlias("server", "tumbler.server"); OnlyMonitor = config.GetOrDefault <bool>("onlymonitor", false); Cooperative = config.GetOrDefault <bool>("cooperative", true); TumblerServer = config.GetOrDefault("tumbler.server", null as TumblerUrlBuilder); TorPath = config.GetOrDefault <string>("torpath", "tor"); RPCArgs = RPCArgs.Parse(config, Network); if (!OnlyMonitor && TumblerServer == null) { throw new ConfigException("tumbler.server not configured"); } try { var key = config.GetOrDefault("outputwallet.extpubkey", null as string); if (key != null) { OutputWallet.RootKey = new BitcoinExtPubKey(key, Network); } } catch { throw new ConfigException("outputwallet.extpubkey is not configured correctly"); } OutputWallet.KeyPath = new KeyPath("0"); string keyPathString = config.GetOrDefault("outputwallet.keypath", null as string); if (keyPathString != null) { try { OutputWallet.KeyPath = new KeyPath(keyPathString); } catch { throw new ConfigException("outputwallet.keypath is not configured correctly"); } } if (OutputWallet.KeyPath.ToString().Contains("'")) { throw new ConfigException("outputwallet.keypath should not contain any hardened derivation"); } if (OutputWallet.RootKey != null && OutputWallet.RootKey.Network != Network) { throw new ConfigException("outputwallet.extpubkey is pointing an incorrect network"); } OutputWallet.RPCArgs = RPCArgs.Parse(config, Network, "outputwallet"); AliceConnectionSettings = ConnectionSettingsBase.ParseConnectionSettings("alice", config); BobConnectionSettings = ConnectionSettingsBase.ParseConnectionSettings("bob", config); AllowInsecure = config.GetOrDefault <bool>("allowinsecure", IsTest(Network)); return(this); }
public static void MappingFor <T>(this ConnectionSettingsBase <ConnectionSettings> connectionSettings) where T : class { var name = typeof(T).Name.ToLower(); connectionSettings.DefaultMappingFor <T>(m => m.IndexName(name).IndexName(name)); }
public async Task ShowCredentialsPromptAsync( IWin32Window owner, InstanceLocator instanceLocator, ConnectionSettingsBase settings, bool allowJumpToSettings) { var credentialsService = this.serviceProvider.GetService <ICredentialsService>(); // // Determine which options to show in prompt. // var credentialsExist = !string.IsNullOrEmpty(settings.RdpUsername.StringValue) && !string.IsNullOrEmpty(settings.RdpPassword.ClearTextValue); if (settings.RdpCredentialGenerationBehavior.EnumValue == RdpCredentialGenerationBehavior.Force && await IsGrantedPermissionToGenerateCredentials( credentialsService, instanceLocator) .ConfigureAwait(true)) { // Generate new credentials right away and skip the prompt. await credentialsService.GenerateCredentialsAsync( owner, instanceLocator, settings, true) .ConfigureAwait(true); return; } var options = new List <CredentialOption>(); if ((!credentialsExist && settings.RdpCredentialGenerationBehavior.EnumValue == RdpCredentialGenerationBehavior.AllowIfNoCredentialsFound && await IsGrantedPermissionToGenerateCredentials( credentialsService, instanceLocator) .ConfigureAwait(true)) || settings.RdpCredentialGenerationBehavior.EnumValue == RdpCredentialGenerationBehavior.Allow) { options.Add( new CredentialOption() { Title = "Generate new credentials", Apply = () => credentialsService .GenerateCredentialsAsync( owner, instanceLocator, settings, false) }); } if (!credentialsExist && allowJumpToSettings) { options.Add( new CredentialOption() { Title = "Configure credentials", Apply = () => { // Configure credentials -> jump to settings. this.serviceProvider .GetService <IConnectionSettingsWindow>() .ShowWindow(); return(Task.FromException(new OperationCanceledException())); } }); } options.Add( new CredentialOption() { Title = "Connect without configuring credentials", Apply = () => Task.CompletedTask }); // // Prompt. // CredentialOption selectedOption; if (options.Count > 1) { var optionIndex = this.serviceProvider.GetService <ITaskDialog>().ShowOptionsTaskDialog( owner, TaskDialogIcons.TD_INFORMATION_ICON, "Credentials", $"You do not have any saved credentials for {instanceLocator.Name}", "How do you want to proceed?", null, options.Select(o => o.Title).ToList(), null, //"Do not show this prompt again", out bool donotAskAgain); selectedOption = options[optionIndex]; } else { // Do not prompt if there is only one option. selectedOption = options[0]; } // // Apply. // await selectedOption .Apply() .ConfigureAwait(true); }