From 7e3265854e36860c20c2f7b88676a4449be5e84a Mon Sep 17 00:00:00 2001 From: Keith Date: Sun, 28 Jun 2015 12:16:22 -0400 Subject: [PATCH] Added in everything else for Up1 support --- ShareX.UploadersLib/Enums.cs | 4 +- ShareX.UploadersLib/FileUploaders/Up1.cs | 114 ++++++++++++++++++ .../Forms/UploadersConfigForm.Designer.cs | 50 +++++++- .../Forms/UploadersConfigForm.cs | 21 +++- .../ShareX.UploadersLib.csproj | 9 +- ShareX.UploadersLib/UploadersConfig.cs | 7 +- ShareX.UploadersLib/packages.config | 4 +- ShareX/UploadTask.cs | 5 +- 8 files changed, 207 insertions(+), 7 deletions(-) create mode 100644 ShareX.UploadersLib/FileUploaders/Up1.cs diff --git a/ShareX.UploadersLib/Enums.cs b/ShareX.UploadersLib/Enums.cs index d4018b4d5..4914a523f 100644 --- a/ShareX.UploadersLib/Enums.cs +++ b/ShareX.UploadersLib/Enums.cs @@ -90,6 +90,8 @@ public enum FileDestination GoogleDrive, [Description("Copy")] Copy, + [Description("Up1")] + Up1, //[Description("hubiC")] //Hubic, [Description("Box")] @@ -298,4 +300,4 @@ public enum OAuthLoginStatus LoginSuccessful, LoginFailed } -} \ No newline at end of file +} diff --git a/ShareX.UploadersLib/FileUploaders/Up1.cs b/ShareX.UploadersLib/FileUploaders/Up1.cs new file mode 100644 index 000000000..69d6084bc --- /dev/null +++ b/ShareX.UploadersLib/FileUploaders/Up1.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using Newtonsoft.Json; +using Org.BouncyCastle.Crypto.Engines; +using Org.BouncyCastle.Crypto.Modes; +using Org.BouncyCastle.Crypto.Parameters; +using ShareX.HelpersLib; + + +namespace ShareX.UploadersLib.FileUploaders +{ + public sealed class Up1 : FileUploader + { + private const int MacSize = 64; + + public string ApiKey { get; set; } + public string SystemUrl { get; set; } + + public Up1(string systemUrl, string apiKey) + { + SystemUrl = systemUrl; + ApiKey = apiKey; + } + + + public static string UrlBase64Encode(byte[] input) + { + return Convert.ToBase64String(input).Replace("=", "").Replace("+", "-").Replace("/", "_"); + } + + public static Stream Encrypt(Stream stream, out string seed_encoded, out string ident_encoded, string fileName) + { + RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider(); + byte[] seed = new byte[16]; + rngCsp.GetBytes(seed); + seed_encoded = UrlBase64Encode(seed); + + SHA512CryptoServiceProvider sha512csp = new SHA512CryptoServiceProvider(); + byte[] seed_result = sha512csp.ComputeHash(seed); + byte[] key = new byte[32]; + Buffer.BlockCopy(seed_result, 0, key, 0, 32); + + byte[] iv = new byte[16]; + Buffer.BlockCopy(seed_result, 32, iv, 0, 16); + + byte[] ident = new byte[16]; + Buffer.BlockCopy(seed_result, 48, ident, 0, 16); + ident_encoded = UrlBase64Encode(ident); + var fi = new FileInfo(fileName); + + Dictionary args = new Dictionary(); + + // text files aren't detected well by the "ClouDeveloper" mime type library, use ShareX's builtin list first. + if (Helpers.IsTextFile(fileName)) + { + args["mime"] = "text/plain"; + } + else + { + var mimeOpts = ClouDeveloper.Mime.MediaTypeNames.GetMediaTypeNames(fi.Extension).ToList(); + args["mime"] = mimeOpts.Count > 0 ? mimeOpts[0] : "image/png"; + } + args["name"] = fileName; + + byte[] d = Encoding.BigEndianUnicode.GetBytes(JsonConvert.SerializeObject(args)); + + byte[] rawdata = d.Concat(new byte[] { 0, 0 }).Concat(stream.GetBytes()).ToArray(); + + int l = FindIVLen(rawdata.Length); + byte[] civ = new byte[l]; + Array.Copy(iv, civ, l); + KeyParameter key_param = new KeyParameter(key); + var ccmparams = new CcmParameters(key_param, MacSize, civ, new byte[0]); + var ccmMode = new CcmBlockCipher(new AesFastEngine()); + ccmMode.Init(true, ccmparams); + var encBytes = new byte[ccmMode.GetOutputSize(rawdata.Length)]; + var res = ccmMode.ProcessBytes(rawdata, 0, rawdata.Length, encBytes, 0); + ccmMode.DoFinal(encBytes, res); + + return new MemoryStream(encBytes); + } + + private static int FindIVLen(int bufferLength) + { + if (bufferLength < 0xFFFF) return 15 - 2; + if (bufferLength < 0xFFFFFF) return 15 - 3; + return 15 - 4; + } + + + public override UploadResult Upload(Stream stream, string fileName) + { + string seed, ident; + Stream encryptedStream = Encrypt(stream, out seed, out ident, fileName); + Dictionary args = new Dictionary(); + args["ident"] = ident; + args["api_key"] = ApiKey; + UploadResult result = UploadData(encryptedStream, SystemUrl + "/up", "blob", "file", args); + + if (result.IsSuccess) + { + Dictionary values = JsonConvert.DeserializeObject>(result.Response); + result.URL = SystemUrl + "/#" + seed; + result.DeletionURL = SystemUrl + "/del?ident=" + ident + "&delkey=" + values["delkey"]; + } + + return result; + } + } +} diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs index cd6a0225e..02270c330 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs @@ -428,6 +428,11 @@ private void InitializeComponent() this.atcGoogleURLShortenerAccountType = new ShareX.UploadersLib.AccountTypeControl(); this.oauthTwitter = new ShareX.UploadersLib.OAuthControl(); this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl(); + this.tpUp1 = new System.Windows.Forms.TabPage(); + this.txtUp1Key = new System.Windows.Forms.TextBox(); + this.txtUp1Host = new System.Windows.Forms.TextBox(); + this.lblUp1Key = new System.Windows.Forms.Label(); + this.lblUp1Host = new System.Windows.Forms.Label(); this.tpOtherUploaders.SuspendLayout(); this.tcOtherUploaders.SuspendLayout(); this.tpTwitter.SuspendLayout(); @@ -489,6 +494,7 @@ private void InitializeComponent() this.tpPicasa.SuspendLayout(); this.tpChevereto.SuspendLayout(); this.tcUploaders.SuspendLayout(); + this.tpUp1.SuspendLayout(); this.SuspendLayout(); // // txtRapidSharePremiumUserName @@ -1202,6 +1208,7 @@ private void InitializeComponent() this.tcFileUploaders.Controls.Add(this.tpGoogleDrive); this.tcFileUploaders.Controls.Add(this.tpBox); this.tcFileUploaders.Controls.Add(this.tpCopy); + this.tcFileUploaders.Controls.Add(this.tpUp1); this.tcFileUploaders.Controls.Add(this.tpHubic); this.tcFileUploaders.Controls.Add(this.tpAmazonS3); this.tcFileUploaders.Controls.Add(this.tpMega); @@ -3398,6 +3405,40 @@ private void InitializeComponent() resources.ApplyResources(this.actRapidShareAccountType, "actRapidShareAccountType"); this.actRapidShareAccountType.Name = "actRapidShareAccountType"; this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous; + + // ++ // tpUp1 ++ // ++ this.tpUp1.Controls.Add(this.txtUp1Key); ++ this.tpUp1.Controls.Add(this.txtUp1Host); ++ this.tpUp1.Controls.Add(this.lblUp1Key); ++ this.tpUp1.Controls.Add(this.lblUp1Host); ++ resources.ApplyResources(this.tpUp1, "tpUp1"); ++ this.tpUp1.Name = "tpUp1"; ++ this.tpUp1.UseVisualStyleBackColor = true; ++ // ++ // txtUp1Key ++ // ++ resources.ApplyResources(this.txtUp1Key, "txtUp1Key"); ++ this.txtUp1Key.Name = "txtUp1Key"; ++ this.txtUp1Key.TextChanged += new System.EventHandler(this.txtUp1Key_TextChanged); ++ // ++ // txtUp1Host ++ // ++ resources.ApplyResources(this.txtUp1Host, "txtUp1Host"); ++ this.txtUp1Host.Name = "txtUp1Host"; ++ this.txtUp1Host.TextChanged += new System.EventHandler(this.txtUp1Host_TextChanged); ++ // ++ // lblUp1Key ++ // ++ resources.ApplyResources(this.lblUp1Key, "lblUp1Key"); ++ this.lblUp1Key.Name = "lblUp1Key"; ++ // ++ // lblUp1Host ++ // ++ resources.ApplyResources(this.lblUp1Host, "lblUp1Host"); ++ this.lblUp1Host.Name = "lblUp1Host"; + // // UploadersConfigForm // @@ -3516,6 +3557,8 @@ private void InitializeComponent() this.tpChevereto.ResumeLayout(false); this.tpChevereto.PerformLayout(); this.tcUploaders.ResumeLayout(false); + this.tpUp1.ResumeLayout(false); + this.tpUp1.PerformLayout(); this.ResumeLayout(false); } @@ -3920,5 +3963,10 @@ private void InitializeComponent() private HelpersLib.MyListView lvTwitterAccounts; private System.Windows.Forms.ColumnHeader chTwitterAccount; private System.Windows.Forms.Label lblCustomUploaderRegexTip; + private System.Windows.Forms.TabPage tpUp1; + private System.Windows.Forms.TextBox txtUp1Key; + private System.Windows.Forms.TextBox txtUp1Host; + private System.Windows.Forms.Label lblUp1Key; + private System.Windows.Forms.Label lblUp1Host; } -} \ No newline at end of file +} diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs index d26dbde5d..616af8c21 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs @@ -537,6 +537,11 @@ public void LoadSettings(UploadersConfig uploadersConfig) txtMediaFirePath.Text = Config.MediaFirePath; cbMediaFireUseLongLink.Checked = Config.MediaFireUseLongLink; + // Up1 + + txtUp1Host.Text = Config.Up1Host; + txtUp1Key.Text = Config.Up1Key; + // Lambda txtLambdaApiKey.Text = Config.LambdaSettings.UserAPIKey; @@ -1870,6 +1875,20 @@ private void cbOwnCloudIgnoreInvalidCert_CheckedChanged(object sender, EventArgs #endregion ownCloud + #region Up1 + + private void txtUp1Host_TextChanged(object sender, EventArgs e) + { + Config.Up1Host = txtUp1Host.Text; + } + + private void txtUp1Key_TextChanged(object sender, EventArgs e) + { + Config.Up1Key = txtUp1Key.Text; + } + + #endregion Up1 + #region Pushbullet private void txtPushbulletUserKey_TextChanged(object sender, EventArgs e) @@ -2480,4 +2499,4 @@ private void txtCustomUploaderLog_LinkClicked(object sender, LinkClickedEventArg #endregion Other Uploaders } -} \ No newline at end of file +} diff --git a/ShareX.UploadersLib/ShareX.UploadersLib.csproj b/ShareX.UploadersLib/ShareX.UploadersLib.csproj index b44d9473b..c57fda2cf 100644 --- a/ShareX.UploadersLib/ShareX.UploadersLib.csproj +++ b/ShareX.UploadersLib/ShareX.UploadersLib.csproj @@ -76,6 +76,12 @@ ..\packages\MegaApiClient.1.1.0\lib\net40\MegaApiClient.dll True + + ..\packages\cloudeveloper.mime.1.0.0\lib\net40-client\ClouDeveloper.Mime.dll + + + ..\packages\Portable.BouncyCastle.1.7.0.2\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10\crypto.dll + ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll True @@ -293,6 +299,7 @@ + @@ -759,4 +766,4 @@ if not exist APIKeysLocal.cs ( --> - \ No newline at end of file + diff --git a/ShareX.UploadersLib/UploadersConfig.cs b/ShareX.UploadersLib/UploadersConfig.cs index d58ee0ade..04501a7a7 100644 --- a/ShareX.UploadersLib/UploadersConfig.cs +++ b/ShareX.UploadersLib/UploadersConfig.cs @@ -241,6 +241,11 @@ public class UploadersConfig : SettingsBase public PushbulletSettings PushbulletSettings = new PushbulletSettings(); + // Up1 + + public string Up1Host = "https://up1.ca"; + public string Up1Key = "c61540b5ceecd05092799f936e27755f"; + // Lambda public LambdaSettings LambdaSettings = new LambdaSettings(); @@ -476,4 +481,4 @@ public int GetLocalhostIndex(EDataType dataType) #endregion Helper Methods } -} \ No newline at end of file +} diff --git a/ShareX.UploadersLib/packages.config b/ShareX.UploadersLib/packages.config index 55e0c179a..27980aea2 100644 --- a/ShareX.UploadersLib/packages.config +++ b/ShareX.UploadersLib/packages.config @@ -5,4 +5,6 @@ - \ No newline at end of file + + + diff --git a/ShareX/UploadTask.cs b/ShareX/UploadTask.cs index 77441c5ae..42bcbac7d 100644 --- a/ShareX/UploadTask.cs +++ b/ShareX/UploadTask.cs @@ -1009,6 +1009,9 @@ public UploadResult UploadFile(Stream stream, string fileName) case FileDestination.Dropfile: fileUploader = new Dropfile(); break; + case FileDestination.Up1: + fileUploader = new Up1(Program.UploadersConfig.Up1Host, Program.UploadersConfig.Up1Key); + break; } if (fileUploader != null) @@ -1307,4 +1310,4 @@ public void Dispose() } } } -} \ No newline at end of file +}