Skip to content

Commit

Permalink
fix: Modified modulus, exponent and challenge to Base64 standard (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoGiuliani authored Feb 19, 2024
1 parent cb58af0 commit 7b2db2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {

Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ protected Transaction createTransactionFromIdpayTransactionEntity(IdpayTransacti
transaction.setTimestamp(entity.idpayTransaction.getTimestamp());
transaction.setGoodsCost(entity.idpayTransaction.getGoodsCost());
if (createTransaction) {
transaction.setChallenge(entity.idpayTransaction.getTrxCode().getBytes(StandardCharsets.UTF_8));
transaction.setChallenge(Base64.getEncoder().encode(entity.idpayTransaction.getTrxCode().getBytes(StandardCharsets.UTF_8)));
}
transaction.setTrxCode(entity.idpayTransaction.getTrxCode());
transaction.setQrCode(qrCode);
Expand Down

0 comments on commit 7b2db2f

Please sign in to comment.