Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pagopa/mil-idpay
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.0.5
Choose a base ref
...
head repository: pagopa/mil-idpay
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Feb 12, 2024

  1. Copy the full SHA
    8761ecb View commit details
  2. pom.xml updated with new version 5.0.6

    GitHub Workflow committed Feb 12, 2024
    Copy the full SHA
    aa21d5c View commit details
  3. Copy the full SHA
    347eb95 View commit details
  4. pom.xml updated with new version 5.0.7

    GitHub Workflow committed Feb 12, 2024
    Copy the full SHA
    e833ec0 View commit details
  5. Copy the full SHA
    13ba4b3 View commit details
  6. pom.xml updated with new version 5.0.8

    GitHub Workflow committed Feb 12, 2024
    Copy the full SHA
    e47393c View commit details

Commits on Feb 16, 2024

  1. Copy the full SHA
    7c1bfb2 View commit details
  2. fix: Modified string input to byte[] (#32)

    Co-authored-by: EBOBROAFF <alexander.bobrov@nttdata.com>
    RiccardoGiuliani and AlexBobrov75 authored Feb 16, 2024
    Copy the full SHA
    d1dbeda View commit details

Commits on Feb 19, 2024

  1. pom.xml updated with new version 5.0.9

    GitHub Workflow committed Feb 19, 2024
    Copy the full SHA
    5752063 View commit details
  2. Copy the full SHA
    8dd777a View commit details
  3. pom.xml updated with new version 5.0.10

    GitHub Workflow committed Feb 19, 2024
    Copy the full SHA
    cb58af0 View commit details
  4. Copy the full SHA
    7b2db2f View commit details
  5. pom.xml updated with new version 5.0.11

    GitHub Workflow committed Feb 19, 2024
    Copy the full SHA
    7957bd3 View commit details

Commits on Feb 20, 2024

  1. Copy the full SHA
    89c37cd View commit details
  2. pom.xml updated with new version 5.0.12

    GitHub Workflow committed Feb 20, 2024
    Copy the full SHA
    9dfd37c View commit details

Commits on Feb 21, 2024

  1. Copy the full SHA
    2e39304 View commit details
  2. pom.xml updated with new version 5.0.13

    GitHub Workflow committed Feb 21, 2024
    Copy the full SHA
    dac97e6 View commit details

Commits on Apr 5, 2024

  1. Copy the full SHA
    1be5421 View commit details

Commits on Apr 9, 2024

  1. pom.xml updated with new version 5.1.0

    GitHub Workflow committed Apr 9, 2024
    Copy the full SHA
    aaf862e View commit details

Commits on May 22, 2024

  1. Copy the full SHA
    568ac17 View commit details
  2. pom.xml updated with new version 5.1.1

    GitHub Workflow committed May 22, 2024
    Copy the full SHA
    b934a27 View commit details

Commits on Sep 11, 2024

  1. Update CODEOWNERS

    antoniotarricone authored Sep 11, 2024
    Copy the full SHA
    d876357 View commit details
Showing with 236 additions and 219 deletions.
  1. +1 −1 CODEOWNERS
  2. +1 −1 pom.xml
  3. +1 −6 src/main/java/it/pagopa/swclient/mil/idpay/ErrorCode.java
  4. +13 −9 src/main/java/it/pagopa/swclient/mil/idpay/azurekeyvault/service/AzureKeyVaultService.java
  5. +22 −16 src/main/java/it/pagopa/swclient/mil/idpay/azurekeyvault/util/EncryptUtil.java
  6. +2 −2 src/main/java/it/pagopa/swclient/mil/idpay/bean/AuthCodeBlockData.java
  7. +0 −5 src/main/java/it/pagopa/swclient/mil/idpay/bean/AuthMessageType.java
  8. +11 −2 src/main/java/it/pagopa/swclient/mil/idpay/bean/AuthTransactionResponse.java
  9. +0 −21 src/main/java/it/pagopa/swclient/mil/idpay/bean/AuthTransactionResponseOk.java
  10. +0 −14 src/main/java/it/pagopa/swclient/mil/idpay/bean/AuthTransactionResponseWrong.java
  11. +19 −5 src/main/java/it/pagopa/swclient/mil/idpay/client/IdpayRestClient.java
  12. +2 −2 src/main/java/it/pagopa/swclient/mil/idpay/client/bean/PreAuthPaymentResponseDTO.java
  13. +3 −3 src/main/java/it/pagopa/swclient/mil/idpay/client/bean/TransactionResponse.java
  14. +14 −7 src/main/java/it/pagopa/swclient/mil/idpay/resource/TransactionsResource.java
  15. +28 −43 src/main/java/it/pagopa/swclient/mil/idpay/service/TransactionsService.java
  16. +22 −12 src/main/resources/META-INF/openapi.yaml
  17. +1 −1 src/main/resources/application.properties
  18. +79 −48 src/test/java/it/pagopa/swclient/mil/idpay/TransactionResourceAuthorizationTest.java
  19. +4 −4 src/test/java/it/pagopa/swclient/mil/idpay/TransactionsResourceTest.java
  20. +8 −12 src/test/java/it/pagopa/swclient/mil/idpay/util/TransactionsTestData.java
  21. +5 −5 src/test/postman/postman_collection.json
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @pagopa/swc-mil-team
* @pagopa/swc-mil-team-admin
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.pagopa.swclient.mil</groupId>
<artifactId>idpay</artifactId>
<version>5.0.5</version>
<version>5.1.1</version>
<description>IDPay Microservice for Multi-channel Integration Layer of SW Client Project</description>
<properties>
<java.version>17</java.version>
7 changes: 1 addition & 6 deletions src/main/java/it/pagopa/swclient/mil/idpay/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -44,8 +44,7 @@ public final class ErrorCode {
public static final String ERROR_CALLING_IDPAY_REST_SERVICES = MODULE_ID + "000050";
public static final String ERROR_NOT_FOUND_IDPAY_REST_SERVICES = MODULE_ID + "000051";
public static final String ERROR_CALLING_AUTHORIZE_REST_SERVICES = MODULE_ID + "000052";
public static final String ERROR_IDPAY_WRONG_AUTH_CODE = MODULE_ID + "000053";
public static final String ERROR_IDPAY_UNKNOWN_ERROR_CODE = MODULE_ID + "000054";
public static final String ERROR_IDPAY_PAYMENT_INVALID_PINBLOCK = MODULE_ID + "000053";
public static final String ERROR_RETRIEVING_SECOND_FACTOR = MODULE_ID + "000055";
public static final String ERROR_PIN_CIE_CURRENT_USER = MODULE_ID + "000056";

@@ -95,8 +94,6 @@ public final class ErrorCode {
public static final String ERROR_RETRIEVING_KEY_PAIR_DESCR = "Azure KV key pair retrieving error";
public static final String ERROR_CALLING_AUTHORIZE_REST_SERVICES_DESCR = "Error calling IdPay rest service with authorize transaction";
public static final String ERROR_RETRIEVING_PUBLIC_KEY_IDPAY_DESCR = "IDPay public key retrieving error";
public static final String ERROR_IDPAY_WRONG_AUTH_CODE_DESCR = "IDPay responds with WRONG_AUTH_CODE";
public static final String ERROR_IDPAY_UNKNOWN_ERROR_DESCR = "IDPay responds with an unknown error 500";
public static final String ERROR_ENCRYPTING_SESSION_KEY_DESCR = "Error occurs during encrypting session key";
public static final String ERROR_RETRIEVING_SECOND_FACTOR_DESCR = "Error retrieving second factor";
public static final String ERROR_RETRIEVING_CERT_FOR_IDPAY_DESCR = "Azure KV certificate for idpay retrieving error";
@@ -126,8 +123,6 @@ public final class ErrorCode {
public static final String ERROR_RETRIEVING_KEY_PAIR_MSG = "[" + ERROR_RETRIEVING_KEY_PAIR + "] " + ERROR_RETRIEVING_KEY_PAIR_DESCR;
public static final String ERROR_CALLING_AUTHORIZE_REST_SERVICES_MSG = "[" + ERROR_CALLING_AUTHORIZE_REST_SERVICES + "] " + ERROR_CALLING_AUTHORIZE_REST_SERVICES_DESCR;
public static final String ERROR_RETRIEVING_PUBLIC_KEY_IDPAY_MSG = "[" + ERROR_RETRIEVING_PUBLIC_KEY_IDPAY + "] " + ERROR_RETRIEVING_PUBLIC_KEY_IDPAY_DESCR;
public static final String ERROR_IDPAY_WRONG_AUTH_CODE_MSG = "[" + ERROR_IDPAY_WRONG_AUTH_CODE + "] " + ERROR_IDPAY_WRONG_AUTH_CODE_DESCR;
public static final String ERROR_IDPAY_UNKNOWN_ERROR_MSG = "[" + ERROR_IDPAY_UNKNOWN_ERROR_CODE + "] " + ERROR_IDPAY_UNKNOWN_ERROR_DESCR;
public static final String ERROR_ENCRYPTING_SESSION_KEY_MSG = "[" + ERROR_ENCRYPTING_SESSION_KEY + "] " + ERROR_ENCRYPTING_SESSION_KEY_DESCR;
public static final String ERROR_RETRIEVING_SECOND_FACTOR_MSG = "[" + ERROR_RETRIEVING_SECOND_FACTOR + "] " + ERROR_RETRIEVING_SECOND_FACTOR_DESCR;
public static final String ERROR_RETRIEVING_CERT_FOR_IDPAY_MSG = "[" + ERROR_RETRIEVING_CERT_FOR_IDPAY + "] " + ERROR_RETRIEVING_CERT_FOR_IDPAY_DESCR;
Original file line number Diff line number Diff line change
@@ -15,17 +15,13 @@
import it.pagopa.swclient.mil.idpay.bean.PublicKeyUse;
import it.pagopa.swclient.mil.idpay.client.bean.azure.AccessToken;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;

@ApplicationScoped
public class AzureKeyVaultService {
@@ -46,8 +42,11 @@ public class AzureKeyVaultService {

private static final String BEARER = "Bearer ";

@Inject
KidUtil kidUtil;
private final KidUtil kidUtil;

public AzureKeyVaultService(KidUtil kidUtil) {
this.kidUtil = kidUtil;
}

public Uni<PublicKeyIDPay> getAzureKVKey(AccessToken accessToken, CommonHeader headers) {

@@ -204,11 +203,16 @@ private PublicKeyIDPay generateKVKey(DetailedKey key) {

KeyNameAndVersion keyNameAndVersion = kidUtil.getNameAndVersionFromAzureKid(key.getDetails().getKid());

//Exponent and modulus converted to base64 standard
String exponent = Base64.getEncoder().encodeToString(Base64.getUrlDecoder().decode(key.getDetails().getExponent()));
String modulus = Base64.getEncoder().encodeToString(Base64.getUrlDecoder().decode(key.getDetails().getModulus()));


return new PublicKeyIDPay(
key.getDetails().getExponent(),
exponent,
PublicKeyUse.enc,
kidUtil.getMyKidFromNameAndVersion(keyNameAndVersion),
key.getDetails().getModulus(),
modulus,
KeyType.RSA,
key.getAttributes().getExp(),
key.getAttributes().getCreated(),
Original file line number Diff line number Diff line change
@@ -3,30 +3,29 @@
import it.pagopa.swclient.mil.idpay.bean.PublicKeyIDPay;
import jakarta.enterprise.context.ApplicationScoped;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.OAEPParameterSpec;
import javax.crypto.spec.PSource;
import java.math.BigInteger;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;

@ApplicationScoped
public class EncryptUtil {

public String encryptSessionKeyForIdpay(PublicKeyIDPay publicKeyIDPay, String sessionKey) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
public String encryptSessionKeyForIdpay(PublicKeyIDPay publicKeyIDPay, String sessionKey) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {
String modulusBase64 = publicKeyIDPay.getN();
String exponentBase64 = publicKeyIDPay.getE();

// Decode Base64 values in byte
byte[] modulusBytes = Base64.getUrlDecoder().decode(modulusBase64);
byte[] exponentBytes = Base64.getUrlDecoder().decode(exponentBase64);
byte[] modulusBytes = decodeBase64UrlOrBase64(modulusBase64);
byte[] exponentBytes = decodeBase64UrlOrBase64(exponentBase64);

// Create specific RSA public key
RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(
@@ -38,12 +37,19 @@ public String encryptSessionKeyForIdpay(PublicKeyIDPay publicKeyIDPay, String se
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey rsaPublicKey = keyFactory.generatePublic(rsaPublicKeySpec);

Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
byte[] sessionKeyBytes = sessionKey.getBytes(StandardCharsets.UTF_8);
cipher.init(Cipher.ENCRYPT_MODE, rsaPublicKey);
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPPadding");
OAEPParameterSpec oaepParams = new OAEPParameterSpec("SHA-256", "MGF1",
new MGF1ParameterSpec("SHA-256"), PSource.PSpecified.DEFAULT);
cipher.init(Cipher.ENCRYPT_MODE, rsaPublicKey, oaepParams);

byte[] sessionKeyBytes = decodeBase64UrlOrBase64(sessionKey);
byte[] encryptedSessionKeyBytes = cipher.doFinal(sessionKeyBytes);

// encryptedSessionKeyBytes contains encrypted session key
return Base64.getUrlEncoder().encodeToString(encryptedSessionKeyBytes);
return Base64.getEncoder().encodeToString(encryptedSessionKeyBytes);
}

private byte[] decodeBase64UrlOrBase64(String base64) {
return (base64.contains("-") || base64.contains("_") ? Base64.getUrlDecoder() : Base64.getDecoder()).decode(base64);
}
}
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@ public class AuthCodeBlockData {

@NotNull(message = "[" + ErrorCode.ERROR_ENCSESSIONKEY_MUST_NOT_BE_NULL + "] encSessionKey must not be null")
@Size(min = 256, max = 2048, message = "[" + ErrorCode.ERROR_ENCSESSIONKEY_MUST_BE_BETWEEN + "] encSessionKey must be between than {min} and {max}")
private String encSessionKey;
private byte[] encSessionKey;

@NotNull(message = "[" + ErrorCode.ERROR_AUTHCODEBLOCK_MUST_NOT_BE_NULL + "] authCodeBlock must not be null")
@Size(min = 16, max = 16, message = "[" + ErrorCode.ERROR_AUTHCODEBLOCK_MUST_BE_BETWEEN + "] authCodeBlock must be between than {min} and {max}")
private String authCodeBlock;
private byte[] authCodeBlock;

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;

@Data
@Builder
@@ -13,6 +14,14 @@
@RegisterForReflection
public class AuthTransactionResponse {

private AuthTransactionResponseOk authTransactionResponseOk;
private AuthTransactionResponseWrong authTransactionResponseWrong;
private String id;
private String trxCode;
private Date trxDate;
private String initiativeId;
private String initiativeName;
private String businessName;
private TransactionStatus status;
private Long rewardCents;
private Long amountCents;
private Long residualBudgetCents;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -21,30 +21,44 @@ public interface IdpayRestClient {
@GET
@Path("/idpay/mil/merchant/initiatives")
@ClientHeaderParam(name = "Ocp-Apim-Subscription-Key", value = "${idpay-rest-client.apim-subscription-key}", required = false)
Uni<List<InitiativeDTO>> getMerchantInitiativeList(@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId, @HeaderParam("x-acquirer-id") @NotNull String xAcquirerId);
Uni<List<InitiativeDTO>> getMerchantInitiativeList(
@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId,
@HeaderParam("x-acquirer-id") @NotNull String xAcquirerId);

/*
* TRANSACTIONS
*/
@POST
@Path("/idpay/mil/payment")
@ClientHeaderParam(name = "Ocp-Apim-Subscription-Key", value = "${idpay-rest-client.apim-subscription-key}", required = false)
Uni<TransactionResponse> createTransaction(@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId, @HeaderParam("x-acquirer-id") @NotNull String xAcquirerId, TransactionCreationRequest transactionCreationRequest);
Uni<TransactionResponse> createTransaction(
@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId,
@HeaderParam("x-acquirer-id") @NotNull String xAcquirerId,
TransactionCreationRequest transactionCreationRequest);

@GET
@Path("/idpay/mil/payment/{transactionId}/status")
@ClientHeaderParam(name = "Ocp-Apim-Subscription-Key", value = "${idpay-rest-client.apim-subscription-key}", required = false)
Uni<SyncTrxStatus> getStatusTransaction(@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId, @HeaderParam("x-acquirer-id") @NotNull String xAcquirerId, @PathParam("transactionId") String transactionId);
Uni<SyncTrxStatus> getStatusTransaction(
@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId,
@HeaderParam("x-acquirer-id") @NotNull String xAcquirerId,
@PathParam("transactionId") String transactionId);

@PUT
@Path("/idpay/mil/payment/idpay-code/{transactionId}/preview")
@ClientHeaderParam(name = "Ocp-Apim-Subscription-Key", value = "${idpay-rest-client.apim-subscription-key}", required = false)
Uni<PreAuthPaymentResponseDTO> putPreviewPreAuthPayment(@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId, @HeaderParam("x-acquirer-id") @NotNull String xAcquirerId, @PathParam("transactionId") String transactionId);
Uni<PreAuthPaymentResponseDTO> putPreviewPreAuthPayment(
@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId,
@HeaderParam("x-acquirer-id") @NotNull String xAcquirerId,
@PathParam("transactionId") String transactionId);

@DELETE
@Path("/idpay/mil/payment/{transactionId}")
@ClientHeaderParam(name = "Ocp-Apim-Subscription-Key", value = "${idpay-rest-client.apim-subscription-key}", required = false)
Uni<Void> deleteTransaction(@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId, @HeaderParam("x-acquirer-id") @NotNull String xAcquirerId, @PathParam("transactionId") String transactionId);
Uni<Void> deleteTransaction(
@HeaderParam("x-merchant-fiscalcode") @NotNull String idpayMerchantId,
@HeaderParam("x-acquirer-id") @NotNull String xAcquirerId,
@PathParam("transactionId") String transactionId);

/*
* AUTHORIZE TRANSACTIONS
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ public class PreAuthPaymentResponseDTO {
private String initiativeName;
private String businessName;
private TransactionStatus status;
private Long reward;
private Long rewardCents;
private Long amountCents;
private BigDecimal residualBudget;
private BigDecimal residualBudgetCents;
private String secondFactor;
}
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ public class TransactionResponse {
private String merchantId;
private String idTrxAcquirer;
private Date trxDate;
private BigDecimal trxExpirationMinutes;
private BigDecimal trxExpirationSeconds;
private Long amountCents;
private String amountCurrency;
private String mcc;
@@ -31,7 +31,7 @@ public class TransactionResponse {
private String vat;
private Boolean splitPayment;
private Long residualAmountCents;
private String trxPngUrl;
private String trxTxtUrl;
private String qrcodePngUrl;
private String qrcodeTxtUrl;

}
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
import it.pagopa.swclient.mil.idpay.bean.VerifyCie;
import it.pagopa.swclient.mil.idpay.service.TransactionsService;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
@@ -24,8 +23,12 @@

@Path("/transactions")
public class TransactionsResource {
@Inject
TransactionsService transactionsService;

private final TransactionsService transactionsService;

public TransactionsResource(TransactionsService transactionsService) {
this.transactionsService = transactionsService;
}

/**
* The value of the Max-Retries header to be sent in response to the createTransaction API
@@ -118,10 +121,14 @@ public Uni<Response> cancelTransaction(@Valid @BeanParam CommonHeader headers,
*/
AcqMerchMapper.map(headers);

return transactionsService.cancelTransaction(headers, transactionId).chain(() ->
Uni.createFrom().item(
Response.status(Status.NO_CONTENT).build())
);
return transactionsService.cancelTransaction(headers, transactionId).chain(res -> {
Log.debugf("TransactionsResource -> TransactionsService -> cancelTransaction - Response %s", res);

return Uni.createFrom().item(
Response.status(Response.Status.OK)
.entity(res)
.build());
});
}

private URI getTransactionURI(String milTransactionId) {
Loading