Skip to content

Commit

Permalink
Merge pull request #248 from wultra/develop
Browse files Browse the repository at this point in the history
Prepare release 1.3.0
  • Loading branch information
romanstrobl authored Jun 16, 2022
2 parents 46b534a + fa96ca1 commit d991346
Show file tree
Hide file tree
Showing 15 changed files with 542 additions and 113 deletions.
127 changes: 86 additions & 41 deletions docs/Readme.md

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<groupId>io.getlime.security</groupId>
<artifactId>powerauth-cmd-parent</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>pom</packaging>

<inceptionYear>2016</inceptionYear>
Expand Down Expand Up @@ -76,8 +76,19 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-deploy-plugin.version>3.0.0-M2</maven-deploy-plugin.version>
<maven-javadoc-plugin.version>3.4.0</maven-javadoc-plugin.version>
<spring-boot.version>2.6.8</spring-boot.version>
<bc.version>1.70</bc.version>
<jackson.version>2.13.3</jackson.version>
<commons-cli.version>1.5.0</commons-cli.version>
<commons-io.version>2.11.0</commons-io.version>
<json-simple.version>1.1.1</json-simple.version>
<powerauth.version>1.3.0</powerauth.version>
<wultra-java-core.version>1.5.0</wultra-java-core.version>
<lombok.version>1.18.24</lombok.version>
<junit.version>5.8.2</junit.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>

<build>
Expand Down
28 changes: 14 additions & 14 deletions powerauth-java-cmd-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerauth-java-cmd-lib</artifactId>
<description>PowerAuth Command-line Utility - Java Library</description>
<version>1.2.0</version>
<version>1.3.0</version>

<parent>
<artifactId>powerauth-cmd-parent</artifactId>
<groupId>io.getlime.security</groupId>
<version>1.2.0</version>
<version>1.3.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.5.0</version>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<version>${json-simple.version}</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
Expand All @@ -45,30 +45,30 @@
<dependency>
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-restful-model</artifactId>
<version>1.2.0</version>
<version>${powerauth.version}</version>
</dependency>
<dependency>
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-java-crypto</artifactId>
<version>1.2.0</version>
<version>${powerauth.version}</version>
</dependency>
<dependency>
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-java-http</artifactId>
<version>1.2.0</version>
<version>${powerauth.version}</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.69</version>
<version>${bc.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.6.1</version>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<artifactId>log4j-to-slf4j</artifactId>
Expand All @@ -79,19 +79,19 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.6.1</version>
<version>${spring-boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.getlime.core</groupId>
<artifactId>rest-client-base</artifactId>
<version>1.4.0</version>
<version>${wultra-java-core.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<version>${lombok.version}</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public enum PowerAuthStep {
*/
TOKEN_CREATE("token-create", "Token Create", "create-token"),

/**
* Send an encrypted request with token-based authentication
*/
TOKEN_ENCRYPT("token-encrypt", "Encrypt Request and Validate Token Digest", "token-encrypt"),

/**
* Removing a previously created token
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.getlime.security.powerauth.lib.cmd.steps.model.data.EncryptionHeaderData;
import io.getlime.security.powerauth.lib.cmd.steps.model.data.SignatureHeaderData;
import io.getlime.security.powerauth.lib.cmd.steps.model.data.TokenAndEncryptionHeaderData;
import io.getlime.security.powerauth.lib.cmd.steps.model.data.TokenHeaderData;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -59,4 +60,14 @@ public <M extends TokenHeaderData> TokenHeaderProvider getHeaderProvider(M model
return new TokenHeaderProvider();
}

/**
* Creates a token and encryption header provider instance
* @param model Step model
* @param <M> Model class based on {@link TokenAndEncryptionHeaderData}
* @return New token and encryption header provider instance
*/
public <M extends TokenAndEncryptionHeaderData> TokenAndEncryptionHeaderProvider getHeaderProvider(M model) {
return new TokenAndEncryptionHeaderProvider();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* PowerAuth Command-line utility
* Copyright 2022 Wultra s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.getlime.security.powerauth.lib.cmd.header;

import io.getlime.security.powerauth.lib.cmd.steps.context.StepContext;
import io.getlime.security.powerauth.lib.cmd.steps.model.data.EncryptionHeaderData;
import io.getlime.security.powerauth.lib.cmd.steps.model.data.TokenAndEncryptionHeaderData;
import io.getlime.security.powerauth.lib.cmd.steps.model.data.TokenHeaderData;

import static io.getlime.security.powerauth.lib.cmd.consts.BackwardCompatibilityConst.POWER_AUTH_HEADER_FACTORY;

/**
* Token and encryption header provider.
*
* @author Roman Strobl, [email protected]
*/
public class TokenAndEncryptionHeaderProvider implements PowerAuthHeaderProvider<TokenAndEncryptionHeaderData> {

/**
* Adds a token and encryption headers to the request context
* @param stepContext Step context
*/
@Override
public void addHeader(StepContext<? extends TokenAndEncryptionHeaderData, ?> stepContext) throws Exception {
TokenHeaderData tokenHeaderData = stepContext.getModel();
POWER_AUTH_HEADER_FACTORY.getHeaderProvider(tokenHeaderData).addHeader(stepContext);
EncryptionHeaderData encryptionHeaderData = stepContext.getModel();
POWER_AUTH_HEADER_FACTORY.getHeaderProvider(encryptionHeaderData).addHeader(stepContext);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public final JSONObject execute(StepLogger stepLogger, Map<String, Object> conte
* @param stepContext Context of this step
* @param applicationSecret Application secret
* @param eciesSharedInfo Parameter sharedInfo1
* @param data Request data for the encyption
* @param data Request data for the encryption
* @throws Exception when an error during encryption of the request data occurred
*/
public void addEncryptedRequest(StepContext<M, R> stepContext, String applicationSecret, EciesSharedInfo1 eciesSharedInfo, byte[] data) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* PowerAuth Command-line utility
* Copyright 2022 Wultra s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.getlime.security.powerauth.lib.cmd.steps.model;

import io.getlime.security.powerauth.lib.cmd.steps.model.data.TokenAndEncryptionHeaderData;
import io.getlime.security.powerauth.lib.cmd.steps.model.feature.DryRunCapable;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Map;

/**
* Model representing parameters of the step for verifying token digest.
*
* @author Petr Dvorak, [email protected]
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class TokenAndEncryptStepModel extends BaseStepModel
implements DryRunCapable, TokenAndEncryptionHeaderData {

/**
* Token ID.
*/
private String tokenId;

/**
* Token secret.
*/
private String tokenSecret;

/**
* HTTP method.
*/
private String httpMethod;

/**
* HTTP request data.
*/
private byte[] data;

/**
* Application key.
*/
private String applicationKey;

/**
* Application secret.
*/
private String applicationSecret;

/**
* Flag indicating that this step should be terminated before the networking call.
*/
private boolean dryRun;

@Override
public Map<String, Object> toMap() {
Map<String, Object> context = super.toMap();
context.put("TOKEN_ID", tokenId);
context.put("TOKEN_SECRET", tokenSecret);
context.put("APPLICATION_KEY", applicationKey);
context.put("APPLICATION_SECRET", applicationSecret);
context.put("HTTP_METHOD", httpMethod);
context.put("DATA", data);
context.put("DRY_RUN", dryRun);
return context;
}

@Override
public void fromMap(Map<String, Object> context) {
super.fromMap(context);
setTokenId((String) context.get("TOKEN_ID"));
setTokenSecret((String) context.get("TOKEN_SECRET"));
setApplicationKey((String) context.get("APPLICATION_KEY"));
setApplicationSecret((String) context.get("APPLICATION_SECRET"));
setHttpMethod((String) context.get("HTTP_METHOD"));
setData((byte[]) context.get("DATA"));
setDryRun((boolean) context.get("DRY_RUN"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* PowerAuth Command-line utility
* Copyright 2022 Wultra s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.getlime.security.powerauth.lib.cmd.steps.model.data;

/**
* Data used for computing a token and encryption header values.
*
* @author Roman Strobl, [email protected]
*/
public interface TokenAndEncryptionHeaderData extends TokenHeaderData, EncryptionHeaderData {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
*/
package io.getlime.security.powerauth.lib.cmd.steps.v3;

import com.google.common.io.BaseEncoding;
import io.getlime.security.powerauth.crypto.lib.encryptor.ecies.EciesEncryptor;
import io.getlime.security.powerauth.crypto.lib.encryptor.ecies.EciesFactory;
import io.getlime.security.powerauth.crypto.lib.encryptor.ecies.model.EciesCryptogram;
import io.getlime.security.powerauth.crypto.lib.encryptor.ecies.model.EciesSharedInfo1;
import io.getlime.security.powerauth.http.PowerAuthEncryptionHttpHeader;
import io.getlime.security.powerauth.lib.cmd.consts.BackwardCompatibilityConst;
Expand All @@ -35,6 +33,7 @@
import io.getlime.security.powerauth.lib.cmd.steps.context.security.SimpleSecurityContext;
import io.getlime.security.powerauth.lib.cmd.steps.model.EncryptStepModel;
import io.getlime.security.powerauth.lib.cmd.steps.pojo.ResultStatusObject;
import io.getlime.security.powerauth.lib.cmd.util.EncryptionUtil;
import io.getlime.security.powerauth.lib.cmd.util.SecurityUtil;
import io.getlime.security.powerauth.rest.api.model.response.v3.EciesEncryptedResponse;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -168,27 +167,7 @@ public StepContext<EncryptStepModel, EciesEncryptedResponse> prepareStepContext(

@Override
public void processResponse(StepContext<EncryptStepModel, EciesEncryptedResponse> stepContext) throws Exception {
EncryptStepModel model = stepContext.getModel();
EciesEncryptor encryptor = ((SimpleSecurityContext) stepContext.getSecurityContext()).getEncryptor();

EciesEncryptedResponse encryptedResponse = stepContext.getResponseContext().getResponseBodyObject();

byte[] macResponse = BaseEncoding.base64().decode(encryptedResponse.getMac());
byte[] encryptedDataResponse = BaseEncoding.base64().decode(encryptedResponse.getEncryptedData());
EciesCryptogram eciesCryptogramResponse = new EciesCryptogram(macResponse, encryptedDataResponse);

final byte[] decryptedBytes = encryptor.decryptResponse(eciesCryptogramResponse);

String decryptedMessage = new String(decryptedBytes, StandardCharsets.UTF_8);
model.getResultStatus().setResponseData(decryptedMessage);

stepContext.getStepLogger().writeItem(
getStep().id() + "-response-decrypt",
"Decrypted Response",
"Following data were decrypted",
"OK",
decryptedMessage
);
EncryptionUtil.processEncryptedResponse(stepContext, getStep().id());
}

}
Loading

0 comments on commit d991346

Please sign in to comment.