-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from peter-szrnka/356-gms-177-secret-value-si…
…ze-calculator GMS-177 secret value size calculator
- Loading branch information
Showing
44 changed files
with
811 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
code/gms-backend/src/main/java/io/github/gms/common/dto/BooleanValueDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.gms.common.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* @author Peter Szrnka | ||
* @since 1.0 | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class BooleanValueDto implements Serializable { | ||
@Serial | ||
private static final long serialVersionUID = -7426749389683654760L; | ||
|
||
private Boolean value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/gms-backend/src/main/java/io/github/gms/functions/api/ApiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ms-backend/src/main/java/io/github/gms/functions/secret/SecretLengthValidatorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.github.gms.functions.secret; | ||
|
||
import io.github.gms.common.dto.BooleanValueDto; | ||
import io.github.gms.common.model.GetKeystore; | ||
import io.github.gms.common.model.KeystorePair; | ||
import io.github.gms.common.service.CryptoService; | ||
import io.github.gms.common.types.GmsException; | ||
import io.github.gms.functions.keystore.*; | ||
import io.github.gms.functions.secret.dto.SecretValueDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.security.KeyStore; | ||
|
||
import static io.github.gms.common.types.ErrorCode.GMS_002; | ||
import static io.github.gms.common.util.Constants.SLASH; | ||
|
||
/** | ||
* @author Peter Szrnka | ||
* @since 1.0 | ||
*/ | ||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SecretLengthValidatorService { | ||
|
||
private final KeystoreRepository keystoreRepository; | ||
private final KeystoreAliasRepository keystoreAliasRepository; | ||
private final KeystoreDataService keystoreDataService; | ||
private final CryptoService cryptoService; | ||
|
||
@Value("${config.location.keystore.path}") | ||
private String keystorePath; | ||
|
||
public BooleanValueDto validateValueLength(SecretValueDto dto) { | ||
try { | ||
KeystoreEntity keystoreEntity = keystoreRepository.findById(dto.getKeystoreId()) | ||
.orElseThrow(() -> new GmsException("KeystoreEntity not found!", GMS_002)); | ||
|
||
KeystoreAliasEntity keystoreAliasEntity = keystoreAliasRepository.findById(dto.getKeystoreAliasId()) | ||
.orElseThrow(() -> new GmsException("KeystoreAliasEntity not found!", GMS_002)); | ||
|
||
KeyStore keystore = keystoreDataService.getKeyStore(GetKeystore.builder() | ||
.keystoreEntity(keystoreEntity) | ||
.keystorePath(keystorePath + keystoreEntity.getUserId() + SLASH + keystoreEntity.getFileName()) | ||
.build()); | ||
|
||
String encryptedValue = cryptoService.encrypt(dto.getValue(), new KeystorePair(keystoreAliasEntity, keystore)); | ||
|
||
log.info("Encrypted secret value size: {}", encryptedValue.length()); | ||
return new BooleanValueDto(true); | ||
} catch (Exception e) { | ||
return new BooleanValueDto(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...functions/secret/GetSecretRequestDto.java → ...tions/secret/dto/GetSecretRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/functions/secret/GetSecureValueDto.java → ...nctions/secret/dto/GetSecureValueDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...unctions/secret/SaveSecretRequestDto.java → ...ions/secret/dto/SaveSecretRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ithub/gms/functions/secret/SecretDto.java → ...b/gms/functions/secret/dto/SecretDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...b/gms/functions/secret/SecretListDto.java → ...s/functions/secret/dto/SecretListDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
code/gms-backend/src/main/java/io/github/gms/functions/secret/dto/SecretValueDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.gms.functions.secret.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SecretValueDto { | ||
|
||
private Long keystoreId; | ||
private Long keystoreAliasId; | ||
private String value; | ||
} |
2 changes: 1 addition & 1 deletion
2
code/gms-backend/src/test/java/io/github/gms/functions/api/ApiControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/gms-backend/src/test/java/io/github/gms/functions/api/ApiServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.