Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Java 17 #467

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.

## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-common/releases/tag/vNEXT) 2025

### Quality

- Update source and target compatibility to Java 17. (#467)
- Migrated to Jakarta EE APIs. (#467)

### Dependency Upgrades

- Update Spring Boot to `3.0.13`. (#467)
- Update Google Guava to `32.1.3-jre`. (#467)
- Update Zip4j ot `2.11.5`. (#467)
- Update `org.glassfish:javax.el:3.0.0` to `org.glassfish:jakarta.el:5.0.0-M1`. (#467)

## [[8.6.0]](https://github.com/iExecBlockchainComputing/iexec-common/releases/tag/v8.6.0) 2024-12-19

### New Features
Expand Down
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ repositories {
// 'api' configuration allows to expose dependencies with 'compile' scope in pom
// 'implementation' configuration allows to expose dependencies with 'runtime' scope in pom
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.18')
implementation platform('org.springframework.boot:spring-boot-dependencies:3.0.13')

// feign
api "io.github.openfeign:feign-jackson:$openFeignVersion"
Expand All @@ -61,21 +61,21 @@ dependencies {
// apache commons-lang3
implementation 'org.apache.commons:commons-lang3'

//jaxb required with Java 11
implementation 'javax.xml.bind:jaxb-api'
// xml binding for java 17
implementation 'jakarta.xml.bind:jakarta.xml.bind-api'

// zip
implementation 'net.lingala.zip4j:zip4j:2.3.1'
implementation 'net.lingala.zip4j:zip4j:2.11.5'

// google core libs
implementation 'com.google.guava:guava:28.2-jre'
implementation 'com.google.guava:guava:32.1.3-jre'

implementation 'ch.qos.logback:logback-classic'

implementation 'javax.annotation:javax.annotation-api'
implementation 'javax.validation:validation-api'
implementation 'jakarta.annotation:jakarta.annotation-api'
implementation 'jakarta.validation:jakarta.validation-api'
implementation 'org.hibernate.validator:hibernate-validator'
implementation 'org.glassfish:javax.el:3.0.0'
implementation 'org.glassfish:jakarta.el:5.0.0-M1'

// expiring map
implementation 'net.jodah:expiringmap:0.5.10'
Expand All @@ -85,8 +85,8 @@ java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
sourceCompatibility = "11"
targetCompatibility = "11"
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withJavadocJar()
withSourcesJar()
}
Expand All @@ -96,9 +96,9 @@ testing {
test {
useJUnitJupiter()
dependencies {
implementation 'org.assertj:assertj-core'
implementation 'org.junit.jupiter:junit-jupiter'
implementation 'org.mockito:mockito-junit-jupiter'
implementation 'org.assertj:assertj-core'
// mock-server
implementation "org.mock-server:mockserver-client-java:$mockServerVersion"
implementation "org.mock-server:mockserver-junit-jupiter:$mockServerVersion"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version=8.6.0
iexecCommonsPocoVersion=4.2.0
iexecCommonsPocoVersion=4.2.0-NEXT-SNAPSHOT

nexusUser
nexusPassword
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import com.iexec.commons.poco.utils.BytesUtils;
import com.iexec.commons.poco.utils.EthAddress;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class EthereumNonZeroAddressValidator
implements ConstraintValidator<ValidNonZeroEthereumAddress, String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

package com.iexec.common.chain.validation;

import javax.validation.Constraint;
import javax.validation.Payload;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Constraint(validatedBy = EthereumNonZeroAddressValidator.class)
@Target({ ElementType.METHOD, ElementType.FIELD })
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidNonZeroEthereumAddress {
String message() default "Invalid non-zero Ethereum address";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 IEXEC BLOCKCHAIN TECH
* Copyright 2022-2025 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class PurgeService {
Expand All @@ -28,11 +27,12 @@ public class PurgeService {
public PurgeService(List<Purgeable> services) {
this.services = services;
log.info("The following services are registered to be purged on task completion: {}",
services.stream().map(Purgeable::getClass).collect(Collectors.toList()));
services.stream().map(Purgeable::getClass).toList());
}

/**
* On each registered service, calls {@link Purgeable#purgeTask(String)} with given chain task ID.
*
* @param chainTaskId Task ID whose data should be purged from registered services.
* @return {@literal true} if there's no more reference to task data in all registered services,
* {@literal false} otherwise.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.iexec.common.lifecycle.purge;

import javax.annotation.PreDestroy;
import jakarta.annotation.PreDestroy;

public interface Purgeable {
/**
Expand Down
73 changes: 36 additions & 37 deletions src/main/java/com/iexec/common/security/CipherUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,17 +17,16 @@
package com.iexec.common.security;

import com.iexec.common.utils.FileHelper;
import jakarta.annotation.Nonnull;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nonnull;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.*;
Expand All @@ -49,7 +48,7 @@ public class CipherUtils {

/**
* Generate a 256 bits AES key.
*
*
* @return 256 bits key if success,
* empty byte array otherwise.
*/
Expand All @@ -60,7 +59,7 @@ public static byte[] generateAesKey() {
/**
* Generate an AES symmetric key with the
* given size.
*
*
* @param size
* @return Generated AES key if success,
* empty byte array otherwise.
Expand All @@ -79,6 +78,7 @@ public static byte[] generateAesKey(int size) {

/**
* Generate a 16 bytes initialization vector.
*
* @return generated binary IV.
*/
public static byte[] generateIv() {
Expand All @@ -88,6 +88,7 @@ public static byte[] generateIv() {
/**
* Generate an initialization vector with
* the given size.
*
* @param size
* @return generated binary IV.
*/
Expand All @@ -101,7 +102,7 @@ public static byte[] generateIv(int size) {
* Extract IV (initialization vector) from the
* encrypted data. The IV occupies the first
* 16 bytes of the data.
*
*
* @param dataWithIv
* @return Extracted 16 bytes IV
*/
Expand All @@ -112,7 +113,7 @@ public static byte[] getIvFromEncryptedData(byte[] dataWithIv) {
/**
* Remove prepended IV (initialization vector)
* from the encrypted data.
*
*
* @param dataWithIv
* @return a new array without the IV.
*/
Expand All @@ -123,7 +124,7 @@ public static byte[] stripIvFromEncryptedData(byte[] dataWithIv) {
/**
* Concatenate IV (initialization vector) to the
* beginning of the encrypted data.
*
*
* @param iv
* @param encryptedData
* @return
Expand All @@ -146,12 +147,11 @@ public static byte[] prependIvToEncryptedData(byte[] iv, byte[] encryptedData)
* Note: PKCS5Padding is equivalent to PKCS7Padding
* <p>
* Ref: https://stackoverflow.com/a/10194082/7631879
*
*
* @param plainData to encrypt
* @param base64Key Base64 encoded AES key
* @return encrypted data prepended with the IV.
* @throws GeneralSecurityException
*
* @see <a href="https://stackoverflow.com/a/34004582">AES encryption on file over 1GB</a> for large files
*/
public static byte[] aesEncrypt(byte[] plainData, byte[] base64Key)
Expand All @@ -170,18 +170,17 @@ public static byte[] aesEncrypt(byte[] plainData, byte[] base64Key)
* Note: PKCS5Padding is equivalent to PKCS7Padding
* <p>
* Ref: https://stackoverflow.com/a/10194082/7631879
*
*
* @param plainData to encrypt
* @param key
* @param iv initialization vector
* @param iv initialization vector
* @return Encrypted data
* @throws GeneralSecurityException
*
* @see <a href="https://stackoverflow.com/a/34004582">AES encryption on file over 1GB</a> for large files
*/
public static byte[] aesEncrypt(
@Nonnull byte[] plainData,
@Nonnull byte[] key,
@Nonnull byte[] plainData,
@Nonnull byte[] key,
@Nonnull byte[] iv) throws GeneralSecurityException {
Objects.requireNonNull(plainData, "data cannot be null");
Objects.requireNonNull(key, "AES key cannot be null");
Expand All @@ -202,14 +201,13 @@ public static byte[] aesEncrypt(
* Note: PKCS5Padding is equivalent to PKCS7Padding
* <p>
* Ref: https://stackoverflow.com/a/10194082/7631879
*
*
* @param ivAndEncryptedData to decrypt
* @param base64Key Base64 encoded AES key
* @param base64Key Base64 encoded AES key
* @return Decrypted data
* @throws GeneralSecurityException
* @throws IllegalArgumentException if the data's length
* is less than 16 bytes.
*
* is less than 16 bytes.
* @see <a href="https://stackoverflow.com/a/34004582">AES encryption on file over 1GB</a> for large files
*/
public static byte[] aesDecrypt(byte[] ivAndEncryptedData, byte[] base64Key)
Expand All @@ -231,7 +229,7 @@ public static byte[] aesDecrypt(byte[] ivAndEncryptedData, byte[] base64Key)
* Note: PKCS5Padding is equivalent to PKCS7Padding
* <p>
* Ref: https://stackoverflow.com/a/10194082/7631879
*
*
* @param plainData
* @param key
* @param iv
Expand All @@ -258,7 +256,7 @@ public static byte[] aesDecrypt(

/**
* Generate 2048 bits RSA key pair.
*
*
* @return Optional of generated key pair
* if success, empty optional otherwise.
*/
Expand All @@ -268,7 +266,7 @@ public static Optional<KeyPair> generateRsaKeyPair() {

/**
* Generate RSA key pair with the given size.
*
*
* @param size in bits
* @return Optional of generated key pair if
* success, empty optional otherwise.
Expand All @@ -287,28 +285,28 @@ public static Optional<KeyPair> generateRsaKeyPair(int size) {

/**
* RSA-Encrypt data with the public key.
*
*
* @param plainData to encrypt
* @param publicKey
* @return encrypted data
* @throws GeneralSecurityException
*/
public static byte[] rsaEncrypt(
@Nonnull byte[] plainData,
public static byte[] rsaEncrypt(
@Nonnull byte[] plainData,
@Nonnull PublicKey publicKey) throws GeneralSecurityException {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return cipher.doFinal(plainData);
}
}

/**
* RSA-Decrypt data with the private key.
*
* @param encryptedData
* @param privateKey
* @return
* @throws GeneralSecurityException
*/
/**
* RSA-Decrypt data with the private key.
*
* @param encryptedData
* @param privateKey
* @return
* @throws GeneralSecurityException
*/
public static byte[] rsaDecrypt(
@Nonnull byte[] encryptedData,
@Nonnull PrivateKey privateKey) throws GeneralSecurityException {
Expand All @@ -319,7 +317,7 @@ public static byte[] rsaDecrypt(

/**
* Read RSA key pair from files.
*
*
* @param publicKeyFilepath
* @param privateKeyFilepath
* @return Optional of keyPair if success,
Expand All @@ -339,10 +337,10 @@ public static Optional<KeyPair> readRsaKeyPair(String publicKeyFilepath, String
KeyPair keyPair = new KeyPair(publicKey.get(), privateKey.get());
return Optional.of(keyPair);
}

/**
* Get RSA public key from Base64 string.
*
*
* @param base64RsaPublicKey
* @return Optional of publicKey is success,
* empty optional otherwise.
Expand All @@ -365,6 +363,7 @@ public static Optional<PublicKey> base64ToRsaPublicKey(String base64RsaPublicKey

/**
* Get RSA private key from Base64 text.
*
* @param base64RsaPrivateKey
* @return Optional of privateKey if success,
* empty optional otherwise.
Expand Down
Loading