-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSslPrompt.cs
132 lines (115 loc) · 3.41 KB
/
SslPrompt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace P4EXP
{
public partial class SslPrompt : Form
{
public SslPrompt()
{
Icon = System.Drawing.SystemIcons.Warning;
InitializeComponent();
}
public string password = null;
private void OKBtn_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void passwordTB_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
if (sender != null)
OKBtn_Click(null, null);
e.Handled = true;
}
}
public static string FingerPrint { get; set; }
private static bool IsHexDigit(char c)
{
if (char.IsDigit(c))
{
return true;
}
switch (c)
{
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
return true;
}
return false;
}
public static DialogResult ShowFirstContact(string[] msg)
{
SslPrompt dlg = new SslPrompt();
dlg.WarningTB.Text = string.Empty;
for (int idx = 0; idx < msg.Length; idx++)
{
if (string.IsNullOrEmpty(msg[idx]) == false)
{
dlg.WarningTB.Text += msg[idx];
if (IsHexDigit(msg[idx][0]) && IsHexDigit(msg[idx][1]))
{
FingerPrint = msg[idx];
break;
}
dlg.WarningTB.Text += "\r\n";
}
}
dlg.ShowWarningLabel = false;
dlg.WarningTB.SelectionLength = 0;
dlg.TrustCB.Focus();
return dlg.ShowDialog();
}
public static DialogResult ShowNewFingerprint(string[] msg)
{
SslPrompt dlg = new SslPrompt();
dlg.WarningTB.Text = string.Empty;
//skip first line
for (int idx = 1; idx < msg.Length; idx++)
{
if (string.IsNullOrEmpty(msg[idx]) == false)
{
dlg.WarningTB.Text += msg[idx];
if (IsHexDigit(msg[idx][0]) && IsHexDigit(msg[idx][1]))
{
FingerPrint = msg[idx];
break;
}
dlg.WarningTB.Text += "\r\n";
}
}
dlg.ShowWarningLabel = true;
dlg.WarningTB.SelectionLength = 0;
dlg.TrustCB.Focus();
return dlg.ShowDialog();
}
public bool ShowWarningLabel
{
get { return WarningLbl.Visible; }
set
{
WarningLbl.Visible = value;
}
}
private void TrustCB_CheckedChanged(object sender, EventArgs e)
{
ConnectBtn.Enabled = TrustCB.Checked;
}
}
}