Skip to content

Commit

Permalink
Merge pull request #208 from mahammedtaheer/dev-hash-gen
Browse files Browse the repository at this point in the history
[ES-423] Added new API to generate Argon2 Hash.
  • Loading branch information
mahammedtaheer authored Nov 9, 2023
2 parents be8f703 + 7378004 commit 1a4fe23
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 13 deletions.
2 changes: 2 additions & 0 deletions kernel/kernel-keymanager-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ ENV loader_path_env=${loader_path}

ADD configure_start.sh configure_start.sh

ADD ./lib/* "${loader_path_env}"/

RUN chmod +x configure_start.sh

# creating folder to copy additional supporting jar files required at run-time.
Expand Down
Binary file not shown.
19 changes: 15 additions & 4 deletions kernel/kernel-keymanager-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
<jacoco.maven.plugin.version>0.8.5</jacoco.maven.plugin.version>
<com.nimbusds.nimbus-jose-jwt.version>9.14</com.nimbusds.nimbus-jose-jwt.version>
<com.fasterxml.jackson.core.version>2.12.0</com.fasterxml.jackson.core.version>
<io.projectreactor.reactor-core.version>3.1.7.RELEASE</io.projectreactor.reactor-core.version>
<de.mkammerer.argon2-jvm-nolibs.version>2.11</de.mkammerer.argon2-jvm-nolibs.version>
<net.java.dev.jna.version>5.13.0</net.java.dev.jna.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -266,10 +269,18 @@
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.1.7.RELEASE</version>
<version>${io.projectreactor.reactor-core.version}</version>
</dependency>
<dependency>
<groupId>de.mkammerer</groupId>
<artifactId>argon2-jvm-nolibs</artifactId>
<version>${de.mkammerer.argon2-jvm-nolibs.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${net.java.dev.jna.version}</version>
</dependency>


</dependencies>

<distributionManagement>
Expand All @@ -283,7 +294,7 @@
</repository>
</distributionManagement>
<build>
<plugins>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,12 @@ private CryptomanagerConstant() {
public static final String JSON_HEADER_JWK_KEY = "jku";

public static final String JSON_HEADER_TYPE_KEY = "typ";

public static final String GEN_ARGON2_HASH = "Crypto-Manager-Gen-Argon2-Hash";

public static final String CACHE_AES_KEY = "cacheAESKey";

public static final String CACHE_INT_COUNTER = "cacheIntCounter";

}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.mosip.kernel.core.http.RequestWrapper;
import io.mosip.kernel.core.http.ResponseFilter;
import io.mosip.kernel.core.http.ResponseWrapper;
import io.mosip.kernel.cryptomanager.dto.Argon2GenerateHashRequestDto;
import io.mosip.kernel.cryptomanager.dto.Argon2GenerateHashResponseDto;
import io.mosip.kernel.cryptomanager.dto.CryptoWithPinRequestDto;
import io.mosip.kernel.cryptomanager.dto.CryptoWithPinResponseDto;
import io.mosip.kernel.cryptomanager.dto.CryptomanagerRequestDto;
Expand Down Expand Up @@ -191,4 +193,26 @@ public ResponseWrapper<JWTCipherResponseDto> jwtDecrypt(
response.setResponse(cryptomanagerService.jwtDecrypt(jwtCipherRequestDto.getRequest()));
return response;
}

/**
* Controller to create Argon2 HASH for the input data.
*
* @param argon2GenHashRequestDto {@link Argon2GenerateHashRequestDto} request
* @return {@link Argon2GenerateHashResponseDto} the hash value and salt value
*/
@Operation(summary = "Argon2 hash generation", description = "Performs Hash generation using Argon2 algorithm", tags = { "cryptomanager" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Success or you may find errors in error array in response"),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) })
@PreAuthorize("hasAnyRole(@cryptoManagerAuthRoles.getPostgenerateargon2hash())")
@ResponseFilter
@PostMapping(value = "/generateArgon2Hash", produces = "application/json")
public ResponseWrapper<Argon2GenerateHashResponseDto> generateArgon2Hash(
@ApiParam("Data to generate Argon2 ") @RequestBody @Valid RequestWrapper<Argon2GenerateHashRequestDto> argon2GenHashRequestDto) {
ResponseWrapper<Argon2GenerateHashResponseDto> response = new ResponseWrapper<>();
response.setResponse(cryptomanagerService.generateArgon2Hash(argon2GenHashRequestDto.getRequest()));
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*
*
*
*
*/
package io.mosip.kernel.cryptomanager.dto;

import javax.validation.constraints.NotBlank;

import io.mosip.kernel.cryptomanager.constant.CryptomanagerConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* To generate Argon2 Hash Request model
*
* @author Mahammed Taheer
*
* @since 1.2.1
*/

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "Model representing a to generate Argon2 Hash Request")
public class Argon2GenerateHashRequestDto {

/**
* Input data for hash generation
*/
@ApiModelProperty(notes = "Input data for hash generation.", example = "SOME-BASE64-ENCODED-STRING", required = true)
@NotBlank(message = CryptomanagerConstant.INVALID_REQUEST)
private String inputData;

/**
* Salt to be included in the hash generation (Optional)
*/
@ApiModelProperty(notes = "Salt value to be included in hash generation", example = "RANDOM-BYTES-DATA")
private String salt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
*
*
*
*/
package io.mosip.kernel.cryptomanager.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* To generate Argon2 Hash Response model
*
* @author Mahammed Taheer
*
* @since 1.2.1
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "Model representing to generate Argon2 Hash Response")
public class Argon2GenerateHashResponseDto {

/**
* Argon2 generated Hash value
*/
@ApiModelProperty(notes = "generate Argon2 Hash")
private String hashValue;

/**
* Salt value used in hash generation
*/
@ApiModelProperty(notes = "Salt value used in Argon2 Hash")
private String salt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class AuthorizedRolesDTO

private List<String> postjwtdecrypt;

private List<String> postgenerateargon2hash;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package io.mosip.kernel.cryptomanager.service;

import io.mosip.kernel.cryptomanager.dto.Argon2GenerateHashRequestDto;
import io.mosip.kernel.cryptomanager.dto.Argon2GenerateHashResponseDto;
import io.mosip.kernel.cryptomanager.dto.CryptoWithPinRequestDto;
import io.mosip.kernel.cryptomanager.dto.CryptoWithPinResponseDto;
import io.mosip.kernel.cryptomanager.dto.CryptomanagerRequestDto;
Expand Down Expand Up @@ -71,4 +73,13 @@ public interface CryptomanagerService {
* @return decrypted data (actual data)
*/
public JWTCipherResponseDto jwtDecrypt(JWTDecryptRequestDto jwtCipherRequestDto);


/**
* Performs generation of Hash using Argon2 .
*
* @param argon2GenHashRequestDto {@link Argon2GenerateHashRequestDto} instance
* @return {@link Argon2GenerateHashResponseDto}
*/
public Argon2GenerateHashResponseDto generateArgon2Hash(Argon2GenerateHashRequestDto argon2GenHashRequestDto);
}
Loading

0 comments on commit 1a4fe23

Please sign in to comment.