@@ -100,27 +100,32 @@ def decrypt(data, private_key_path=os.getenv("STACKS_PRIVATE_KEY_PATH"), must_de
100
100
string_encrypted_base64 ,
101
101
) = data .removeprefix ("ENC[" ).removesuffix ("]" ).split (";" )
102
102
103
- with open (private_key_path , "rb" ) as f :
104
- private_key = cryptography .hazmat .primitives .serialization .load_pem_private_key (
105
- f .read (),
106
- password = None ,
107
- backend = cryptography .hazmat .backends .default_backend (),
108
- )
109
-
110
- try :
111
- symmetric_key = private_key .decrypt (
112
- base64 .b64decode (symmetric_key_encrypted_base64 .encode ()),
113
- cryptography .hazmat .primitives .asymmetric .padding .OAEP (
114
- mgf = cryptography .hazmat .primitives .asymmetric .padding .MGF1 (algorithm = cryptography .hazmat .primitives .hashes .SHA256 ()),
115
- algorithm = cryptography .hazmat .primitives .hashes .SHA256 (),
116
- label = None ,
117
- ),
118
- )
119
- except ValueError as e :
120
- if must_decrypt :
121
- raise e
122
- else :
123
- return data
103
+ private_key_paths = private_key_path .split ("," )
104
+ for i in range (len (private_key_paths )):
105
+ with open (private_key_paths [i ], "rb" ) as f :
106
+ private_key = cryptography .hazmat .primitives .serialization .load_pem_private_key (
107
+ f .read (),
108
+ password = None ,
109
+ backend = cryptography .hazmat .backends .default_backend (),
110
+ )
111
+
112
+ try :
113
+ symmetric_key = private_key .decrypt (
114
+ base64 .b64decode (symmetric_key_encrypted_base64 .encode ()),
115
+ cryptography .hazmat .primitives .asymmetric .padding .OAEP (
116
+ mgf = cryptography .hazmat .primitives .asymmetric .padding .MGF1 (algorithm = cryptography .hazmat .primitives .hashes .SHA256 ()),
117
+ algorithm = cryptography .hazmat .primitives .hashes .SHA256 (),
118
+ label = None ,
119
+ ),
120
+ )
121
+ break
122
+ except ValueError as e :
123
+ if i < len (private_key_paths )- 1 :
124
+ continue
125
+ elif must_decrypt :
126
+ raise e
127
+ else :
128
+ return data
124
129
125
130
init_vector = base64 .b64decode (init_vector_base64 .encode ())
126
131
0 commit comments