Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b9f2558
fix: problems of side effects of the write method
yososs May 3, 2016
70efde6
fix: problems of side effects of the write method
yososs May 3, 2016
f7ff14f
fix: problems of side effects of the write method
yososs May 3, 2016
6348eb1
fix: problems of side effects of the write method
yososs May 3, 2016
462e33b
fix: problems of side effects of the write method
yososs May 3, 2016
19cd9f0
fix: problems of side effects of the write method
yososs May 3, 2016
6d0135d
Update KeePassFile.java
yososs May 3, 2016
2bb42ca
fix: problems of side effects of the write method
yososs May 3, 2016
fa5b753
fix: problems of side effects of the write method
yososs May 3, 2016
5616009
fix: problems of side effects of the write method
yososs May 3, 2016
b62354d
fix: problems of side effects of the write method
yososs May 3, 2016
0466405
fix: problems of side effects of the write method
yososs May 3, 2016
6f81d07
fix: problems of side effects of the write method
yososs May 3, 2016
d33e8cb
fix: problems of side effects of the write method
yososs May 3, 2016
a2aa37f
fix: problems of side effects of the write method
yososs May 3, 2016
2726f30
fix: problems of side effects of the write method
yososs May 3, 2016
d64054a
Update KeePassFile.java
yososs May 3, 2016
a4cd545
fix: problems of side effects of the write method
yososs May 3, 2016
8c0f356
fix: problems of side effects of the write method
yososs May 3, 2016
235ee10
fix: problems of side effects of the write method
yososs May 3, 2016
5e083a9
Merge branch 'master' of https://github.com/yososs/openkeepass.git
yososs May 7, 2016
c6ae241
fix: Clone Method
yososs May 7, 2016
8715ef3
fix: Clone Method
yososs May 7, 2016
17b5ee7
Merge branch 'master' of https://github.com/cternes/openkeepass.git
yososs May 8, 2016
ede1533
fix: problems of side effects of the write method
yososs May 3, 2016
74ea0b9
fix: problems of side effects of the write method
yososs May 3, 2016
2ade0ad
fix: problems of side effects of the write method
yososs May 3, 2016
cdd279a
fix: problems of side effects of the write method
yososs May 3, 2016
1e4830f
fix: problems of side effects of the write method
yososs May 3, 2016
f35991c
fix: problems of side effects of the write method
yososs May 3, 2016
8c4adb7
Update KeePassFile.java
yososs May 3, 2016
98c77fd
fix: problems of side effects of the write method
yososs May 3, 2016
aa9961f
fix: problems of side effects of the write method
yososs May 3, 2016
1257a43
fix: problems of side effects of the write method
yososs May 3, 2016
5a332de
fix: Clone Method
yososs May 7, 2016
379a364
fix: Clone Method
yososs May 7, 2016
a4324f6
Merge branch 'master' of https://github.com/yososs/openkeepass.git
yososs Jun 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import de.slackspace.openkeepass.crypto.RandomGenerator;
import de.slackspace.openkeepass.crypto.Salsa20;
import de.slackspace.openkeepass.crypto.Sha256;
import de.slackspace.openkeepass.domain.Group;
import de.slackspace.openkeepass.domain.GroupBuilder;
import de.slackspace.openkeepass.domain.KeePassFile;
import de.slackspace.openkeepass.domain.KeePassFileBuilder;
import de.slackspace.openkeepass.domain.KeePassHeader;
import de.slackspace.openkeepass.domain.zipper.GroupZipper;
import de.slackspace.openkeepass.exception.KeePassDatabaseUnwriteableException;
Expand Down Expand Up @@ -85,12 +88,17 @@ private ByteArrayOutputStream hashBlockStream(ByteArrayOutputStream streamToUnzi
}

private byte[] marshallXml(KeePassFile keePassFile, KeePassHeader header) {
KeePassFile clonedKeePassFile = new GroupZipper(keePassFile).cloneKeePassFile();

// KeePassFile clonedKeePassFile = new GroupZipper(keePassFile).cloneKeePassFile();
KeePassFile clonedKeePassFile;
try {
clonedKeePassFile = (KeePassFile)keePassFile.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(e);
}
ProtectedStringCrypto protectedStringCrypto = Salsa20.createInstance(header.getProtectedStreamKey());
new ProtectedValueProcessor().processProtectedValues(new EncryptionStrategy(protectedStringCrypto), clonedKeePassFile);

return new KeePassDatabaseXmlParser().toXml(keePassFile).toByteArray();
return new KeePassDatabaseXmlParser().toXml(clonedKeePassFile).toByteArray();
}

private ByteArrayOutputStream compressStream(byte[] keePassFilePayload) throws IOException {
Expand All @@ -112,4 +120,9 @@ private static boolean validateKeePassFile(KeePassFile keePassFile) {

return true;
}





}
11 changes: 10 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CustomIcon {
public class CustomIcon implements Cloneable{

@XmlElement(name = "UUID")
@XmlJavaTypeAdapter(UUIDXmlAdapter.class)
Expand Down Expand Up @@ -80,4 +80,13 @@ public final boolean equals(Object obj) {
return true;
}

@Override
protected Object clone() throws CloneNotSupportedException {
CustomIcon ret = new CustomIcon();
ret.uuid = this.uuid;
if(this.data!=null){
ret.data = Arrays.copyOf(this.data, this.data.length);
}
return ret;
}
}
11 changes: 10 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CustomIcons {
public class CustomIcons implements Cloneable{

@XmlElement(name = "Icon")
private List<CustomIcon> customIconList = new ArrayList<CustomIcon>();
Expand Down Expand Up @@ -78,4 +78,13 @@ public final boolean equals(Object obj) {
return true;
}


@Override
protected Object clone() throws CloneNotSupportedException {
CustomIcons ret = new CustomIcons();
for( CustomIcon customIcon:this.customIconList){
ret.customIconList.add((CustomIcon)customIcon.clone());
}
return ret;
}
}
25 changes: 24 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/Entry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.slackspace.openkeepass.domain;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

Expand All @@ -19,7 +20,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Entry implements KeePassFileElement {
public class Entry implements KeePassFileElement, Cloneable {

private static final String USER_NAME = "UserName";
private static final String NOTES = "Notes";
Expand Down Expand Up @@ -248,4 +249,26 @@ public String toString() {
return "Entry [uuid=" + uuid + ", getTitle()=" + getTitle() + ", getPassword()=" + getPassword() + ", getUsername()=" + getUsername() + "]";
}


@Override
protected Object clone() throws CloneNotSupportedException {
Entry ret = new Entry();
ret.uuid = this.uuid;
ret.iconId = this.iconId;
if(this.iconData!=null){
ret.iconData = Arrays.copyOf(this.iconData, this.iconData.length);
}
ret.customIconUUID = this.customIconUUID;

for(Property property:properties){
ret.properties.add((Property) property.clone());
}
if(this.history!=null){
ret.history = (History) this.history.clone();
}
if(this.times!=null){
ret.times = (Times) this.times.clone();
}
return ret;
}
}
24 changes: 23 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/Group.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.slackspace.openkeepass.domain;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

Expand All @@ -21,7 +22,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Group implements KeePassFileElement {
public class Group implements KeePassFileElement, Cloneable {

@XmlElement(name = "UUID")
@XmlJavaTypeAdapter(UUIDXmlAdapter.class)
Expand Down Expand Up @@ -235,4 +236,25 @@ public final boolean equals(Object obj) {
return true;
}

protected Object clone() throws CloneNotSupportedException {
Group ret = new Group();
ret.uuid = this.uuid;
ret.name = this.name;
ret.iconId = this.iconId;
if(this.iconData!=null){
ret.iconData = Arrays.copyOf(this.iconData, this.iconData.length);
}
ret.customIconUUID = this.customIconUUID;
if(this.times!=null){
ret.times = (Times) this.times.clone();
}
ret.isExpanded = this.isExpanded;
for(final Group g:this.getGroups()){
ret.groups.add((Group)g.clone());
}
for(final Entry e:this.getEntries()){
ret.entries.add((Entry)e.clone());
}
return ret;
}
}
11 changes: 10 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class History {
public class History implements Cloneable{

@XmlElement(name = "Entry")
private List<Entry> entries = new ArrayList<Entry>();
Expand Down Expand Up @@ -43,5 +43,14 @@ public final boolean equals(Object obj) {
return false;
return true;
}

@Override
protected Object clone() throws CloneNotSupportedException {
History ret = new History();
for(Entry entry:entries){
ret.entries.add((Entry) entry.clone());
}
return ret;
}

}
16 changes: 15 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@XmlRootElement(name = "KeePassFile")
@XmlAccessorType(XmlAccessType.FIELD)
public class KeePassFile implements KeePassFileElement {
public class KeePassFile implements KeePassFileElement, Cloneable {

@XmlElement(name = "Meta")
private Meta meta;
Expand Down Expand Up @@ -323,4 +323,18 @@ public boolean matches(Group item) {
return null;
}
}



@Override
public Object clone() throws CloneNotSupportedException {
KeePassFile ret = new KeePassFile();
if(this.meta!=null){
ret.meta = (Meta) this.meta.clone();
}
if(this.root!=null){
ret.root = (Group) this.root.clone();
}
return ret;
}
}
33 changes: 32 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Meta {
public class Meta implements Cloneable{

@XmlElement(name = "Generator")
private String generator;
Expand Down Expand Up @@ -211,4 +211,35 @@ public final boolean equals(Object obj) {
public String toString() {
return "Meta [generator=" + generator + ", databaseName=" + databaseName + ", databaseDescription=" + databaseDescription + "]";
}


@Override
protected Object clone() throws CloneNotSupportedException {

Meta ret = new Meta();
ret.generator = this.generator;
ret.databaseName = this.databaseName;
ret.databaseDescription = this.databaseDescription;
if(this.databaseNameChanged!=null){
ret.databaseNameChanged = (Calendar)this.databaseNameChanged.clone();
}
if(this.databaseDescriptionChanged!=null){
ret.databaseDescriptionChanged = (Calendar)this.databaseDescriptionChanged.clone();
}
ret.maintenanceHistoryDays = this.maintenanceHistoryDays;
ret.recycleBinUuid = this.recycleBinUuid;

if(this.recycleBinChanged!=null){
ret.recycleBinChanged = (Calendar)this.recycleBinChanged.clone();
}
ret.recycleBinEnabled = this.recycleBinEnabled;
ret.historyMaxItems = this.historyMaxItems;
ret.historyMaxSize = this.historyMaxSize;
if(this.customIcons != null){
ret.customIcons = (CustomIcons) this.customIcons.clone();
}
return ret;
}


}
7 changes: 6 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Property implements KeePassFileElement {
public class Property implements KeePassFileElement, Cloneable{

@XmlElement(name = "Key")
private String key;
Expand Down Expand Up @@ -79,5 +79,10 @@ public final boolean equals(Object obj) {
return false;
return true;
}

@Override
protected Object clone() throws CloneNotSupportedException {
return new Property(this.getKey(), this.getValue(), this.isProtected());
}

}
26 changes: 25 additions & 1 deletion src/main/java/de/slackspace/openkeepass/domain/Times.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Times {
public class Times implements Cloneable{

@XmlElement(name = "LastModificationTime")
private Calendar lastModificationTime;
Expand Down Expand Up @@ -145,4 +145,28 @@ public String toString() {
return "Times [lastModificationTime=" + lastModificationTime + ", creationTime=" + creationTime + "]";
}


@Override
protected Object clone() throws CloneNotSupportedException {
Times ret = new Times();
if(this.lastModificationTime!=null){
ret.lastModificationTime = (Calendar)this.lastModificationTime.clone();
}
if(this.creationTime!=null){
ret.creationTime = (Calendar)this.creationTime.clone();
}
if(this.lastAccessTime!=null){
ret.lastAccessTime = (Calendar)this.lastAccessTime.clone();
}
if(this.expiryTime!=null){
ret.expiryTime = (Calendar)this.expiryTime.clone();
}
ret.expires = this.expires;
ret.usageCount = this.usageCount;

if(this.locationChanged!=null){
ret.locationChanged = (Calendar)this.locationChanged.clone();
}
return ret;
}
}