SSHOptionPanel.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:11k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: SSHOptionPanel.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.Windows.Forms;
  7. using System.Diagnostics;
  8. using Poderosa.Toolkit;
  9. using Poderosa.Config;
  10. using Poderosa.SSH;
  11. using Poderosa.UI;
  12. using Granados.SSHC;
  13. using Granados.PKI;
  14. namespace Poderosa.Forms
  15. {
  16. /// <summary>
  17. /// SSHOptionPanel 偺奣梫偺愢柧偱偡丅
  18. /// </summary>
  19. internal class SSHOptionPanel : OptionDialog.CategoryPanel
  20. {
  21. private string[] _cipherAlgorithmOrder;
  22. private System.Windows.Forms.GroupBox _cipherOrderGroup;
  23. private System.Windows.Forms.ListBox _cipherOrderList;
  24. private System.Windows.Forms.Button _algorithmOrderUp;
  25. private System.Windows.Forms.Button _algorithmOrderDown;
  26. private System.Windows.Forms.GroupBox _ssh2OptionGroup;
  27. private System.Windows.Forms.Label _hostKeyLabel;
  28. private ComboBox _hostKeyBox;
  29. private System.Windows.Forms.Label _windowSizeLabel;
  30. private TextBox _windowSizeBox;
  31. private System.Windows.Forms.GroupBox _sshMiscGroup;
  32. private CheckBox _retainsPassphrase;
  33. private CheckBox _sshCheckMAC;
  34. public SSHOptionPanel()
  35. {
  36. InitializeComponent();
  37. FillText();
  38. }
  39. private void InitializeComponent() {
  40. this._cipherOrderGroup = new System.Windows.Forms.GroupBox();
  41. this._cipherOrderList = new System.Windows.Forms.ListBox();
  42. this._algorithmOrderUp = new System.Windows.Forms.Button();
  43. this._algorithmOrderDown = new System.Windows.Forms.Button();
  44. this._ssh2OptionGroup = new System.Windows.Forms.GroupBox();
  45. this._hostKeyLabel = new System.Windows.Forms.Label();
  46. this._hostKeyBox = new ComboBox();
  47. this._windowSizeLabel = new System.Windows.Forms.Label();
  48. this._windowSizeBox = new TextBox();
  49. this._sshMiscGroup = new System.Windows.Forms.GroupBox();
  50. this._retainsPassphrase = new System.Windows.Forms.CheckBox();
  51. this._sshCheckMAC = new System.Windows.Forms.CheckBox();
  52. this._cipherOrderGroup.SuspendLayout();
  53. this._ssh2OptionGroup.SuspendLayout();
  54. this._sshMiscGroup.SuspendLayout();
  55. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  56.    this._cipherOrderGroup,
  57.    this._ssh2OptionGroup,
  58.    this._sshMiscGroup});
  59. // 
  60. // _cipherOrderGroup
  61. // 
  62. this._cipherOrderGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  63. this._cipherOrderList,
  64. this._algorithmOrderUp,
  65. this._algorithmOrderDown});
  66. this._cipherOrderGroup.Location = new System.Drawing.Point(8, 8);
  67. this._cipherOrderGroup.Name = "_cipherOrderGroup";
  68. this._cipherOrderGroup.FlatStyle = FlatStyle.System;
  69. this._cipherOrderGroup.Size = new System.Drawing.Size(416, 80);
  70. this._cipherOrderGroup.TabIndex = 0;
  71. this._cipherOrderGroup.TabStop = false;
  72. // 
  73. // _cipherOrderList
  74. // 
  75. this._cipherOrderList.ItemHeight = 12;
  76. this._cipherOrderList.Location = new System.Drawing.Point(8, 16);
  77. this._cipherOrderList.Name = "_cipherOrderList";
  78. this._cipherOrderList.Size = new System.Drawing.Size(208, 56);
  79. this._cipherOrderList.TabIndex = 1;
  80. // 
  81. // _algorithmOrderUp
  82. // 
  83. this._algorithmOrderUp.Location = new System.Drawing.Point(232, 16);
  84. this._algorithmOrderUp.Name = "_algorithmOrderUp";
  85. this._algorithmOrderUp.FlatStyle = FlatStyle.System;
  86. this._algorithmOrderUp.TabIndex = 2;
  87. this._algorithmOrderUp.Click += new System.EventHandler(this.OnCipherAlgorithmOrderUp);
  88. // 
  89. // _algorithmOrderDown
  90. // 
  91. this._algorithmOrderDown.Location = new System.Drawing.Point(232, 48);
  92. this._algorithmOrderDown.Name = "_algorithmOrderDown";
  93. this._algorithmOrderDown.FlatStyle = FlatStyle.System;
  94. this._algorithmOrderDown.TabIndex = 3;
  95. this._algorithmOrderDown.Click += new System.EventHandler(this.OnCipherAlgorithmOrderDown);
  96. // 
  97. // _ssh2OptionGroup
  98. // 
  99. this._ssh2OptionGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  100.    this._hostKeyLabel,
  101.    this._hostKeyBox,
  102.    this._windowSizeLabel,
  103.    this._windowSizeBox});
  104. this._ssh2OptionGroup.Location = new System.Drawing.Point(8, 96);
  105. this._ssh2OptionGroup.Name = "_ssh2OptionGroup";
  106. this._ssh2OptionGroup.FlatStyle = FlatStyle.System;
  107. this._ssh2OptionGroup.Size = new System.Drawing.Size(416, 80);
  108. this._ssh2OptionGroup.TabIndex = 4;
  109. this._ssh2OptionGroup.TabStop = false;
  110. // 
  111. // _hostKeyLabel
  112. // 
  113. this._hostKeyLabel.Location = new System.Drawing.Point(8, 16);
  114. this._hostKeyLabel.Name = "_hostKeyLabel";
  115. this._hostKeyLabel.Size = new System.Drawing.Size(200, 23);
  116. this._hostKeyLabel.TabIndex = 5;
  117. this._hostKeyLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  118. // 
  119. // _hostKeyBox
  120. // 
  121. this._hostKeyBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  122. this._hostKeyBox.Items.AddRange(new object[] {
  123.  "DSA",
  124.  "RSA"});
  125. this._hostKeyBox.Location = new System.Drawing.Point(224, 16);
  126. this._hostKeyBox.Name = "_hostKeyBox";
  127. this._hostKeyBox.Size = new System.Drawing.Size(121, 20);
  128. this._hostKeyBox.TabIndex = 6;
  129. // 
  130. // _windowSizeLabel
  131. // 
  132. this._windowSizeLabel.Location = new System.Drawing.Point(8, 48);
  133. this._windowSizeLabel.Name = "_windowSizeLabel";
  134. this._windowSizeLabel.Size = new System.Drawing.Size(192, 23);
  135. this._windowSizeLabel.TabIndex = 7;
  136. this._windowSizeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  137. // 
  138. // _windowSizeBox
  139. // 
  140. this._windowSizeBox.Location = new System.Drawing.Point(224, 48);
  141. this._windowSizeBox.MaxLength = 5;
  142. this._windowSizeBox.Name = "_windowSizeBox";
  143. this._windowSizeBox.Size = new System.Drawing.Size(120, 19);
  144. this._windowSizeBox.TabIndex = 8;
  145. this._windowSizeBox.Text = "0";
  146. // 
  147. // _sshMiscGroup
  148. // 
  149. this._sshMiscGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  150. this._sshCheckMAC,
  151. this._retainsPassphrase});
  152. this._sshMiscGroup.Location = new System.Drawing.Point(8, 180);
  153. this._sshMiscGroup.Name = "_sshMiscGroup";
  154. this._sshMiscGroup.FlatStyle = FlatStyle.System;
  155. this._sshMiscGroup.Size = new System.Drawing.Size(416, 80);
  156. this._sshMiscGroup.TabIndex = 9;
  157. this._sshMiscGroup.TabStop = false;
  158. // 
  159. // _retainsPassphrase
  160. // 
  161. this._retainsPassphrase.Location = new System.Drawing.Point(8, 14);
  162. this._retainsPassphrase.Name = "_retainsPassphrase";
  163. this._retainsPassphrase.FlatStyle = FlatStyle.System;
  164. this._retainsPassphrase.Size = new System.Drawing.Size(400, 23);
  165. this._retainsPassphrase.TabIndex = 10;
  166. // 
  167. // _sshCheckMAC
  168. // 
  169. this._sshCheckMAC.Location = new System.Drawing.Point(8, 33);
  170. this._sshCheckMAC.Name = "_sshCheckMAC";
  171. this._sshCheckMAC.FlatStyle = FlatStyle.System;
  172. this._sshCheckMAC.Size = new System.Drawing.Size(400, 37);
  173. this._sshCheckMAC.TabIndex = 11;
  174. this.BackColor = ThemeUtil.TabPaneBackColor;
  175. this._cipherOrderGroup.ResumeLayout();
  176. this._ssh2OptionGroup.ResumeLayout();
  177. this._sshMiscGroup.ResumeLayout();
  178. }
  179. private void FillText() {
  180. this._cipherOrderGroup.Text = GApp.Strings.GetString("Form.OptionDialog._cipherOrderGroup");
  181. this._algorithmOrderUp.Text = GApp.Strings.GetString("Form.OptionDialog._algorithmOrderUp");
  182. this._algorithmOrderDown.Text = GApp.Strings.GetString("Form.OptionDialog._algorithmOrderDown");
  183. this._ssh2OptionGroup.Text = GApp.Strings.GetString("Form.OptionDialog._ssh2OptionGroup");
  184. this._hostKeyLabel.Text = GApp.Strings.GetString("Form.OptionDialog._hostKeyLabel");
  185. this._windowSizeLabel.Text = GApp.Strings.GetString("Form.OptionDialog._windowSizeLabel");
  186. this._sshMiscGroup.Text = GApp.Strings.GetString("Form.OptionDialog._sshMiscGroup");
  187. this._retainsPassphrase.Text = GApp.Strings.GetString("Form.OptionDialog._retainsPassphrase");
  188. this._sshCheckMAC.Text = GApp.Strings.GetString("Form.OptionDialog._sshCheckMAC");
  189. }
  190. public override void InitUI(ContainerOptions options) {
  191. _cipherOrderList.Items.Clear();
  192. string[] co = options.CipherAlgorithmOrder;
  193. foreach(string c in co)
  194. _cipherOrderList.Items.Add(c);
  195. _hostKeyBox.SelectedIndex = LocalSSHUtil.ParsePublicKeyAlgorithm(options.HostKeyAlgorithmOrder[0])==PublicKeyAlgorithm.DSA? 0 : 1; //偙傟偼DSA/RSA偺偳偪傜偐偟偐側偄
  196. _windowSizeBox.Text = options.SSHWindowSize.ToString();
  197. _retainsPassphrase.Checked = options.RetainsPassphrase;
  198. _sshCheckMAC.Checked = options.SSHCheckMAC;
  199. _cipherAlgorithmOrder = options.CipherAlgorithmOrder;
  200. }
  201. public override bool Commit(ContainerOptions options) {
  202. //埫崋傾儖僑儕僘儉弴彉偼options傪捈愙偄偠偭偰偄傞偺偱偙偙偱偼壗傕偟側偔偰傛偄
  203. try {
  204. PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
  205. if(_hostKeyBox.SelectedIndex==0) {
  206. pa[0] = PublicKeyAlgorithm.DSA;
  207. pa[1] = PublicKeyAlgorithm.RSA;
  208. }
  209. else {
  210. pa[0] = PublicKeyAlgorithm.RSA;
  211. pa[1] = PublicKeyAlgorithm.DSA;
  212. }
  213. options.HostKeyAlgorithmOrder = LocalSSHUtil.FormatPublicKeyAlgorithmList(pa);
  214. try {
  215. options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
  216. }
  217. catch(FormatException) {
  218. GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.InvalidWindowSize"));
  219. return false;
  220. }
  221. options.RetainsPassphrase = _retainsPassphrase.Checked;
  222. options.SSHCheckMAC = _sshCheckMAC.Checked;
  223. options.CipherAlgorithmOrder = _cipherAlgorithmOrder;
  224. return true;
  225. }
  226. catch(Exception ex) {
  227. GUtil.Warning(this, ex.Message);
  228. return false;
  229. }
  230. }
  231. //SSH僆僾僔儑儞娭學
  232. private void OnCipherAlgorithmOrderUp(object sender, EventArgs args) {
  233. int i = _cipherOrderList.SelectedIndex;
  234. if(i==-1 || i==0) return; //慖戰偝傟偰偄側偄偐婛偵僩僢僾側傜壗傕偟側偄
  235. string temp1 = _cipherAlgorithmOrder[i];
  236. _cipherAlgorithmOrder[i] = _cipherAlgorithmOrder[i-1];
  237. _cipherAlgorithmOrder[i-1] = temp1;
  238. object temp2 = _cipherOrderList.SelectedItem;
  239. _cipherOrderList.Items.RemoveAt(i);
  240. _cipherOrderList.Items.Insert(i-1, temp2);
  241. _cipherOrderList.SelectedIndex = i-1;
  242. }
  243. private void OnCipherAlgorithmOrderDown(object sender, EventArgs args) {
  244. int i = _cipherOrderList.SelectedIndex;
  245. if(i==-1 || i==_cipherOrderList.Items.Count-1) return; //慖戰偝傟偰偄側偗傟偽壗傕偟側偄
  246. string temp1 = _cipherAlgorithmOrder[i];
  247. _cipherAlgorithmOrder[i] = _cipherAlgorithmOrder[i+1];
  248. _cipherAlgorithmOrder[i+1] = temp1;
  249. object temp2 = _cipherOrderList.SelectedItem;
  250. _cipherOrderList.Items.RemoveAt(i);
  251. _cipherOrderList.Items.Insert(i+1, temp2);
  252. _cipherOrderList.SelectedIndex = i+1;
  253. }
  254. //傾儖僑儕僘儉柤
  255. private static string CipherAlgorithmName(CipherAlgorithm a) {
  256. switch(a) {
  257. case CipherAlgorithm.AES128:
  258. return "AES(Rijndael) (SSH2 only)";
  259. case CipherAlgorithm.Blowfish:
  260. return "Blowfish";
  261. case CipherAlgorithm.TripleDES:
  262. return "TripleDES";
  263. default:
  264. throw new Exception("Unexpected Algorithm "+a);
  265. }
  266. }
  267. }
  268. }