Search in sources :

Example 1 with LEDataOutputStream

use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.

the class KdfParameters method serialize.

public static byte[] serialize(KdfParameters kdf) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LEDataOutputStream los = new LEDataOutputStream(bos);
    KdfParameters.serialize(kdf, los);
    return bos.toByteArray();
}
Also used : LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with LEDataOutputStream

use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.

the class PwDbHeaderOutputV4 method output.

public void output() throws IOException {
    los.writeUInt(PwDbHeader.PWM_DBSIG_1);
    los.writeUInt(PwDbHeaderV4.DBSIG_2);
    los.writeUInt(header.version);
    writeHeaderField(PwDbHeaderV4Fields.CipherID, Types.UUIDtoBytes(db.dataCipher));
    writeHeaderField(PwDbHeaderV4Fields.CompressionFlags, LEDataOutputStream.writeIntBuf(db.compressionAlgorithm.id));
    writeHeaderField(PwDbHeaderV4Fields.MasterSeed, header.masterSeed);
    if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
        writeHeaderField(PwDbHeaderV4Fields.TransformSeed, header.getTransformSeed());
        writeHeaderField(PwDbHeaderV4Fields.TransformRounds, LEDataOutputStream.writeLongBuf(db.numKeyEncRounds));
    } else {
        writeHeaderField(PwDbHeaderV4Fields.KdfParameters, KdfParameters.serialize(db.kdfParameters));
    }
    if (header.encryptionIV.length > 0) {
        writeHeaderField(PwDbHeaderV4Fields.EncryptionIV, header.encryptionIV);
    }
    if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
        writeHeaderField(PwDbHeaderV4Fields.InnerRandomstreamKey, header.innerRandomStreamKey);
        writeHeaderField(PwDbHeaderV4Fields.StreamStartBytes, header.streamStartBytes);
        writeHeaderField(PwDbHeaderV4Fields.InnerRandomStreamID, LEDataOutputStream.writeIntBuf(header.innerRandomStream.id));
    }
    if (db.publicCustomData.size() > 0) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        LEDataOutputStream los = new LEDataOutputStream(bos);
        VariantDictionary.serialize(db.publicCustomData, los);
        writeHeaderField(PwDbHeaderV4Fields.PublicCustomData, bos.toByteArray());
    }
    writeHeaderField(PwDbHeaderV4Fields.EndOfHeader, EndHeaderValue);
    los.flush();
    hashOfHeader = dos.getMessageDigest().digest();
    headerHmac = mos.getMac();
}
Also used : LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with LEDataOutputStream

use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.

the class PwDbV3Output method outputPlanGroupAndEntries.

public void outputPlanGroupAndEntries(OutputStream os) throws PwDbOutputException {
    LEDataOutputStream los = new LEDataOutputStream(os);
    if (useHeaderHash() && headerHashBlock != null) {
        try {
            los.writeUShort(0x0000);
            los.writeInt(headerHashBlock.length);
            los.write(headerHashBlock);
        } catch (IOException e) {
            throw new PwDbOutputException("Failed to output header hash: " + e.getMessage());
        }
    }
    // Groups
    List<PwGroup> groups = mPM.getGroups();
    for (int i = 0; i < groups.size(); i++) {
        PwGroupV3 pg = (PwGroupV3) groups.get(i);
        PwGroupOutputV3 pgo = new PwGroupOutputV3(pg, os);
        try {
            pgo.output();
        } catch (IOException e) {
            throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
        }
    }
    // Entries
    for (int i = 0; i < mPM.entries.size(); i++) {
        PwEntryV3 pe = (PwEntryV3) mPM.entries.get(i);
        PwEntryOutputV3 peo = new PwEntryOutputV3(pe, os);
        try {
            peo.output();
        } catch (IOException e) {
            throw new PwDbOutputException("Failed to output an entry.");
        }
    }
}
Also used : LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) PwGroupV3(com.keepassdroid.database.PwGroupV3) PwEntryV3(com.keepassdroid.database.PwEntryV3) PwDbOutputException(com.keepassdroid.database.exception.PwDbOutputException) PwGroup(com.keepassdroid.database.PwGroup) IOException(java.io.IOException)

Example 4 with LEDataOutputStream

use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.

the class PwDbV3Output method writeExtData.

private void writeExtData(byte[] headerDigest, OutputStream os) throws IOException {
    LEDataOutputStream los = new LEDataOutputStream(os);
    writeExtDataField(los, 0x0001, headerDigest, headerDigest.length);
    byte[] headerRandom = new byte[32];
    SecureRandom rand = new SecureRandom();
    rand.nextBytes(headerRandom);
    writeExtDataField(los, 0x0002, headerRandom, headerRandom.length);
    writeExtDataField(los, 0xFFFF, null, 0);
}
Also used : LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) SecureRandom(java.security.SecureRandom)

Example 5 with LEDataOutputStream

use of com.keepassdroid.stream.LEDataOutputStream in project KeePassDX by Kunzisoft.

the class TypesTest method testULongMax.

public void testULongMax() throws Exception {
    byte[] ulongBytes = new byte[8];
    for (int i = 0; i < ulongBytes.length; i++) {
        ulongBytes[i] = -1;
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LEDataOutputStream leos = new LEDataOutputStream(bos);
    leos.writeLong(Types.ULONG_MAX_VALUE);
    leos.close();
    byte[] uLongMax = bos.toByteArray();
    assertArrayEquals(ulongBytes, uLongMax);
}
Also used : LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

LEDataOutputStream (com.keepassdroid.stream.LEDataOutputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PwEntryV3 (com.keepassdroid.database.PwEntryV3)1 PwGroup (com.keepassdroid.database.PwGroup)1 PwGroupV3 (com.keepassdroid.database.PwGroupV3)1 PwDbOutputException (com.keepassdroid.database.exception.PwDbOutputException)1 IOException (java.io.IOException)1 SecureRandom (java.security.SecureRandom)1