diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d750a715..b8391c93 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,4 +19,5 @@ jobs: # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Use only 'java' to analyze code written in Java, Kotlin or both # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support \ No newline at end of file + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + java_version: 21 \ No newline at end of file diff --git a/.github/workflows/maven-deploy.yml b/.github/workflows/maven-deploy.yml index 58607393..2235cefb 100644 --- a/.github/workflows/maven-deploy.yml +++ b/.github/workflows/maven-deploy.yml @@ -34,6 +34,7 @@ jobs: with: environment: internal-publish release_type: snapshot + java_version: 21 secrets: username: ${{ secrets.MAVEN_CENTRAL_USERNAME }} password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} @@ -45,6 +46,7 @@ jobs: with: environment: ${{ inputs.environment }} release_type: ${{ inputs.release_type }} + java_version: 21 secrets: username: ${{ secrets.MAVEN_CENTRAL_USERNAME }} password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} diff --git a/.github/workflows/maven-test.yml b/.github/workflows/maven-test.yml index 4bba5877..d7d33039 100644 --- a/.github/workflows/maven-test.yml +++ b/.github/workflows/maven-test.yml @@ -17,4 +17,6 @@ on: jobs: maven-tests: uses: wultra/wultra-infrastructure/.github/workflows/maven-test.yml@develop - secrets: inherit \ No newline at end of file + secrets: inherit + with: + java_version: 21 \ No newline at end of file diff --git a/pom.xml b/pom.xml index f7825c57..3e8161a8 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ io.getlime.security powerauth-cmd-parent - 1.6.0 + 1.7.0 pom 2016 @@ -76,24 +76,22 @@ 17 ${java.version} - 3.12.1 - 3.3.0 + 3.13.0 + 3.3.1 3.1.1 3.6.3 3.4.1 - 3.2.3 - 3.1.6 + 3.2.5 + 3.2.4 1.77 1.6.0 - 2.15.1 + 2.16.1 1.1.1 - - 1.4.14 - 1.6.0 - 1.6.0 - 1.8.0 + 1.7.0 + 1.7.0 + 1.9.0 @@ -106,18 +104,6 @@ import - - - ch.qos.logback - logback-classic - ${logback.version} - - - ch.qos.logback - logback-core - ${logback.version} - - io.getlime.security powerauth-java-cmd-lib @@ -191,26 +177,19 @@ org.apache.maven.plugins maven-enforcer-plugin ${maven-enforcer-plugin.version} - - - de.skuzzle.enforcer - restrict-imports-enforcer-rule - 2.4.0 - - - enforce-banned-java-imports + enforce-banned-dependencies enforce - - - Guava depends on jsr305 but we prefer jakarta in our code - javax.annotation.** - + + + com.google.guava:guava*:*:*:compile + + diff --git a/powerauth-java-cmd-lib/pom.xml b/powerauth-java-cmd-lib/pom.xml index 531b45c4..cdcd98a5 100644 --- a/powerauth-java-cmd-lib/pom.xml +++ b/powerauth-java-cmd-lib/pom.xml @@ -10,7 +10,7 @@ powerauth-cmd-parent io.getlime.security - 1.6.0 + 1.7.0 diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/consts/PowerAuthVersion.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/consts/PowerAuthVersion.java index fbada7ca..6f8997fb 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/consts/PowerAuthVersion.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/consts/PowerAuthVersion.java @@ -16,9 +16,8 @@ */ package io.getlime.security.powerauth.lib.cmd.consts; -import com.google.common.collect.ImmutableList; - import java.util.Arrays; +import java.util.List; /** * PowerAuth protocol version enumeration @@ -45,7 +44,7 @@ public enum PowerAuthVersion { /** * All supported versions */ - public static final ImmutableList ALL_VERSIONS = ImmutableList.copyOf(values()); + public static final List ALL_VERSIONS = List.of(values()); /** * Default version @@ -55,7 +54,7 @@ public enum PowerAuthVersion { /** * All versions belonging to major version 3 */ - public static final ImmutableList VERSION_3 = ImmutableList.of(V3_0, V3_1, V3_2); + public static final List VERSION_3 = List.of(V3_0, V3_1, V3_2); /** * Major version value diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/service/StepExecutionService.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/service/StepExecutionService.java index 58fd7b5d..bee7f16e 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/service/StepExecutionService.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/service/StepExecutionService.java @@ -80,9 +80,9 @@ public ResultStatusObject execute(PowerAuthStep stepId, PowerAuthVersion version throw new PowerAuthCmdException(); } - BaseStep step = stepProvider.getStep(stepId, version); + final BaseStep step = stepProvider.getStep(stepId, version); - ResultStatusObject result = step.execute(model.toMap()); + final ResultStatusObject result = step.execute(stepLogger, model.toMap()); if (result == null) { throw new PowerAuthCmdException(); } diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/AbstractBaseStep.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/AbstractBaseStep.java index ec2fc039..02b5c662 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/AbstractBaseStep.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/AbstractBaseStep.java @@ -17,7 +17,6 @@ package io.getlime.security.powerauth.lib.cmd.steps; -import com.google.common.collect.ImmutableList; import com.wultra.core.rest.client.base.RestClient; import com.wultra.core.rest.client.base.RestClientException; import io.getlime.security.powerauth.crypto.lib.encryptor.ClientEncryptor; @@ -27,8 +26,6 @@ import io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorId; import io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorParameters; import io.getlime.security.powerauth.crypto.lib.encryptor.model.v3.ClientEncryptorSecrets; -import io.getlime.security.powerauth.crypto.lib.generator.KeyGenerator; -import io.getlime.security.powerauth.crypto.lib.util.KeyConvertor; import io.getlime.security.powerauth.lib.cmd.consts.PowerAuthStep; import io.getlime.security.powerauth.lib.cmd.consts.PowerAuthVersion; import io.getlime.security.powerauth.lib.cmd.logging.DisabledStepLogger; @@ -80,7 +77,7 @@ public abstract class AbstractBaseStep implements Bas * Supported versions of PowerAuth by this step */ @Getter - private final ImmutableList supportedVersions; + private final List supportedVersions; /** * Result status service @@ -93,8 +90,6 @@ public abstract class AbstractBaseStep implements Bas protected final StepLoggerFactory stepLoggerFactory; private static final EncryptorFactory ENCRYPTOR_FACTORY = new EncryptorFactory(); - private static final KeyGenerator KEY_GENERATOR = new KeyGenerator(); - private static final KeyConvertor KEY_CONVERTOR = new KeyConvertor(); /** * Constructor @@ -109,7 +104,7 @@ public AbstractBaseStep(PowerAuthStep step, ResultStatusService resultStatusService, StepLoggerFactory stepLoggerFactory) { this.step = step; - this.supportedVersions = ImmutableList.copyOf(supportedVersions); + this.supportedVersions = List.copyOf(supportedVersions); this.resultStatusService = resultStatusService; this.stepLoggerFactory = stepLoggerFactory; @@ -130,26 +125,6 @@ public AbstractBaseStep(PowerAuthStep step, */ protected abstract ParameterizedTypeReference getResponseTypeReference(); - /** - * Executes this step with a given context - * - * @param context Provided context - * @return Result status object, null in case of failure. - * @throws Exception In case of any error. - */ - @Override - public ResultStatusObject execute(Map context) throws Exception { - StepLogger stepLogger = stepLoggerFactory.createStepLogger(); - stepLogger.start(); - JSONObject jsonObject = execute(stepLogger, context); - stepLogger.close(); - if (jsonObject == null) { - return null; - } else { - return ResultStatusObject.fromJsonObject(jsonObject); - } - } - /** * Execute this step with given logger and context objects. * @@ -160,7 +135,7 @@ public ResultStatusObject execute(Map context) throws Exception * @return Result status object (with current activation status), null in case of failure. * @throws Exception In case of a failure. */ - public final JSONObject execute(StepLogger stepLogger, Map context) throws Exception { + public final ResultStatusObject execute(StepLogger stepLogger, Map context) throws Exception { if (stepLogger == null) { stepLogger = DisabledStepLogger.INSTANCE; } @@ -192,7 +167,12 @@ public final JSONObject execute(StepLogger stepLogger, Map conte return null; } - return stepContext.getModel().getResultStatusObject(); + final JSONObject resultStatusObject = stepContext.getModel().getResultStatusObject(); + if (resultStatusObject == null) { + return null; + } else { + return ResultStatusObject.fromJsonObject(resultStatusObject); + } } /** @@ -236,7 +216,6 @@ public void addEncryptedRequest(StepContext stepContext, String applicatio * @throws Exception when an error during encryption of the request data occurred */ public void addEncryptedRequest(StepContext stepContext, ClientEncryptor encryptor, byte[] data) throws Exception { - M model = stepContext.getModel(); SimpleSecurityContext securityContext = (SimpleSecurityContext) stepContext.getSecurityContext(); if (securityContext == null) { stepContext.setSecurityContext( @@ -306,8 +285,8 @@ public void processResponse(StepContext stepContext) throws Exception { } * @throws Exception when an error during response processing occurred */ public final void processResponse(StepContext stepContext, byte[] responseBody, Class responseObjectClass) throws Exception { - R responseBodyObject = HttpUtil.fromBytes(responseBody, responseObjectClass); - ResponseEntity responseEntity = ResponseEntity.of(Optional.of(responseBodyObject)); + final R responseBodyObject = HttpUtil.fromBytes(responseBody, responseObjectClass); + final ResponseEntity responseEntity = ResponseEntity.ofNullable(responseBodyObject); addResponseContext(stepContext, responseEntity); processResponse(stepContext); } diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/BaseStep.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/BaseStep.java index c8fab8f1..fede5e1d 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/BaseStep.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/BaseStep.java @@ -18,6 +18,7 @@ import io.getlime.security.powerauth.lib.cmd.consts.PowerAuthStep; import io.getlime.security.powerauth.lib.cmd.consts.PowerAuthVersion; +import io.getlime.security.powerauth.lib.cmd.logging.StepLogger; import io.getlime.security.powerauth.lib.cmd.steps.pojo.ResultStatusObject; import java.util.List; @@ -34,11 +35,12 @@ public interface BaseStep { /** * Execute this step with given context objects. * + * @param stepLogger Step logger. * @param context Context objects. * @return Result status object (with current activation status), null in case of failure. * @throws Exception In case of a failure. */ - ResultStatusObject execute(Map context) throws Exception; + ResultStatusObject execute(StepLogger stepLogger, Map context) throws Exception; /** * @return Corresponding PowerAuth step diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/pojo/ResultStatusObject.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/pojo/ResultStatusObject.java index d01827e7..9b11ea3d 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/pojo/ResultStatusObject.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/pojo/ResultStatusObject.java @@ -188,7 +188,10 @@ public void setServerPublicKey(String serverPublicKey) { */ @JsonIgnore public SecretKey getSignatureBiometryKeyObject() { - String signatureBiometryKey = (String) jsonObject.get("signatureBiometryKey"); + final String signatureBiometryKey = (String) jsonObject.get("signatureBiometryKey"); + if (signatureBiometryKey == null) { + return null; + } return KEY_CONVERTOR.convertBytesToSharedSecretKey(Base64.getDecoder().decode(signatureBiometryKey)); } @@ -290,7 +293,10 @@ public void setSignatureKnowledgeKeySalt(String signatureKnowledgeKeySalt) { */ @JsonIgnore public SecretKey getSignaturePossessionKeyObject() { - String signaturePossessionKey = (String) jsonObject.get("signaturePossessionKey"); + final String signaturePossessionKey = (String) jsonObject.get("signaturePossessionKey"); + if (signaturePossessionKey == null) { + return null; + } return KEY_CONVERTOR.convertBytesToSharedSecretKey(Base64.getDecoder().decode(signaturePossessionKey)); } @@ -324,7 +330,10 @@ public void setSignaturePossessionKey(String signaturePossessionKey) { */ @JsonIgnore public SecretKey getTransportMasterKeyObject() { - String transportMasterKey = (String) jsonObject.get("transportMasterKey"); + final String transportMasterKey = (String) jsonObject.get("transportMasterKey"); + if (transportMasterKey == null) { + return null; + } return KEY_CONVERTOR.convertBytesToSharedSecretKey(Base64.getDecoder().decode(transportMasterKey)); } diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/ConfirmRecoveryCodeStep.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/ConfirmRecoveryCodeStep.java index ddd59f24..264f67c0 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/ConfirmRecoveryCodeStep.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/ConfirmRecoveryCodeStep.java @@ -123,7 +123,7 @@ public StepContext prepare public void processResponse(StepContext stepContext) throws Exception { final ConfirmRecoveryResponsePayload confirmResponsePayload = decryptResponse(stepContext, ConfirmRecoveryResponsePayload.class); Map objectMap = new HashMap<>(); - objectMap.put("alreadyConfirmed", confirmResponsePayload.getAlreadyConfirmed()); + objectMap.put("alreadyConfirmed", confirmResponsePayload.isAlreadyConfirmed()); stepContext.getStepLogger().writeItem( getStep().id() + "-confirmation-done", diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/CreateTokenStep.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/CreateTokenStep.java index 64409baa..662a670a 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/CreateTokenStep.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/CreateTokenStep.java @@ -16,7 +16,6 @@ */ package io.getlime.security.powerauth.lib.cmd.steps.v3; -import com.google.common.collect.ImmutableMap; import io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorId; import io.getlime.security.powerauth.lib.cmd.consts.BackwardCompatibilityConst; import io.getlime.security.powerauth.lib.cmd.consts.PowerAuthConst; @@ -119,11 +118,8 @@ public void processResponse(StepContextbuilder() - .put("tokenId", tokenResponsePayload.getTokenId()) - .put("tokenSecret", tokenResponsePayload.getTokenSecret()) - .build() - + Map.of("tokenId", tokenResponsePayload.getTokenId(), + "tokenSecret",tokenResponsePayload.getTokenSecret()) ); } diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/GetStatusStep.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/GetStatusStep.java index cecfdb51..081503a1 100755 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/GetStatusStep.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/GetStatusStep.java @@ -38,6 +38,7 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.stereotype.Component; +import javax.crypto.SecretKey; import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -144,7 +145,16 @@ public void processResponse(StepContext customObject = responseObject.getCustomObject(); byte[] challenge = (byte[]) stepContext.getAttributes().get(ATTRIBUTE_CHALLENGE); - final ActivationStatusBlobInfo statusBlobRaw = ACTIVATION.getStatusFromEncryptedBlob(cStatusBlob, challenge, cStatusBlobNonce, resultStatusObject.getTransportMasterKeyObject()); + final SecretKey transportMasterKey = resultStatusObject.getTransportMasterKeyObject(); + if (transportMasterKey == null) { + stepContext.getStepLogger().writeError( + getStep().id() + "-failed", + "Get Status Failed", + "transportMasterKey is null"); + return; + } + + final ActivationStatusBlobInfo statusBlobRaw = ACTIVATION.getStatusFromEncryptedBlob(cStatusBlob, challenge, cStatusBlobNonce, transportMasterKey); final ExtendedActivationStatusBlobInfo statusBlob = ExtendedActivationStatusBlobInfo.copy(statusBlobRaw); final Map objectMap = new HashMap<>(); diff --git a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/StartUpgradeStep.java b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/StartUpgradeStep.java index 43840f1e..c6313051 100644 --- a/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/StartUpgradeStep.java +++ b/powerauth-java-cmd-lib/src/main/java/io/getlime/security/powerauth/lib/cmd/steps/v3/StartUpgradeStep.java @@ -15,7 +15,6 @@ */ package io.getlime.security.powerauth.lib.cmd.steps.v3; -import com.google.common.collect.ImmutableMap; import io.getlime.security.powerauth.crypto.lib.encryptor.model.EncryptorId; import io.getlime.security.powerauth.lib.cmd.consts.BackwardCompatibilityConst; import io.getlime.security.powerauth.lib.cmd.consts.PowerAuthConst; @@ -119,7 +118,7 @@ public void processResponse(StepContext io.getlime.security powerauth-cmd-parent - 1.6.0 + 1.7.0 diff --git a/powerauth-java-cmd/src/main/java/io/getlime/security/powerauth/app/cmd/Application.java b/powerauth-java-cmd/src/main/java/io/getlime/security/powerauth/app/cmd/Application.java index 089a160e..fc15dcfa 100755 --- a/powerauth-java-cmd/src/main/java/io/getlime/security/powerauth/app/cmd/Application.java +++ b/powerauth-java-cmd/src/main/java/io/getlime/security/powerauth/app/cmd/Application.java @@ -289,15 +289,8 @@ public static void main(String[] args) { stepExecutionService.execute(powerAuthStep, version, model); } - case ACTIVATION_CREATE, ACTIVATION_PREPARE -> { - if (powerAuthStep.equals(PowerAuthStep.ACTIVATION_PREPARE)) { - System.err.println("The 'prepare' step name is deprecated, use the 'create' step name instead"); - powerAuthStep = PowerAuthStep.ACTIVATION_CREATE; - } - - String customAttributesFileName = cmd.getOptionValue("C"); - Map customAttributes = - FileUtil.readDataFromFile(stepLogger, customAttributesFileName, HashMap.class, "custom-attributes", "custom attributes"); + case ACTIVATION_CREATE -> { + final Map customAttributes = getCustomAttributes(cmd, stepLogger); PrepareActivationStepModel model = new PrepareActivationStepModel(); model.setActivationCode(cmd.getOptionValue("a")); @@ -387,9 +380,7 @@ public static void main(String[] args) { Map identityAttributes = FileUtil.readDataFromFile(stepLogger, identityAttributesFileName, HashMap.class, "identity-attributes", "identity attributes"); - String customAttributesFileName = cmd.getOptionValue("C"); - Map customAttributes = - FileUtil.readDataFromFile(stepLogger, customAttributesFileName, HashMap.class, "custom-attributes", "custom attributes"); + final Map customAttributes = getCustomAttributes(cmd, stepLogger); CreateActivationStepModel model = new CreateActivationStepModel(); model.setActivationName(ConfigurationUtil.getApplicationName(clientConfigObject)); @@ -499,9 +490,7 @@ public static void main(String[] args) { Map identityAttributes = FileUtil.readDataFromFile(stepLogger, identityAttributesFileName, HashMap.class, "identity-attributes", "identity attributes"); - String customAttributesFileName = cmd.getOptionValue("C"); - Map customAttributes = - FileUtil.readDataFromFile(stepLogger, customAttributesFileName, HashMap.class, "custom-attributes", "custom attributes"); + final Map customAttributes = getCustomAttributes(cmd, stepLogger); ActivationRecoveryStepModel model = new ActivationRecoveryStepModel(); model.setActivationName(ConfigurationUtil.getApplicationName(clientConfigObject)); @@ -569,6 +558,18 @@ public static void main(String[] args) { } + @SuppressWarnings("unchecked") + private static Map getCustomAttributes(CommandLine cmd, StepLogger stepLogger) throws Exception { + final String customAttributesFileName = cmd.getOptionValue("C"); + final Map customAttributes; + if (customAttributesFileName != null) { + customAttributes = FileUtil.readDataFromFile(stepLogger, customAttributesFileName, HashMap.class, "custom-attributes", "custom attributes"); + } else { + customAttributes = Collections.emptyMap(); + } + return customAttributes; + } + private static void printPowerAuthStepsHelp(StepProvider stepProvider) { System.out.println("Available PowerAuth steps and supported versions.\n"); System.out.printf("%-22s%s%n", "PowerAuth step", "Supported versions");