From 8ae6277f4bf9957506520abf17fc84f9514d5a29 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 27 Jul 2012 18:00:55 +0200 Subject: [PATCH 1/2] invite: start new thread to not freeze the UI when accepting --- .../HTML/protocol-handler-test/invite.xml | 2 +- .../protocol-handler-test.htm | 2 +- SparkleShare/SparkleControllerBase.cs | 4 ++-- SparkleShare/SparkleSetupController.cs | 21 +++++++++++-------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/SparkleShare/Common/HTML/protocol-handler-test/invite.xml b/SparkleShare/Common/HTML/protocol-handler-test/invite.xml index 5c4f9d18..38988903 100644 --- a/SparkleShare/Common/HTML/protocol-handler-test/invite.xml +++ b/SparkleShare/Common/HTML/protocol-handler-test/invite.xml @@ -3,7 +3,7 @@
ssh://git@github.com/
/hbons/Stuff - http://www.sparkleshare.org/test.php + http://www.sparkleshare.org/test2.php
diff --git a/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm b/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm index 9e0a1226..965e5062 100644 --- a/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm +++ b/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm @@ -29,7 +29,7 @@
hbons's stuff on Github - + Add to SparkleShare
diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 4a1ace17..56b2fd1a 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -417,11 +417,11 @@ namespace SparkleShare { // fully downloaded yet, so we try to read it several times int tries = 0; while (!invite.IsValid) { - Thread.Sleep (250); + Thread.Sleep (100); invite = new SparkleInvite (args.FullPath); tries++; - if (tries > 20) { + if (tries > 10) { AlertNotificationRaised ("Oh noes!", "This invite seems screwed up..."); break; } diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index a06506ea..29a83eb8 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -429,17 +429,20 @@ namespace SparkleShare { ChangePageEvent (PageType.Syncing, null); - if (!PendingInvite.Accept ()) { - ChangePageEvent (PageType.Error, null); - return; - } + new Thread (() => { + if (!PendingInvite.Accept ()) { + ChangePageEvent (PageType.Error, null); + return; + } - Program.Controller.FolderFetched += InvitePageFetchedDelegate; - Program.Controller.FolderFetchError += InvitePageFetchErrorDelegate; - Program.Controller.FolderFetching += SyncingPageFetchingDelegate; + Program.Controller.FolderFetched += InvitePageFetchedDelegate; + Program.Controller.FolderFetchError += InvitePageFetchErrorDelegate; + Program.Controller.FolderFetching += SyncingPageFetchingDelegate; - Program.Controller.StartFetcher (PendingInvite.Address, PendingInvite.Fingerprint, - PendingInvite.RemotePath, PendingInvite.AnnouncementsUrl, false); // TODO: checkbox on invite page + Program.Controller.StartFetcher (PendingInvite.Address, PendingInvite.Fingerprint, + PendingInvite.RemotePath, PendingInvite.AnnouncementsUrl, false); // TODO: checkbox on invite page + + }).Start (); } // The following private methods are From cf4d6a7811d32d0b1bc2af065eaf86d2737679ad Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 27 Jul 2012 20:34:43 +0200 Subject: [PATCH 2/2] invites: don't crash on wrong accept urls. Fixes #860 --- SparkleLib/SparkleFetcherBase.cs | 6 +-- .../HTML/protocol-handler-test/invite.xml | 2 +- .../protocol-handler-test.htm | 2 +- SparkleShare/Mac/SparkleSetup.cs | 4 +- SparkleShare/SparkleControllerBase.cs | 12 +++-- SparkleShare/SparkleInvite.cs | 48 ++++++++++--------- SparkleShare/SparkleSetupController.cs | 10 ++-- 7 files changed, 46 insertions(+), 38 deletions(-) diff --git a/SparkleLib/SparkleFetcherBase.cs b/SparkleLib/SparkleFetcherBase.cs index c22bc2e5..54581049 100755 --- a/SparkleLib/SparkleFetcherBase.cs +++ b/SparkleLib/SparkleFetcherBase.cs @@ -133,10 +133,10 @@ namespace SparkleLib { if (RequiredFingerprint != null) { string host_fingerprint = GetFingerprint (host_key); - if (host_fingerprint == null || - !RequiredFingerprint.Equals (host_fingerprint)) { - + if (host_fingerprint == null || !RequiredFingerprint.Equals (host_fingerprint)) { SparkleHelpers.DebugInfo ("Auth", "Fingerprint doesn't match"); + + this.errors.Add ("error: Host fingerprint doesn't match"); Failed (); return; diff --git a/SparkleShare/Common/HTML/protocol-handler-test/invite.xml b/SparkleShare/Common/HTML/protocol-handler-test/invite.xml index 38988903..5c4f9d18 100644 --- a/SparkleShare/Common/HTML/protocol-handler-test/invite.xml +++ b/SparkleShare/Common/HTML/protocol-handler-test/invite.xml @@ -3,7 +3,7 @@
ssh://git@github.com/
/hbons/Stuff - http://www.sparkleshare.org/test2.php + http://www.sparkleshare.org/test.php
diff --git a/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm b/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm index 965e5062..75da7cb5 100644 --- a/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm +++ b/SparkleShare/Common/HTML/protocol-handler-test/protocol-handler-test.htm @@ -29,7 +29,7 @@
hbons's stuff on Github - + Add to SparkleShare
diff --git a/SparkleShare/Mac/SparkleSetup.cs b/SparkleShare/Mac/SparkleSetup.cs index b67e1781..62c80cda 100755 --- a/SparkleShare/Mac/SparkleSetup.cs +++ b/SparkleShare/Mac/SparkleSetup.cs @@ -451,7 +451,7 @@ namespace SparkleShare { if (type == PageType.Syncing) { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; - Description = "This may take a while on big projects. Isn't it coffee-o'clock?"; + Description = "This may take a while on big projects.\nIsn't it coffee-o'clock?"; ProgressIndicator = new NSProgressIndicator () { @@ -491,7 +491,7 @@ namespace SparkleShare { Buttons.Add (FinishButton); Buttons.Add (CancelButton); } - + if (type == PageType.Error) { Header = "Oops! Something went wrong…"; Description = "Please check the following:"; diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 56b2fd1a..cd5761bb 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -195,17 +195,21 @@ namespace SparkleShare { if (file_name.EndsWith (".key")) { key_file_path = Path.Combine (keys_path, file_name); SparkleKeys.ImportPrivateKey (key_file_path); + + break; } } if (!string.IsNullOrEmpty (key_file_path)) { - string pubkey_file_path = key_file_path + ".pub"; - string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt"); + string public_key_file_path = key_file_path + ".pub"; + string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt"); // Create an easily accessible copy of the public // key in the user's SparkleShare folder - if (File.Exists (pubkey_file_path) && !File.Exists (link_code_file_path)) - File.Copy (pubkey_file_path, link_code_file_path, true /* Overwriting allowed */ ); + if (File.Exists (public_key_file_path) && !File.Exists (link_code_file_path)) + File.Copy (public_key_file_path, link_code_file_path, true); + + CurrentUser.PublicKey = File.ReadAllText (public_key_file_path); } SparkleKeys.ListPrivateKeys (); diff --git a/SparkleShare/SparkleInvite.cs b/SparkleShare/SparkleInvite.cs index ee4ff3f6..bad2cc7c 100644 --- a/SparkleShare/SparkleInvite.cs +++ b/SparkleShare/SparkleInvite.cs @@ -79,40 +79,42 @@ namespace SparkleShare { } - public bool Accept () + public bool Accept (string public_key) { if (string.IsNullOrEmpty (AcceptUrl)) return true; + string post_data = "public_key=" + public_key; + byte [] post_bytes = Encoding.UTF8.GetBytes (post_data); + + WebRequest request = WebRequest.Create (AcceptUrl); + + request.Method = "POST"; + request.ContentType = "application/x-www-form-urlencoded"; + request.ContentLength = post_bytes.Length; + + Stream data_stream = request.GetRequestStream (); + data_stream.Write (post_bytes, 0, post_bytes.Length); + data_stream.Close (); + + HttpWebResponse response = null; + try { - WebRequest request = WebRequest.Create (AcceptUrl); - - request.Method = "POST"; - request.ContentType = "application/x-www-form-urlencoded"; - string post_data = "pubkey=" + SparkleConfig.DefaultConfig.User.PublicKey; - byte [] post_bytes = Encoding.UTF8.GetBytes (post_data); - request.ContentLength = post_bytes.Length; - - Stream data_stream = request.GetRequestStream (); - data_stream.Write (post_bytes, 0, post_bytes.Length); - data_stream.Close (); - - WebResponse response = request.GetResponse (); + response = (HttpWebResponse) request.GetResponse (); response.Close (); - if ((response as HttpWebResponse).StatusCode == HttpStatusCode.OK) { - SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl); - return true; - - } else { - SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl); - return false; - } - } catch (WebException e) { SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message); return false; } + + if (response != null && response.StatusCode == HttpStatusCode.OK) { + SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl); + return true; + + } else { + return false; + } } diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index 29a83eb8..e0bced2a 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -382,8 +382,7 @@ namespace SparkleShare { try { string address = remote_url.Replace (uri.AbsolutePath, ""); - new_plugin = SparklePlugin.Create ( - uri.Host, address, address, "", "", "/path/to/project"); + new_plugin = SparklePlugin.Create (uri.Host, address, address, "", "", "/path/to/project"); if (new_plugin != null) { Plugins.Insert (1, new_plugin); @@ -430,8 +429,11 @@ namespace SparkleShare { ChangePageEvent (PageType.Syncing, null); new Thread (() => { - if (!PendingInvite.Accept ()) { - ChangePageEvent (PageType.Error, null); + if (!PendingInvite.Accept (Program.Controller.CurrentUser.PublicKey)) { + PreviousUrl = PendingInvite.Address + + PendingInvite.RemotePath.TrimStart ("/".ToCharArray ()); + + ChangePageEvent (PageType.Error, new string [] { "error: Failed to upload the public key" }); return; }