This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom action aware encryption converters
Previously all transfer settings values were encrypted once they are persisted independent from the location. Now only configs written to disk are encrypted using a custom converter. Changed default @Encrypted handling and removed persistence callbacks in transfer settings. Deprecated generic AbtractInitOperation#writeXmlObject. Every *TO should use its own save method because the above case has shown that persistence isn't generic in all cases.
- Loading branch information
Showing
9 changed files
with
139 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ny-lib/src/main/java/org/syncany/plugins/transfer/EncryptedTransferSettingsConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.syncany.plugins.transfer; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.List; | ||
|
||
import org.simpleframework.xml.convert.Converter; | ||
import org.simpleframework.xml.stream.InputNode; | ||
import org.simpleframework.xml.stream.OutputNode; | ||
import org.syncany.util.ReflectionUtil; | ||
import com.google.common.collect.Lists; | ||
|
||
/** | ||
* @author Christian Roth <christian.roth@port17.de> | ||
*/ | ||
public class EncryptedTransferSettingsConverter implements Converter<String> { | ||
|
||
private Class<? extends TransferSettings> transferSettingsClass; | ||
private List<String> encryptedFields; | ||
|
||
public EncryptedTransferSettingsConverter() { | ||
} | ||
|
||
public EncryptedTransferSettingsConverter(Class<? extends TransferSettings> transferSettingsClass) { | ||
this.transferSettingsClass = transferSettingsClass; | ||
encryptedFields = getEncryptedFields(transferSettingsClass); | ||
} | ||
|
||
@Override | ||
public String read(InputNode node) throws Exception { | ||
InputNode encryptedAttribute = node.getAttribute("encrypted"); | ||
if (encryptedAttribute != null && encryptedAttribute.getValue().equals(Boolean.TRUE.toString())) { | ||
return TransferSettings.decrypt(node.getValue()); | ||
} | ||
|
||
return node.getValue(); | ||
} | ||
|
||
@Override | ||
public void write(OutputNode node, String raw) throws Exception { | ||
if (encryptedFields.contains(node.getName())) { | ||
node.setValue(TransferSettings.encrypt(raw)); | ||
node.setAttribute("encrypted", Boolean.TRUE.toString()); | ||
return; | ||
} | ||
|
||
node.setValue(raw); | ||
} | ||
|
||
private List<String> getEncryptedFields(Class<? extends TransferSettings> clazz) { | ||
List<String> encryptedFields = Lists.newArrayList(); | ||
for (Field field : ReflectionUtil.getAllFieldsWithAnnotation(clazz, Encrypted.class)) { | ||
encryptedFields.add(field.getName()); | ||
} | ||
return encryptedFields; | ||
} | ||
|
||
} |
Oops, something went wrong.