From 2790711a8c0e1f0d64e761a4acab56f661f22c37 Mon Sep 17 00:00:00 2001 From: JanisEst Date: Sat, 24 Feb 2018 16:06:04 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 252 +++++++++++++++++++++++++++++++ DelayedEventHandler.cs | 39 +++++ KeePassHIBP.csproj | 76 ++++++++++ KeePassHIBP.sln | 37 +++++ KeePassHIBPExt.cs | 158 +++++++++++++++++++ Properties/AssemblyInfo.cs | 36 +++++ Properties/Resources.Designer.cs | 73 +++++++++ Properties/Resources.resx | 124 +++++++++++++++ README.md | 20 +++ Resources/B16x16_Icon.png | Bin 0 -> 590 bytes keepass.version | 3 + 11 files changed, 818 insertions(+) create mode 100644 .gitignore create mode 100644 DelayedEventHandler.cs create mode 100644 KeePassHIBP.csproj create mode 100644 KeePassHIBP.sln create mode 100644 KeePassHIBPExt.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 Properties/Resources.Designer.cs create mode 100644 Properties/Resources.resx create mode 100644 README.md create mode 100644 Resources/B16x16_Icon.png create mode 100644 keepass.version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1e3d20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,252 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml diff --git a/DelayedEventHandler.cs b/DelayedEventHandler.cs new file mode 100644 index 0000000..ffebee0 --- /dev/null +++ b/DelayedEventHandler.cs @@ -0,0 +1,39 @@ +using System; +using System.Windows.Forms; + +namespace KeePassHIBP +{ + public class DelayedEventHandler + { + private readonly Timer delayTimer = new Timer(); + + private object delegatedSender; + private EventArgs delegatedEventArgs; + + public EventHandler OnDelay; + + public DelayedEventHandler(TimeSpan delay, EventHandler eventDelegate) + { + delayTimer.Interval = (int)delay.TotalMilliseconds; + delayTimer.Tick += delegate + { + delayTimer.Stop(); + + if (eventDelegate != null) + { + eventDelegate.Invoke(delegatedSender, delegatedEventArgs); + } + }; + + OnDelay = delegate (object sender, EventArgs e) + { + delegatedSender = sender; + delegatedEventArgs = e; + + delayTimer.Stop(); + + delayTimer.Start(); + }; + } + } +} diff --git a/KeePassHIBP.csproj b/KeePassHIBP.csproj new file mode 100644 index 0000000..76dd2fe --- /dev/null +++ b/KeePassHIBP.csproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + {6A249FA1-3F87-4C81-8D31-6BDF62308F48} + Library + Properties + KeePassHIBP + KeePassHIBP + v4.0 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + {10938016-dee2-4a25-9a5a-8fd3444379ca} + KeePass + + + + + + + + \ No newline at end of file diff --git a/KeePassHIBP.sln b/KeePassHIBP.sln new file mode 100644 index 0000000..f039acb --- /dev/null +++ b/KeePassHIBP.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2027 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeePassHIBP", "KeePassHIBP.csproj", "{6A249FA1-3F87-4C81-8D31-6BDF62308F48}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeePass", "..\KeePass\KeePass\KeePass.csproj", "{10938016-DEE2-4A25-9A5A-8FD3444379CA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B6024896-002F-4562-91BA-DCF0E56EF345}" + ProjectSection(SolutionItems) = preProject + keepass.version = keepass.version + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6A249FA1-3F87-4C81-8D31-6BDF62308F48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A249FA1-3F87-4C81-8D31-6BDF62308F48}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A249FA1-3F87-4C81-8D31-6BDF62308F48}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A249FA1-3F87-4C81-8D31-6BDF62308F48}.Release|Any CPU.Build.0 = Release|Any CPU + {10938016-DEE2-4A25-9A5A-8FD3444379CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10938016-DEE2-4A25-9A5A-8FD3444379CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10938016-DEE2-4A25-9A5A-8FD3444379CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10938016-DEE2-4A25-9A5A-8FD3444379CA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E1AD4ACB-ACCA-40ED-AF9B-4443BF8D623C} + EndGlobalSection +EndGlobal diff --git a/KeePassHIBPExt.cs b/KeePassHIBPExt.cs new file mode 100644 index 0000000..0539488 --- /dev/null +++ b/KeePassHIBPExt.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Security.Cryptography; +using System.Threading; +using System.Windows.Forms; +using KeePass.Forms; +using KeePass.Plugins; +using KeePass.UI; +using KeePassLib.Serialization; +using KeePassLib.Utility; + +namespace KeePassHIBP +{ + public class KeePassHIBPExt : Plugin + { + public override Image SmallIcon + { + get { return Properties.Resources.B16x16_Icon; } + } + + public override string UpdateUrl + { + get { return "https://github.com/JanisEst/KeePassHIBP/raw/master/keepass.version"; } + } + + public override bool Initialize(IPluginHost host) + { + //Debugger.Launch(); + + // Workaround to support Tsl1.2 on .NET 4.0 + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol |= (SecurityProtocolType)768 | (SecurityProtocolType)3072; + + GlobalWindowManager.WindowAdded += WindowAddedHandler; + + return true; + } + + public override void Terminate() + { + GlobalWindowManager.WindowAdded -= WindowAddedHandler; + } + + /// + /// Used to modify other form when they load. + /// + /// + /// + private void WindowAddedHandler(object sender, GwmWindowEventArgs e) + { + if (e.Form is PwEntryForm || e.Form is KeyCreationForm) + { + e.Form.Shown += delegate + { + var fieldInfo = e.Form.GetType().GetField("m_icgPassword", BindingFlags.Instance | BindingFlags.NonPublic); + if (fieldInfo != null) + { + var icg = fieldInfo.GetValue(e.Form) as PwInputControlGroup; + if (icg != null) + { + var m_tbPassword = e.Form.Controls.Find("m_tbPassword", true).FirstOrDefault() as TextBox; + if (m_tbPassword != null) + { + m_tbPassword.TextChanged += new DelayedEventHandler(TimeSpan.FromMilliseconds(500), delegate + { + var pwBytes = icg.GetPasswordUtf8(); + var hash = CreateSha1Hash(pwBytes); + MemUtil.ZeroByteArray(pwBytes); + + ThreadPool.QueueUserWorkItem(delegate(object oHash) + { + var strHash = (string)oHash; + try + { + var knownHashes = RequestPwnedHashes(strHash); + + if (knownHashes.Contains(hash)) + { + m_tbPassword.Invoke((MethodInvoker)delegate + { + var toolTip = new ToolTip(); + var pt = new Point(0, 0); + pt.Offset(0, m_tbPassword.Height + 1); + toolTip.Show("Warning: This password has previously appeared in a data breach.", m_tbPassword, pt, 2500); + }); + } + } + catch + { + // Service may not be available. + } + }, hash); + + MemUtil.ZeroByteArray(pwBytes); + }).OnDelay; + } + } + } + }; + } + } + + private static List RequestPwnedHashes(string hash) + { + const string ApiUrl = "https://api.pwnedpasswords.com/range/"; + + var first5Chars = hash.Substring(0, 5); + + var result = DownloadString(ApiUrl + first5Chars); + + result = StrUtil.NormalizeNewLines(result, false); + + const int Sha1SuffixLength = 35; + + return result + .Split('\n') + .Where(l => l.Length >= Sha1SuffixLength) + .Select(l => first5Chars + l.Substring(0, Sha1SuffixLength)) + .ToList(); + } + + private static string DownloadString(string url) + { + var ioc = IOConnectionInfo.FromPath(url); + + using (var s = IOConnection.OpenRead(ioc)) + { + if (s == null) + { + throw new InvalidOperationException(); + } + + using (var ms = new MemoryStream()) + { + MemUtil.CopyStream(s, ms); + + return StrUtil.Utf8.GetString(ms.ToArray()); + } + } + } + + private static string CreateSha1Hash(byte[] data) + { + using (var sha1 = new SHA1Managed()) + { + var hash = sha1.ComputeHash(data); + + return MemUtil.ByteArrayToHexString(hash); + } + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..79ef110 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("KeePassHIBP")] +[assembly: AssemblyDescription("KeePass 2.x plugin which checks passwords on https://haveibeenpwned.com/")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Janis Estelmann")] +[assembly: AssemblyProduct("KeePass Plugin")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("6a249fa1-3f87-4c81-8d31-6bee62308f39")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..3ef2168 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace KeePassHIBP.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("KeePassHIBP.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap B16x16_Icon { + get { + object obj = ResourceManager.GetObject("B16x16_Icon", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..8cbc664 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\B16x16_Icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5835c56 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +KeePassHIBP +================================= + +OVERVIEW +----- +KeePassHIBP (Have I Been Pwned) is a plug-in for KeePass 2.x which tests your passwords against the [Have I Been Pwned](https://haveibeenpwned.com/) database. + +The plugin hooks into two windows in KeePass (the 'Create Composite Master Key' form and the 'Edit Entry' form). When you type in the password field your input gets checked if it has previously appeared in a data breach. You can get [here](https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/) more informations about how the API of HIBP works. + +INSTALLATION +----- +- Download from https://github.com/JanisEst/KeePassHIBP/releases +- Copy the plug-in (KeePassHIBP.plgx) into the KeePass plugin directory +- Start KeePass + +HOW TO USE +----- +Type into the password field in one of the mentioned forms. If the password is weak you will see a little tooltip: + +![alt tag](https://abload.de/img/hibpksq5z.jpg) diff --git a/Resources/B16x16_Icon.png b/Resources/B16x16_Icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c24c057381c90ffa3bf4dc2150f0e3d17197a82d GIT binary patch literal 590 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJOS+@4BLl<6e(pbstU$g(vPY0F z14ES>14Ba#1H&(%P{RubhEf9thF1v;3|2E37{m+a>6aD}H zf8JHm9-tFVN`m}?8O-%G_S&vq#`d#{snVphiIsWoS`Hx*aYG(OQ={nPM~xd!9N-ia z<+BfGnRSF~Pi^ovYlBxov;G71GbVYvyO^xp`0_81!(QU)>&pI!NnAicu4nH8U7%2o zr;B5V#O36K0}MSrD{9ij!a^9$%J@PU{q)$_^72#|<>J`#?CKarT$`K@DXqBWa#Z3- zWu>ah(j}Ft2}zrZKIw3Ed3`!%z$jW6YRXuu!1ydPBWvNTg=-gg9}2&I**!ENVMUi# zLduy2b_RyM%xo!Lx0ND*_Ntb+MwFx^mZVxG7o`Fz1|tJQ3ta;vT_fWVLo+KNGB(gP mFt;)=sACjMK+%w!pOTqYiCY7I%(^>34Gf;HelF{r5}E+RHIwxK literal 0 HcmV?d00001 diff --git a/keepass.version b/keepass.version new file mode 100644 index 0000000..543629f --- /dev/null +++ b/keepass.version @@ -0,0 +1,3 @@ +: +KeePassHIBP:1.0.0 +: