Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build 1.3.7 #16

Merged
merged 7 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change log

### Release 1.3.7
**KPCLib**
- Added `GetOtpUrl()`

### Release 1.3.6
**PassXYZLib**
- Added LogFilePath
Expand Down
2 changes: 1 addition & 1 deletion KPCLib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>KPCLib</id>
<version>1.3.6.0</version>
<version>1.3.7.0</version>
<authors>Roger Ye</authors>
<owners>Roger Ye</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
46 changes: 46 additions & 0 deletions KPCLib.xunit/PureOtpTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xunit;

using PureOtp;

namespace KPCLib.xunit
{
public class PureOtpTests
{
[Theory]
[InlineData("/kpclibpy/Database/Oracle")]
[InlineData("http://www.google.com/test?secret=JBSWY3DPEHPK3PXP")]
[InlineData("otpauth://totp/test01%3Abad_url_test%40gmail.com?secret=098")]
[InlineData("otpauth://totp/Google%3Apxentry_test%40gmail.com")]
[InlineData("otpauth://totp/Google%3Apxentry_test%40gmail.com?secret=JBSWY3DPEHPK3PXP")]
[InlineData("otpauth://totp/Google%3Apxentry_test%40gmail.com?secret=JBSWY3DPEHPK3PXP&issuer=Google")]
public void RawUrlTest(string rawUrl)
{
try
{
var otp = KeyUrl.FromUrl(rawUrl);
if (otp is Totp totp)
{
var url = new Uri(rawUrl);
Assert.True(true);
Debug.WriteLine($"{rawUrl} is a valid URL.");
}
else
{
Debug.WriteLine($"{rawUrl} is an invalid URL.");
}
}
catch (Exception ex)
{
Debug.WriteLine($"{ex}");
Assert.False(false);
}
}
}
}
6 changes: 3 additions & 3 deletions KPCLib/KPCLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<OutputType>Library</OutputType>
<StartupObject />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.3.6</Version>
<Version>1.3.7</Version>
<PackageProjectUrl>https://github.com/passxyz/KPCLib</PackageProjectUrl>
<RepositoryUrl>https://github.com/passxyz/KPCLib</RepositoryUrl>
<Description>This is the build of KeePassLib in Xamarin Portable Class Library. Three platforms, UWP, Android and iOS, are supported and tested.</Description>
Expand All @@ -15,8 +15,8 @@
<Company>PassXYZ Inc.</Company>
<PackageReleaseNotes></PackageReleaseNotes>
<NeutralLanguage>en-US</NeutralLanguage>
<AssemblyVersion>1.3.6.0</AssemblyVersion>
<FileVersion>1.3.6.0</FileVersion>
<AssemblyVersion>1.3.7.0</AssemblyVersion>
<FileVersion>1.3.7.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
5 changes: 5 additions & 0 deletions KPCLib/PwEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ public void UpdateToken()
}
}

public string GetOtpUrl()
{
return CustomData.Get(PassXYZLib.PxDefs.PxCustomDataOtpUrl);
}

/// <summary>
/// Update the OTP Url.
/// If it is new, create a PxOtpUrl key in CustomData.
Expand Down
2 changes: 1 addition & 1 deletion PassXYZLib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>PassXYZLib</id>
<version>1.3.6.0</version>
<version>1.3.7.0</version>
<authors>Roger Ye</authors>
<owners>Roger Ye</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
96 changes: 90 additions & 6 deletions PassXYZLib/PxDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public class PxDatabase : PwDatabase
public PwGroup CurrentGroup
{
get {
if (!IsOpen) { return null; }

if(RootGroup.Uuid == LastSelectedGroup || LastSelectedGroup.Equals(PwUuid.Zero))
{
LastSelectedGroup = RootGroup.Uuid;
Expand Down Expand Up @@ -203,9 +205,9 @@ public PwGroup CurrentGroup
public string CurrentPath
{
get {
if(CurrentGroup == null)
if(CurrentGroup == null)
{
return null;
return string.Empty;
}
else
{
Expand Down Expand Up @@ -262,9 +264,9 @@ public PxDatabase() : base()
/// <param name="password">The password of data file</param>
public void Open(string filename, string password)
{
if (filename == null || filename == String.Empty)
if (filename == null || filename == String.Empty)
{ Debug.Assert(false); throw new ArgumentNullException("filename"); }
if (password == null || password == String.Empty)
if (password == null || password == String.Empty)
{ Debug.Assert(false); throw new ArgumentNullException("password"); }

var logger = new KPCLibLogger();
Expand Down Expand Up @@ -302,6 +304,8 @@ public void Open(PassXYZLib.User user)
{
if (user == null)
{ Debug.Assert(false); throw new ArgumentNullException("PassXYZLib.User"); }
if (user.Password == null || user.Password == String.Empty)
{ Debug.Assert(false); throw new ArgumentNullException("Password"); }

var logger = new KPCLibLogger();

Expand All @@ -328,7 +332,7 @@ public void Open(PassXYZLib.User user)
}
catch (PassXYZ.Services.InvalidDeviceLockException ex)
{
try { cmpKey.AddUserKey(new KcpKeyFile(user.KeFilePath)); }
try { cmpKey.AddUserKey(new KcpKeyFile(user.KeyFilePath)); }
catch (Exception exFile)
{
Debug.Write($"{exFile} in {ex}");
Expand Down Expand Up @@ -392,7 +396,7 @@ public bool ChangeMasterPassword(string newPassword, PassXYZLib.User user)
}
catch (PassXYZ.Services.InvalidDeviceLockException ex)
{
try { cmpKey.AddUserKey(new KcpKeyFile(user.KeFilePath)); }
try { cmpKey.AddUserKey(new KcpKeyFile(user.KeyFilePath)); }
catch (Exception exFile)
{
Debug.Write($"{exFile} in {ex}");
Expand Down Expand Up @@ -527,6 +531,34 @@ private void EnsureRecycleBin(ref PwGroup pgRecycleBin)
else { Debug.Assert(pgRecycleBin.Uuid.Equals(this.RecycleBinUuid)); }
}

/// <summary>
/// Remove RecycleBin before merge. RecycleBin should be kept locally and should not be merged.
/// </summary>
/// <param name="pwDb"></param>
/// <returns></returns>
private bool DeleteRecycleBin(PwDatabase pwDb)
{
if (pwDb == null) { return false; }

PwGroup pgRecycleBin = pwDb.RootGroup.FindGroup(pwDb.RecycleBinUuid, true);

if (pgRecycleBin != null)
{
pwDb.RootGroup.Groups.Remove(pgRecycleBin);
pgRecycleBin.DeleteAllObjects(pwDb);
PwDeletedObject pdo = new PwDeletedObject(pgRecycleBin.Uuid, DateTime.UtcNow);
pwDb.DeletedObjects.Add(pdo);
Debug.WriteLine("DeleteRecycleBin successfully.");
return true;
}
else
{
Debug.WriteLine("DeleteRecycleBin failure.");
return false;
}
}


/// <summary>
/// Find an entry or a group.
/// </summary>
Expand Down Expand Up @@ -962,6 +994,58 @@ orderby e.LastModificationTime descending
return resultsList;
}

public bool Merge(string path, PwMergeMethod mm)
{
var pwImp = new PwDatabase();
var ioInfo = IOConnectionInfo.FromPath(path);

var compositeKey = MasterKey;

KPCLibLogger swLogger = new KPCLibLogger();
try
{
swLogger.StartLogging("Merge: Opening database ...", true);
pwImp.Open(ioInfo, compositeKey, swLogger);
swLogger.EndLogging();
}
catch (Exception e)
{
Debug.WriteLine($"$Failed to open database: {e.Message}.");
return false;
}

// We only merge, if these are the same database with different versions.
if (RootGroup.EqualsGroup(pwImp.RootGroup, (PwCompareOptions.IgnoreLastBackup |
PwCompareOptions.IgnoreHistory | PwCompareOptions.IgnoreParentGroup |
PwCompareOptions.IgnoreTimes | PwCompareOptions.PropertiesOnly), MemProtCmpMode.None))
{
Debug.WriteLine($"Merge: Root group are the same. Merge method is {mm}.");
}
else
{
Debug.WriteLine($"Merge: Root group are different DBase={RootGroup}, pwImp={pwImp.RootGroup}.");
pwImp.Close();
return false;
}

try
{
// Need to remove RecycleBin first before merge.
DeleteRecycleBin(pwImp);

MergeIn(pwImp, mm, swLogger);
DescriptionChanged = DateTime.UtcNow;
Save(swLogger);
pwImp.Close();
}
catch (Exception exMerge)
{
Debug.WriteLine($"Merge failed {exMerge}");
return false;
}
return true;
}

// The end of PxDatabase
}

Expand Down
Loading