Skip to content

Commit

Permalink
Support multiple otp datasets in Google Authenticator import
Browse files Browse the repository at this point in the history
  • Loading branch information
Rookiestyle committed Oct 14, 2020
1 parent 29f34b0 commit 4d4dffc
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 40 deletions.
12 changes: 10 additions & 2 deletions Translations/KeePassOTP.de.language.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Translation>
<TranslationVersion>10</TranslationVersion>
<TranslationVersion>11</TranslationVersion>
<item>
<key>OTPCopyTrayNoEntries</key>
<value>KPOTP - Keine Einträge vorhanden</value>
Expand Down Expand Up @@ -79,7 +79,7 @@
</item>
<item>
<key>TimeCorrection</key>
<value>Zeitversatz ausgleichen - Nur für TOTP && Steam</value>
<value>Zeitversatz ausgleichen - Nur für TOTP &amp;&amp; Steam</value>
</item>
<item>
<key>URL</key>
Expand Down Expand Up @@ -247,4 +247,12 @@ Die Daten müssen manuell wiederhergestellt werden.</value>
<key>Placeholder</key>
<value>Platzhalter:</value>
</item>
<item>
<key>SelectSingleEntry</key>
<value>Bitte markiere den zu verwendenden Eintrag</value>
</item>
<item>
<key>Issuer</key>
<value>Aussteller</value>
</item>
</Translation>
39 changes: 29 additions & 10 deletions Translations/KeePassOTP.template.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</item>
<item>
<key>TimeCorrection</key>
<value>Time correction - TOTP && Steam only</value>
<value>Time correction - TOTP &amp;&amp; Steam only</value>
</item>
<item>
<key>URL</key>
Expand Down Expand Up @@ -229,16 +229,16 @@ All occurrences of {0} need to be replaced by {1} for Auto-Type to work.
Replace now in currently loaded databases?</value>
</item>
<item>
<key>ConfirmOTPDBDelete</key>
<value>This will deactivate the OTP database.
It will NOT delete the OTP database.
<key>ConfirmOTPDBDelete</key>
<value>This will deactivate the KeePassOTP database.
It will NOT delete the KeePassOTP database.

Click '{0}' to deactivate AND delete OTP database.
Click '{1}' to deactivate but not delete OTP database.</value>
Click '{0}' to deactivate AND delete KeePassOTP database.
Click '{1}' to deactivate but not delete KeePassOTP database.</value>
</item>
<item>
<key>OTPBackupDone</key>
<value>Unlocking the existing OTP database failed and its content has been overwritten.
<key>OTPBackupDone</key>
<value>Unlocking the existing OTP database failed and its content has been overwritten.
A backup was saved as attachment in the following entry:
{0}

Expand All @@ -247,10 +247,29 @@ Restoring the data needs to be done manually.</value>
</item>
<item>
<key>Placeholder</key>
<value>Placeholder:</value>
<value>Placeholder:</value>
</item>
<item>
<key>PlaceholderAutoSubmit</key>
<value>{0} + Enter</value>
<value>{0} + Enter</value>
</item>
<item>
<key>ErrorGoogleAuthImport</key>
<value>Error parsing data</value>
</item>
<item>
<key>ErrorGoogleAuthImportCount</key>
<value>Error parsing data

Expected amount of OTP entries: 1
Found amount of OTP entries: {0}</value>
</item>
<item>
<key>SelectSingleEntry</key>
<value>Please check the single entry to use</value>
</item>
<item>
<key>Issuer</key>
<value>Issuer</value>
</item>
</Translation>
Binary file added images/GoogleAuthImport_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using KeePass.Resources;
using KeePassLib.Security;
using PluginTranslation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KeePassOTP
{
public partial class GoogleAuthenticatorImportSelection : Form
{
private List<GoogleAuthenticatorImport.OtpParameters> m_Entries = null;
public GoogleAuthenticatorImport.OtpParameters SelectedEntry
{
get
{
if (lvEntries.CheckedIndices.Count != 1) return null;
return m_Entries[lvEntries.CheckedIndices[0]];
}
}

public GoogleAuthenticatorImportSelection()
{
InitializeComponent();

Text = PluginTranslate.PluginName;
bOK.Text = KPRes.Ok;
bCancel.Text = KPRes.Cancel;
lDesc.Text = PluginTranslate.SelectSingleEntry;
chIssuer.Text = PluginTranslate.Issuer;
chLabel.Text = KPRes.UserName;
}

public void InitEx(List<GoogleAuthenticatorImport.OtpParameters> lEntries)
{
m_Entries = lEntries;
lvEntries.Items.Clear();
foreach (var otp in m_Entries)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = otp.Issuer;
string label = string.IsNullOrEmpty(otp.Issuer) ? otp.Name : otp.Name.Remove(0, otp.Issuer.Length + 1);
lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, label));
lvEntries.Items.Add(lvi);
}
}

private void lvEntries_ItemChecked(object sender, ItemCheckedEventArgs e)
{
lvEntries.ItemChecked -= lvEntries_ItemChecked;
foreach (ListViewItem lvi in lvEntries.Items)
lvi.Checked = lvi.Index == e.Item.Index && e.Item.Checked;
lvEntries.ItemChecked += lvEntries_ItemChecked;
bOK.Enabled = lvEntries.CheckedItems.Count == 1;
}

private void GoogleAuthenticatorImportSelection_Shown(object sender, EventArgs e)
{
chIssuer.Width = chLabel.Width = lvEntries.ClientSize.Width / 2;
lvEntries.Items[0].Checked = true;
}
}
}
12 changes: 9 additions & 3 deletions src/KeePassOTP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup>
<PlgxConfiguration>
<PlgxConfiguration>
<Prerequisites>
<KeePassVersion>2.42</KeePassVersion>
<DotNetVersion>$(TargetFrameworkVersion.Replace('v', ''))</DotNetVersion>
<DotNetVersion>$(TargetFrameworkVersion.Replace('v', ''))</DotNetVersion>
</Prerequisites>
</PlgxConfiguration>
</PropertyGroup>
Expand All @@ -67,6 +67,12 @@
<Compile Include="DAO\OTPDAO_Entry.cs" />
<Compile Include="DAO\OTPDAO.cs" />
<Compile Include="GoogleAuthenticatorImport\GoogleAuthenticatorImport.cs" />
<Compile Include="GoogleAuthenticatorImport\GoogleAuthenticatorImportSelection.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GoogleAuthenticatorImport\GoogleAuthenticatorImportSelection.Designer.cs">
<DependentUpon>GoogleAuthenticatorImportSelection.cs</DependentUpon>
</Compile>
<Compile Include="HotkeyManager.cs" />
<Compile Include="Migration.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down Expand Up @@ -146,7 +152,7 @@
<ItemGroup>
<PackageReference Include="PlgxTool">
<Version>1.0.0</Version>
<ExcludeFromPlgx />
<ExcludeFromPlgx />
</PackageReference>
<PackageReference Include="protobuf-net">
<Version>3.0.52</Version>
Expand Down
Loading

0 comments on commit 4d4dffc

Please sign in to comment.