Skip to content

Commit 143c741

Browse files
Merge branch 'main' into dependabot/maven/org.json-json-20231013
2 parents 6a66aa2 + b81c8cb commit 143c741

32 files changed

+431
-125
lines changed

.github/workflows/maven-test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ jobs:
1515
strategy:
1616
matrix:
1717
java:
18-
- 8
19-
- 9
2018
- 11
21-
- 12
22-
- 13
23-
- 14
19+
- 17
2420
steps:
25-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v1
2622
with:
2723
fetch-depth: 0
2824
- name: 'Set up JDK ${{ matrix.java }}'

.github/workflows/sonar-scan.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,27 @@ jobs:
1414
build:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
17+
18+
- name: Set up JDK
19+
uses: actions/setup-java@v1
20+
with:
21+
java-version: 17
22+
java-package: jdk
23+
24+
- uses: actions/checkout@v1
1825
with:
1926
fetch-depth: 0
27+
2028
- name: Check for external PR
2129
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'safe') ||
2230
github.event.pull_request.head.repo.full_name == github.repository ||
2331
github.event_name != 'pull_request_target') }}
2432
run: echo "Unsecure PR, must be labelled with the 'safe' label, then run the workflow again" && exit 1
25-
- name: Set up JDK
26-
uses: actions/setup-java@v1
27-
with:
28-
java-version: 11
33+
2934
- name: Build with Maven
30-
run: mvn clean install -Dgpg.signature.skip=true --file pom.xml
35+
run: >-
36+
mvn clean install -Dgpg.signature.skip=true --file pom.xml
37+
3138
- name: Sonar Scan
3239
env:
3340
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Overview](#overview)
1313
* [Compatibility](#compatibility)
1414
* [References](#references)
15+
* [Versioning and Deprecation Policy](#versioning)
1516
- [Usage](#usage)
1617
* [Prerequisites](#prerequisites)
1718
* [Adding the Library to Your Project](#adding-the-library-to-your-project)
@@ -28,12 +29,15 @@
2829
Library for Mastercard API compliant payload encryption/decryption.
2930

3031
### Compatibility <a name="compatibility"></a>
31-
Java 8+
32+
Java 11+
3233

3334
### References <a name="references"></a>
3435
* [JSON Web Encryption (JWE)](https://datatracker.ietf.org/doc/html/rfc7516)
3536
* [Securing Sensitive Data Using Payload Encryption](https://developer.mastercard.com/platform/documentation/security-and-authentication/securing-sensitive-data-using-payload-encryption/)
3637

38+
### Versioning and Deprecation Policy <a name="versioning"></a>
39+
* [Mastercard Versioning and Deprecation Policy](https://github.com/Mastercard/.github/blob/main/CLIENT_LIBRARY_DEPRECATION_POLICY.md)
40+
3741
## Usage <a name="usage"></a>
3842
### Prerequisites <a name="prerequisites"></a>
3943
Before using this library, you will need to set up a project in the [Mastercard Developers Portal](https://developer.mastercard.com).
@@ -67,7 +71,7 @@ See: https://search.maven.org/artifact/com.mastercard.developer/client-encryptio
6771

6872
This library requires one of the following dependencies to be added to your classpath:
6973

70-
* [Jackson](https://search.maven.org/artifact/com.fasterxml.jackson.core/jackson-databind) 2.4.5+
74+
* [Jackson](https://search.maven.org/artifact/com.fasterxml.jackson.core/jackson-databind) 2.5.0+
7175
* [Google Gson](https://search.maven.org/artifact/com.google.code.gson/gson) 2.3.1+
7276
* [Json-smart](https://search.maven.org/artifact/net.minidev/json-smart) 2.1.1+
7377
* [Jettison](https://search.maven.org/artifact/org.codehaus.jettison/jettison) 1.0+
@@ -166,6 +170,7 @@ JweConfig config = JweConfigBuilder.aJweEncryptionConfig()
166170
.withEncryptionPath("$.path.to.foo", "$.path.to.encryptedFoo")
167171
.withDecryptionPath("$.path.to.encryptedFoo.encryptedValue", "$.path.to.foo")
168172
.withEncryptedValueFieldName("encryptedValue")
173+
.withIVSize(16) // available values are 12 or 16. If not specified, default value is 16.
169174
.build();
170175
```
171176

pom.xml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
<groupId>com.mastercard.developer</groupId>
88
<artifactId>client-encryption</artifactId>
9-
<version>1.7.10</version>
9+
<version>1.8.2</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>
1313
<name>client-encryption</name>
1414

1515
<properties>
16-
<okhttp2-version>2.7.5</okhttp2-version>
17-
<okhttp3-version>4.8.1</okhttp3-version>
18-
<google-api-client-version>1.23.0</google-api-client-version>
19-
<feign-version>9.7.0</feign-version>
16+
<okhttp3-version>4.12.0</okhttp3-version>
17+
<google-api-client-version>2.4.0</google-api-client-version>
18+
<feign-version>13.2.1</feign-version>
2019
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2120
<gpg.signature.skip>false</gpg.signature.skip>
2221
</properties>
@@ -52,7 +51,7 @@
5251
<dependency>
5352
<groupId>com.jayway.jsonpath</groupId>
5453
<artifactId>json-path</artifactId>
55-
<version>2.6.0</version>
54+
<version>2.9.0</version>
5655
</dependency>
5756

5857
<dependency>
@@ -69,13 +68,6 @@
6968
<scope>provided</scope>
7069
</dependency>
7170

72-
<dependency>
73-
<groupId>com.squareup.okhttp</groupId>
74-
<artifactId>okhttp</artifactId>
75-
<version>${okhttp2-version}</version>
76-
<scope>provided</scope>
77-
</dependency>
78-
7971
<dependency>
8072
<groupId>com.google.api-client</groupId>
8173
<artifactId>google-api-client</artifactId>
@@ -96,7 +88,6 @@
9688
<version>4.13.1</version>
9789
<scope>test</scope>
9890
</dependency>
99-
10091
<dependency>
10192
<groupId>org.junit.jupiter</groupId>
10293
<artifactId>junit-jupiter-params</artifactId>
@@ -107,7 +98,7 @@
10798
<dependency>
10899
<groupId>org.mockito</groupId>
109100
<artifactId>mockito-core</artifactId>
110-
<version>3.5.5</version>
101+
<version>5.10.0</version>
111102
<scope>test</scope>
112103
</dependency>
113104

@@ -135,7 +126,7 @@
135126
<dependency>
136127
<groupId>net.minidev</groupId>
137128
<artifactId>json-smart</artifactId>
138-
<version>2.4.9</version>
129+
<version>2.5.0</version>
139130
<scope>test</scope>
140131
</dependency>
141132

@@ -163,9 +154,23 @@
163154

164155
<profiles>
165156
<profile>
166-
<id>java11+</id>
157+
<id>java11</id>
158+
<activation>
159+
<jdk>11</jdk>
160+
</activation>
161+
<properties>
162+
<!-- The Javadoc generation started to fail with OpenJDK 11.0.2 (11.0.1 was OK) and OpenJDK 12-ea:
163+
"The code being documented uses modules but the packages defined in
164+
https://docs.oracle.com/javase/7/docs/api/ are in the unnamed module."
165+
See: https://bugs.openjdk.java.net/browse/JDK-8212233
166+
-->
167+
<maven.javadoc.skip>true</maven.javadoc.skip>
168+
</properties>
169+
</profile>
170+
<profile>
171+
<id>java17</id>
167172
<activation>
168-
<jdk>[11,)</jdk>
173+
<jdk>17</jdk>
169174
</activation>
170175
<properties>
171176
<!-- The Javadoc generation started to fail with OpenJDK 11.0.2 (11.0.1 was OK) and OpenJDK 12-ea:
@@ -184,7 +189,7 @@
184189
<plugin>
185190
<groupId>org.apache.maven.plugins</groupId>
186191
<artifactId>maven-compiler-plugin</artifactId>
187-
<version>3.8.1</version>
192+
<version>3.12.1</version>
188193
<configuration>
189194
<source>1.8</source>
190195
<target>1.8</target>
@@ -196,7 +201,7 @@
196201
<plugin>
197202
<groupId>org.jacoco</groupId>
198203
<artifactId>jacoco-maven-plugin</artifactId>
199-
<version>0.8.5</version>
204+
<version>0.8.7</version>
200205
<executions>
201206
<execution>
202207
<id>pre-unit-test</id>
@@ -216,7 +221,7 @@
216221
<plugin>
217222
<groupId>org.apache.maven.plugins</groupId>
218223
<artifactId>maven-gpg-plugin</artifactId>
219-
<version>1.6</version>
224+
<version>3.1.0</version>
220225
<executions>
221226
<execution>
222227
<id>sign-artifacts</id>
@@ -233,7 +238,7 @@
233238
<plugin>
234239
<groupId>org.apache.maven.plugins</groupId>
235240
<artifactId>maven-source-plugin</artifactId>
236-
<version>3.2.1</version>
241+
<version>3.3.0</version>
237242
<executions>
238243
<execution>
239244
<id>attach-sources</id>
@@ -246,7 +251,7 @@
246251
<plugin>
247252
<groupId>org.apache.maven.plugins</groupId>
248253
<artifactId>maven-javadoc-plugin</artifactId>
249-
<version>3.2.0</version>
254+
<version>3.6.3</version>
250255
<executions>
251256
<execution>
252257
<id>generate-javadoc</id>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public enum Scheme {
4646
*/
4747
PrivateKey decryptionKey;
4848

49+
50+
/**
51+
* IV size in bytes
52+
*/
53+
54+
Integer ivSize = 16;
55+
4956
/**
5057
* A list of JSON paths to encrypt in request payloads.
5158
* Example:
@@ -107,4 +114,6 @@ Map<String, String> getDecryptionPaths() {
107114
String getEncryptedValueFieldName() {
108115
return encryptedValueFieldName;
109116
}
117+
118+
public Integer getIVSize() { return ivSize; }
110119
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ abstract class EncryptionConfigBuilder {
2323
protected Map<String, String> decryptionPaths = new HashMap<>();
2424
protected String encryptedValueFieldName;
2525

26+
protected Integer ivSize = 16;
27+
2628
void computeEncryptionKeyFingerprintWhenNeeded() throws EncryptionException {
2729
try {
2830
if ((encryptionCertificate == null && encryptionKey == null) || !isNullOrEmpty(encryptionKeyFingerprint)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private static Object readAndDeleteJsonKey(DocumentContext context, String objec
210210
}
211211
JsonProvider jsonProvider = JsonParser.jsonPathConfig.jsonProvider();
212212
Object value = jsonProvider.getMapValue(object, key);
213-
context.delete(objectPath + "." + key);
213+
JsonParser.deleteIfExists(context, objectPath + "." + key);
214214
return value;
215215
}
216216
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ public FieldLevelEncryptionConfigBuilder withEncryptionKeyFingerprintHeaderName(
186186
return this;
187187
}
188188

189+
/**
190+
* See: {@link EncryptionConfig#ivSize}.
191+
*/
192+
public FieldLevelEncryptionConfigBuilder withEncryptionIVSize(Integer ivSize) {
193+
if (ivSize == 12 || ivSize == 16) {
194+
this.ivSize = ivSize;
195+
return this;
196+
}
197+
throw new IllegalArgumentException("Supported IV Sizes are either 12 or 16!");
198+
}
189199
/**
190200
* Build a {@link com.mastercard.developer.encryption.FieldLevelEncryptionConfig}.
191201
* @throws EncryptionException
@@ -209,6 +219,7 @@ public FieldLevelEncryptionConfig build() throws EncryptionException {
209219
config.encryptionCertificate = this.encryptionCertificate;
210220
config.oaepPaddingDigestAlgorithm = this.oaepPaddingDigestAlgorithm;
211221
config.ivFieldName = this.ivFieldName;
222+
config.ivSize = this.ivSize;
212223
config.oaepPaddingDigestAlgorithmFieldName = this.oaepPaddingDigestAlgorithmFieldName;
213224
config.decryptionPaths = this.decryptionPaths;
214225
config.encryptedKeyFieldName = this.encryptedKeyFieldName;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public FieldLevelEncryptionParams(String ivValue, String encryptedKeyValue, Stri
4343
public static FieldLevelEncryptionParams generate(FieldLevelEncryptionConfig config) throws EncryptionException {
4444

4545
// Generate a random IV
46-
IvParameterSpec ivParameterSpec = AESEncryption.generateIv();
46+
IvParameterSpec ivParameterSpec = AESEncryption.generateIv(config.getIVSize());
4747
String ivSpecValue = encodeBytes(ivParameterSpec.getIV(), config.fieldValueEncoding);
4848

4949
// Generate an AES secret key

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void addDecryptedDataToPayload(DocumentContext payloadContext, String dec
4747
int length = jsonProvider.length(decryptedValueJsonElement);
4848
Collection<String> propertyKeys = (0 == length) ? Collections.emptyList() : jsonProvider.getPropertyKeys(decryptedValueJsonElement);
4949
for (String key : propertyKeys) {
50-
payloadContext.delete(jsonPathOut + "." + key);
50+
deleteIfExists( payloadContext, jsonPathOut + "." + key);
5151
payloadContext.put(jsonPathOut, key, jsonProvider.getMapValue(decryptedValueJsonElement, key));
5252
}
5353
}
@@ -86,4 +86,11 @@ static Object readJsonObject(DocumentContext context, String jsonPathString) {
8686
}
8787
return jsonElement;
8888
}
89+
90+
static void deleteIfExists(DocumentContext context, String jsonPathString){
91+
Object value = context.read(jsonPathString);
92+
if(value != null){
93+
context.delete(jsonPathString);
94+
}
95+
}
8996
}

0 commit comments

Comments
 (0)