-
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.
- Loading branch information
Showing
122 changed files
with
4,025 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
file/ | ||
private/ | ||
tests/security_file.json | ||
/vendor/ |
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,5 @@ | ||
### 2023-05-17 | ||
- Done kms client php. | ||
|
||
### 2023-05-18 | ||
- Change encode param url |
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,19 @@ | ||
{ | ||
"name": "vcc/kms-client", | ||
"description": "KMS is a key management system for data encryption, decryption, signing and verification", | ||
"type": "library", | ||
"license": "proprietary", | ||
"autoload": { | ||
"psr-4": { | ||
"": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "cuongpm", | ||
"email": "cuongphammanh@tech.admicro.vn" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": {} | ||
} |
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,34 @@ | ||
<?php | ||
require_once 'HandlerResponseHttp.php'; | ||
require_once 'constants/Constants.php'; | ||
class ChangeStateKMSKeyRepository extends HandlerResponseHttp | ||
{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
|
||
public function change_state_kms_key($change_state_dto) | ||
{ | ||
$result = $this->http_caller->post( | ||
Constants::CHANGE_STATE_KEY_API, | ||
json_encode($change_state_dto), | ||
['Content-type: application/json'], | ||
null, | ||
10 | ||
); | ||
$response_body = json_decode($result); | ||
return $this->handler_response($response_body); | ||
} | ||
|
||
public function handler_response_success($result) | ||
{ | ||
return empty($result->data) ? null : $result->data[0]; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
require_once 'HandlerResponseHttp.php'; | ||
require_once 'constants/Constants.php'; | ||
class CreateKMSKeyRepository extends HandlerResponseHttp | ||
{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
|
||
public function create_kms_key($kms_key_dto) | ||
{ | ||
$result = $this->http_caller->post( | ||
Constants::CREATE_KEY_API, | ||
json_encode($kms_key_dto), | ||
['Content-type: application/json'], | ||
null, | ||
10 | ||
); | ||
$response_body = json_decode($result); | ||
return $this->handler_response($response_body); | ||
} | ||
|
||
public function handler_response_success($result) | ||
{ | ||
return empty($result->data) ? null : $result->data[0]; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
require_once 'dtos/KMSKeyDto.php'; | ||
require_once 'models/KeyState.php'; | ||
require_once 'CreateKMSKeyRepository.php'; | ||
require_once 'models/CreateKMSKeyResult.php'; | ||
class CreateKMSKeyService | ||
{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
public function create_kms_key($request) | ||
{ | ||
$kms_key_dto = new KMSKeyDto(null, $request->description, $request->alias, KeyState::ENABLED, $request->algorithm); | ||
$create_kms_key_repository = new CreateKMSKeyRepository($this->http_caller); | ||
$kms_key_dto = $create_kms_key_repository->create_kms_key($kms_key_dto); | ||
return new CreateKMSKeyResult($kms_key_dto->id, $kms_key_dto->alias, $kms_key_dto->algorithm, $kms_key_dto->state, $kms_key_dto->description); | ||
} | ||
|
||
|
||
} |
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,60 @@ | ||
<?php | ||
require_once 'HandlerResponseHttp.php'; | ||
require_once 'constants/Constants.php'; | ||
class DecryptRepository extends HandlerResponseHttp{ | ||
|
||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
|
||
public function decrypt($decrypt_dto) | ||
{ | ||
$result = $this->http_caller->post( | ||
Constants::DECRYPT_API, | ||
json_encode($decrypt_dto), | ||
['Content-type: application/json'], | ||
null, | ||
10 | ||
); | ||
$response_body = json_decode($result); | ||
return $this->handler_response($response_body); | ||
} | ||
|
||
public function decrypt_with_data_key($decrypt_dto) | ||
{ | ||
$result = $this->http_caller->post( | ||
Constants::DECRYPT_WITH_DATA_KEY_API, | ||
json_encode($decrypt_dto), | ||
['Content-type: application/json'], | ||
null, | ||
10 | ||
); | ||
$response_body = json_decode($result); | ||
return $this->handler_response($response_body); | ||
} | ||
|
||
public function decrypt_with_data_key_pair($decrypt_dto) | ||
{ | ||
$result = $this->http_caller->post( | ||
Constants::DECRYPT_WITH_DATA_KEY_PAIR_API, | ||
json_encode($decrypt_dto), | ||
['Content-type: application/json'], | ||
null, | ||
10 | ||
); | ||
$response_body = json_decode($result); | ||
return $this->handler_response($response_body); | ||
} | ||
|
||
public function handler_response_success($result) | ||
{ | ||
return empty($result->data) ? null : $result->data[0]; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
require_once 'dtos/DecryptDto.php'; | ||
require_once 'models/ContentType.php'; | ||
require_once 'models/Action.php'; | ||
require_once 'DecryptRepository.php'; | ||
require_once 'models/DecryptResult.php'; | ||
class DecryptService{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
public function decrypt($request){ | ||
$decrypt_dto = new DecryptDto( | ||
$request->key_id, | ||
$request->content_type == ContentType::SINGLE_STRING ? $request->input : null, | ||
$request->content_type == ContentType::LIST_STRING ? $request->input : null, | ||
$request->content_type == ContentType::LIST_JSON_OBJECT ? $request->input : null, | ||
Action::DECRYPT, | ||
$request->content_type | ||
); | ||
|
||
$decrypt_repository = new DecryptRepository($this->http_caller); | ||
$decrypt_dto = $decrypt_repository->decrypt($decrypt_dto); | ||
|
||
$output = null; | ||
if($request->content_type == ContentType::SINGLE_STRING){ | ||
$output = $decrypt_dto->text; | ||
} | ||
if($request->content_type == ContentType::LIST_STRING){ | ||
$output = $decrypt_dto->texts; | ||
} | ||
if($request->content_type == ContentType::LIST_JSON_OBJECT){ | ||
$output = $decrypt_dto->jsons; | ||
} | ||
|
||
return new DecryptResult($decrypt_dto->keyId, $output); | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
require_once 'dtos/DecryptDto.php'; | ||
require_once 'models/ContentType.php'; | ||
require_once 'models/Action.php'; | ||
require_once 'DecryptRepository.php'; | ||
require_once 'models/DecryptWithDataKeyPairResult.php'; | ||
class DecryptWithDataKeyPairService{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
public function decrypt_with_data_key_pair($request){ | ||
$decrypt_dto = new DecryptDto( | ||
$request->key_id, | ||
$request->content_type == ContentType::SINGLE_STRING ? $request->input : null, | ||
$request->content_type == ContentType::LIST_STRING ? $request->input : null, | ||
$request->content_type == ContentType::LIST_JSON_OBJECT ? $request->input : null, | ||
Action::DECRYPT_WITH_DATA_KEY_PAIR, | ||
$request->content_type | ||
); | ||
|
||
$decrypt_repository = new DecryptRepository($this->http_caller); | ||
$decrypt_dto = $decrypt_repository->decrypt_with_data_key_pair($decrypt_dto); | ||
|
||
$output = null; | ||
if($request->content_type == ContentType::SINGLE_STRING){ | ||
$output = $decrypt_dto->text; | ||
} | ||
if($request->content_type == ContentType::LIST_STRING){ | ||
$output = $decrypt_dto->texts; | ||
} | ||
if($request->content_type == ContentType::LIST_JSON_OBJECT){ | ||
$output = $decrypt_dto->jsons; | ||
} | ||
|
||
return new DecryptWithDataKeyPairResult($decrypt_dto->keyId, $output); | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
require_once 'dtos/DecryptDto.php'; | ||
require_once 'models/ContentType.php'; | ||
require_once 'models/Action.php'; | ||
require_once 'DecryptRepository.php'; | ||
require_once 'models/DecryptWithDataKeyResult.php'; | ||
class DecryptWithDataKeyService{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
public function decrypt_with_data_key($request){ | ||
$decrypt_dto = new DecryptDto( | ||
$request->key_id, | ||
$request->content_type == ContentType::SINGLE_STRING ? $request->input : null, | ||
$request->content_type == ContentType::LIST_STRING ? $request->input : null, | ||
$request->content_type == ContentType::LIST_JSON_OBJECT ? $request->input : null, | ||
Action::DECRYPT_WITH_DATA_KEY, | ||
$request->content_type | ||
); | ||
|
||
$decrypt_repository = new DecryptRepository($this->http_caller); | ||
$decrypt_dto = $decrypt_repository->decrypt_with_data_key($decrypt_dto); | ||
|
||
$output = null; | ||
if($request->content_type == ContentType::SINGLE_STRING){ | ||
$output = $decrypt_dto->text; | ||
} | ||
if($request->content_type == ContentType::LIST_STRING){ | ||
$output = $decrypt_dto->texts; | ||
} | ||
if($request->content_type == ContentType::LIST_JSON_OBJECT){ | ||
$output = $decrypt_dto->jsons; | ||
} | ||
|
||
return new DecryptWithDataKeyResult($decrypt_dto->keyId, $output); | ||
} | ||
|
||
} |
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,23 @@ | ||
<?php | ||
require_once 'dtos/AliasKeyDto.php'; | ||
require_once 'ManageAliasKeyRepository.php'; | ||
require_once 'models/DeleteAliasKeyResult.php'; | ||
require_once 'models/Action.php'; | ||
class DeleteAliasKeyService{ | ||
private $http_caller; | ||
|
||
/** | ||
* @param $http_caller | ||
*/ | ||
public function __construct($http_caller) | ||
{ | ||
$this->http_caller = $http_caller; | ||
} | ||
|
||
public function delete_alias_key($request){ | ||
$alias_key_dto = new AliasKeyDto($request->key_id, null, Action::DELETE_ALIAS); | ||
$manage_alias_key_repository = new ManageAliasKeyRepository($this->http_caller); | ||
$alias_key_dto = $manage_alias_key_repository->delete_alias($alias_key_dto); | ||
return new DeleteAliasKeyResult($alias_key_dto->keyId); | ||
} | ||
} |
Oops, something went wrong.