From b9f2558b1568951957c3d2695f282cf81c0ddb74 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:56:09 +0900 Subject: [PATCH 01/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/CustomIcon.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java b/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java index 7221495..a250f7d 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java +++ b/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java @@ -17,7 +17,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class CustomIcon { +public class CustomIcon implements Cloneable{ @XmlElement(name = "UUID") @XmlJavaTypeAdapter(UUIDXmlAdapter.class) @@ -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; + } } From 70efde6cde9407f7ea9062d68401350b4b111963 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:57:10 +0900 Subject: [PATCH 02/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/CustomIcons.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java b/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java index a054fb5..3c44875 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java +++ b/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java @@ -15,7 +15,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class CustomIcons { +public class CustomIcons implements Cloneable{ @XmlElement(name = "Icon") private List customIconList = new ArrayList(); @@ -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; + } } From f7ff14f5ec3e06fe94f48729235a22a6795c8697 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:59:58 +0900 Subject: [PATCH 03/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Entry.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Entry.java b/src/main/java/de/slackspace/openkeepass/domain/Entry.java index 3964adc..d0c7835 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Entry.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Entry.java @@ -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; @@ -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"; @@ -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(ret.times!=null){ + ret.times = (Times) this.times.clone(); + } + return ret; + } } From 6348eb1328e186f5e83d9026125942184dfd9691 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:01:32 +0900 Subject: [PATCH 04/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Group.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Group.java b/src/main/java/de/slackspace/openkeepass/domain/Group.java index d610169..d0cf1ec 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Group.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Group.java @@ -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; @@ -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) @@ -235,4 +236,25 @@ public final boolean equals(Object obj) { return true; } + protected Object clone() throws CloneNotSupportedException { + Group group = new Group(); + group.uuid = this.uuid; + group.name = this.name; + group.iconId = this.iconId; + if(this.iconData!=null){ + group.iconData = Arrays.copyOf(this.iconData, this.iconData.length); + } + group.customIconUUID = this.customIconUUID; + if(group.times!=null){ + group.times = (Times) this.times.clone(); + } + group.isExpanded = this.isExpanded; + for(Group g:this.getGroups()){ + group.groups.add((Group)g.clone()); + } + for(Entry e:this.getEntries()){ + group.entries.add((Entry)e.clone()); + } + return group; + } } From 462e33b9dabee23accacfe29cac80fc6f4a39c79 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:04:41 +0900 Subject: [PATCH 05/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/History.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/History.java b/src/main/java/de/slackspace/openkeepass/domain/History.java index 29315af..e4248dd 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/History.java +++ b/src/main/java/de/slackspace/openkeepass/domain/History.java @@ -10,7 +10,7 @@ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class History { +public class History implements Cloneable{ @XmlElement(name = "Entry") private List entries = new ArrayList(); @@ -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; + } } From 19cd9f03409839c6b5c82952c5c2a21101099b53 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:06:27 +0900 Subject: [PATCH 06/34] fix: problems of side effects of the write method --- .../api/KeePassDatabaseWriter.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java b/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java index b1082b7..8a6341f 100644 --- a/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java +++ b/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java @@ -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; @@ -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 { @@ -112,4 +120,9 @@ private static boolean validateKeePassFile(KeePassFile keePassFile) { return true; } + + + + + } From 6d0135d9281944de3f5d93342a83f51de003ae70 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:07:22 +0900 Subject: [PATCH 07/34] Update KeePassFile.java --- .../openkeepass/domain/KeePassFile.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java b/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java index d006376..7f496cc 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java +++ b/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java @@ -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; @@ -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; + } } From 2bb42ca3e5e43540a48d2d95cf5751d5cb3dcc88 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:09:30 +0900 Subject: [PATCH 08/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Meta.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Meta.java b/src/main/java/de/slackspace/openkeepass/domain/Meta.java index 7d481f0..2072110 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Meta.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Meta.java @@ -19,7 +19,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Meta { +public class Meta implements Cloneable{ @XmlElement(name = "Generator") private String generator; @@ -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; + } + + } From fa5b75361ba86306a185d2c30a112245b2aca021 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:10:30 +0900 Subject: [PATCH 09/34] fix: problems of side effects of the write method --- .../java/de/slackspace/openkeepass/domain/Property.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Property.java b/src/main/java/de/slackspace/openkeepass/domain/Property.java index faeb23c..feb3eb7 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Property.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Property.java @@ -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; @@ -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()); + } } From 5616009cfba4e293a6d6e631ee728ce007267c44 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:11:21 +0900 Subject: [PATCH 10/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Times.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Times.java b/src/main/java/de/slackspace/openkeepass/domain/Times.java index 9d439c7..1253f6a 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Times.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Times.java @@ -16,7 +16,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Times { +public class Times implements Cloneable{ @XmlElement(name = "LastModificationTime") private Calendar lastModificationTime; @@ -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; + } } From b62354dc39d42ad7d8e704e1f4182e756899c9de Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:56:09 +0900 Subject: [PATCH 11/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/CustomIcon.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java b/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java index 7221495..a250f7d 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java +++ b/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java @@ -17,7 +17,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class CustomIcon { +public class CustomIcon implements Cloneable{ @XmlElement(name = "UUID") @XmlJavaTypeAdapter(UUIDXmlAdapter.class) @@ -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; + } } From 0466405d37093b6910b06190d473c1af99f2978f Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:57:10 +0900 Subject: [PATCH 12/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/CustomIcons.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java b/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java index a054fb5..3c44875 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java +++ b/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java @@ -15,7 +15,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class CustomIcons { +public class CustomIcons implements Cloneable{ @XmlElement(name = "Icon") private List customIconList = new ArrayList(); @@ -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; + } } From 6f81d07bfff3372d83d84560fc60ffb1b8461cba Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:59:58 +0900 Subject: [PATCH 13/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Entry.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Entry.java b/src/main/java/de/slackspace/openkeepass/domain/Entry.java index 3964adc..d0c7835 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Entry.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Entry.java @@ -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; @@ -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"; @@ -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(ret.times!=null){ + ret.times = (Times) this.times.clone(); + } + return ret; + } } From d33e8cbac7957b229dbead44213121b16ef0cb00 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:01:32 +0900 Subject: [PATCH 14/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Group.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Group.java b/src/main/java/de/slackspace/openkeepass/domain/Group.java index d610169..d0cf1ec 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Group.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Group.java @@ -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; @@ -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) @@ -235,4 +236,25 @@ public final boolean equals(Object obj) { return true; } + protected Object clone() throws CloneNotSupportedException { + Group group = new Group(); + group.uuid = this.uuid; + group.name = this.name; + group.iconId = this.iconId; + if(this.iconData!=null){ + group.iconData = Arrays.copyOf(this.iconData, this.iconData.length); + } + group.customIconUUID = this.customIconUUID; + if(group.times!=null){ + group.times = (Times) this.times.clone(); + } + group.isExpanded = this.isExpanded; + for(Group g:this.getGroups()){ + group.groups.add((Group)g.clone()); + } + for(Entry e:this.getEntries()){ + group.entries.add((Entry)e.clone()); + } + return group; + } } From a2aa37f8346d91b5e95abff902b8eb911f27d526 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:04:41 +0900 Subject: [PATCH 15/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/History.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/History.java b/src/main/java/de/slackspace/openkeepass/domain/History.java index 29315af..e4248dd 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/History.java +++ b/src/main/java/de/slackspace/openkeepass/domain/History.java @@ -10,7 +10,7 @@ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class History { +public class History implements Cloneable{ @XmlElement(name = "Entry") private List entries = new ArrayList(); @@ -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; + } } From 2726f307da907a0273a3ff9178e29cc19331a18c Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:06:27 +0900 Subject: [PATCH 16/34] fix: problems of side effects of the write method --- .../api/KeePassDatabaseWriter.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java b/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java index b1082b7..8a6341f 100644 --- a/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java +++ b/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java @@ -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; @@ -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 { @@ -112,4 +120,9 @@ private static boolean validateKeePassFile(KeePassFile keePassFile) { return true; } + + + + + } From d64054a3ff1482bf218e9db4dca2e1b1b428b220 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:07:22 +0900 Subject: [PATCH 17/34] Update KeePassFile.java --- .../openkeepass/domain/KeePassFile.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java b/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java index d006376..7f496cc 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java +++ b/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java @@ -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; @@ -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; + } } From a4cd54518b73c0b08ee34c2d61bd553bb46fc566 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:09:30 +0900 Subject: [PATCH 18/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Meta.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Meta.java b/src/main/java/de/slackspace/openkeepass/domain/Meta.java index 7d481f0..2072110 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Meta.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Meta.java @@ -19,7 +19,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Meta { +public class Meta implements Cloneable{ @XmlElement(name = "Generator") private String generator; @@ -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; + } + + } From 8c0f3563af1a7015445a794f6a6b11b53b797a87 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:10:30 +0900 Subject: [PATCH 19/34] fix: problems of side effects of the write method --- .../java/de/slackspace/openkeepass/domain/Property.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Property.java b/src/main/java/de/slackspace/openkeepass/domain/Property.java index faeb23c..feb3eb7 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Property.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Property.java @@ -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; @@ -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()); + } } From 235ee10ed307f5a3a1d083afb042bb9624d1ef79 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:11:21 +0900 Subject: [PATCH 20/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Times.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Times.java b/src/main/java/de/slackspace/openkeepass/domain/Times.java index 9d439c7..1253f6a 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Times.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Times.java @@ -16,7 +16,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Times { +public class Times implements Cloneable{ @XmlElement(name = "LastModificationTime") private Calendar lastModificationTime; @@ -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; + } } From c6ae2419c56a4c51daf12b53cbf31b9763d4e3e6 Mon Sep 17 00:00:00 2001 From: yosbits Date: Sun, 8 May 2016 00:51:32 +0900 Subject: [PATCH 21/34] fix: Clone Method --- src/main/java/de/slackspace/openkeepass/domain/Entry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Entry.java b/src/main/java/de/slackspace/openkeepass/domain/Entry.java index d0c7835..410022d 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Entry.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Entry.java @@ -266,7 +266,7 @@ protected Object clone() throws CloneNotSupportedException { if(this.history!=null){ ret.history = (History) this.history.clone(); } - if(ret.times!=null){ + if(this.times!=null){ ret.times = (Times) this.times.clone(); } return ret; From 8715ef36f8c60db425d2b6b1d06ee6aea46f3d55 Mon Sep 17 00:00:00 2001 From: yosbits Date: Sun, 8 May 2016 00:53:01 +0900 Subject: [PATCH 22/34] fix: Clone Method --- .../slackspace/openkeepass/domain/Group.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Group.java b/src/main/java/de/slackspace/openkeepass/domain/Group.java index d0cf1ec..6dbea69 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Group.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Group.java @@ -237,24 +237,24 @@ public final boolean equals(Object obj) { } protected Object clone() throws CloneNotSupportedException { - Group group = new Group(); - group.uuid = this.uuid; - group.name = this.name; - group.iconId = this.iconId; + Group ret = new Group(); + ret.uuid = this.uuid; + ret.name = this.name; + ret.iconId = this.iconId; if(this.iconData!=null){ - group.iconData = Arrays.copyOf(this.iconData, this.iconData.length); + ret.iconData = Arrays.copyOf(this.iconData, this.iconData.length); } - group.customIconUUID = this.customIconUUID; - if(group.times!=null){ - group.times = (Times) this.times.clone(); + ret.customIconUUID = this.customIconUUID; + if(this.times!=null){ + ret.times = (Times) this.times.clone(); } - group.isExpanded = this.isExpanded; - for(Group g:this.getGroups()){ - group.groups.add((Group)g.clone()); + ret.isExpanded = this.isExpanded; + for(final Group g:this.getGroups()){ + ret.groups.add((Group)g.clone()); } - for(Entry e:this.getEntries()){ - group.entries.add((Entry)e.clone()); + for(final Entry e:this.getEntries()){ + ret.entries.add((Entry)e.clone()); } - return group; + return ret; } } From ede1533b417a1cd55dbdf4d9af35847f56cd71fe Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:56:09 +0900 Subject: [PATCH 23/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/CustomIcon.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java b/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java index 7221495..a250f7d 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java +++ b/src/main/java/de/slackspace/openkeepass/domain/CustomIcon.java @@ -17,7 +17,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class CustomIcon { +public class CustomIcon implements Cloneable{ @XmlElement(name = "UUID") @XmlJavaTypeAdapter(UUIDXmlAdapter.class) @@ -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; + } } From 74ea0b987cc5ab25216a81982d88a8e2e8d27f51 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:57:10 +0900 Subject: [PATCH 24/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/CustomIcons.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java b/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java index a054fb5..3c44875 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java +++ b/src/main/java/de/slackspace/openkeepass/domain/CustomIcons.java @@ -15,7 +15,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class CustomIcons { +public class CustomIcons implements Cloneable{ @XmlElement(name = "Icon") private List customIconList = new ArrayList(); @@ -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; + } } From 2ade0adc1fc6b2e8dfcc9434b48f1989dbc4c412 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 17:59:58 +0900 Subject: [PATCH 25/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Entry.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Entry.java b/src/main/java/de/slackspace/openkeepass/domain/Entry.java index 3964adc..d0c7835 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Entry.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Entry.java @@ -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; @@ -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"; @@ -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(ret.times!=null){ + ret.times = (Times) this.times.clone(); + } + return ret; + } } From cdd279ac3f117f17fcdeb299377122f1fe07b6da Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:01:32 +0900 Subject: [PATCH 26/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Group.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Group.java b/src/main/java/de/slackspace/openkeepass/domain/Group.java index d610169..d0cf1ec 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Group.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Group.java @@ -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; @@ -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) @@ -235,4 +236,25 @@ public final boolean equals(Object obj) { return true; } + protected Object clone() throws CloneNotSupportedException { + Group group = new Group(); + group.uuid = this.uuid; + group.name = this.name; + group.iconId = this.iconId; + if(this.iconData!=null){ + group.iconData = Arrays.copyOf(this.iconData, this.iconData.length); + } + group.customIconUUID = this.customIconUUID; + if(group.times!=null){ + group.times = (Times) this.times.clone(); + } + group.isExpanded = this.isExpanded; + for(Group g:this.getGroups()){ + group.groups.add((Group)g.clone()); + } + for(Entry e:this.getEntries()){ + group.entries.add((Entry)e.clone()); + } + return group; + } } From 1e4830f6352c7ad114dc71b3eba36daab175590d Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:04:41 +0900 Subject: [PATCH 27/34] fix: problems of side effects of the write method --- .../de/slackspace/openkeepass/domain/History.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/History.java b/src/main/java/de/slackspace/openkeepass/domain/History.java index 29315af..e4248dd 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/History.java +++ b/src/main/java/de/slackspace/openkeepass/domain/History.java @@ -10,7 +10,7 @@ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class History { +public class History implements Cloneable{ @XmlElement(name = "Entry") private List entries = new ArrayList(); @@ -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; + } } From f35991cda9b817b48bf44b6d6066fb70c70b67b2 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:06:27 +0900 Subject: [PATCH 28/34] fix: problems of side effects of the write method --- .../api/KeePassDatabaseWriter.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java b/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java index b1082b7..8a6341f 100644 --- a/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java +++ b/src/main/java/de/slackspace/openkeepass/api/KeePassDatabaseWriter.java @@ -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; @@ -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 { @@ -112,4 +120,9 @@ private static boolean validateKeePassFile(KeePassFile keePassFile) { return true; } + + + + + } From 8c4adb72d1bdd329ddeca7002be15f10411b37c2 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:07:22 +0900 Subject: [PATCH 29/34] Update KeePassFile.java --- .../openkeepass/domain/KeePassFile.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java b/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java index d006376..7f496cc 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java +++ b/src/main/java/de/slackspace/openkeepass/domain/KeePassFile.java @@ -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; @@ -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; + } } From 98c77fd603e58362d0dbe698b9295740f9f7ad19 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:09:30 +0900 Subject: [PATCH 30/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Meta.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Meta.java b/src/main/java/de/slackspace/openkeepass/domain/Meta.java index 7d481f0..2072110 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Meta.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Meta.java @@ -19,7 +19,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Meta { +public class Meta implements Cloneable{ @XmlElement(name = "Generator") private String generator; @@ -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; + } + + } From aa9961f7050be14ad4bae921d276ababd865415b Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:10:30 +0900 Subject: [PATCH 31/34] fix: problems of side effects of the write method --- .../java/de/slackspace/openkeepass/domain/Property.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Property.java b/src/main/java/de/slackspace/openkeepass/domain/Property.java index faeb23c..feb3eb7 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Property.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Property.java @@ -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; @@ -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()); + } } From 1257a4319b588c2c16f23c32eaa9a8ea370590b1 Mon Sep 17 00:00:00 2001 From: yosbits Date: Tue, 3 May 2016 18:11:21 +0900 Subject: [PATCH 32/34] fix: problems of side effects of the write method --- .../slackspace/openkeepass/domain/Times.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Times.java b/src/main/java/de/slackspace/openkeepass/domain/Times.java index 9d439c7..1253f6a 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Times.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Times.java @@ -16,7 +16,7 @@ */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Times { +public class Times implements Cloneable{ @XmlElement(name = "LastModificationTime") private Calendar lastModificationTime; @@ -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; + } } From 5a332de628760dc41ae70ddbfce8619652b534e8 Mon Sep 17 00:00:00 2001 From: yosbits Date: Sun, 8 May 2016 00:51:32 +0900 Subject: [PATCH 33/34] fix: Clone Method --- src/main/java/de/slackspace/openkeepass/domain/Entry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Entry.java b/src/main/java/de/slackspace/openkeepass/domain/Entry.java index d0c7835..410022d 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Entry.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Entry.java @@ -266,7 +266,7 @@ protected Object clone() throws CloneNotSupportedException { if(this.history!=null){ ret.history = (History) this.history.clone(); } - if(ret.times!=null){ + if(this.times!=null){ ret.times = (Times) this.times.clone(); } return ret; From 379a364dacc4e746897ff8a3c1ede6157eb5e923 Mon Sep 17 00:00:00 2001 From: yosbits Date: Sun, 8 May 2016 00:53:01 +0900 Subject: [PATCH 34/34] fix: Clone Method --- .../slackspace/openkeepass/domain/Group.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/slackspace/openkeepass/domain/Group.java b/src/main/java/de/slackspace/openkeepass/domain/Group.java index d0cf1ec..6dbea69 100644 --- a/src/main/java/de/slackspace/openkeepass/domain/Group.java +++ b/src/main/java/de/slackspace/openkeepass/domain/Group.java @@ -237,24 +237,24 @@ public final boolean equals(Object obj) { } protected Object clone() throws CloneNotSupportedException { - Group group = new Group(); - group.uuid = this.uuid; - group.name = this.name; - group.iconId = this.iconId; + Group ret = new Group(); + ret.uuid = this.uuid; + ret.name = this.name; + ret.iconId = this.iconId; if(this.iconData!=null){ - group.iconData = Arrays.copyOf(this.iconData, this.iconData.length); + ret.iconData = Arrays.copyOf(this.iconData, this.iconData.length); } - group.customIconUUID = this.customIconUUID; - if(group.times!=null){ - group.times = (Times) this.times.clone(); + ret.customIconUUID = this.customIconUUID; + if(this.times!=null){ + ret.times = (Times) this.times.clone(); } - group.isExpanded = this.isExpanded; - for(Group g:this.getGroups()){ - group.groups.add((Group)g.clone()); + ret.isExpanded = this.isExpanded; + for(final Group g:this.getGroups()){ + ret.groups.add((Group)g.clone()); } - for(Entry e:this.getEntries()){ - group.entries.add((Entry)e.clone()); + for(final Entry e:this.getEntries()){ + ret.entries.add((Entry)e.clone()); } - return group; + return ret; } }