forked from winauth/winauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionForm.cs
More file actions
229 lines (207 loc) · 6.79 KB
/
Copy pathExceptionForm.cs
File metadata and controls
229 lines (207 loc) · 6.79 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* Copyright (C) 2013 Colin Mackie.
* This software is distributed under the terms of the GNU General Public License.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.Web;
using WinAuth.Resources;
namespace WinAuth
{
/// <summary>
/// General error report form
/// </summary>
public partial class ExceptionForm : WinAuth.ResourceForm
{
/// <summary>
/// Exception that caused the error report
/// </summary>
public Exception ErrorException { get; set; }
/// <summary>
/// Current config
/// </summary>
public WinAuthConfig Config { get; set; }
/// <summary>
/// Create the Form
/// </summary>
public ExceptionForm()
{
InitializeComponent();
}
/// <summary>
/// Load the error report form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ExceptionForm_Load(object sender, EventArgs e)
{
errorIcon.Image = SystemIcons.Error.ToBitmap();
this.Height = detailsButton.Top + detailsButton.Height + 45;
this.errorLabel.Text = string.Format(this.errorLabel.Text, (ErrorException != null ? ErrorException.Message : strings.UnknownError));
// build data
#if DEBUG
dataText.Text = string.Format("{0}\n\n{1}", this.ErrorException.Message, new System.Diagnostics.StackTrace(this.ErrorException).ToString());
#else
try
{
dataText.Text = WinAuthHelper.PGPEncrypt(BuildDiagnostics(), WinAuthHelper.WINAUTH_PGP_PUBLICKEY);
}
catch (Exception ex)
{
dataText.Text = string.Format("{0}\n\n{1}", ex.Message, new System.Diagnostics.StackTrace(ex).ToString());
}
#endif
}
/// <summary>
/// Build a diagnostics string for the current Config and any exception that had been thrown
/// </summary>
/// <returns>diagnostics information</returns>
private string BuildDiagnostics()
{
StringBuilder diag = new StringBuilder();
Version version;
#if NETFX_4
if (Version.TryParse(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion, out version) == true)
{
diag.Append("Version:" + version.ToString(4));
}
#endif
#if NETFX_3
try
{
version = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion);
diag.Append("Version:" + version.ToString(4));
}
catch (Exception) { }
#endif
// add winauth log
try
{
string dir = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), WinAuthMain.APPLICATION_NAME);
if (Directory.Exists(dir) == true)
{
string winauthlog = Path.Combine(dir, "winauth.log");
if (File.Exists(winauthlog) == true)
{
diag.Append("--WINAUTH.LOG--").Append(Environment.NewLine);
diag.Append(File.ReadAllText(winauthlog)).Append(Environment.NewLine).Append(Environment.NewLine);
}
// add authenticator.xml
foreach (string file in Directory.GetFiles(dir, "*.xml"))
{
diag.Append("--" + file + "--").Append(Environment.NewLine);
diag.Append(File.ReadAllText(file)).Append(Environment.NewLine).Append(Environment.NewLine);
}
}
}
catch (Exception) { }
// add the current config
if (this.Config != null)
{
using (var ms = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (var xml = XmlWriter.Create(ms, settings))
{
this.Config.WriteXmlString(xml);
}
ms.Position = 0;
diag.Append("-- Config --").Append(Environment.NewLine);
diag.Append(new StreamReader(ms).ReadToEnd()).Append(Environment.NewLine).Append(Environment.NewLine);
}
}
// add the exception
if (ErrorException != null)
{
diag.Append("--EXCEPTION--").Append(Environment.NewLine);
Exception ex = ErrorException;
while (ex != null)
{
diag.Append("Stack: ").Append(ex.Message).Append(Environment.NewLine).Append(new System.Diagnostics.StackTrace(ex).ToString()).Append(Environment.NewLine);
ex = ex.InnerException;
}
if (ErrorException is InvalidEncryptionException)
{
diag.Append("Plain: " + ((InvalidEncryptionException)ErrorException).Plain).Append(Environment.NewLine);
diag.Append("Password: " + ((InvalidEncryptionException)ErrorException).Password).Append(Environment.NewLine);
diag.Append("Encrypted: " + ((InvalidEncryptionException)ErrorException).Encrypted).Append(Environment.NewLine);
diag.Append("Decrypted: " + ((InvalidEncryptionException)ErrorException).Decrypted).Append(Environment.NewLine);
}
else if (ErrorException is InvalidSecretDataException)
{
diag.Append("EncType: " + ((InvalidSecretDataException)ErrorException).EncType).Append(Environment.NewLine);
diag.Append("Password: " + ((InvalidSecretDataException)ErrorException).Password).Append(Environment.NewLine);
foreach (string data in ((InvalidSecretDataException)ErrorException).Decrypted)
{
diag.Append("Data: " + data).Append(Environment.NewLine);
}
}
}
return diag.ToString();
}
/// <summary>
/// Click the Quit button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void quitButton_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// Click the Continue button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void continueButton_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// Click to show the details
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void detailsButton_Click(object sender, EventArgs e)
{
dataText.Visible = !dataText.Visible;
if (dataText.Visible == true)
{
this.detailsButton.Text = strings.HideDetails;
this.Height += 160;
}
else
{
this.detailsButton.Text = strings._ExceptionForm_detailsButton_;
this.Height -= 160;
}
}
}
}