Reorg, renaming.

This commit is contained in:
Brian Pellin
2010-04-24 17:42:34 -05:00
parent 66bb24d96f
commit b815a4de07
8 changed files with 76 additions and 32 deletions

View File

@@ -23,6 +23,4 @@ public abstract class PwDbHeader {
public static final int PWM_DBSIG_1 = 0x9AA2D903;
public abstract boolean matchesHeader(int sig1, int sig2);
}

View File

@@ -29,14 +29,14 @@ import com.keepassdroid.utils.Types;
public class PwDbHeaderV3 extends PwDbHeader {
// DB sig from KeePass 1.03
public static final int PWM_DBSIG_2 = 0xB54BFB65;
public static final int DBSIG_2 = 0xB54BFB65;
// DB sig from KeePass 1.03
public static final int PWM_DBVER_DW = 0x00030002;
public static final int DBVER_DW = 0x00030002;
public static final int PWM_FLAG_SHA2 = 1;
public static final int PWM_FLAG_RIJNDAEL = 2;
public static final int PWM_FLAG_ARCFOUR = 4;
public static final int PWM_FLAG_TWOFISH = 8;
public static final int FLAG_SHA2 = 1;
public static final int FLAG_RIJNDAEL = 2;
public static final int FLAG_ARCFOUR = 4;
public static final int FLAG_TWOFISH = 8;
public static final int ALGO_AES = 0;
public static final int ALGO_TWOFISH = 1;
@@ -47,7 +47,7 @@ public class PwDbHeaderV3 extends PwDbHeader {
public int signature1; // = PWM_DBSIG_1
public int signature2; // = PWM_DBSIG_2
public int signature2; // = DBSIG_2
public int flags;
public int version;
@@ -94,8 +94,8 @@ public class PwDbHeaderV3 extends PwDbHeader {
}
public boolean matchesHeader(int sig1, int sig2) {
return (sig1 == PWM_DBSIG_1) && (sig2 == PWM_DBSIG_2);
public static boolean matchesHeader(int sig1, int sig2) {
return (sig1 == PWM_DBSIG_1) && (sig2 == DBSIG_2);
}

View File

@@ -19,13 +19,21 @@
*/
package com.keepassdroid.database;
public class PwDbHeaderV4 extends PwDbHeader {
public static final int PWM_DBSIG_PRE2 = 0xB54BFB66;
public static final int PWM_DBSIG_2 = 0xB54BFB67;
import java.io.InputStream;
@Override
public boolean matchesHeader(int sig1, int sig2) {
return (sig1 == PWM_DBSIG_1) && ( (sig2 == PWM_DBSIG_2) || (sig2 == PWM_DBSIG_2) );
public class PwDbHeaderV4 extends PwDbHeader {
public static final int DBSIG_PRE2 = 0xB54BFB66;
public static final int DBSIG_2 = 0xB54BFB67;
/** Assumes the input stream is at the beginning of the .kdbx file
* @param is
*/
public PwDbHeaderV4(InputStream is) {
}
public static boolean matchesHeader(int sig1, int sig2) {
return (sig1 == PWM_DBSIG_1) && ( (sig2 == DBSIG_2) || (sig2 == DBSIG_2) );
}
}

View File

@@ -19,7 +19,16 @@
*/
package com.keepassdroid.database.load;
public class Importer {
import java.io.IOException;
import java.io.InputStream;
import com.keepassdroid.UpdateStatus;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.exception.InvalidDBSignatureException;
import com.keepassdroid.database.exception.InvalidKeyFileException;
import com.keepassdroid.database.exception.InvalidPasswordException;
public abstract class Importer {
public static final boolean DEBUG = true;
protected final boolean mDebug;
@@ -32,6 +41,11 @@ public class Importer {
mDebug = debug;
}
public abstract PwDatabase openDatabase( InputStream inStream, String password, String keyfile )
throws IOException, InvalidKeyFileException, InvalidPasswordException, InvalidDBSignatureException;
public abstract PwDatabase openDatabase( InputStream inStream, String password, String keyfile, UpdateStatus status )
throws IOException, InvalidKeyFileException, InvalidPasswordException, InvalidDBSignatureException;
}

View File

@@ -39,12 +39,9 @@ public class ImporterFactory {
int sig1 = Types.readInt(is);
int sig2 = Types.readInt(is);
PwDbHeaderV3 h3 = new PwDbHeaderV3();
PwDbHeaderV4 h4 = new PwDbHeaderV4();
if ( h3.matchesHeader(sig1, sig2) ) {
if ( PwDbHeaderV3.matchesHeader(sig1, sig2) ) {
return new ImporterV3(debug);
} else if ( h4.matchesHeader(sig1, sig2) ) {
} else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) {
throw new Kdb4Exception();
//return new ImporterV4();
}

View File

@@ -121,11 +121,11 @@ public class ImporterV3 extends Importer {
throw new IOException( "File too short for header" );
PwDbHeaderV3 hdr = new PwDbHeaderV3( filebuf, 0 );
if( (hdr.signature1 != PwDbHeaderV3.PWM_DBSIG_1) || (hdr.signature2 != PwDbHeaderV3.PWM_DBSIG_2) ) {
if( (hdr.signature1 != PwDbHeaderV3.PWM_DBSIG_1) || (hdr.signature2 != PwDbHeaderV3.DBSIG_2) ) {
throw new InvalidDBSignatureException();
}
if( hdr.version != PwDbHeaderV3.PWM_DBVER_DW ) {
if( hdr.version != PwDbHeaderV3.DBVER_DW ) {
//throw new IOException( "Bad database file version" );
}
@@ -134,9 +134,9 @@ public class ImporterV3 extends Importer {
newManager.setMasterKey( password, keyfile );
// Select algorithm
if( (hdr.flags & PwDbHeaderV3.PWM_FLAG_RIJNDAEL) != 0 ) {
if( (hdr.flags & PwDbHeaderV3.FLAG_RIJNDAEL) != 0 ) {
newManager.algorithm = PwDbHeaderV3.ALGO_AES;
} else if( (hdr.flags & PwDbHeaderV3.PWM_FLAG_TWOFISH) != 0 ) {
} else if( (hdr.flags & PwDbHeaderV3.FLAG_TWOFISH) != 0 ) {
newManager.algorithm = PwDbHeaderV3.ALGO_TWOFISH;
} else {
throw new IOException( "Unknown algorithm." );

View File

@@ -19,6 +19,33 @@
*/
package com.keepassdroid.database.load;
import java.io.IOException;
import java.io.InputStream;
import com.keepassdroid.UpdateStatus;
import com.keepassdroid.database.PwDatabaseV4;
import com.keepassdroid.database.exception.InvalidDBSignatureException;
import com.keepassdroid.database.exception.InvalidKeyFileException;
import com.keepassdroid.database.exception.InvalidPasswordException;
public class ImporterV4 extends Importer {
@Override
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
String keyfile) throws IOException, InvalidKeyFileException,
InvalidPasswordException, InvalidDBSignatureException {
return openDatabase(inStream, password, keyfile, new UpdateStatus());
}
@Override
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
String keyfile, UpdateStatus status) throws IOException,
InvalidKeyFileException, InvalidPasswordException,
InvalidDBSignatureException {
return null;
}
}

View File

@@ -115,19 +115,19 @@ public class PwDbV3Output {
// Build header
PwDbHeaderV3 header = new PwDbHeaderV3();
header.signature1 = PwDbHeaderV3.PWM_DBSIG_1;
header.signature2 = PwDbHeaderV3.PWM_DBSIG_2;
header.flags = PwDbHeaderV3.PWM_FLAG_SHA2;
header.signature2 = PwDbHeaderV3.DBSIG_2;
header.flags = PwDbHeaderV3.FLAG_SHA2;
if ( mPM.getAlgorithm() == PwDbHeaderV3.ALGO_AES ) {
header.flags |= PwDbHeaderV3.PWM_FLAG_RIJNDAEL;
header.flags |= PwDbHeaderV3.FLAG_RIJNDAEL;
} else if ( mPM.getAlgorithm() == PwDbHeaderV3.ALGO_TWOFISH ) {
header.flags |= PwDbHeaderV3.PWM_FLAG_TWOFISH;
header.flags |= PwDbHeaderV3.FLAG_TWOFISH;
throw new PwDbOutputException("Unsupported algorithm.");
} else {
throw new PwDbOutputException("Unsupported algorithm.");
}
header.version = PwDbHeaderV3.PWM_DBVER_DW;
header.version = PwDbHeaderV3.DBVER_DW;
header.numGroups = mPM.groups.size();
header.numEntries = mPM.entries.size();
header.numKeyEncRounds = mPM.getNumKeyEncRecords();