Encrypt all file uploader settings

This commit is contained in:
Jaex 2020-06-01 04:17:04 +03:00
parent db38dd6797
commit 1b60df4bd4
12 changed files with 236 additions and 143 deletions

View file

@ -48,7 +48,7 @@ public class FTPAccount : ICloneable
[Category("FTP")]
public string Username { get; set; }
[Category("FTP"), PasswordPropertyText(true)]
[Category("FTP"), PasswordPropertyText(true), JsonEncrypt]
public string Password { get; set; }
[Category("FTP"), Description("Set true for active or false for passive"), DefaultValue(false)]
@ -131,7 +131,7 @@ public string PreviewHttpPath
[Editor(typeof(KeyFileNameEditor), typeof(UITypeEditor))]
public string Keypath { get; set; }
[Category("SFTP"), Description("OpenSSH key passphrase"), PasswordPropertyText(true)]
[Category("SFTP"), Description("OpenSSH key passphrase"), PasswordPropertyText(true), JsonEncrypt]
public string Passphrase { get; set; }
public FTPAccount()

View file

@ -136,7 +136,9 @@ public override UploadResult Upload(Stream stream, string fileName)
public class Ge_ttLogin
{
public string Expires { get; set; }
[JsonEncrypt]
public string AccessToken { get; set; }
[JsonEncrypt]
public string RefreshToken { get; set; }
}

View file

@ -26,6 +26,7 @@
// Credits: https://github.com/mstojcevich
using Newtonsoft.Json;
using ShareX.HelpersLib;
using ShareX.UploadersLib.Properties;
using System.Collections.Generic;
using System.Drawing;
@ -114,7 +115,8 @@ internal class LambdaFile
public class LambdaSettings
{
public string UserAPIKey = "";
public string UploadURL = "https://lbda.net/";
[JsonEncrypt]
public string UserAPIKey { get; set; } = "";
public string UploadURL { get; set; } = "https://lbda.net/";
}
}

View file

@ -26,6 +26,7 @@
// Credits: https://github.com/lithium720
using Newtonsoft.Json;
using ShareX.HelpersLib;
using ShareX.UploadersLib.Properties;
using System;
using System.Collections.Generic;
@ -135,6 +136,7 @@ private class LithiioFetchAPIKeyResponse : LithiioResponse
public class LithiioSettings
{
[JsonEncrypt]
public string UserAPIKey { get; set; } = "";
}
}

View file

@ -46,7 +46,7 @@ public class LocalhostAccount : ICloneable
[Category("Localhost")]
public string UserName { get; set; }
[Category("Localhost"), PasswordPropertyText(true)]
[Category("Localhost"), PasswordPropertyText(true), JsonEncrypt]
public string Password { get; set; }
[Category("Localhost"), Description("Localhost Sub-folder Path, e.g. screenshots, %y = year, %mo = month. SubFolderPath will be automatically appended to HttpHomePath if HttpHomePath does not start with @")]

View file

@ -50,7 +50,7 @@ public override bool CheckConfig(UploadersConfig config)
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
return new Mega(config.MegaAuthInfos, config.MegaParentNodeId);
return new Mega(config.MegaAuthInfos?.GetMegaApiClientAuthInfos(), config.MegaParentNodeId);
}
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpMega;

View file

@ -0,0 +1,57 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2020 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using CG.Web.MegaApiClient;
using ShareX.HelpersLib;
using System;
namespace ShareX.UploadersLib
{
public class MegaAuthInfos
{
public string Email { get; set; }
[JsonEncrypt]
public string Hash { get; set; }
[JsonEncrypt]
public string PasswordAesKey { get; set; }
public MegaAuthInfos()
{
}
public MegaAuthInfos(MegaApiClient.AuthInfos authInfos)
{
Email = authInfos.Email;
Hash = authInfos.Hash;
PasswordAesKey = Convert.ToBase64String(authInfos.PasswordAesKey);
}
public MegaApiClient.AuthInfos GetMegaApiClientAuthInfos()
{
byte[] passwordAesKey = Convert.FromBase64String(PasswordAesKey);
return new MegaApiClient.AuthInfos(Email, Hash, passwordAesKey);
}
}
}

View file

@ -23,20 +23,24 @@
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
namespace ShareX.UploadersLib.FileUploaders
{
public class PlikSettings
{
public string URL = "";
public string APIKey = "";
public bool IsSecured = false;
public string Login = "";
public string Password = "";
public bool Removable = false;
public bool OneShot = false;
public int TTLUnit = 2;
public decimal TTL = 30;
public bool HasComment = false;
public string Comment = "";
public string URL { get; set; } = "";
[JsonEncrypt]
public string APIKey { get; set; } = "";
public bool IsSecured { get; set; } = false;
public string Login { get; set; } = "";
[JsonEncrypt]
public string Password { get; set; } = "";
public bool Removable { get; set; } = false;
public bool OneShot { get; set; } = false;
public int TTLUnit { get; set; } = 2;
public decimal TTL { get; set; } = 30;
public bool HasComment { get; set; } = false;
public string Comment { get; set; } = "";
}
}

View file

@ -241,16 +241,19 @@ public class PushbulletDevice
public class PushbulletSettings
{
public string UserAPIKey = "";
public List<PushbulletDevice> DeviceList = new List<PushbulletDevice>();
public int SelectedDevice = 0;
[JsonEncrypt]
public string UserAPIKey { get; set; } = "";
public List<PushbulletDevice> DeviceList { get; set; } = new List<PushbulletDevice>();
public int SelectedDevice { get; set; } = 0;
public PushbulletDevice CurrentDevice
{
get
{
if (DeviceList.IsValidIndex(SelectedDevice))
{
return DeviceList[SelectedDevice];
}
return null;
}

View file

@ -2073,7 +2073,8 @@ private void MegaConfigureTab(bool tryLogin)
{
cbMegaFolder.Items.Clear();
Mega mega = new Mega(Config.MegaAuthInfos);
Mega mega = new Mega(Config.MegaAuthInfos?.GetMegaApiClientAuthInfos());
if (!tryLogin || mega.TryLogin())
{
lblMegaStatus.Text = Resources.UploadersConfigForm_MegaConfigureTab_Configured;
@ -2108,7 +2109,15 @@ private void btnMegaLogin_Click(object sender, EventArgs e)
return;
}
Config.MegaAuthInfos = new MegaApiClient().GenerateAuthInfos(txtMegaEmail.Text, txtMegaPassword.Text);
MegaApiClient.AuthInfos megaAuthInfos = new MegaApiClient().GenerateAuthInfos(txtMegaEmail.Text, txtMegaPassword.Text);
if (megaAuthInfos != null)
{
Config.MegaAuthInfos = new MegaAuthInfos(megaAuthInfos);
}
else
{
Config.MegaAuthInfos = null;
}
MegaConfigureTab(true);
}

View file

@ -133,6 +133,7 @@
<Compile Include="FileUploaders\Box.cs" />
<Compile Include="FileUploaders\GoogleCloudStorage.cs" />
<Compile Include="FileUploaders\Lithiio.cs" />
<Compile Include="FileUploaders\MegaAuthInfos.cs" />
<Compile Include="FileUploaders\Plik.cs" />
<Compile Include="FileUploaders\PlikSettings.cs" />
<Compile Include="FileUploaders\Puush.cs" />

View file

@ -156,10 +156,10 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
#region Dropbox
public OAuth2Info DropboxOAuth2Info = null;
public string DropboxUploadPath = "ShareX/%y/%mo";
public bool DropboxAutoCreateShareableLink = true;
public bool DropboxUseDirectLink = false;
public OAuth2Info DropboxOAuth2Info { get; set; } = null;
public string DropboxUploadPath { get; set; } = "ShareX/%y/%mo";
public bool DropboxAutoCreateShareableLink { get; set; } = true;
public bool DropboxUseDirectLink { get; set; } = false;
// TEMP: For backward compatibility
public DropboxURLType DropboxURLType = DropboxURLType.Default;
@ -168,119 +168,123 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
#region FTP
public List<FTPAccount> FTPAccountList = new List<FTPAccount>();
public int FTPSelectedImage = 0;
public int FTPSelectedText = 0;
public int FTPSelectedFile = 0;
public List<FTPAccount> FTPAccountList { get; set; } = new List<FTPAccount>();
public int FTPSelectedImage { get; set; } = 0;
public int FTPSelectedText { get; set; } = 0;
public int FTPSelectedFile { get; set; } = 0;
#endregion FTP
#region OneDrive
public OAuth2Info OneDriveV2OAuth2Info = null;
public OneDriveFileInfo OneDriveV2SelectedFolder = OneDrive.RootFolder;
public bool OneDriveAutoCreateShareableLink = true;
public OAuth2Info OneDriveV2OAuth2Info { get; set; } = null;
public OneDriveFileInfo OneDriveV2SelectedFolder { get; set; } = OneDrive.RootFolder;
public bool OneDriveAutoCreateShareableLink { get; set; } = true;
#endregion OneDrive
#region Gfycat
public OAuth2Info GfycatOAuth2Info = null;
public AccountType GfycatAccountType = AccountType.Anonymous;
public bool GfycatIsPublic = false;
public bool GfycatKeepAudio = true;
public OAuth2Info GfycatOAuth2Info { get; set; } = null;
public AccountType GfycatAccountType { get; set; } = AccountType.Anonymous;
public bool GfycatIsPublic { get; set; } = false;
public bool GfycatKeepAudio { get; set; } = true;
#endregion Gfycat
#region Google Drive
public OAuth2Info GoogleDriveOAuth2Info = null;
public bool GoogleDriveIsPublic = true;
public bool GoogleDriveDirectLink = false;
public bool GoogleDriveUseFolder = false;
public string GoogleDriveFolderID = "";
public OAuth2Info GoogleDriveOAuth2Info { get; set; } = null;
public bool GoogleDriveIsPublic { get; set; } = true;
public bool GoogleDriveDirectLink { get; set; } = false;
public bool GoogleDriveUseFolder { get; set; } = false;
public string GoogleDriveFolderID { get; set; } = "";
#endregion Google Drive
#region puush
public string PuushAPIKey = "";
[JsonEncrypt]
public string PuushAPIKey { get; set; } = "";
#endregion puush
#region SendSpace
public AccountType SendSpaceAccountType = AccountType.Anonymous;
public string SendSpaceUsername = "";
public string SendSpacePassword = "";
public AccountType SendSpaceAccountType { get; set; } = AccountType.Anonymous;
public string SendSpaceUsername { get; set; } = "";
[JsonEncrypt]
public string SendSpacePassword { get; set; } = "";
#endregion SendSpace
#region Box
public OAuth2Info BoxOAuth2Info = null;
public BoxFileEntry BoxSelectedFolder = Box.RootFolder;
public bool BoxShare = true;
public BoxShareAccessLevel BoxShareAccessLevel = BoxShareAccessLevel.Open;
public OAuth2Info BoxOAuth2Info { get; set; } = null;
public BoxFileEntry BoxSelectedFolder { get; set; } = Box.RootFolder;
public bool BoxShare { get; set; } = true;
public BoxShareAccessLevel BoxShareAccessLevel { get; set; } = BoxShareAccessLevel.Open;
#endregion Box
#region Ge.tt
public Ge_ttLogin Ge_ttLogin = null;
public Ge_ttLogin Ge_ttLogin { get; set; } = null;
#endregion Ge.tt
#region Localhostr
public string LocalhostrEmail = "";
public string LocalhostrPassword = "";
public bool LocalhostrDirectURL = true;
public string LocalhostrEmail { get; set; } = "";
[JsonEncrypt]
public string LocalhostrPassword { get; set; } = "";
public bool LocalhostrDirectURL { get; set; } = true;
#endregion Localhostr
#region Shared folder
public List<LocalhostAccount> LocalhostAccountList = new List<LocalhostAccount>();
public int LocalhostSelectedImages = 0;
public int LocalhostSelectedText = 0;
public int LocalhostSelectedFiles = 0;
public List<LocalhostAccount> LocalhostAccountList { get; set; } = new List<LocalhostAccount>();
public int LocalhostSelectedImages { get; set; } = 0;
public int LocalhostSelectedText { get; set; } = 0;
public int LocalhostSelectedFiles { get; set; } = 0;
#endregion Shared folder
#region Email
public string EmailSmtpServer = "smtp.gmail.com";
public int EmailSmtpPort = 587;
public string EmailFrom = "...@gmail.com";
public string EmailPassword = "";
public bool EmailRememberLastTo = true;
public string EmailLastTo = "";
public string EmailDefaultSubject = "Sending email from ShareX";
public string EmailDefaultBody = "Screenshot is attached.";
public bool EmailAutomaticSend = false;
public string EmailAutomaticSendTo = "";
public string EmailSmtpServer { get; set; } = "smtp.gmail.com";
public int EmailSmtpPort { get; set; } = 587;
public string EmailFrom { get; set; } = "...@gmail.com";
[JsonEncrypt]
public string EmailPassword { get; set; } = "";
public bool EmailRememberLastTo { get; set; } = true;
public string EmailLastTo { get; set; } = "";
public string EmailDefaultSubject { get; set; } = "Sending email from ShareX";
public string EmailDefaultBody { get; set; } = "Screenshot is attached.";
public bool EmailAutomaticSend { get; set; } = false;
public string EmailAutomaticSendTo { get; set; } = "";
#endregion Email
#region Jira
public string JiraHost = "http://";
public string JiraIssuePrefix = "PROJECT-";
public OAuthInfo JiraOAuthInfo = null;
public string JiraHost { get; set; } = "http://";
public string JiraIssuePrefix { get; set; } = "PROJECT-";
public OAuthInfo JiraOAuthInfo { get; set; } = null;
#endregion Jira
#region Mega
public MegaApiClient.AuthInfos MegaAuthInfos = null;
public string MegaParentNodeId = null;
public MegaAuthInfos MegaAuthInfos { get; set; } = null;
public string MegaParentNodeId { get; set; } = null;
#endregion Mega
#region Amazon S3
public AmazonS3Settings AmazonS3Settings = new AmazonS3Settings()
public AmazonS3Settings AmazonS3Settings { get; set; } = new AmazonS3Settings()
{
ObjectPrefix = "ShareX/%y/%mo"
};
@ -289,145 +293,154 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
#region ownCloud / Nextcloud
public string OwnCloudHost = "";
public string OwnCloudUsername = "";
public string OwnCloudPassword = "";
public string OwnCloudPath = "/";
public int OwnCloudExpiryTime = 7;
public bool OwnCloudCreateShare = true;
public bool OwnCloudDirectLink = false;
public bool OwnCloud81Compatibility = true;
public bool OwnCloudUsePreviewLinks = false;
public bool OwnCloudAutoExpire = false;
public string OwnCloudHost { get; set; } = "";
public string OwnCloudUsername { get; set; } = "";
[JsonEncrypt]
public string OwnCloudPassword { get; set; } = "";
public string OwnCloudPath { get; set; } = "/";
public int OwnCloudExpiryTime { get; set; } = 7;
public bool OwnCloudCreateShare { get; set; } = true;
public bool OwnCloudDirectLink { get; set; } = false;
public bool OwnCloud81Compatibility { get; set; } = true;
public bool OwnCloudUsePreviewLinks { get; set; } = false;
public bool OwnCloudAutoExpire { get; set; } = false;
#endregion ownCloud / Nextcloud
#region MediaFire
public string MediaFireUsername = "";
public string MediaFirePassword = "";
public string MediaFirePath = "";
public bool MediaFireUseLongLink = false;
public string MediaFireUsername { get; set; } = "";
[JsonEncrypt]
public string MediaFirePassword { get; set; } = "";
public string MediaFirePath { get; set; } = "";
public bool MediaFireUseLongLink { get; set; } = false;
#endregion MediaFire
#region Pushbullet
public PushbulletSettings PushbulletSettings = new PushbulletSettings();
public PushbulletSettings PushbulletSettings { get; set; } = new PushbulletSettings();
#endregion Pushbullet
#region Lambda
public LambdaSettings LambdaSettings = new LambdaSettings();
public LambdaSettings LambdaSettings { get; set; } = new LambdaSettings();
#endregion Lambda
#region Lithiio
public LithiioSettings LithiioSettings = new LithiioSettings();
public LithiioSettings LithiioSettings { get; set; } = new LithiioSettings();
#endregion Lithiio
#region Teknik
public OAuth2Info TeknikOAuth2Info = null;
public string TeknikUploadAPIUrl = Teknik.DefaultUploadAPIURL;
public string TeknikPasteAPIUrl = Teknik.DefaultPasteAPIURL;
public string TeknikUrlShortenerAPIUrl = Teknik.DefaultUrlShortenerAPIURL;
public string TeknikAuthUrl = Teknik.DefaultAuthURL;
public TeknikExpirationUnit TeknikExpirationUnit = TeknikExpirationUnit.Never;
public int TeknikExpirationLength = 1;
public bool TeknikEncryption = false;
public bool TeknikGenerateDeletionKey = false;
public OAuth2Info TeknikOAuth2Info { get; set; } = null;
public string TeknikUploadAPIUrl { get; set; } = Teknik.DefaultUploadAPIURL;
public string TeknikPasteAPIUrl { get; set; } = Teknik.DefaultPasteAPIURL;
public string TeknikUrlShortenerAPIUrl { get; set; } = Teknik.DefaultUrlShortenerAPIURL;
public string TeknikAuthUrl { get; set; } = Teknik.DefaultAuthURL;
public TeknikExpirationUnit TeknikExpirationUnit { get; set; } = TeknikExpirationUnit.Never;
public int TeknikExpirationLength { get; set; } = 1;
public bool TeknikEncryption { get; set; } = false;
public bool TeknikGenerateDeletionKey { get; set; } = false;
#endregion Teknik
#region Pomf
public PomfUploader PomfUploader = new PomfUploader();
public PomfUploader PomfUploader { get; set; } = new PomfUploader();
#endregion Pomf
#region s-ul
public string SulAPIKey = "";
[JsonEncrypt]
public string SulAPIKey { get; set; } = "";
#endregion s-ul
#region Seafile
public string SeafileAPIURL = "";
public string SeafileAuthToken = "";
public string SeafileRepoID = "";
public string SeafilePath = "/";
public bool SeafileIsLibraryEncrypted = false;
public string SeafileEncryptedLibraryPassword = "";
public bool SeafileCreateShareableURL = true;
public bool SeafileCreateShareableURLRaw = false;
public bool SeafileIgnoreInvalidCert = false;
public int SeafileShareDaysToExpire = 0;
public string SeafileSharePassword = "";
public string SeafileAccInfoEmail = "";
public string SeafileAccInfoUsage = "";
public string SeafileAPIURL { get; set; } = "";
[JsonEncrypt]
public string SeafileAuthToken { get; set; } = "";
public string SeafileRepoID { get; set; } = "";
public string SeafilePath { get; set; } = "/";
public bool SeafileIsLibraryEncrypted { get; set; } = false;
[JsonEncrypt]
public string SeafileEncryptedLibraryPassword { get; set; } = "";
public bool SeafileCreateShareableURL { get; set; } = true;
public bool SeafileCreateShareableURLRaw { get; set; } = false;
public bool SeafileIgnoreInvalidCert { get; set; } = false;
public int SeafileShareDaysToExpire { get; set; } = 0;
[JsonEncrypt]
public string SeafileSharePassword { get; set; } = "";
public string SeafileAccInfoEmail { get; set; } = "";
public string SeafileAccInfoUsage { get; set; } = "";
#endregion Seafile
#region Streamable
public bool StreamableAnonymous = true;
public string StreamableUsername = "";
public string StreamablePassword = "";
public bool StreamableUseDirectURL = false;
public bool StreamableAnonymous { get; set; } = true;
public string StreamableUsername { get; set; } = "";
[JsonEncrypt]
public string StreamablePassword { get; set; } = "";
public bool StreamableUseDirectURL { get; set; } = false;
#endregion Streamable
#region Azure Storage
public string AzureStorageAccountName = "";
public string AzureStorageAccountAccessKey = "";
public string AzureStorageContainer = "";
public string AzureStorageEnvironment = "blob.core.windows.net";
public string AzureStorageCustomDomain = "";
public string AzureStorageUploadPath = "";
public string AzureStorageAccountName { get; set; } = "";
[JsonEncrypt]
public string AzureStorageAccountAccessKey { get; set; } = "";
public string AzureStorageContainer { get; set; } = "";
public string AzureStorageEnvironment { get; set; } = "blob.core.windows.net";
public string AzureStorageCustomDomain { get; set; } = "";
public string AzureStorageUploadPath { get; set; } = "";
#endregion Azure Storage
#region Backblaze B2
public string B2ApplicationKeyId = "";
public string B2ApplicationKey = "";
public string B2BucketName = "";
public string B2UploadPath = "ShareX/%y/%mo";
public bool B2UseCustomUrl = false;
public string B2CustomUrl = "https://example.com";
public string B2ApplicationKeyId { get; set; } = "";
[JsonEncrypt]
public string B2ApplicationKey { get; set; } = "";
public string B2BucketName { get; set; } = "";
public string B2UploadPath { get; set; } = "ShareX/%y/%mo";
public bool B2UseCustomUrl { get; set; } = false;
public string B2CustomUrl { get; set; } = "https://example.com";
#endregion Backblaze B2
#region Plik
public PlikSettings PlikSettings = new PlikSettings();
public PlikSettings PlikSettings { get; set; } = new PlikSettings();
#endregion Plik
#region YouTube
public OAuth2Info YouTubeOAuth2Info = null;
public YouTubeVideoPrivacy YouTubePrivacyType = YouTubeVideoPrivacy.Public;
public bool YouTubeUseShortenedLink = false;
public OAuth2Info YouTubeOAuth2Info { get; set; } = null;
public YouTubeVideoPrivacy YouTubePrivacyType { get; set; } = YouTubeVideoPrivacy.Public;
public bool YouTubeUseShortenedLink { get; set; } = false;
#endregion YouTube
#region Google Cloud Storage
public OAuth2Info GoogleCloudStorageOAuth2Info = null;
public string GoogleCloudStorageBucket = "";
public string GoogleCloudStorageDomain = "";
public string GoogleCloudStorageObjectPrefix = "ShareX/%y/%mo";
public bool GoogleCloudStorageRemoveExtensionImage = false;
public bool GoogleCloudStorageRemoveExtensionVideo = false;
public bool GoogleCloudStorageRemoveExtensionText = false;
public bool GoogleCloudStorageSetPublicACL = true;
public OAuth2Info GoogleCloudStorageOAuth2Info { get; set; } = null;
public string GoogleCloudStorageBucket { get; set; } = "";
public string GoogleCloudStorageDomain { get; set; } = "";
public string GoogleCloudStorageObjectPrefix { get; set; } = "ShareX/%y/%mo";
public bool GoogleCloudStorageRemoveExtensionImage { get; set; } = false;
public bool GoogleCloudStorageRemoveExtensionVideo { get; set; } = false;
public bool GoogleCloudStorageRemoveExtensionText { get; set; } = false;
public bool GoogleCloudStorageSetPublicACL { get; set; } = true;
#endregion Google Cloud Storage