minor changes

This commit is contained in:
Philipp Crocoll 2014-06-19 16:13:16 +02:00
parent 9f8f00bb26
commit c882981a29
3 changed files with 95 additions and 13 deletions

2
.gitignore vendored
View File

@ -258,3 +258,5 @@ Thumbs.db
/src/java/PluginInputStick/bin
/src/java/PluginInputStick/icons
/src/PluginSdkBinding/bin/Release

View File

@ -1,17 +1,27 @@
using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using KeeChallenge;
using KeePassLib.Serialization;
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 const int RequestCodeChallengeYubikey = 98;
protected override void OnCreate(Bundle bundle)
{
@ -20,30 +30,87 @@ namespace ArtTestApp
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
_ioConnectionInfo = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallenge.xml" };
_ioConnectionInfoOut = new IOConnectionInfo() { Path = "/mnt/sdcard/keepass/keechallengeOut.xml" };
// Get our button from the layout resource,
// and attach an event to it
FindViewById<Button>(Resource.Id.MyButton1).Click += (sender, args) =>
{
try
{
StartActivity(typeof (Activity2));
}
catch (Exception ex)
{
Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
}
Decrypt(_ioConnectionInfo);
};
FindViewById<Button>(Resource.Id.MyButton2).Click += (sender, args) =>
{
Intent i = new Intent("blabla");
StartActivityForResult(i, 1);
Decrypt(_ioConnectionInfoOut);
};
FindViewById<Button>(Resource.Id.MyButton3).Click += (sender, args) => StartActivityForResult(typeof(PrefActivity), 1);
}
private void Decrypt(IOConnectionInfo ioConnectionInfo)
{
try
{
//StartActivity(typeof (Activity2));
_chalInfo = ChallengeInfo.Load(ioConnectionInfo);
Intent chalIntent = new Intent("com.yubichallenge.NFCActivity.CHALLENGE");
chalIntent.PutExtra("challenge", _chalInfo.Challenge);
chalIntent.PutExtra("slot", 2);
chalIntent.AddFlags(ActivityFlags.SingleTop);
IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
StartActivityForResult(chalIntent, RequestCodeChallengeYubikey);
}
}
catch (Exception ex)
{
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,6 +50,9 @@
<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" />
@ -73,6 +76,16 @@
<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.