private void CredentialsChanged(object sender, EventArgs e) { if (!_profileNameUserCreated) { _profileNameTextBox.Text = CredentialsUI.GetQualifiedUserName(_logonCredentialsUI.UserNameTextBox.Text, _logonCredentialsUI.DomainTextBox.Text); _profileNameUserCreated = false; } }
private void PasswordEncryptionMethodCombo_Changed(object sender, EventArgs e) { switch (_passwordEncryptionMethodCombo.SelectedValue) { case EncryptionMethod.LogonCredentials: _passwordEncryptionDataLabel.Text = "用户名:"; _passwordEncryptionDataButton.Text = CredentialsUI.GetLoggedInUser(); _passwordEncryptionDataButton.Tag = null; _passwordEncryptionDataButton.Enabled = false; _passwordEncryptionDataInfoLabel.Text = string.Empty; break; case EncryptionMethod.Certificate: { X509Certificate2 x509Certificate = _passwordEncryptionDataButton.Tag as X509Certificate2; if (x509Certificate == null) { try { base.Enabled = false; x509Certificate = Encryption.SelectCertificate(); } finally { base.Enabled = true; } } if (x509Certificate != null) { SetSelectedCertificate(x509Certificate); } else { _passwordEncryptionMethodCombo.SelectedValue = _passwordEncryptionMethodPrevious; } break; } default: throw new NotImplementedException("Unexpected encryption method '{0}'".InvariantFormat(_passwordEncryptionMethodCombo.SelectedValue.ToString())); } _passwordEncryptionMethodPrevious = _passwordEncryptionMethodCombo.SelectedValue; }
public void CreateControls(LogonCredentialsDialogOptions options) { int tabIndex = 0; int rowIndex = 0; CreateInheritanceControl(ref rowIndex, ref tabIndex); if (base.InheritanceControl != null) { base.InheritanceControl.EnabledChanged += delegate(bool enabled) { _useGatewayServerCheckBox.Enabled = enabled; UseGatewayServerCheckBox_CheckedChanged(null, null); }; } _useGatewayServerCheckBox = FormTools.AddCheckBox(this, "使用TS网关服务器", base.Settings.UseGatewayServer, 1, ref rowIndex, ref tabIndex); _useGatewayServerCheckBox.CheckedChanged += UseGatewayServerCheckBox_CheckedChanged; _gatewayHostNameTextBox = FormTools.AddLabeledTextBox(this, "服务器名称:", base.Settings.HostName, ref rowIndex, ref tabIndex); _gatewayHostNameTextBox.Validate = delegate { if (_gatewayHostNameTextBox.Enabled) { _gatewayHostNameTextBox.Text = _gatewayHostNameTextBox.Text.Trim(); string text = _gatewayHostNameTextBox.Text; if (text.Length == 0) { return("请输入服务器名称"); } } return(null); }; _gatewayLocalBypassCheckBox = FormTools.AddCheckBox(this, "绕过本地地址", base.Settings.BypassGatewayForLocalAddresses, 1, ref rowIndex, ref tabIndex); _gatewayLogonMethodCombo = FormTools.AddLabeledEnumDropDown(this, "登录方式", base.Settings.LogonMethod, ref rowIndex, ref tabIndex, RdpClient.GatewayLogonMethodToString); _gatewayLogonMethodCombo.SelectedValueChanged += GatewayLogonMethodComboBox_SelectedValueChanged; if (RdpClient.SupportsGatewayCredentials) { _gatewayCredSharingCheckBox = FormTools.AddCheckBox(this, "与远程计算机共享网关证书", base.Settings.CredentialSharing, 1, ref rowIndex, ref tabIndex); _gatewayCredSharingCheckBox.CheckedChanged += GatewayCredSharingCheckBox_CheckedChanged; _credentialsUI = new CredentialsUI(base.InheritanceControl); _credentialsUI.AddControlsToParent(this, options, ref rowIndex, ref tabIndex); } }
private unsafe static string DecryptStringUsingLocalUser(string encryptedString) { Crypto.DataBlob optionalEntropy = default(Crypto.DataBlob); Crypto.CryptProtectPromptStruct promptStruct = default(Crypto.CryptProtectPromptStruct); if (string.IsNullOrEmpty(encryptedString)) { return(string.Empty); } optionalEntropy.Size = 0; promptStruct.Size = 0; byte[] array = Convert.FromBase64String(encryptedString); Crypto.DataBlob dataIn = default(Crypto.DataBlob); dataIn.Size = array.Length; Crypto.DataBlob dataOut; string result; fixed(byte *value = array) { dataIn.Data = (IntPtr)(void *)value; if (!Crypto.CryptUnprotectData(ref dataIn, null, ref optionalEntropy, (IntPtr)null, ref promptStruct, 0, out dataOut)) { throw new Exception("使用{0}证书解密失败".InvariantFormat(CredentialsUI.GetLoggedInUser())); } char *ptr = (char *)(void *)dataOut.Data; char[] array2 = new char[dataOut.Size / 2]; for (int i = 0; i < array2.Length; i++) { array2[i] = ptr[i]; } result = new string(array2); } Crypto.LocalFree(dataOut.Data); return(result); }
protected LogonSettingsDialog(string title, string buttonText) : base(title, buttonText, null) { SuspendLayout(); _logonCredentialsUI = new CredentialsUI(null); }
static EncryptionSettings() { typeof(EncryptionSettings).GetSettingProperties(out _settingProperties); _settingProperties["CredentialName"].Attribute.DefaultValue = CredentialsUI.GetLoggedInUser(); }