44from .utils .crypto import decrypt_b64 , encrypt_b64 , fetch_app_key , random_key_pair , reconstruct_secret
55from .version import __version__ , __ph_version__
66
7+ DEFAULT_KMS_HOST = "https://kms.phase.dev"
8+
79
810@dataclass
911class AppSecret :
@@ -18,8 +20,9 @@ class Phase:
1820 _app_id = ''
1921 _app_pub_key = ''
2022 _app_secret = None
23+ _kms_host = ''
2124
22- def __init__ (self , app_id , app_secret ):
25+ def __init__ (self , app_id , app_secret , custom_kms_host = None ):
2326 app_id_pattern = re .compile (r"^phApp:v(\d+):([a-fA-F0-9]{64})$" )
2427 app_secret_pattern = re .compile (
2528 r"^pss:v(\d+):([a-fA-F0-9]{64}):([a-fA-F0-9]{64,128}):([a-fA-F0-9]{64})$" )
@@ -32,9 +35,10 @@ def __init__(self, app_id, app_secret):
3235
3336 self ._app_id = app_id
3437 self ._app_pub_key = app_id .split (':' )[2 ]
35- app_secret_segments = app_secret .split (':' )
3638
39+ app_secret_segments = app_secret .split (':' )
3740 self ._app_secret = AppSecret (* app_secret_segments )
41+ self ._kms_host = f"{ custom_kms_host } /kms" if custom_kms_host else DEFAULT_KMS_HOST
3842
3943 def encrypt (self , plaintext , tag = "" ) -> str | None :
4044 """
@@ -81,7 +85,7 @@ def decrypt(self, phase_ciphertext) -> str | None:
8185 client_pub_key = bytes .fromhex (client_pub_key_hex )
8286
8387 keyshare1 = fetch_app_key (
84- self ._app_secret .app_token , self ._app_secret .keyshare1_unwrap_key , self ._app_id , len (ct )/ 2 )
88+ self ._app_secret .app_token , self ._app_secret .keyshare1_unwrap_key , self ._app_id , len (ct )/ 2 , self . _kms_host )
8589
8690 app_priv_key = reconstruct_secret (
8791 [self ._app_secret .keyshare0 , keyshare1 ])
0 commit comments