Skip to content

Commit

Permalink
Merge pull request #1 from admicrovn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cuongpm999 authored Apr 15, 2024
2 parents 656dc12 + 20ce6e3 commit 9eacd7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ file/
private/
tests/security_file.json
/vendor/
tests/*.pem
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Install library

### Install
```php
```shell
$ composer require admicro/kms-client
```

Expand Down
36 changes: 19 additions & 17 deletions src/vcc_kms_client/auth/KMSCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class KMSCredentials
private $ca_file_path;
private $domain;

public function __construct($security_file_directory)


public function __construct($path)
{
$security_file = file_get_contents($security_file_directory);
$security_file = file_get_contents($path . DIRECTORY_SEPARATOR . 'security_file.json');

$keystore_base64 = json_decode($security_file)->keystore_base64;
$truststore_base64 = json_decode($security_file)->truststore_base64;
Expand All @@ -23,21 +25,21 @@ public function __construct($security_file_directory)
$truststore_p12 = array();
openssl_pkcs12_read($truststore_string, $truststore_p12, json_decode($security_file)->password_file);

$cer_file_path = 'cer.pem';
$ca_file_path = 'ca.pem';
$key_file_path = 'key.pem';

if (!is_file($key_file_path)) {
openssl_pkey_export_to_file($keystore_p12['pkey'], $key_file_path);
}

if (!is_file($cer_file_path)) {
openssl_x509_export_to_file($keystore_p12['cert'], $cer_file_path);
}

if (!is_file($ca_file_path)) {
openssl_x509_export_to_file($truststore_p12['extracerts'][0], $ca_file_path);
}
$cer_file_path = $path . DIRECTORY_SEPARATOR . 'cer.pem';
$ca_file_path = $path . DIRECTORY_SEPARATOR . 'ca.pem';
$key_file_path = $path . DIRECTORY_SEPARATOR . 'key.pem';

// if (!is_file($key_file_path)) {
// openssl_pkey_export_to_file($keystore_p12['pkey'], $key_file_path);
// }
//
// if (!is_file($cer_file_path)) {
// openssl_x509_export_to_file($keystore_p12['cert'], $cer_file_path);
// }
//
// if (!is_file($ca_file_path)) {
// openssl_x509_export_to_file($truststore_p12['extracerts'][0], $ca_file_path);
// }

$this->ca_file_path = $ca_file_path;
$this->cer_file_path = $cer_file_path;
Expand Down
17 changes: 0 additions & 17 deletions src/vcc_kms_client/https/HttpCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function get($api, $headers, $params, $timeout)
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);

$resp = curl_exec($curl);
$this->deleteFiles();
curl_close($curl);
return $resp;
}
Expand Down Expand Up @@ -69,23 +68,7 @@ public function post($api, $body, $headers, $params, $timeout)
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);

$resp = curl_exec($curl);
$this->deleteFiles();
curl_close($curl);
return $resp;
}

function deleteFiles()
{
if(is_file('key.pem')) {
unlink('key.pem');
}
if(is_file('ca.pem')) {
unlink('ca.pem');
}
if(is_file('cer.pem')) {
unlink('cer.pem');
}

}

}
2 changes: 1 addition & 1 deletion tests/create_kms_key_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require_once '../src/vcc_kms_client/models/CreateKMSKeyRequest.php';
require_once '../src/vcc_kms_client/models/Algorithm.php';

$credentials = new KMSCredentials('security_file.json');
$credentials = new KMSCredentials('/home/cuongpham/Desktop/Project/KMSClientPHP/tests');
$kms = new KMSClient($credentials);
$request = new CreateKMSKeyRequest(null, null, Algorithm::AES_256);
print($kms->create_key($request));

0 comments on commit 9eacd7f

Please sign in to comment.