invites: don't crash on wrong accept urls. Fixes #860
This commit is contained in:
parent
8ae6277f4b
commit
cf4d6a7811
|
@ -133,10 +133,10 @@ namespace SparkleLib {
|
||||||
if (RequiredFingerprint != null) {
|
if (RequiredFingerprint != null) {
|
||||||
string host_fingerprint = GetFingerprint (host_key);
|
string host_fingerprint = GetFingerprint (host_key);
|
||||||
|
|
||||||
if (host_fingerprint == null ||
|
if (host_fingerprint == null || !RequiredFingerprint.Equals (host_fingerprint)) {
|
||||||
!RequiredFingerprint.Equals (host_fingerprint)) {
|
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Auth", "Fingerprint doesn't match");
|
SparkleHelpers.DebugInfo ("Auth", "Fingerprint doesn't match");
|
||||||
|
|
||||||
|
this.errors.Add ("error: Host fingerprint doesn't match");
|
||||||
Failed ();
|
Failed ();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<invite>
|
<invite>
|
||||||
<address>ssh://git@github.com/</address>
|
<address>ssh://git@github.com/</address>
|
||||||
<remote_path>/hbons/Stuff</remote_path>
|
<remote_path>/hbons/Stuff</remote_path>
|
||||||
<accept_url>http://www.sparkleshare.org/test2.php</accept_url>
|
<accept_url>http://www.sparkleshare.org/test.php</accept_url>
|
||||||
</invite>
|
</invite>
|
||||||
</sparkleshare>
|
</sparkleshare>
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<b>hbons's stuff</b> on <b>Github</b>
|
<b>hbons's stuff</b> on <b>Github</b>
|
||||||
<a href="sparkleshare://raw.github.com/hbons/SparkleShare/test/SparkleShare/Common/HTML/protocol-handler-test/invite.xml">
|
<a href="sparkleshare://raw.github.com/hbons/SparkleShare/master/SparkleShare/Common/HTML/protocol-handler-test/invite.xml">
|
||||||
<img src="add-to-sparkleshare-button.png" alt="Add to SparkleShare">
|
<img src="add-to-sparkleshare-button.png" alt="Add to SparkleShare">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -451,7 +451,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
if (type == PageType.Syncing) {
|
if (type == PageType.Syncing) {
|
||||||
Header = "Adding project ‘" + Controller.SyncingFolder + "’…";
|
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 () {
|
ProgressIndicator = new NSProgressIndicator () {
|
||||||
|
@ -491,7 +491,7 @@ namespace SparkleShare {
|
||||||
Buttons.Add (FinishButton);
|
Buttons.Add (FinishButton);
|
||||||
Buttons.Add (CancelButton);
|
Buttons.Add (CancelButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == PageType.Error) {
|
if (type == PageType.Error) {
|
||||||
Header = "Oops! Something went wrong…";
|
Header = "Oops! Something went wrong…";
|
||||||
Description = "Please check the following:";
|
Description = "Please check the following:";
|
||||||
|
|
|
@ -195,17 +195,21 @@ namespace SparkleShare {
|
||||||
if (file_name.EndsWith (".key")) {
|
if (file_name.EndsWith (".key")) {
|
||||||
key_file_path = Path.Combine (keys_path, file_name);
|
key_file_path = Path.Combine (keys_path, file_name);
|
||||||
SparkleKeys.ImportPrivateKey (key_file_path);
|
SparkleKeys.ImportPrivateKey (key_file_path);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty (key_file_path)) {
|
if (!string.IsNullOrEmpty (key_file_path)) {
|
||||||
string pubkey_file_path = key_file_path + ".pub";
|
string public_key_file_path = key_file_path + ".pub";
|
||||||
string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt");
|
string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt");
|
||||||
|
|
||||||
// Create an easily accessible copy of the public
|
// Create an easily accessible copy of the public
|
||||||
// key in the user's SparkleShare folder
|
// key in the user's SparkleShare folder
|
||||||
if (File.Exists (pubkey_file_path) && !File.Exists (link_code_file_path))
|
if (File.Exists (public_key_file_path) && !File.Exists (link_code_file_path))
|
||||||
File.Copy (pubkey_file_path, link_code_file_path, true /* Overwriting allowed */ );
|
File.Copy (public_key_file_path, link_code_file_path, true);
|
||||||
|
|
||||||
|
CurrentUser.PublicKey = File.ReadAllText (public_key_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
SparkleKeys.ListPrivateKeys ();
|
SparkleKeys.ListPrivateKeys ();
|
||||||
|
|
|
@ -79,40 +79,42 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool Accept ()
|
public bool Accept (string public_key)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty (AcceptUrl))
|
if (string.IsNullOrEmpty (AcceptUrl))
|
||||||
return true;
|
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 {
|
try {
|
||||||
WebRequest request = WebRequest.Create (AcceptUrl);
|
response = (HttpWebResponse) request.GetResponse ();
|
||||||
|
|
||||||
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.Close ();
|
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) {
|
} catch (WebException e) {
|
||||||
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
|
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response != null && response.StatusCode == HttpStatusCode.OK) {
|
||||||
|
SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -382,8 +382,7 @@ namespace SparkleShare {
|
||||||
try {
|
try {
|
||||||
string address = remote_url.Replace (uri.AbsolutePath, "");
|
string address = remote_url.Replace (uri.AbsolutePath, "");
|
||||||
|
|
||||||
new_plugin = SparklePlugin.Create (
|
new_plugin = SparklePlugin.Create (uri.Host, address, address, "", "", "/path/to/project");
|
||||||
uri.Host, address, address, "", "", "/path/to/project");
|
|
||||||
|
|
||||||
if (new_plugin != null) {
|
if (new_plugin != null) {
|
||||||
Plugins.Insert (1, new_plugin);
|
Plugins.Insert (1, new_plugin);
|
||||||
|
@ -430,8 +429,11 @@ namespace SparkleShare {
|
||||||
ChangePageEvent (PageType.Syncing, null);
|
ChangePageEvent (PageType.Syncing, null);
|
||||||
|
|
||||||
new Thread (() => {
|
new Thread (() => {
|
||||||
if (!PendingInvite.Accept ()) {
|
if (!PendingInvite.Accept (Program.Controller.CurrentUser.PublicKey)) {
|
||||||
ChangePageEvent (PageType.Error, null);
|
PreviousUrl = PendingInvite.Address +
|
||||||
|
PendingInvite.RemotePath.TrimStart ("/".ToCharArray ());
|
||||||
|
|
||||||
|
ChangePageEvent (PageType.Error, new string [] { "error: Failed to upload the public key" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue