diff options
author | Valentin <fritz.valentin@live.fr> | 2021-06-26 14:39:05 +0300 |
---|---|---|
committer | Valentin <fritz.valentin@live.fr> | 2021-06-26 14:39:05 +0300 |
commit | eda3666bc7e4ea81501c9cc406f485a61384db65 (patch) | |
tree | 279a291af7b3bb598bd2d7abb0562185a02022da | |
parent | 5af46b6eecc9fe04c140ec5304dabdd50bdaa3af (diff) |
Add support for mega.nz two fa authentication
4 files changed, 23 insertions, 6 deletions
diff --git a/Duplicati/Library/Backend/Mega/Duplicati.Library.Backend.Mega.csproj b/Duplicati/Library/Backend/Mega/Duplicati.Library.Backend.Mega.csproj index c8871b0e0..27a9e9cd4 100644 --- a/Duplicati/Library/Backend/Mega/Duplicati.Library.Backend.Mega.csproj +++ b/Duplicati/Library/Backend/Mega/Duplicati.Library.Backend.Mega.csproj @@ -31,12 +31,15 @@ <ConsolePause>false</ConsolePause> </PropertyGroup> <ItemGroup> - <Reference Include="MegaApiClient, Version=1.7.1.495, Culture=neutral, PublicKeyToken=0480d311efbeb4e2, processorArchitecture=MSIL"> - <HintPath>..\..\..\..\packages\MegaApiClient.1.7.1\lib\net46\MegaApiClient.dll</HintPath> + <Reference Include="MegaApiClient, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0480d311efbeb4e2"> + <HintPath>..\..\..\..\packages\MegaApiClient.1.9.0\lib\net46\MegaApiClient.dll</HintPath> </Reference> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\..\..\..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> + <Reference Include="Otp.NET, Version=1.2.2.0, Culture=neutral, PublicKeyToken=38a48df817e173a6"> + <HintPath>..\..\..\..\packages\Otp.NET.1.2.2\lib\net45\Otp.NET.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Net.Http" /> <Reference Include="System.Web" /> diff --git a/Duplicati/Library/Backend/Mega/MegaBackend.cs b/Duplicati/Library/Backend/Mega/MegaBackend.cs index 184a63769..c3878b1e1 100644 --- a/Duplicati/Library/Backend/Mega/MegaBackend.cs +++ b/Duplicati/Library/Backend/Mega/MegaBackend.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using OtpNet;
namespace Duplicati.Library.Backend.Mega
{
@@ -31,6 +32,7 @@ namespace Duplicati.Library.Backend.Mega {
private readonly string m_username = null;
private readonly string m_password = null;
+ private readonly string m_twoFactorKey = null;
private Dictionary<string, List<INode>> m_filecache;
private INode m_currentFolder = null;
private readonly string m_prefix = null;
@@ -48,7 +50,13 @@ namespace Duplicati.Library.Backend.Mega if (m_client == null)
{
var cl = new MegaApiClient();
- cl.Login(m_username, m_password);
+ if (m_twoFactorKey == null)
+ cl.Login(m_username, m_password);
+ else
+ {
+ var totp = new Totp(Base32Encoding.ToBytes(m_twoFactorKey)).ComputeTotp();
+ cl.Login(m_username, m_password, totp);
+ }
m_client = cl;
}
@@ -64,6 +72,8 @@ namespace Duplicati.Library.Backend.Mega m_username = options["auth-username"];
if (options.ContainsKey("auth-password"))
m_password = options["auth-password"];
+ if (options.ContainsKey("auth-two-factor-key"))
+ m_twoFactorKey = options["auth-two-factor-key"];
if (!string.IsNullOrEmpty(uri.Username))
m_username = uri.Username;
@@ -253,6 +263,7 @@ namespace Duplicati.Library.Backend.Mega return new List<ICommandLineArgument>(new ICommandLineArgument[] {
new CommandLineArgument("auth-password", CommandLineArgument.ArgumentType.Password, Strings.MegaBackend.AuthPasswordDescriptionShort, Strings.MegaBackend.AuthPasswordDescriptionLong),
new CommandLineArgument("auth-username", CommandLineArgument.ArgumentType.String, Strings.MegaBackend.AuthUsernameDescriptionShort, Strings.MegaBackend.AuthUsernameDescriptionLong),
+ new CommandLineArgument("auth-two-factor-key", CommandLineArgument.ArgumentType.Password, Strings.MegaBackend.AuthTwoFactorKeyDescriptionShort, Strings.MegaBackend.AuthTwoFactorKeyDescriptionLong),
});
}
}
diff --git a/Duplicati/Library/Backend/Mega/Strings.cs b/Duplicati/Library/Backend/Mega/Strings.cs index d52089191..e3572f0e7 100644 --- a/Duplicati/Library/Backend/Mega/Strings.cs +++ b/Duplicati/Library/Backend/Mega/Strings.cs @@ -6,8 +6,10 @@ namespace Duplicati.Library.Backend.Strings { public static string AuthPasswordDescriptionShort { get { return LC.L(@"Supplies the password used to connect to the server"); } }
public static string AuthUsernameDescriptionLong { get { return LC.L(@"The username used to connect to the server. This may also be supplied as the environment variable ""AUTH_USERNAME""."); } }
public static string AuthUsernameDescriptionShort { get { return LC.L(@"Supplies the username used to connect to the server"); } }
+ public static string AuthTwoFactorKeyDescriptionShort { get { return LC.L(@"Supplies the two-factor key used to connect to the server"); } }
+ public static string AuthTwoFactorKeyDescriptionLong { get { return LC.L(@"The two-factor authentication key used to connect to the server."); } }
public static string NoPasswordError { get { return LC.L(@"No password given"); } }
public static string NoUsernameError { get { return LC.L(@"No username given"); } }
public static string Description { get { return LC.L(@"This backend can read and write data to Mega.co.nz. Allowed formats are: ""mega://folder/subfolder"""); } }
}
-}
+}
\ No newline at end of file diff --git a/Duplicati/Library/Backend/Mega/packages.config b/Duplicati/Library/Backend/Mega/packages.config index 06ff32662..c90fbddd1 100644 --- a/Duplicati/Library/Backend/Mega/packages.config +++ b/Duplicati/Library/Backend/Mega/packages.config @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="MegaApiClient" version="1.7.1" targetFramework="net471" /> + <package id="MegaApiClient" version="1.9.0" targetFramework="net471" /> <package id="Newtonsoft.Json" version="12.0.2" targetFramework="net471" /> -</packages> + <package id="Otp.NET" version="1.2.2" targetFramework="net471" /> +</packages>
\ No newline at end of file |