Skip to content

Commit

Permalink
Fixes #32 and #31
Browse files Browse the repository at this point in the history
  • Loading branch information
tiuub committed Sep 24, 2021
1 parent a507f6b commit 7cb4640
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
Releases/
Debug/
*.user
/packages/*
89 changes: 89 additions & 0 deletions KeeOtp2.Tests/KeeOtp2.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.4.3\build\net452\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.4.3\build\net452\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DCB1C09A-E92C-413F-8927-79E96331F56B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KeeOtp2.Tests</RootNamespace>
<AssemblyName>KeeOtp2.Tests</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="KeePass, Version=2.47.0.21109, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\KeePass\KeePass.exe</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="KeeOtp2Migration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KeeOtp2\KeeOtp2.csproj">
<Project>{6239ec51-8ea1-4aec-883f-086663f24d40}</Project>
<Name>KeeOtp2</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.4.3\build\net452\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.4.3\build\net452\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
</Project>
38 changes: 38 additions & 0 deletions KeeOtp2.Tests/KeeOtp2Migration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using KeeOtp2;
using KeePassLib;
using KeePassLib.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace KeeOtp2.Tests
{
public class KeeOtp2Migration
{
[Theory]
[InlineData("otp", "wroiv2p5agecswssthwzyjn2xzgdquyk", MigrationMode.KeeOtp1ToBuiltIn, true, false)]
[InlineData("otp", "wroiv2p5agecswssthwzyjn2xzgdq", MigrationMode.KeeOtp1ToBuiltIn, true, false)]
[InlineData("otp", "key=wroiv2p5agecswssthwzyjn2xzgdquyk", MigrationMode.KeeOtp1ToBuiltIn, true, true)]
[InlineData("TimeOtp-Secret-Base32", "wroi v2p5 agec swss thwz yjn2 xzgd quyk", MigrationMode.BuiltInToKeeOtp1, true, true)]
[InlineData("TimeOtp-Secret-Base32", "wroi v2p5 agec swss thwz yjn2 xzgd quyk", MigrationMode.KeeOtp1ToBuiltIn, false, true)]
[InlineData("TimeOtp-Secret-Base32", "wroiv2p5agecswssthwzyjn2xzgdquyk", MigrationMode.BuiltInToKeeOtp1, true, true)]
//[InlineData("otp", "", MigrationMode.BuiltInToKeeOtp1, false)]
//[InlineData("otp", "", MigrationMode.BuiltInToKeeOtp1, false)]
public void TestKeyFormat(string keyStringName, string keyStringValue, MigrationMode migrateMode,
bool canMigrate, bool canLoad)
{

var pwdEntry = new PwEntry(true, true);
pwdEntry.Strings.Set(keyStringName, new ProtectedString(true, keyStringValue));
Console.WriteLine(keyStringValue);
Assert.Equal(canMigrate, OtpAuthUtils.checkEntryMigratable(pwdEntry, migrateMode));
if (canLoad)
Assert.NotNull(OtpAuthUtils.loadData(pwdEntry));
else
Assert.Null(OtpAuthUtils.loadData(pwdEntry));
}
}
}
36 changes: 36 additions & 0 deletions KeeOtp2.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("KeeOtp2.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeeOtp2.Tests")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dcb1c09a-e92c-413f-8927-79e96331f56b")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
11 changes: 11 additions & 0 deletions KeeOtp2.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.4.1" targetFramework="net472" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net472" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net472" />
<package id="xunit.assert" version="2.4.1" targetFramework="net472" />
<package id="xunit.core" version="2.4.1" targetFramework="net472" />
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net472" />
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net472" />
<package id="xunit.runner.visualstudio" version="2.4.3" targetFramework="net472" developmentDependency="true" />
</packages>
6 changes: 6 additions & 0 deletions KeeOtp2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.329
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeeOtp2", "KeeOtp2\KeeOtp2.csproj", "{6239EC51-8EA1-4AEC-883F-086663F24D40}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeeOtp2.Tests", "KeeOtp2.Tests\KeeOtp2.Tests.csproj", "{DCB1C09A-E92C-413F-8927-79E96331F56B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{6239EC51-8EA1-4AEC-883F-086663F24D40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6239EC51-8EA1-4AEC-883F-086663F24D40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6239EC51-8EA1-4AEC-883F-086663F24D40}.Release|Any CPU.Build.0 = Release|Any CPU
{DCB1C09A-E92C-413F-8927-79E96331F56B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCB1C09A-E92C-413F-8927-79E96331F56B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCB1C09A-E92C-413F-8927-79E96331F56B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCB1C09A-E92C-413F-8927-79E96331F56B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
29 changes: 17 additions & 12 deletions KeeOtp2/Forms/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,34 @@ public About(IPluginHost host)
{
InitializeComponent();

this.host = host;
}

private void About_Load(object sender, EventArgs e)
{
Point location = this.Owner.Location;
location.Offset(20, 20);
this.Location = location;

this.Icon = this.host.MainWindow.Icon;
this.TopMost = this.host.MainWindow.TopMost;

PluginUtils.CheckKeeTheme(this);
}

public void InitEx()
{
pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
pictureBoxBanner.Height,
KeePass.UI.BannerStyle.Default,
Resources.info_white,
KeeOtp2Statics.About,
KeeOtp2Statics.AboutSubline);

this.Icon = host.MainWindow.Icon;

this.host = host;
this.TopMost = host.MainWindow.TopMost;

groupBoxDependencies.Text = KeeOtp2Statics.Dependencies;
linkLabelGitHubRepository.Text = KeeOtp2Statics.GitHubRepository;
linkLabelDonate.Text = KeeOtp2Statics.Doante;
buttonOK.Text = KeeOtp2Statics.OK;
}

private void About_Load(object sender, EventArgs e)
{
this.Left = this.host.MainWindow.Left + 20;
this.Top = this.host.MainWindow.Top + 20;

groupBoxAbout.Text = KeeOtp2Statics.About;

Assembly assembly = Assembly.GetExecutingAssembly();
Expand Down
63 changes: 41 additions & 22 deletions KeeOtp2/Forms/OtpInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,51 @@
using KeePass.Plugins;
using OtpNet;
using ZXing;
using KeePassLib;

namespace KeeOtp2
{
public partial class OtpInformation : Form
{
private readonly KeePassLib.PwEntry entry;
private readonly IPluginHost host;
private IPluginHost host;
private PwEntry entry;
private OtpAuthData data;

bool scanQRMode = true;

private Dictionary<int, int> comboBoxLengthIndexValue;
private Dictionary<int, OtpType> comboBoxTypeIndexValue;

public OtpInformation(OtpAuthData data, KeePassLib.PwEntry entry, IPluginHost host)
public OtpInformation(IPluginHost host, PwEntry entry, OtpAuthData data)
{
InitializeComponent();

this.host = host;
this.entry = entry;
this.data = data;
}

private void OtpInformation_Load(object sender, EventArgs e)
{
Point location = this.Owner.Location;
location.Offset(20, 20);
this.Location = location;

this.Icon = this.host.MainWindow.Icon;
this.TopMost = this.host.MainWindow.TopMost;

PluginUtils.CheckKeeTheme(this);
}

public void InitEx()
{
pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
pictureBoxBanner.Height,
KeePass.UI.BannerStyle.Default,
Resources.lock_white,
KeeOtp2Statics.OtpInformation,
KeeOtp2Statics.OtpInformationSubline);

this.Icon = host.MainWindow.Icon;

this.data = data;
this.entry = entry;
this.host = host;

this.TopMost = host.MainWindow.TopMost;

groupBoxKey.Text = KeeOtp2Statics.OtpInformationKeyUri;
linkLabelLoadUriScanQR.Text = KeeOtp2Statics.OtpInformationScanQr;
checkBoxCustomSettings.Text = KeeOtp2Statics.OtpInformationCustomSettings + KeeOtp2Statics.InformationChar;
Expand Down Expand Up @@ -74,25 +86,20 @@ public OtpInformation(OtpAuthData data, KeePassLib.PwEntry entry, IPluginHost ho
toolTip.SetToolTip(checkboxOldKeeOtp, KeeOtp2Statics.ToolTipOtpInformationUseOldKeeOtpSaveMode);

comboBoxLengthIndexValue = new Dictionary<int, int>();
for (int i = 5; i<=10; i++)
for (int i = 5; i <= 10; i++)
{
if (i == 6 || i == 8)
comboBoxLengthIndexValue[comboBoxLength.Items.Add(String.Format("{0} ({1})", i, KeeOtp2Statics.CommonAbbreviation.ToLower() + KeeOtp2Statics.InformationChar))] = i;
else
comboBoxLengthIndexValue[comboBoxLength.Items.Add(i.ToString())] = i;
}
comboBoxTypeIndexValue = new Dictionary<int, OtpType>();
foreach (OtpType type in Enum.GetValues(typeof(OtpType))){
foreach (OtpType type in Enum.GetValues(typeof(OtpType)))
{
comboBoxTypeIndexValue[comboBoxType.Items.Add(type.ToString())] = type;
}
}

private void OtpInformation_Load(object sender, EventArgs e)
{
this.Left = this.host.MainWindow.Left + 20;
this.Top = this.host.MainWindow.Top + 20;
}

private void OtpInformation_Shown(object sender, EventArgs e)
{
loadData();
Expand Down Expand Up @@ -122,9 +129,10 @@ private void OtpInformation_FormClosing(object sender, FormClosingEventArgs e)
}


this.entry.Touch(true);
this.entry.Touch(true, false);
this.host.MainWindow.ActiveDatabase.Modified = true;
this.host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
this.host.MainWindow.RefreshEntriesList();
}
catch (InvalidBase32FormatException ex)
{
Expand Down Expand Up @@ -540,7 +548,13 @@ private void scanQRCode()
Bitmap bmpScreenshot;
Graphics gfxScreenshot;

this.Hide();
Form p = this;
while (p != null)
{
p.Hide();
p = p.Owner;
}

foreach (Screen sc in Screen.AllScreens)
{
bmpScreenshot = new Bitmap(sc.Bounds.Width, sc.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Expand All @@ -552,7 +566,12 @@ private void scanQRCode()
uri = new Uri(result.ToString());
}

this.Show();
p = this;
while (p != null)
{
p.Show();
p = p.Owner;
}

if (uri != null)
{
Expand Down
Loading

0 comments on commit 7cb4640

Please sign in to comment.