Devin Martin avatar Devin Martin committed 14f6000

Initial checkin of limited but functional plugin

Comments (0)

Files changed (11)

+syntax: glob
+bin/*
+obj/*
+*.suo
+*.user
+*.orig
+TestResults
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.50727</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{4C1BB6F8-D2CD-49C2-9053-21705681356C}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>KeeOtp</RootNamespace>
+    <AssemblyName>KeeOtp</AssemblyName>
+    <SignAssembly>true</SignAssembly>
+    <AssemblyOriginatorKeyFile>
+    </AssemblyOriginatorKeyFile>
+    <FileUpgradeFlags>
+    </FileUpgradeFlags>
+    <OldToolsVersion>4.0</OldToolsVersion>
+    <UpgradeBackupLocation>
+    </UpgradeBackupLocation>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <PublishUrl>publish\</PublishUrl>
+    <Install>true</Install>
+    <InstallFrom>Disk</InstallFrom>
+    <UpdateEnabled>false</UpdateEnabled>
+    <UpdateMode>Foreground</UpdateMode>
+    <UpdateInterval>7</UpdateInterval>
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+    <UpdatePeriodically>false</UpdatePeriodically>
+    <UpdateRequired>false</UpdateRequired>
+    <MapFileExtensions>true</MapFileExtensions>
+    <ApplicationRevision>0</ApplicationRevision>
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <UseApplicationTrust>false</UseApplicationTrust>
+    <BootstrapperEnabled>true</BootstrapperEnabled>
+  </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>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </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>
+    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="KeePass">
+      <HintPath>Libraries\KeePass.exe</HintPath>
+    </Reference>
+    <Reference Include="OtpSharp">
+      <HintPath>Libraries\OtpSharp.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="KeeOtpExt.cs" />
+    <Compile Include="ShowOneTimePasswords.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="ShowOneTimePasswords.Designer.cs">
+      <DependentUpon>ShowOneTimePasswords.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
+      <Install>true</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+      <Visible>False</Visible>
+      <ProductName>Windows Installer 3.1</ProductName>
+      <Install>true</Install>
+    </BootstrapperPackage>
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="ShowOneTimePasswords.resx">
+      <DependentUpon>ShowOneTimePasswords.cs</DependentUpon>
+    </EmbeddedResource>
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeeOtp", "KeeOtp.csproj", "{4C1BB6F8-D2CD-49C2-9053-21705681356C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{4C1BB6F8-D2CD-49C2-9053-21705681356C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4C1BB6F8-D2CD-49C2-9053-21705681356C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4C1BB6F8-D2CD-49C2-9053-21705681356C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4C1BB6F8-D2CD-49C2-9053-21705681356C}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal
+using System;
+using System.Diagnostics;
+using System.Windows.Forms;
+using KeePass.Plugins;
+
+namespace KeeOtp
+{
+    public sealed class KeeOtpExt : Plugin
+    {
+        private IPluginHost host = null;
+        private ToolStripItem otpDialogToolStripItem;
+
+        /// <summary>
+        /// The <c>Initialize</c> function is called by KeePass when
+        /// you should initialize your plugin (create menu items, etc.).
+        /// </summary>
+        /// <param name="host">Plugin host interface. By using this
+        /// interface, you can access the KeePass main window and the
+        /// currently opened database.</param>
+        /// <returns>You must return <c>true</c> in order to signal
+        /// successful initialization. If you return <c>false</c>,
+        /// KeePass unloads your plugin (without calling the
+        /// <c>Terminate</c> function of your plugin).</returns>
+        public override bool Initialize(IPluginHost host)
+        {
+            Debug.Assert(host != null);
+            if (host == null) return false;
+            this.host = host;
+            this.otpDialogToolStripItem = host.MainWindow.EntryContextMenu.Items.Add("One Time Passwords");
+            this.otpDialogToolStripItem.Click += new EventHandler(otpDialogToolStripItem_Click);
+            return true; // Initialization successful
+        }
+
+        /// <summary>
+        /// The <c>Terminate</c> function is called by KeePass when
+        /// you should free all resources, close open files/streams,
+        /// etc. It is also recommended that you remove all your
+        /// plugin menu items from the KeePass menu.
+        /// </summary>
+        public override void Terminate()
+        {
+            // Remove all of our menu items
+            ToolStripItemCollection tsMenu = host.MainWindow.EntryContextMenu.Items;
+            tsMenu.Remove(otpDialogToolStripItem);
+        }
+
+        void otpDialogToolStripItem_Click(object sender, EventArgs e)
+        {
+            var entries = this.host.MainWindow.GetSelectedEntries();
+            if (entries.Length > 1)
+                MessageBox.Show("Please select only one entry");
+            else if (entries.Length == 0)
+                MessageBox.Show("Please select an entry");
+
+            // grab the entry that we care about
+            var entry = entries[0];
+
+            ShowOneTimePasswords form = new ShowOneTimePasswords(entry);
+            form.Show();
+        }
+    }
+}
Add a comment to this file

KeePass.XmlSerializers.dll

Binary file added.

Binary file added.

Binary file added.

Properties/AssemblyInfo.cs

+/*
+  KeePass Password Safe - The Open-Source Password Manager
+  Copyright (C) 2003-2009 Dominik Reichl <dominik.reichl@t-online.de>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General assembly properties
+[assembly: AssemblyTitle("Sample Plugin for Developers")]
+[assembly: AssemblyDescription("A sample plugin for developers that demonstrates how to add menu items, password groups and entries.")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Dominik Reichl")]
+[assembly: AssemblyProduct("KeePass Plugin")]
+[assembly: AssemblyCopyright("Copyright © 2006-2009 Dominik Reichl")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// COM settings
+[assembly: ComVisible(false)]
+
+// Assembly GUID
+[assembly: Guid("1cb02044-8fc3-40f7-9b0f-29cce26d8840")]
+
+// Assembly version information
+[assembly: AssemblyVersion("2.0.9.*")]
+[assembly: AssemblyFileVersion("2.0.9.0")]

ShowOneTimePasswords.Designer.cs

+namespace KeeOtp
+{
+    partial class ShowOneTimePasswords
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.timerUpdateTotp = new System.Windows.Forms.Timer(this.components);
+            this.labelOtp = new System.Windows.Forms.Label();
+            this.labelRemaining = new System.Windows.Forms.Label();
+            this.labelRemainingLabel = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // labelOtp
+            // 
+            this.labelOtp.AutoSize = true;
+            this.labelOtp.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.labelOtp.Location = new System.Drawing.Point(24, 51);
+            this.labelOtp.Name = "labelOtp";
+            this.labelOtp.Size = new System.Drawing.Size(248, 73);
+            this.labelOtp.TabIndex = 0;
+            this.labelOtp.Text = "012345";
+            // 
+            // labelRemaining
+            // 
+            this.labelRemaining.AutoSize = true;
+            this.labelRemaining.Location = new System.Drawing.Point(145, 124);
+            this.labelRemaining.Name = "labelRemaining";
+            this.labelRemaining.Size = new System.Drawing.Size(35, 13);
+            this.labelRemaining.TabIndex = 1;
+            this.labelRemaining.Text = "label2";
+            // 
+            // labelRemainingLabel
+            // 
+            this.labelRemainingLabel.AutoSize = true;
+            this.labelRemainingLabel.Location = new System.Drawing.Point(53, 124);
+            this.labelRemainingLabel.Name = "labelRemainingLabel";
+            this.labelRemainingLabel.Size = new System.Drawing.Size(86, 13);
+            this.labelRemainingLabel.TabIndex = 2;
+            this.labelRemainingLabel.Text = "Time Remaining:";
+            // 
+            // ShowOneTimePasswords
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(284, 262);
+            this.Controls.Add(this.labelRemainingLabel);
+            this.Controls.Add(this.labelRemaining);
+            this.Controls.Add(this.labelOtp);
+            this.Name = "ShowOneTimePasswords";
+            this.Text = "Timed Passwords";
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Timer timerUpdateTotp;
+        private System.Windows.Forms.Label labelOtp;
+        private System.Windows.Forms.Label labelRemaining;
+        private System.Windows.Forms.Label labelRemainingLabel;
+    }
+}

ShowOneTimePasswords.cs

+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows.Forms;
+using KeePassLib.Security;
+using OtpSharp;
+
+namespace KeeOtp
+{
+    public partial class ShowOneTimePasswords : Form
+    {
+        private KeePassLib.PwEntry entry;
+        private Totp totp;
+        private int lastCode;
+        private int lastRemainingTime;
+
+        public ShowOneTimePasswords(KeePassLib.PwEntry entry)
+        {
+            this.entry = entry;
+            InitializeComponent();
+            this.Shown += (sender, e) => FormWasShown();
+            this.timerUpdateTotp.Tick += (sender, e) => UpdateDisplay();
+        }
+
+        private void UpdateDisplay()
+        {
+            var totp = this.totp;
+            if (totp != null)
+            {
+                var code = totp.ComputeTotp();
+                var remaining = totp.RemainingSeconds();
+
+                if (code != lastCode)
+                {
+                    lastCode = code;
+                    this.labelOtp.Text = code.ToString().PadLeft(6, '0');
+                }
+                if (remaining != lastRemainingTime)
+                {
+                    lastRemainingTime = remaining;
+                    this.labelRemaining.Text = remaining.ToString();
+                }
+            }
+            else
+            {
+                MessageBox.Show("Please add a one time password field");
+                this.Close();
+            }
+        }
+
+        private void FormWasShown()
+        {
+            if (!entry.Strings.Exists("OTP"))
+            {
+                MessageBox.Show("Please add a one time password field");
+                this.Close();
+            }
+            else
+            {
+                try
+                {
+                    var otpEncodedKey = entry.Strings.Get("OTP");
+                    var key = Base32.Decode(otpEncodedKey.ReadString());
+                    this.totp = new Totp(key);
+                    this.timerUpdateTotp.Enabled = true;
+                }
+                catch (Exception e)
+                {
+                    MessageBox.Show(e.Message);
+                }
+            }
+
+            //entry.Strings.Set("TOTP", new ProtectedString(true, "test"));
+
+            //host.MainWindow.UpdateUI(false, null, true, host.Database.RootGroup,
+            //true, null, true);
+        }
+    }
+}

ShowOneTimePasswords.resx

+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="timerUpdateTotp.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+</root>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.