forked from intel/ehsm
-
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.
1. add BYOK interface for python/rust/go sdk and add test 2. format python files 3. disabled timeout setting in Python sdk to pass BYOK testing Signed-off-by: lisiteng <[email protected]>
- Loading branch information
Showing
27 changed files
with
1,772 additions
and
652 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
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,117 @@ | ||
package ehsm | ||
|
||
import ( | ||
"crypto" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/iancoleman/orderedmap" | ||
) | ||
|
||
/* | ||
Description: | ||
Queries the parameters that are used to import key material for a customer master key (CMK). | ||
Input: | ||
keyid -- The unique keyid of import CMK. | ||
keyspec -- The type of the public key that is used to encrypt key material. | ||
Output: | ||
pubkey -- The public key that is used to encrypt key material.The public key is Base64-encoded. | ||
import_token -- The import_token is Base64-encoded string. | ||
*/ | ||
func (c *Client) GetParametersForImport(keyid, keyspec string) (crypto.PublicKey, string, error) { | ||
payload := orderedmap.New() | ||
|
||
payload.Set("keyid", keyid) | ||
payload.Set("keyspec", keyspec) | ||
params := c.initParams(payload) | ||
|
||
c.modifyLock.Lock() | ||
defer c.modifyLock.Unlock() | ||
|
||
// call ehsm kms | ||
resp, err := c.doPost(params, "GetParametersForImport") | ||
if err != nil { | ||
return "", "", err | ||
} | ||
result, ok := resp["result"].(map[string]interface{}) | ||
|
||
if !ok { | ||
return "", "", fmt.Errorf("result field is not a valid map") | ||
} | ||
pubkey, ok := result["pubkey"].(string) | ||
if !ok { | ||
return "", "", fmt.Errorf("pubkey field is not a valid string") | ||
} | ||
|
||
import_token, ok := result["importToken"].(string) | ||
if !ok { | ||
return "", "", fmt.Errorf("import_token field is not a valid string") | ||
} | ||
pemBytes := []byte(pubkey) | ||
derBytes, _ := pem.Decode(pemBytes) | ||
if derBytes == nil { | ||
return "", "", errors.New("PEM decoding failed") | ||
} | ||
switch derBytes.Type { | ||
case string(PublicKeyPEMType): | ||
pub_key, err := x509.ParsePKIXPublicKey(derBytes.Bytes) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
return pub_key, import_token, nil | ||
case string(PKCS1PublicKeyPEMType): | ||
pub_key, err := x509.ParsePKCS1PublicKey(derBytes.Bytes) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
return pub_key, import_token, nil | ||
default: | ||
return "", "", fmt.Errorf("unknown Public key PEM file type: %v. Are you passing the correct public key?", | ||
derBytes.Type) | ||
} | ||
|
||
} | ||
|
||
/* | ||
Description: | ||
Call the ImportKeyMaterial operation to import the key material. | ||
Input: | ||
keyid -- The unique keyid of import CMK. | ||
padding_mode -- The padding mode that is used to encrypt key material. | ||
key_material -- The encrypted symmetric key. | ||
import_token -- The import_token is Base64-encoded string. | ||
Output: | ||
message -- The description of result(success or failed). | ||
*/ | ||
func (c *Client) ImportKeyMaterial(keyid, padding_mode, key_material, import_token string) (bool, error) { | ||
|
||
payload := orderedmap.New() | ||
|
||
payload.Set("keyid", keyid) | ||
payload.Set("padding_mode", padding_mode) | ||
payload.Set("key_material", key_material) | ||
payload.Set("importToken", import_token) | ||
|
||
params := c.initParams(payload) | ||
|
||
c.modifyLock.Lock() | ||
defer c.modifyLock.Unlock() | ||
|
||
// call ehsm kms | ||
resp, err := c.doPost(params, "ImportKeyMaterial") | ||
if err != nil { | ||
return false, err | ||
} | ||
resultString, ok := resp["result"].(map[string]interface{}) | ||
if !ok { | ||
return false, fmt.Errorf("import_token field is not a valid string") | ||
} | ||
result, ok := resultString["result"].(bool) | ||
if !ok { | ||
return false, fmt.Errorf("result field is not a valid bool") | ||
} | ||
|
||
return result, nil | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
from . import serializers | ||
from . import exceptions | ||
from . import session | ||
from . import utils | ||
from . import utils |
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.