From 5f4d467da49f6e2d2a8a8a8beb602d40541d1b7a Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Sat, 6 Jul 2013 16:10:33 +0200 Subject: [PATCH] Added custom logger for better tracability of problems --- .../KeePassLib2Android.csproj | 3 +- src/KeePassLib2Android/Keys/CompositeKey.cs | 5 +- src/KeePassLib2Android/Kp2aLog.cs | 58 +++++++++++++++++++ src/KeePassLib2Android/Native/NativeLib.cs | 2 +- .../Serialization/IOConnection.cs | 5 +- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/KeePassLib2Android/Kp2aLog.cs diff --git a/src/KeePassLib2Android/KeePassLib2Android.csproj b/src/KeePassLib2Android/KeePassLib2Android.csproj index b01ed8b8..05457bb1 100644 --- a/src/KeePassLib2Android/KeePassLib2Android.csproj +++ b/src/KeePassLib2Android/KeePassLib2Android.csproj @@ -1,4 +1,4 @@ - + Debug @@ -55,6 +55,7 @@ + diff --git a/src/KeePassLib2Android/Keys/CompositeKey.cs b/src/KeePassLib2Android/Keys/CompositeKey.cs index c942550e..9a0e6b13 100644 --- a/src/KeePassLib2Android/Keys/CompositeKey.cs +++ b/src/KeePassLib2Android/Keys/CompositeKey.cs @@ -28,6 +28,7 @@ using KeePassLib.Native; using KeePassLib.Resources; using KeePassLib.Security; using KeePassLib.Utility; +using keepass2android; namespace KeePassLib.Keys { @@ -266,7 +267,7 @@ namespace KeePassLib.Keys if (NativeLib.TransformKey256(pbNewKey, pbKeySeed32, uNumRounds)) { sw.Stop(); - Android.Util.Log.Debug("DEBUG", "Native transform:" +sw.ElapsedMilliseconds+"ms"); + Kp2aLog.Log("Native transform:" +sw.ElapsedMilliseconds+"ms"); return pbNewKey; } @@ -274,7 +275,7 @@ namespace KeePassLib.Keys if(TransformKeyManaged(pbNewKey, pbKeySeed32, uNumRounds) == false) return null; sw.Stop(); - Android.Util.Log.Debug("DEBUG", "Managed transform:" +sw.ElapsedMilliseconds+"ms"); + Kp2aLog.Log("Managed transform:" +sw.ElapsedMilliseconds+"ms"); SHA256Managed sha256 = new SHA256Managed(); return sha256.ComputeHash(pbNewKey); diff --git a/src/KeePassLib2Android/Kp2aLog.cs b/src/KeePassLib2Android/Kp2aLog.cs new file mode 100644 index 00000000..9a0eb96f --- /dev/null +++ b/src/KeePassLib2Android/Kp2aLog.cs @@ -0,0 +1,58 @@ +/* +This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. + + Keepass2Android 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. + + Keepass2Android 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 Keepass2Android. If not, see . + */ + +using System; +using System.IO; +using Android.Preferences; +using KeePassLib.Serialization; + +namespace keepass2android +{ + public static class Kp2aLog + { + private static bool? _logToFile; + + public static void Log(string message) + { + Android.Util.Log.Debug("KP2A", message); + if (LogToFile) + { + using (var streamWriter = File.AppendText(LogFilename)) + { + string stringToLog = DateTime.Now+":"+DateTime.Now.Millisecond+ " -- " + message; + streamWriter.WriteLine(stringToLog); + } + } + + } + + private static string LogFilename + { + get { return "/mnt/sdcard/keepass2android.log"; } + } + + private static bool LogToFile + { + get + { + if (_logToFile == null) + _logToFile = File.Exists(LogFilename); + return (bool) _logToFile; + } + } + } +} \ No newline at end of file diff --git a/src/KeePassLib2Android/Native/NativeLib.cs b/src/KeePassLib2Android/Native/NativeLib.cs index 030b2f08..8cda400c 100644 --- a/src/KeePassLib2Android/Native/NativeLib.cs +++ b/src/KeePassLib2Android/Native/NativeLib.cs @@ -164,7 +164,7 @@ namespace KeePassLib.Native try { - //Android.Util.Log.Debug("DEBUG", "4+1"+new Kp2atest.TestClass().Add1(4)); + //Kp2aLog.Log("4+1"+new Kp2atest.TestClass().Add1(4)); Com.Keepassdroid.Crypto.Finalkey.NativeFinalKey key = new Com.Keepassdroid.Crypto.Finalkey.NativeFinalKey(); byte[] newKey = key.TransformMasterKey(pKey256, pBuf256, (int)uRounds); diff --git a/src/KeePassLib2Android/Serialization/IOConnection.cs b/src/KeePassLib2Android/Serialization/IOConnection.cs index 2b45cd6d..0466ec77 100644 --- a/src/KeePassLib2Android/Serialization/IOConnection.cs +++ b/src/KeePassLib2Android/Serialization/IOConnection.cs @@ -34,6 +34,7 @@ using System.Net.Security; using KeePassLib.Native; using KeePassLib.Utility; +using keepass2android; namespace KeePassLib.Serialization { @@ -211,10 +212,10 @@ namespace KeePassLib.Serialization wc.Credentials = credentialCache; } catch (NotImplementedException e) { - Android.Util.Log.Debug("DEBUG", e.ToString()); + Kp2aLog.Log(e.ToString()); } catch (Exception e) { - Android.Util.Log.Debug("DEBUG", e.ToString()); + Kp2aLog.Log(e.ToString()); Debug.Assert(false); } }