diff options
author | Christoph Enzmann <christoph.enzmann@confer.ch> | 2013-12-04 18:45:34 +0100 |
---|---|---|
committer | Christoph Enzmann <christoph.enzmann@confer.ch> | 2013-12-04 18:45:34 +0100 |
commit | 99c53801f3d4269b8058e87fa48b4bc37c7533fd (patch) | |
tree | a5b4317bfdbda4eb6b2df8396d90b9b3a60e54f5 /TwoStepsAuthenticator.UnitTests | |
parent | aefa4764cc1e858da39bc3af4e6a385d924967a2 (diff) | |
download | TwoStepsAuthenticator-99c53801f3d4269b8058e87fa48b4bc37c7533fd.zip TwoStepsAuthenticator-99c53801f3d4269b8058e87fa48b4bc37c7533fd.tar.gz TwoStepsAuthenticator-99c53801f3d4269b8058e87fa48b4bc37c7533fd.tar.bz2 |
Constant time check for codes
Diffstat (limited to 'TwoStepsAuthenticator.UnitTests')
4 files changed, 147 insertions, 0 deletions
diff --git a/TwoStepsAuthenticator.UnitTests/AuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/AuthenticatorTests.cs new file mode 100644 index 0000000..5c250b8 --- /dev/null +++ b/TwoStepsAuthenticator.UnitTests/AuthenticatorTests.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; + +namespace TwoStepsAuthenticator.UnitTests { + + [TestFixture] + public class AuthenticatorTests { + + [Test] + public void CreateKey() { + var authenticator = new Authenticator(); + var secret = authenticator.GenerateKey(); + var code = authenticator.GetCode(secret); + + Assert.IsTrue(authenticator.CheckCode(secret, code), "Generated Code doesn't verify"); + } + + // Test Vectors from http://tools.ietf.org/html/rfc6238#appendix-B have all length 8. We want a length of 6. + // This Test Vectors are from a Ruby implementation. They work with the Google Authentificator app. + [TestCase("DRMK64PPMMC7TDZF", "2013-12-04 18:33:01 +0100", "661188")] + [TestCase("EQOGSM3XZUH6SE2Y", "2013-12-04 18:34:56 +0100", "256804")] + [TestCase("4VU7EQACVDMFJSBG", "2013-12-04 18:36:16 +0100", "800872")] + public void VerifyKeys(string secret, string timeString, string code) { + var date = DateTime.Parse(timeString); + + var authenticator = new Authenticator(() => date); + Assert.IsTrue(authenticator.CheckCode(secret, code)); + + } + } +} diff --git a/TwoStepsAuthenticator.UnitTests/Properties/AssemblyInfo.cs b/TwoStepsAuthenticator.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9654c60 --- /dev/null +++ b/TwoStepsAuthenticator.UnitTests/Properties/AssemblyInfo.cs @@ -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("TwoStepsAuthenticator.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("TwoStepsAuthenticator.UnitTests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] +[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("257d7270-7a19-44d8-afdf-b21267fc0dda")] + +// 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")] diff --git a/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj b/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj new file mode 100644 index 0000000..54dae80 --- /dev/null +++ b/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <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>{E936FFA0-2E6E-4CA7-9841-FB844A817E0C}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>TwoStepsAuthenticator.UnitTests</RootNamespace> + <AssemblyName>TwoStepsAuthenticator.UnitTests</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <TargetFrameworkProfile /> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Prefer32Bit>false</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Prefer32Bit>false</Prefer32Bit> + </PropertyGroup> + <PropertyGroup> + <StartupObject /> + </PropertyGroup> + <ItemGroup> + <Reference Include="nunit.framework"> + <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</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.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="AuthenticatorTests.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\TwoStepsAuthenticator\TwoStepsAuthenticator.csproj"> + <Project>{6c898cd1-0bf3-4711-847e-ad7dac815cd8}</Project> + <Name>TwoStepsAuthenticator</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\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>
\ No newline at end of file diff --git a/TwoStepsAuthenticator.UnitTests/packages.config b/TwoStepsAuthenticator.UnitTests/packages.config new file mode 100644 index 0000000..967502d --- /dev/null +++ b/TwoStepsAuthenticator.UnitTests/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="NUnit" version="2.6.3" targetFramework="net40" /> +</packages>
\ No newline at end of file |