Skip to content

Commit 931e616

Browse files
committed
Fixed "length operation cannot be applied to null" when decrypting certain payloads, next version is 1.7.1
1 parent b235cf5 commit 931e616

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.mastercard.developer</groupId>
88
<artifactId>client-encryption</artifactId>
9-
<version>1.7.1-SNAPSHOT</version>
9+
<version>1.7.1</version>
1010
<packaging>jar</packaging>
1111
<description>Library for Mastercard API compliant payload encryption/decryption</description>
1212
<url>https://github.com/Mastercard/client-encryption-java</url>

src/main/java/com/mastercard/developer/encryption/FieldLevelEncryption.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,14 @@ private static DocumentContext decryptPayloadPath(DocumentContext payloadContext
172172
} else {
173173
JsonParser.checkOrCreateOutObject(payloadContext, jsonPathOut);
174174
JsonParser.addDecryptedDataToPayload(payloadContext, decryptedValue, jsonPathOut);
175-
}
176175

177-
// Remove the input if now empty
178-
Object inJsonElement = JsonParser.readJsonElement(payloadContext, jsonPathIn);
179-
if (0 == jsonProvider.length(inJsonElement) && !"$".equals(jsonPathIn)) {
180-
payloadContext.delete(jsonPathIn);
176+
// Remove the input if now empty
177+
Object inJsonElement = JsonParser.readJsonElement(payloadContext, jsonPathIn);
178+
if (0 == jsonProvider.length(inJsonElement)) {
179+
payloadContext.delete(jsonPathIn);
180+
}
181181
}
182+
182183
return payloadContext;
183184
}
184185

src/test/java/com/mastercard/developer/encryption/FieldLevelEncryptionWithDefaultJsonEngineTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public void testDecryptPayload_ShouldDecryptArrayFields() throws Exception {
752752
public void testDecryptPayload_ShouldDecryptRootArrays() throws Exception {
753753

754754
// GIVEN
755-
String encryptedPayload = "{\n" +
755+
String encryptedPayload = "{" +
756756
" \"encryptedValue\": \"3496b0c505bcea6a849f8e30b553e6d4\"," +
757757
" \"iv\": \"ed82c0496e9d5ac769d77bdb2eb27958\"," +
758758
" \"encryptedKey\": \"29ea447b70bdf85dd509b5d4a23dc0ffb29fd1acf50ed0800ec189fbcf1fb813fa075952c3de2915d63ab42f16be2ed46dc27ba289d692778a1d585b589039ba0b25bad326d699c45f6d3cffd77b5ec37fe12e2c5456d49980b2ccf16402e83a8e9765b9b93ca37d4d5181ec3e5327fd58387bc539238f1c20a8bc9f4174f5d032982a59726b3e0b9cf6011d4d7bfc3afaf617e768dea6762750bce07339e3e55fdbd1a1cd12ee6bbfbc3c7a2d7f4e1313410eb0dad13e594a50a842ee1b2d0ff59d641987c417deaa151d679bc892e5c051b48781dbdefe74a12eb2b604b981e0be32ab81d01797117a24fbf6544850eed9b4aefad0eea7b3f5747b20f65d3f\"," +
@@ -1150,6 +1150,31 @@ public void testDecryptPayload_ShouldSupportRootAsInputPathAndOutputPath() throw
11501150
assertPayloadEquals("{\"field1\":\"value1\",\"field2\":\"value2\"}", payload);
11511151
}
11521152

1153+
@Test
1154+
public void testDecryptPayload_ShouldSupportRootAsOutputPath() throws Exception {
1155+
1156+
// GIVEN
1157+
String encryptedPayload = "{" +
1158+
" \"encryptedData\": {" +
1159+
" \"iv\": \"6fef040c8fe8ad9ec56b74efa194b5f7\"," +
1160+
" \"encryptedKey\": \"b04c69e1ca944fd7641ea79f03e5cd540144759212fa50d07c8a97ab30ca8bded324e2d4b8cd2613b25cd6bceac35b76c2fa1b521ff205b5f33eafaf4102efbefd35cae6707f985953d6dac366cca36295b29d8af3d94d5d5d1532158066b9fecfc2cc000f10e4757967e84c043d7db164d7488f5bef28f59c989c4cd316c870da7b7c1d10cfd73b6d285cd43447e9e96702e3e818011b45b0ecda21b02286db04b7c77ab193dcc4a9036beff065a404689b7cea40b6a348554900ae3eb819af9cb53ab800e158051aac8d8075045a06808e3730cd8cbc1b5334dcdc922d0227f6da1518442914ac5f3abf6751dfb5721074459d0626b62e934f6a6e6fd96020\"," +
1161+
" \"encryptedValue\": \"386cdb354a33a5b5ae44fa73622297d0372857d1f7634b45010f691964958e2afca0f7391742dc1243768ccf0b4fce8b\"," +
1162+
" \"encryptionCertificateFingerprint\": \"80810fc13a8319fcf0e2ec322c82a4c304b782cc3ce671176343cfe8160c2279\"," +
1163+
" \"encryptionKeyFingerprint\": \"761b003c1eade3a5490e5000d37887baa5e6ec0e226c07706e599451fc032a79\"," +
1164+
" \"oaepHashingAlgorithm\": \"SHA256\"" +
1165+
" }" +
1166+
"}";
1167+
FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder()
1168+
.withDecryptionPath("$.encryptedData", "$")
1169+
.build();
1170+
1171+
// WHEN
1172+
String payload = FieldLevelEncryption.decryptPayload(encryptedPayload, config);
1173+
1174+
// THEN
1175+
assertPayloadEquals("{\"field1\":\"value1\",\"field2\":\"value2\"}", payload);
1176+
}
1177+
11531178
@Test
11541179
public void testDecryptPayload_ShouldThrowEncryptionException_WhenDecryptionErrorOccurs() throws Exception {
11551180

0 commit comments

Comments
 (0)