mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-28 20:12:21 -05:00
adaptions to changes in KeePassLib
This commit is contained in:
parent
2e8c76d0c4
commit
6c043e9b79
@ -13,10 +13,10 @@ using Java.Util;
|
|||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Cryptography;
|
using KeePassLib.Cryptography;
|
||||||
using KeePassLib.Cryptography.Cipher;
|
using KeePassLib.Cryptography.Cipher;
|
||||||
|
using KeePassLib.Cryptography.KeyDerivation;
|
||||||
using KeePassLib.Interfaces;
|
using KeePassLib.Interfaces;
|
||||||
using KeePassLib.Keys;
|
using KeePassLib.Keys;
|
||||||
using KeePassLib.Security;
|
using KeePassLib.Security;
|
||||||
using Exception = System.Exception;
|
|
||||||
using PwIcon = KeePassLib.PwIcon;
|
using PwIcon = KeePassLib.PwIcon;
|
||||||
using Random = System.Random;
|
using Random = System.Random;
|
||||||
|
|
||||||
@ -63,7 +63,10 @@ namespace keepass2android
|
|||||||
var dbv3 = importer.OpenDatabase(hashingStream, password, keyfileStream);
|
var dbv3 = importer.OpenDatabase(hashingStream, password, keyfileStream);
|
||||||
|
|
||||||
db.Name = dbv3.Name;
|
db.Name = dbv3.Name;
|
||||||
db.KeyEncryptionRounds = (ulong) dbv3.NumKeyEncRounds;
|
db.KdfParameters = (new AesKdf()).GetDefaultParameters();
|
||||||
|
db.KdfParameters.SetUInt64(AesKdf.ParamRounds, (ulong)dbv3.NumKeyEncRounds);
|
||||||
|
|
||||||
|
|
||||||
db.RootGroup = ConvertGroup(dbv3.RootGroup);
|
db.RootGroup = ConvertGroup(dbv3.RootGroup);
|
||||||
if (dbv3.Algorithm == PwEncryptionAlgorithm.Rjindal)
|
if (dbv3.Algorithm == PwEncryptionAlgorithm.Rjindal)
|
||||||
{
|
{
|
||||||
@ -235,7 +238,20 @@ namespace keepass2android
|
|||||||
keyfileContents = new MemoryStream(keyfile.RawFileData.ReadData());
|
keyfileContents = new MemoryStream(keyfile.RawFileData.ReadData());
|
||||||
}
|
}
|
||||||
db.SetMasterKey(password, keyfileContents);
|
db.SetMasterKey(password, keyfileContents);
|
||||||
db.NumRounds = (long) kpDatabase.KeyEncryptionRounds;
|
|
||||||
|
AesKdf kdf = new AesKdf();
|
||||||
|
if (!kdf.Uuid.Equals(kpDatabase.KdfParameters.KdfUuid))
|
||||||
|
db.NumRounds = (uint)PwDefs.DefaultKeyEncryptionRounds;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ulong uRounds = kpDatabase.KdfParameters.GetUInt64(
|
||||||
|
AesKdf.ParamRounds, PwDefs.DefaultKeyEncryptionRounds);
|
||||||
|
uRounds = Math.Min(uRounds, 0xFFFFFFFEUL);
|
||||||
|
|
||||||
|
db.NumRounds = (uint)uRounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
db.Name = kpDatabase.Name;
|
db.Name = kpDatabase.Name;
|
||||||
if (kpDatabase.DataCipherUuid.Equals(StandardAesEngine.AesUuid))
|
if (kpDatabase.DataCipherUuid.Equals(StandardAesEngine.AesUuid))
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
using KeePassLib.Cryptography.KeyDerivation;
|
||||||
using KeePassLib.Serialization;
|
using KeePassLib.Serialization;
|
||||||
using KeePassLib.Keys;
|
using KeePassLib.Keys;
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
db.KpDatabase.New(_ioc, _key);
|
db.KpDatabase.New(_ioc, _key);
|
||||||
|
|
||||||
db.KpDatabase.KeyEncryptionRounds = DefaultEncryptionRounds;
|
db.KpDatabase.KdfParameters = (new AesKdf()).GetDefaultParameters();
|
||||||
db.KpDatabase.Name = "Keepass2Android Password Database";
|
db.KpDatabase.Name = "Keepass2Android Password Database";
|
||||||
//re-set the name of the root group because the PwDatabase uses UrlUtil which is not appropriate for all file storages:
|
//re-set the name of the root group because the PwDatabase uses UrlUtil which is not appropriate for all file storages:
|
||||||
db.KpDatabase.RootGroup.Name = _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc);
|
db.KpDatabase.RootGroup.Name = _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc);
|
||||||
|
@ -26,6 +26,7 @@ using System.Diagnostics;
|
|||||||
|
|
||||||
using KeePassLib.Cryptography;
|
using KeePassLib.Cryptography;
|
||||||
using KeePassLib.Cryptography.Cipher;
|
using KeePassLib.Cryptography.Cipher;
|
||||||
|
using KeePassLib.Cryptography.KeyDerivation;
|
||||||
using KeePassLib.Keys;
|
using KeePassLib.Keys;
|
||||||
using KeePassLib.Utility;
|
using KeePassLib.Utility;
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ namespace OtpKeyProv
|
|||||||
Array.Copy(pbData, pbEnc, pbData.Length);
|
Array.Copy(pbData, pbEnc, pbData.Length);
|
||||||
|
|
||||||
Salsa20Cipher enc = new Salsa20Cipher(pbKey32, pbIV8);
|
Salsa20Cipher enc = new Salsa20Cipher(pbKey32, pbIV8);
|
||||||
enc.Encrypt(pbEnc, pbEnc.Length, true);
|
enc.Encrypt(pbEnc, 0, pbEnc.Length);
|
||||||
|
|
||||||
return ("s20://" + Convert.ToBase64String(pbEnc,
|
return ("s20://" + Convert.ToBase64String(pbEnc,
|
||||||
Base64FormattingOptions.None));
|
Base64FormattingOptions.None));
|
||||||
@ -90,7 +91,7 @@ namespace OtpKeyProv
|
|||||||
Array.Copy(pbIV16, 0, pbIV8, 0, 8);
|
Array.Copy(pbIV16, 0, pbIV8, 0, 8);
|
||||||
|
|
||||||
Salsa20Cipher dec = new Salsa20Cipher(pbKey32, pbIV8);
|
Salsa20Cipher dec = new Salsa20Cipher(pbKey32, pbIV8);
|
||||||
dec.Encrypt(pb, pb.Length, true);
|
dec.Encrypt(pb, 0, pb.Length);
|
||||||
|
|
||||||
return pb;
|
return pb;
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ namespace OtpKeyProv
|
|||||||
byte[] pbHash = sha256.ComputeHash(pbData);
|
byte[] pbHash = sha256.ComputeHash(pbData);
|
||||||
sha256.Clear();
|
sha256.Clear();
|
||||||
|
|
||||||
if(!CompositeKey.TransformKeyManaged(pbHash, pbTrfKey32, uTrfRounds))
|
if(!AesKdf.TransformKeyManaged(pbHash, pbTrfKey32, uTrfRounds))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
sha256 = new SHA256Managed();
|
sha256 = new SHA256Managed();
|
||||||
|
@ -344,11 +344,11 @@ namespace keepass2android
|
|||||||
Database db = App.Kp2a.GetDb();
|
Database db = App.Kp2a.GetDb();
|
||||||
if (db.Loaded)
|
if (db.Loaded)
|
||||||
{
|
{
|
||||||
Preference rounds = FindPreference(GetString(Resource.String.rounds_key));
|
/*Preference rounds = FindPreference(GetString(Resource.String.rounds_key));
|
||||||
rounds.PreferenceChange += (sender, e) => SetRounds(db, e.Preference);
|
rounds.PreferenceChange += (sender, e) => SetRounds(db, e.Preference);
|
||||||
rounds.Enabled = db.CanWrite;
|
rounds.Enabled = db.CanWrite;
|
||||||
SetRounds(db, rounds);
|
SetRounds(db, rounds);
|
||||||
|
*/
|
||||||
PrepareDefaultUsername(db);
|
PrepareDefaultUsername(db);
|
||||||
PrepareDatabaseName(db);
|
PrepareDatabaseName(db);
|
||||||
PrepareMasterPassword();
|
PrepareMasterPassword();
|
||||||
@ -797,11 +797,11 @@ namespace keepass2android
|
|||||||
return targetIoc;
|
return targetIoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private void SetRounds(Database db, Preference rounds)
|
private void SetRounds(Database db, Preference rounds)
|
||||||
{
|
{
|
||||||
rounds.Summary = db.KpDatabase.KeyEncryptionRounds.ToString(CultureInfo.InvariantCulture);
|
rounds.Summary = db.KpDatabase.KeyEncryptionRounds.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void SetAlgorithm(Database db, Preference algorithm)
|
private void SetAlgorithm(Database db, Preference algorithm)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@ using Android.Widget;
|
|||||||
using Android.Preferences;
|
using Android.Preferences;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using Android.Util;
|
using Android.Util;
|
||||||
|
using KeePassLib.Cryptography.KeyDerivation;
|
||||||
|
|
||||||
namespace keepass2android.settings
|
namespace keepass2android.settings
|
||||||
{
|
{
|
||||||
@ -38,13 +39,32 @@ namespace keepass2android.settings
|
|||||||
|
|
||||||
RoundsView = (TextView) view.FindViewById(Resource.Id.rounds);
|
RoundsView = (TextView) view.FindViewById(Resource.Id.rounds);
|
||||||
|
|
||||||
Database db = App.Kp2a.GetDb();
|
|
||||||
ulong numRounds = db.KpDatabase.KeyEncryptionRounds;
|
ulong numRounds = KeyEncryptionRounds;
|
||||||
RoundsView.Text = numRounds.ToString(CultureInfo.InvariantCulture);
|
RoundsView.Text = numRounds.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ulong KeyEncryptionRounds
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
AesKdf kdf = new AesKdf();
|
||||||
|
if (!kdf.Uuid.Equals(App.Kp2a.GetDb().KpDatabase.KdfParameters.KdfUuid))
|
||||||
|
return (uint) PwDefs.DefaultKeyEncryptionRounds;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ulong uRounds = App.Kp2a.GetDb().KpDatabase.KdfParameters.GetUInt64(
|
||||||
|
AesKdf.ParamRounds, PwDefs.DefaultKeyEncryptionRounds);
|
||||||
|
uRounds = Math.Min(uRounds, 0xFFFFFFFEUL);
|
||||||
|
|
||||||
|
return (uint) uRounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set { App.Kp2a.GetDb().KpDatabase.KdfParameters.SetUInt64(AesKdf.ParamRounds, value); }
|
||||||
|
}
|
||||||
|
|
||||||
public RoundsPreference(Context context, IAttributeSet attrs):base(context, attrs) {
|
public RoundsPreference(Context context, IAttributeSet attrs):base(context, attrs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +90,14 @@ namespace keepass2android.settings
|
|||||||
|
|
||||||
Database db = App.Kp2a.GetDb();
|
Database db = App.Kp2a.GetDb();
|
||||||
|
|
||||||
ulong oldRounds = db.KpDatabase.KeyEncryptionRounds;
|
ulong oldRounds = KeyEncryptionRounds;
|
||||||
|
|
||||||
if (oldRounds == rounds)
|
if (oldRounds == rounds)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
db.KpDatabase.KeyEncryptionRounds = rounds;
|
KeyEncryptionRounds = rounds;
|
||||||
|
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
SaveDb save = new SaveDb(Context, App.Kp2a, new AfterSave(Context, handler, oldRounds, this));
|
SaveDb save = new SaveDb(Context, App.Kp2a, new AfterSave(Context, handler, oldRounds, this));
|
||||||
@ -109,7 +129,7 @@ namespace keepass2android.settings
|
|||||||
} else {
|
} else {
|
||||||
DisplayMessage(_ctx);
|
DisplayMessage(_ctx);
|
||||||
|
|
||||||
App.Kp2a.GetDb().KpDatabase.KeyEncryptionRounds = _oldRounds;
|
App.Kp2a.GetDb().KpDatabase.KdfParameters.SetUInt64(AesKdf.ParamRounds, _oldRounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
base.Run();
|
base.Run();
|
||||||
|
Loading…
Reference in New Issue
Block a user