Commits

Devin Martin  committed b050ad3

Allow spaces in the base32 form. Add banner.

  • Participants
  • Parent commits 48a6f35

Comments (0)

Files changed (10)

File KeeOtp/KeeOtp.csproj

     <Compile Include="OtpType.cs" />
     <Compile Include="KeeOtpExt.cs" />
     <Compile Include="OtpAuthData.cs" />
+    <Compile Include="Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTime>True</DesignTime>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
     <Compile Include="ShowOneTimePasswords.cs">
       <SubType>Form</SubType>
     </Compile>
     <EmbeddedResource Include="OtpInformation.resx">
       <DependentUpon>OtpInformation.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+    </EmbeddedResource>
     <EmbeddedResource Include="ShowOneTimePasswords.resx">
       <DependentUpon>ShowOneTimePasswords.cs</DependentUpon>
     </EmbeddedResource>
       <Name>OtpSharp</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\clock.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Resources\lock-key.png" />
+  </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.

File KeeOtp/OtpInformation.cs

 using System;
 using System.Windows.Forms;
+using KeePass.Plugins;
 using OtpSharp;
 
 namespace KeeOtp
         const string validKeyChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
         public OtpAuthData Data { get; set; }
 
-        public OtpInformation()
+        public OtpInformation(IPluginHost host)
         {
             InitializeComponent();
             this.Shown += (sender, e) => FormWasShown();
+            this.Icon = host.MainWindow.Icon;
         }
 
         private void FormWasShown()
         {
             if (this.Data != null)
             {
-                this.Data.Key.UsePlainKey(key =>this.textBoxKey.Text = Base32.Encode(key));
+                this.Data.Key.UsePlainKey(key => this.textBoxKey.Text = Base32.Encode(key));
                 this.textBoxStep.Text = this.Data.Step.ToString();
 
                 if (this.Data.Size == 8)
 
                 var size = (this.radioButtonEight.Checked) ? 8 : 6;
                 int step;
-                
+
                 if (int.TryParse(this.textBoxStep.Text, out step))
                 {
                     if (step != 30)
                     return;
                 }
 
-                var key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(this.textBoxKey.Text));
+                var key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(this.textBoxKey.Text.Replace(" ", string.Empty)));
                 this.Data = new OtpAuthData()
                 {
                     Key = key,
 
         private void textBoxKey_TextChanged(object sender, EventArgs e)
         {
-            var unpaddedBase32 = this.textBoxKey.Text.ToUpperInvariant().TrimEnd('=');
+            var unpaddedBase32 = this.textBoxKey.Text.Replace(" ", string.Empty).ToUpperInvariant().TrimEnd('=');
 
             bool invalid = false;
             foreach (var c in unpaddedBase32)

File KeeOtp/Resources.Designer.cs

+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.17929
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace KeeOtp {
+    using System;
+    
+    
+    /// <summary>
+    ///   A strongly-typed resource class, for looking up localized strings, etc.
+    /// </summary>
+    // This class was auto-generated by the StronglyTypedResourceBuilder
+    // class via a tool like ResGen or Visual Studio.
+    // To add or remove a member, edit your .ResX file then rerun ResGen
+    // with the /str option, or rebuild your VS project.
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.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() {
+        }
+        
+        /// <summary>
+        ///   Returns the cached ResourceManager instance used by this class.
+        /// </summary>
+        [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("KeeOtp.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+        
+        /// <summary>
+        ///   Overrides the current thread's CurrentUICulture property for all
+        ///   resource lookups using this strongly typed resource class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
+                return resourceCulture;
+            }
+            set {
+                resourceCulture = value;
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap clock {
+            get {
+                object obj = ResourceManager.GetObject("clock", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap lock_key {
+            get {
+                object obj = ResourceManager.GetObject("lock_key", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+    }
+}

File KeeOtp/Resources.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>
+  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="clock" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>Resources\clock.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="lock_key" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>Resources\lock-key.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+</root>

File KeeOtp/Resources/clock.png

Added
New image

File KeeOtp/Resources/lock-key.png

Added
New image

File KeeOtp/ShowOneTimePasswords.Designer.cs

             this.labelOtp = new System.Windows.Forms.Label();
             this.labelRemaining = new System.Windows.Forms.Label();
             this.labelRemainingLabel = new System.Windows.Forms.Label();
-            this.labelInstructions = new System.Windows.Forms.Label();
             this.buttonClose = new System.Windows.Forms.Button();
             this.buttonEdit = new System.Windows.Forms.Button();
             this.buttonIncorrect = new System.Windows.Forms.Button();
+            this.pictureBoxBanner = new System.Windows.Forms.PictureBox();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBanner)).BeginInit();
             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, 36);
+            this.labelOtp.Location = new System.Drawing.Point(24, 73);
             this.labelOtp.Name = "labelOtp";
             this.labelOtp.Size = new System.Drawing.Size(224, 73);
             this.labelOtp.TabIndex = 0;
             // labelRemaining
             // 
             this.labelRemaining.AutoSize = true;
-            this.labelRemaining.Location = new System.Drawing.Point(145, 109);
+            this.labelRemaining.Location = new System.Drawing.Point(145, 146);
             this.labelRemaining.Name = "labelRemaining";
             this.labelRemaining.Size = new System.Drawing.Size(12, 13);
             this.labelRemaining.TabIndex = 1;
             // labelRemainingLabel
             // 
             this.labelRemainingLabel.AutoSize = true;
-            this.labelRemainingLabel.Location = new System.Drawing.Point(53, 109);
+            this.labelRemainingLabel.Location = new System.Drawing.Point(53, 146);
             this.labelRemainingLabel.Name = "labelRemainingLabel";
             this.labelRemainingLabel.Size = new System.Drawing.Size(86, 13);
             this.labelRemainingLabel.TabIndex = 2;
             this.labelRemainingLabel.Text = "Time Remaining:";
             // 
-            // labelInstructions
-            // 
-            this.labelInstructions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-            this.labelInstructions.Location = new System.Drawing.Point(12, 9);
-            this.labelInstructions.Name = "labelInstructions";
-            this.labelInstructions.Size = new System.Drawing.Size(304, 35);
-            this.labelInstructions.TabIndex = 3;
-            this.labelInstructions.Text = "Enter this code in the verification system.";
-            // 
             // buttonClose
             // 
             this.buttonClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonClose.DialogResult = System.Windows.Forms.DialogResult.OK;
-            this.buttonClose.Location = new System.Drawing.Point(241, 160);
+            this.buttonClose.Location = new System.Drawing.Point(241, 181);
             this.buttonClose.Name = "buttonClose";
             this.buttonClose.Size = new System.Drawing.Size(75, 23);
             this.buttonClose.TabIndex = 4;
             // buttonEdit
             // 
             this.buttonEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
-            this.buttonEdit.Location = new System.Drawing.Point(160, 160);
+            this.buttonEdit.Location = new System.Drawing.Point(160, 181);
             this.buttonEdit.Name = "buttonEdit";
             this.buttonEdit.Size = new System.Drawing.Size(75, 23);
             this.buttonEdit.TabIndex = 5;
             // buttonIncorrect
             // 
             this.buttonIncorrect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-            this.buttonIncorrect.Location = new System.Drawing.Point(15, 160);
+            this.buttonIncorrect.Location = new System.Drawing.Point(15, 181);
             this.buttonIncorrect.Name = "buttonIncorrect";
             this.buttonIncorrect.Size = new System.Drawing.Size(124, 23);
             this.buttonIncorrect.TabIndex = 6;
             this.buttonIncorrect.UseVisualStyleBackColor = true;
             this.buttonIncorrect.Click += new System.EventHandler(this.buttonIncorrect_Click);
             // 
+            // pictureBoxBanner
+            // 
+            this.pictureBoxBanner.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.pictureBoxBanner.Location = new System.Drawing.Point(-2, 0);
+            this.pictureBoxBanner.Name = "pictureBoxBanner";
+            this.pictureBoxBanner.Size = new System.Drawing.Size(332, 58);
+            this.pictureBoxBanner.TabIndex = 7;
+            this.pictureBoxBanner.TabStop = false;
+            // 
             // ShowOneTimePasswords
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(328, 198);
+            this.ClientSize = new System.Drawing.Size(328, 219);
+            this.Controls.Add(this.pictureBoxBanner);
             this.Controls.Add(this.buttonIncorrect);
             this.Controls.Add(this.buttonEdit);
             this.Controls.Add(this.buttonClose);
-            this.Controls.Add(this.labelInstructions);
             this.Controls.Add(this.labelRemainingLabel);
             this.Controls.Add(this.labelRemaining);
             this.Controls.Add(this.labelOtp);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
             this.Name = "ShowOneTimePasswords";
             this.Text = "Timed Passwords";
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBanner)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
         private System.Windows.Forms.Label labelOtp;
         private System.Windows.Forms.Label labelRemaining;
         private System.Windows.Forms.Label labelRemainingLabel;
-        private System.Windows.Forms.Label labelInstructions;
         private System.Windows.Forms.Button buttonClose;
         private System.Windows.Forms.Button buttonEdit;
         private System.Windows.Forms.Button buttonIncorrect;
+        private System.Windows.Forms.PictureBox pictureBoxBanner;
     }
 }

File KeeOtp/ShowOneTimePasswords.cs

             InitializeComponent();
             this.Shown += (sender, e) => FormWasShown();
             this.timerUpdateTotp.Tick += (sender, e) => UpdateDisplay();
+
+            pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
+                pictureBoxBanner.Height,
+                KeePass.UI.BannerStyle.Default,
+                Resources.clock.GetThumbnailImage(32, 32, null, IntPtr.Zero),
+                "Timed Passwords",
+                "Enter this code in the verification system.");
+
+            this.Icon = host.MainWindow.Icon;
         }
 
         private void UpdateDisplay()
             this.labelOtp.Text = "xxxxxx";
             this.totp = null;
 
-            var addEditForm = new OtpInformation();
+            var addEditForm = new OtpInformation(this.host);
             addEditForm.Data = this.data;
 
             var result = addEditForm.ShowDialog();
 
         private void buttonIncorrect_Click(object sender, EventArgs e)
         {
-            Troubleshooting troubleshooting = new Troubleshooting();
+            Troubleshooting troubleshooting = new Troubleshooting(this.host);
             troubleshooting.ShowDialog();
         }
     }

File KeeOtp/ShowOneTimePasswords.resx

     <value>2.0</value>
   </resheader>
   <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <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=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+  <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>

File KeeOtp/Troubleshooting.cs

 using System.Diagnostics;
 using System.Threading;
 using System.Windows.Forms;
+using KeePass.Plugins;
 using OtpSharp;
 
 namespace KeeOtp
 {
     public partial class Troubleshooting : Form
     {
-        public Troubleshooting()
+        public Troubleshooting(IPluginHost host)
         {
             InitializeComponent();
+            this.Icon = host.MainWindow.Icon;
         }
 
         private void buttonPingGoogle_Click(object sender, EventArgs e)