@Override public Database load(KdbxCreds creds, InputStream inputStream) throws Exception { return JaxbDatabase.load(creds, inputStream); } }
public JaxbDatabase() { this(createEmptyDatabase().getKeePassFile()); }
@Override public boolean isRootGroup() { return database.getRootGroup().equals(this); }
@Override public JaxbGroup getRecycleBin() { UUID recycleBinUuid = this.keePassFile.getMeta().getRecycleBinUUID(); JaxbGroup g = findGroup(recycleBinUuid); if (g == null && !isRecycleBinEnabled()) { return null; } if (g== null) { g = newGroup("Recycle Bin"); getRootGroup().addGroup(g); this.keePassFile.getMeta().setRecycleBinUUID(g.getUuid()); this.keePassFile.getMeta().setRecycleBinChanged(new Date()); } return g; }
List<Binaries.Binary> binaryList = database.getKeePassFile().getMeta().getBinaries().getBinary(); for (Binaries.Binary binary: binaryList){ if (binary.getID() > max) { Binaries.Binary newBin = database.getObjectFactory().createBinariesBinary(); newBin.setID(max); newBin.setValue(Helpers.zipBinaryContent(value)); BinaryField binaryField = database.getObjectFactory().createBinaryField(); binaryField.setKey(name); BinaryField.Value fieldValue = database.getObjectFactory().createBinaryFieldValue(); fieldValue.setRef(max); binaryField.setValue(fieldValue);
public JaxbGroup(JaxbDatabase database) { this.database = database; this.delegate = database.getObjectFactory().createJaxbGroupBinding(); delegate.setTimes(new ObjectFactory().createTimes()); delegate.setIconID(0); delegate.setName(""); delegate.setUUID(UUID.randomUUID()); }
@NotNull public static JaxbDatabase load(StreamFormat format, Credentials creds, InputStream inputStream) { JaxbSerializableDatabase db = new JaxbSerializableDatabase(); try { format.load(db, creds, inputStream); } catch (IOException e) { throw new IllegalStateException(e); } return new JaxbDatabase(db.getKeePassFile()); }
@Override public boolean isRecycleBin() { return database.getKeePassFile().getMeta().getRecycleBinUUID().equals(this.getUuid()); }
@Override public void save(Credentials creds, OutputStream outputStream) throws IOException { save(new KdbxStreamFormat(), creds, outputStream); }
@Override public void setProperty(String name, String value) { StringField toRemove = null; for (StringField field: delegate.getString()){ if (field.getKey().equals(name)) { toRemove = field; break; } } if (toRemove != null) { delegate.getString().remove(toRemove); } StringField.Value fieldValue = database.getObjectFactory().createStringFieldValue(); fieldValue.setValue(value); fieldValue.setProtected(false); StringField field = database.getObjectFactory().createStringField(); field.setKey(name); field.setValue(fieldValue); delegate.getString().add(field); touch(); }
public static JaxbDatabase createEmptyDatabase() { InputStream inputStream = JaxbDatabase.class.getClassLoader().getResourceAsStream("base.kdbx.xml"); KeePassFile keePassFile = new JaxbSerializableDatabase().load(inputStream).keePassFile; keePassFile.getRoot().getGroup().setUUID(UUID.randomUUID()); return new JaxbDatabase(keePassFile); }
@Override public byte[] getBinaryProperty(String name) { for (BinaryField binaryField : delegate.getBinary()){ if (binaryField.getKey().equals(name)){ Integer ref = binaryField.getValue().getRef(); for (Binaries.Binary binary: database.getKeePassFile().getMeta().getBinaries().getBinary()){ if (binary.getID().equals(ref)) { if (binary.getCompressed()) { return Helpers.unzipBinaryContent(binary.getValue()); } return binary.getValue(); } } } } return null; }
public static JaxbDatabase load(Credentials creds, InputStream inputStream) { StreamFormat format = new KdbxStreamFormat(); return load(format, creds, inputStream); }
public JaxbEntry(JaxbDatabase jaxbDatabase) { this.database = jaxbDatabase; this.delegate = new JaxbEntryBinding(); for (String s: STANDARD_PROPERTY_NAMES) { StringField field = jaxbDatabase.getObjectFactory().createStringField(); field.setKey(s); StringField.Value value = jaxbDatabase.getObjectFactory().createStringFieldValue(); value.setValue(""); field.setValue(value); delegate.getString().add(field); } Date now = new Date(System.currentTimeMillis() / 1000L * 1000L); // to nearest lower second Times times = new Times(); times.setLastModificationTime(now); times.setCreationTime(now); times.setLastAccessTime(now); times.setExpiryTime(now); times.setExpires(false); times.setUsageCount(0); times.setLocationChanged(now); this.delegate.setTimes(times); delegate.setUUID(UUID.randomUUID()); }