+ binary JavaFileStorage

This commit is contained in:
Philipp Crocoll
2014-07-30 06:25:37 +02:00
parent 7fa3dd191f
commit 97bcf753a4
16 changed files with 214 additions and 79 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security.Cryptography;
using Android.App;
using Android.Content;
using Android.Content.PM;
@@ -7,22 +9,27 @@ using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using KeeChallenge;
using KeePassLib.Serialization;
using keepass2android;
using keepass2android.Io;
//using KeePassLib.Serialization;
using MasterPassword;
//using keepass2android;
//using keepass2android.Io;
namespace ArtTestApp
{
[Activity(Label = "ArtTestApp", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
private ChallengeInfo _chalInfo;
private byte[] _challengeSecret;
private IOConnectionInfo _ioConnectionInfo;
private IOConnectionInfo _ioConnectionInfoOut;
//private IOConnectionInfo _ioConnectionInfo;
//private IOConnectionInfo _ioConnectionInfoOut;
private const int RequestCodeChallengeYubikey = 98;
private static byte[] HashHMAC(byte[] key, byte[] message)
{
var hash = new HMACSHA256(key);
return hash.ComputeHash(message);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
@@ -30,20 +37,31 @@ namespace ArtTestApp
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
_ioConnectionInfo = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallenge.xml" };
/*_ioConnectionInfo = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallenge.xml" };
_ioConnectionInfoOut = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallengeOut.xml" };
*/
FindViewById<Button>(Resource.Id.MyButton1).Text = "";
Stopwatch sw = new Stopwatch();
sw.Start();
var key = new MpAlgorithm().GetKeyForPassword("u", "test");
sw.Stop();
string password = MpAlgorithm.GenerateContent("Long Password", "strn", key, 1, HashHMAC);
FindViewById<Button>(Resource.Id.MyButton1).Text = password;
FindViewById<Button>(Resource.Id.MyButton2).Text = sw.ElapsedMilliseconds.ToString();
// Get our button from the layout resource,
// and attach an event to it
FindViewById<Button>(Resource.Id.MyButton1).Click += (sender, args) =>
{
Decrypt(_ioConnectionInfo);
// Decrypt(_ioConnectionInfo);
};
FindViewById<Button>(Resource.Id.MyButton2).Click += (sender, args) =>
{
Decrypt(_ioConnectionInfoOut);
//Decrypt(_ioConnectionInfoOut);
};
@@ -51,7 +69,7 @@ namespace ArtTestApp
}
private void Decrypt(IOConnectionInfo ioConnectionInfo)
/*private void Decrypt(IOConnectionInfo ioConnectionInfo)
{
try
{
@@ -73,44 +91,8 @@ namespace ArtTestApp
{
Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
}
}
}*/
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == RequestCodeChallengeYubikey && resultCode == Result.Ok)
{
try
{
byte[] challengeResponse = data.GetByteArrayExtra("response");
_challengeSecret = KeeChallengeProv.GetSecret(_chalInfo, challengeResponse);
Array.Clear(challengeResponse, 0, challengeResponse.Length);
}
catch (Exception e)
{
Kp2aLog.Log(e.ToString());
Toast.MakeText(this, "Error: " + e.Message, ToastLength.Long).Show();
return;
}
if (_challengeSecret != null)
{
Toast.MakeText(this, "OK!", ToastLength.Long).Show();
ChallengeInfo temp = KeeChallengeProv.Encrypt(_challengeSecret, _chalInfo.IV);
if (!temp.Save(_ioConnectionInfoOut))
{
Toast.MakeText(this, "error writing file", ToastLength.Long).Show();
return;
}
}
else
{
Toast.MakeText(this, "Not good :-(", ToastLength.Long).Show();
return;
}
}
}
}
}

View File

@@ -50,9 +50,6 @@
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="Activity2.cs" />
<Compile Include="App.cs" />
<Compile Include="ChallengeInfo.cs" />
<Compile Include="KeeChallenge.cs" />
<Compile Include="PrefActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -76,16 +73,6 @@
<ItemGroup>
<AndroidResource Include="Resources\Xml\pref.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KeePassLib2Android\KeePassLib2Android.csproj">
<Project>{545b4a6b-8bba-4fbe-92fc-4ac060122a54}</Project>
<Name>KeePassLib2Android</Name>
</ProjectReference>
<ProjectReference Include="..\Kp2aBusinessLogic\Kp2aBusinessLogic.csproj">
<Project>{53a9cb7f-6553-4bc0-b56b-9410bb2e59aa}</Project>
<Name>Kp2aBusinessLogic</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.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.