@Test(expected = UnsupportedOperationException.class) public void whenVersionIsNotSupportedShouldThrowException() throws IOException { KeePassHeader header = new KeePassHeader(new RandomGenerator()); byte[] rawHeader = ByteUtils.hexStringToByteArray("03D9A29A67FB4BB501000500"); header.checkVersionSupport(rawHeader); }
public void checkVersionSupport(byte[] keepassFile) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(keepassFile)); byte[] signature = new byte[VERSION_SIGNATURE_LENGTH]; int readBytes = inputStream.read(signature); if (readBytes == -1) { throw new UnsupportedOperationException("Could not read KeePass header. The provided file seems to be no KeePass database file!"); } ByteBuffer signatureBuffer = ByteBuffer.wrap(signature); signatureBuffer.order(ByteOrder.LITTLE_ENDIAN); int signaturePart1 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int signaturePart2 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int version = signatureBuffer.getInt(); this.fileFormatVersion = version; if (signaturePart1 == DATABASE_V2_FILE_SIGNATURE_1_INT && signaturePart2 == DATABASE_V2_FILE_SIGNATURE_2_INT) { if(!isVersionSupported(version)) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from a newer KeePass version which is not supported!"); } } else if (signaturePart1 == OLD_DATABASE_V1_FILE_SIGNATURE_1_INT && signaturePart2 == OLD_DATABASE_V1_FILE_SIGNATURE_2_INT) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from KeePass 1.x which is not supported!"); } else { throw new UnsupportedOperationException("The provided file seems to be no KeePass database file!"); } }
KeePassHeader { public void checkVersionSupport(byte[] keepassFile) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(keepassFile)); byte[] signature = new byte[VERSION_SIGNATURE_LENGTH]; int readBytes = inputStream.read(signature); if (readBytes == -1) { throw new UnsupportedOperationException("Could not read KeePass header. The provided file seems to be no KeePass database file!"); } ByteBuffer signatureBuffer = ByteBuffer.wrap(signature); signatureBuffer.order(ByteOrder.LITTLE_ENDIAN); int signaturePart1 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int signaturePart2 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int version = signatureBuffer.getInt(); this.fileFormatVersion = version; if (signaturePart1 == DATABASE_V2_FILE_SIGNATURE_1_INT && signaturePart2 == DATABASE_V2_FILE_SIGNATURE_2_INT) { if(!isVersionSupported(version)) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from a newer KeePass version which is not supported!"); } } else if (signaturePart1 == OLD_DATABASE_V1_FILE_SIGNATURE_1_INT && signaturePart2 == OLD_DATABASE_V1_FILE_SIGNATURE_2_INT) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from KeePass 1.x which is not supported!"); } else { throw new UnsupportedOperationException("The provided file seems to be no KeePass database file!"); } } }
KeePassHeader { public void checkVersionSupport(byte[] keepassFile) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(keepassFile)); byte[] signature = new byte[VERSION_SIGNATURE_LENGTH]; int readBytes = inputStream.read(signature); if (readBytes == -1) { throw new UnsupportedOperationException("Could not read KeePass header. The provided file seems to be no KeePass database file!"); } ByteBuffer signatureBuffer = ByteBuffer.wrap(signature); signatureBuffer.order(ByteOrder.LITTLE_ENDIAN); int signaturePart1 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int signaturePart2 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int version = signatureBuffer.getInt(); this.fileFormatVersion = version; if (signaturePart1 == DATABASE_V2_FILE_SIGNATURE_1_INT && signaturePart2 == DATABASE_V2_FILE_SIGNATURE_2_INT) { if(!isVersionSupported(version)) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from a newer KeePass version which is not supported!"); } } else if (signaturePart1 == OLD_DATABASE_V1_FILE_SIGNATURE_1_INT && signaturePart2 == OLD_DATABASE_V1_FILE_SIGNATURE_2_INT) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from KeePass 1.x which is not supported!"); } else { throw new UnsupportedOperationException("The provided file seems to be no KeePass database file!"); } } KeePassHeader();  KeePassHeader(ByteGenerator byteGenerator); }
KeePassHeader { public void checkVersionSupport(byte[] keepassFile) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(keepassFile)); byte[] signature = new byte[VERSION_SIGNATURE_LENGTH]; int readBytes = inputStream.read(signature); if (readBytes == -1) { throw new UnsupportedOperationException("Could not read KeePass header. The provided file seems to be no KeePass database file!"); } ByteBuffer signatureBuffer = ByteBuffer.wrap(signature); signatureBuffer.order(ByteOrder.LITTLE_ENDIAN); int signaturePart1 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int signaturePart2 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int version = signatureBuffer.getInt(); this.fileFormatVersion = version; if (signaturePart1 == DATABASE_V2_FILE_SIGNATURE_1_INT && signaturePart2 == DATABASE_V2_FILE_SIGNATURE_2_INT) { if(!isVersionSupported(version)) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from a newer KeePass version which is not supported!"); } } else if (signaturePart1 == OLD_DATABASE_V1_FILE_SIGNATURE_1_INT && signaturePart2 == OLD_DATABASE_V1_FILE_SIGNATURE_2_INT) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from KeePass 1.x which is not supported!"); } else { throw new UnsupportedOperationException("The provided file seems to be no KeePass database file!"); } } KeePassHeader();  KeePassHeader(ByteGenerator byteGenerator); void setValue(int headerId, byte[] value); void checkVersionSupport(byte[] keepassFile); @SuppressWarnings("resource") void read(byte[] keepassFile); byte[] getBytes(); byte[] getValue(int headerId); void setCompression(CompressionAlgorithm algorithm); byte[] getCipher(); CompressionAlgorithm getCompression(); long getTransformRounds(); void setTransformRounds(long rounds); byte[] getEncryptionIV(); byte[] getStreamStartBytes(); CrsAlgorithm getCrsAlgorithm(); void setCrsAlgorithm(CrsAlgorithm algorithm); byte[] getMasterSeed(); byte[] getTransformSeed(); VariantDictionary getKdfParameters(); int getHeaderSize(); byte[] getProtectedStreamKey(); int getFileFormatVersion(); }
KeePassHeader { public void checkVersionSupport(byte[] keepassFile) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(keepassFile)); byte[] signature = new byte[VERSION_SIGNATURE_LENGTH]; int readBytes = inputStream.read(signature); if (readBytes == -1) { throw new UnsupportedOperationException("Could not read KeePass header. The provided file seems to be no KeePass database file!"); } ByteBuffer signatureBuffer = ByteBuffer.wrap(signature); signatureBuffer.order(ByteOrder.LITTLE_ENDIAN); int signaturePart1 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int signaturePart2 = ByteUtils.toUnsignedInt(signatureBuffer.getInt()); int version = signatureBuffer.getInt(); this.fileFormatVersion = version; if (signaturePart1 == DATABASE_V2_FILE_SIGNATURE_1_INT && signaturePart2 == DATABASE_V2_FILE_SIGNATURE_2_INT) { if(!isVersionSupported(version)) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from a newer KeePass version which is not supported!"); } } else if (signaturePart1 == OLD_DATABASE_V1_FILE_SIGNATURE_1_INT && signaturePart2 == OLD_DATABASE_V1_FILE_SIGNATURE_2_INT) { throw new UnsupportedOperationException("The provided KeePass database file seems to be from KeePass 1.x which is not supported!"); } else { throw new UnsupportedOperationException("The provided file seems to be no KeePass database file!"); } } KeePassHeader();  KeePassHeader(ByteGenerator byteGenerator); void setValue(int headerId, byte[] value); void checkVersionSupport(byte[] keepassFile); @SuppressWarnings("resource") void read(byte[] keepassFile); byte[] getBytes(); byte[] getValue(int headerId); void setCompression(CompressionAlgorithm algorithm); byte[] getCipher(); CompressionAlgorithm getCompression(); long getTransformRounds(); void setTransformRounds(long rounds); byte[] getEncryptionIV(); byte[] getStreamStartBytes(); CrsAlgorithm getCrsAlgorithm(); void setCrsAlgorithm(CrsAlgorithm algorithm); byte[] getMasterSeed(); byte[] getTransformSeed(); VariantDictionary getKdfParameters(); int getHeaderSize(); byte[] getProtectedStreamKey(); int getFileFormatVersion(); static final int CIPHER; static final int COMPRESSION; static final int MASTER_SEED; static final int TRANSFORM_SEED; static final int TRANSFORM_ROUNDS; static final int ENCRYPTION_IV; static final int PROTECTED_STREAM_KEY; static final int STREAM_START_BYTES; static final int INNER_RANDOM_STREAM_ID; static final int KDF_PARAMETERS; static final int PUBLIC_CUSTOM_DATA; static final int VERSION_SIGNATURE_LENGTH; }