Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -103,12 +103,12 @@ public String encrypt(@RequestBody String data, @RequestHeader("Content-Type") M
@PostMapping("/encrypt/{name}/{profiles}")
public String encrypt(@PathVariable String name, @PathVariable String profiles, @RequestBody String data,
@RequestHeader("Content-Type") MediaType type) {
TextEncryptor encryptor = getEncryptor(name, profiles, "");
validateEncryptionWeakness(encryptor);
String input = stripFormData(data, type, false);
TextEncryptor encryptor = getEncryptor(name, profiles, input);
validateEncryptionWeakness(encryptor);
Map<String, String> keys = helper.getEncryptorKeys(name, profiles, input);
String textToEncrypt = helper.stripPrefix(input);
String encrypted = helper.addPrefix(keys, encryptorLocator.locate(keys).encrypt(textToEncrypt));
String encrypted = helper.addPrefix(keys, encryptor.encrypt(textToEncrypt));
if (logger.isInfoEnabled()) {
logger.info("Encrypted data");
}
Expand All @@ -123,11 +123,10 @@ public String decrypt(@RequestBody String data, @RequestHeader("Content-Type") M
@PostMapping("/decrypt/{name}/{profiles}")
public String decrypt(@PathVariable String name, @PathVariable String profiles, @RequestBody String data,
@RequestHeader("Content-Type") MediaType type) {
TextEncryptor encryptor = getEncryptor(name, profiles, "");
checkDecryptionPossible(encryptor);
validateEncryptionWeakness(encryptor);
try {
encryptor = getEncryptor(name, profiles, data);
TextEncryptor encryptor = getEncryptor(name, profiles, data);
checkDecryptionPossible(encryptor);
validateEncryptionWeakness(encryptor);
String input = stripFormData(helper.stripPrefix(data), type, true);
String decrypted = encryptor.decrypt(input);
if (logger.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ public void addEnvironment() {

@Override
public TextEncryptor locate(Map<String, String> keys) {
assertThat(keys.containsKey("key")).as("Missing encryptor key").isTrue();
assertThat(keys.get("key")).as("Bad encryptor key value").isEqualTo("value");
return this.encryptor;
}
};
this.controller = new EncryptionController(locator);
// Add space to input
String cipher = this.controller.encrypt("app", "default", "foo bar", MediaType.TEXT_PLAIN);
String cipher = this.controller.encrypt("app", "default", "{key:value}foo bar", MediaType.TEXT_PLAIN);
assertThat(cipher.contains("{name:app}")).as("Wrong cipher: " + cipher).isFalse();
String decrypt = this.controller.decrypt("app", "default", cipher, MediaType.TEXT_PLAIN);
assertThat(decrypt).as("Wrong decrypted plaintext: " + decrypt).isEqualTo("foo bar");
Expand Down