public frmConfigDebugExec(CConfig conf) { this.loconf = conf; InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // }
internal static bool VerifyLocalKeyfile(string filename, out AuthInfo authinfo) { StreamReader reader = null; string data = ""; authinfo = null; try { reader = new StreamReader(filename); data = reader.ReadToEnd(); reader.Close(); } catch (Exception exc) { MessageBox.Show("Offline key authorization failure: Could not read keyfile.\n\n\n" + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } Regex rx = new Regex(@"\s*Keyfile(\n*|\s*)?" + @"(?<inner>" + @"(?>" + @"\{(?<LEVEL>)" + @"|" + @"\};(?<-LEVEL>)" + @"|" + @"(?!\{|\};)." + @")+" + @"(?(LEVEL)(?!))" + @")" , RegexOptions.IgnoreCase | RegexOptions.Singleline); Match topmatch = rx.Match(data); if (!topmatch.Success) { MessageBox.Show("Offline key authorization failure: Could not find valid 'keyfile' block.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } string keyfile_data = topmatch.Groups["inner"].Value; // Once we have the top matched group, parse each line in it rx = new Regex(@"\s*\b(?<name>[A-Z]*)\b\s*=\s*((" + "\"" + @"\s*(?<single>.*?)\s*" + "\"" + @"\s*;)|(\{(?<multi>.*?)\};))", RegexOptions.Singleline | RegexOptions.IgnoreCase); // 1 = name // 4 = normal definition // 6 = multiline definition string version = ""; string name = ""; string expires = ""; string machinecode = ""; string featurebit = ""; string hash = ""; string signature = ""; string email = ""; foreach (Match m in rx.Matches(keyfile_data)) { switch (m.Groups["name"].Value.ToLower()) { case "version": version = m.Groups["single"].Value; break; case "name": name = m.Groups["single"].Value; break; case "expires": expires = m.Groups["single"].Value; break; case "machinecode": machinecode = m.Groups["single"].Value; break; case "featurebit": featurebit = m.Groups["single"].Value; break; case "hash": hash = m.Groups["single"].Value; break; case "keysignature": signature = m.Groups["multi"].Value; break; case "email": email = m.Groups["single"].Value; break; } } // Clean up signature signature = signature.Replace(" ", ""); signature = signature.Replace("\t", ""); signature = signature.Replace("\n", ""); signature = signature.Replace("\r", ""); // Check field validity if (version == "" || expires == "" || machinecode == "" || featurebit == "" || hash == "" || name == "" || email == "" || signature == "") { MessageBox.Show("Offline key authorization failure: Keyfile construction incomplete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Check version if (version != "1.00") { MessageBox.Show("Offline key authorization failure: Incorrect version (Expected '1.00')", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Check expiration date try { DateTime dt = DateTime.Parse(expires); if (DateTime.Now.Ticks >= dt.Ticks) { MessageBox.Show("Offline key authorization has expired. Please visit www.torquedev.com to request a new offline authorization file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } catch (Exception exc) { MessageBox.Show("Offline key authorization failure: Unable to verify date stamp. Error returned was: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Check if the machine codes match if (machinecode != CConfig.GetHardKey()) { MessageBox.Show("Offline key authorization failure: Machine code mismatch.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Verify hash of data string sighash = CConfig.SHA1(version + name + machinecode + expires + featurebit + email); if (sighash != hash) { MessageBox.Show("Offline key authorization failure: Checksum mismatch.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Verify signature by first loading the public key into memory DSA dsa = new DSACryptoServiceProvider(); try { dsa.FromXmlString(CVerify.PublicKey); } catch (Exception exc) { MessageBox.Show("Offline key authorization failure: Unable to load DSA public key. Error returned was: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Verify the data against the signature try { if (!dsa.VerifySignature(Convert.FromBase64String(hash), Convert.FromBase64String(signature))) { MessageBox.Show("Offline key authorization failure: File signature is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dsa.Clear(); return(false); } else { // Signature checked out. Create the passback reference authinfo = new AuthInfo(version, name, expires, machinecode, featurebit, hash, signature, email); return(true); } } catch (Exception exc) { MessageBox.Show("Offline key authorization failure: DSA verification failure. Error returned was: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dsa.Clear(); return(false); } }
public frmConfig(CConfig prevconf) { // // Required for Windows Form Designer support // InitializeComponent(); this.loconf = (CConfig)prevconf.Clone(); // // TODO: Add any constructor code after InitializeComponent call // }
public object Clone() { //return this.MemberwiseClone(); CConfig temp = new CConfig(); temp = (CConfig)this.MemberwiseClone(); temp.bFirstrun = this.bFirstrun; temp.colors = (Hashtable)this.colors.Clone(); temp.DockbarData = this.DockbarData; temp.recent_files = this.recent_files; temp.bAutoCollapse = this.bAutoCollapse; temp.bCheckUpdates = this.bCheckUpdates; temp.bScrollHint = this.bScrollHint; temp.bShowDebugSummary = this.bShowDebugSummary; temp.menu_shortcuts = (Hashtable)this.menu_shortcuts.Clone(); temp.b_AC_Infopop = this.b_AC_Infopop; temp.b_AC_ObjectML = this.b_AC_ObjectML; temp.b_AC_VariableML = this.b_AC_VariableML; temp.b_AC_TypeAsYouGo = this.b_AC_TypeAsYouGo; temp.b_Ed_BracketHighlight = this.b_Ed_BracketHighlight; temp.b_Ed_ConvertTabsToSpaces = this.b_Ed_ConvertTabsToSpaces; temp.b_Ed_ShowLines = this.b_Ed_ShowLines; temp.b_Ed_ShowNewline = this.b_Ed_ShowNewline; temp.b_Ed_ShowWhitespace = this.b_Ed_ShowWhitespace; temp.b_Ed_Virtlines = this.b_Ed_Virtlines; temp.b_Ed_Wordwrap = this.b_Ed_Wordwrap; temp.b_Ed_ShowTabs = this.b_Ed_ShowTabs; temp.i_Ed_TabSize = this.i_Ed_TabSize; temp.LastMotd = this.LastMotd; temp.DebugTimeout = this.DebugTimeout; temp.b_Ed_CodeFold = this.b_Ed_CodeFold; temp.b_Ed_IndentGuides = this.b_Ed_IndentGuides; temp.ActivationEmail = this.ActivationEmail; temp.ActivationHasT2D = this.ActivationHasT2D; temp.ActivationHasTGE = this.ActivationHasTGE; temp.ActivationHasTSE = this.ActivationHasTSE; temp.ActivationLastHardkey = this.ActivationLastHardkey; temp.ActivationLocal = this.ActivationLocal; temp.ActivationNextCheck = this.ActivationNextCheck; temp.ActivationResponse = this.ActivationResponse; temp.ActivationUser = this.ActivationUser; temp.bIsActivated = this.bIsActivated; temp.b_DeleteDSO = this.b_DeleteDSO; temp.DSOExtension = this.DSOExtension; temp.DebugRun = this.DebugRun; temp.b_Err_BeforeCompile = this.b_Err_BeforeCompile; temp.b_Err_WhileTyping = this.b_Err_WhileTyping; return temp; }
public static void SaveConfig(string filename, CConfig config) { FileStream fstream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None); BinaryFormatter fmtBinary = new BinaryFormatter(); fmtBinary.Serialize(fstream, config); fstream.Close(); }
public static void ClearActivation(CConfig config) { // Clears activation info on the passed config config.ActivationEmail = ""; config.ActivationHasT2D = false; config.ActivationHasTGE = false; config.ActivationHasTSE = false; config.ActivationLastHardkey = ""; config.ActivationLocal = false; config.ActivationNextCheck = 0; config.ActivationResponse = ""; config.ActivationUser = ""; config.bIsActivated = false; }