Added in everything else for Up1 support

This commit is contained in:
Keith 2015-06-28 12:16:22 -04:00
parent 8ea5fa7608
commit 7e3265854e
8 changed files with 207 additions and 7 deletions

View file

@ -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
}
}
}

View file

@ -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<string, string> args = new Dictionary<string, string>();
// 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<string, string> args = new Dictionary<string, string>();
args["ident"] = ident;
args["api_key"] = ApiKey;
UploadResult result = UploadData(encryptedStream, SystemUrl + "/up", "blob", "file", args);
if (result.IsSuccess)
{
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(result.Response);
result.URL = SystemUrl + "/#" + seed;
result.DeletionURL = SystemUrl + "/del?ident=" + ident + "&delkey=" + values["delkey"];
}
return result;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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
}
}
}

View file

@ -76,6 +76,12 @@
<HintPath>..\packages\MegaApiClient.1.1.0\lib\net40\MegaApiClient.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ClouDeveloper.Mime">
<HintPath>..\packages\cloudeveloper.mime.1.0.0\lib\net40-client\ClouDeveloper.Mime.dll</HintPath>
</Reference>
<Reference Include="crypto">
<HintPath>..\packages\Portable.BouncyCastle.1.7.0.2\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10\crypto.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
@ -293,6 +299,7 @@
<Compile Include="FileUploaders\MediaCrushUploader.cs" />
<Compile Include="URLShorteners\VgdURLShortener.cs" />
<Compile Include="URLShorteners\YourlsURLShortener.cs" />
<Compile Include="FileUploaders\Up1.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Controls\AccountsControl.de.resx">
@ -759,4 +766,4 @@ if not exist APIKeysLocal.cs (
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View file

@ -241,6 +241,11 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
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
}
}
}

View file

@ -5,4 +5,6 @@
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net40" />
<package id="SSH.NET" version="2014.4.6-beta1" targetFramework="net40" />
<package id="System.Net.FtpClient" version="1.0.5281.14359" targetFramework="net40" />
</packages>
<package id="cloudeveloper.mime" version="1.0.0" targetFramework="net40" />
<package id="Portable.BouncyCastle" version="1.7.0.2" targetFramework="net40" />
</packages>

View file

@ -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()
}
}
}
}
}