From 7ce9d997d4ef917a8c168ad5e70325574c9633d9 Mon Sep 17 00:00:00 2001 From: Agoston Horvath Date: Tue, 23 Mar 2021 15:51:50 +0100 Subject: [PATCH] fixed issue where silentDecryptionFailure=true still failed on non-encrypted field --- .../java/com/bol/secure/AbstractEncryptionEventListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bol/secure/AbstractEncryptionEventListener.java b/src/main/java/com/bol/secure/AbstractEncryptionEventListener.java index a161d62..25af493 100644 --- a/src/main/java/com/bol/secure/AbstractEncryptionEventListener.java +++ b/src/main/java/com/bol/secure/AbstractEncryptionEventListener.java @@ -29,7 +29,8 @@ public Object apply(Object o) { if (o instanceof Binary) data = ((Binary) o).getData(); else if (o instanceof byte[]) data = (byte[]) o; - else throw new IllegalStateException("Got " + o.getClass() + ", expected: Binary or byte[]"); + else if (!silentDecryptionFailure) throw new IllegalStateException("Got " + o.getClass() + ", expected: Binary or byte[]"); + else return o; // e.g. crypted field not encrypted, other issues - we do our best try { byte[] serialized = cryptVault.decrypt((data)); @@ -66,7 +67,6 @@ public BSONCallback createBSONCallback() { class Encoder extends BasicBSONEncoder implements Function { public Object apply(Object o) { - // FIXME: switch to BsonDocumentWriter // we need to put even BSONObject and BSONList in a wrapping object before serialization, otherwise the type information is not encoded. // this is not particularly effective, however, it is the same that mongo driver itself uses on the wire, so it has 100% compatibility w.r.t de/serialization byte[] serialized = encode(new BasicBSONObject("", o));