@@ -74,6 +74,10 @@ def _load_aws_config_file(self, profile):
74
74
return self ._split_s3_config (s3_config )
75
75
76
76
def _prepare_credentials (self , ** config ):
77
+ import base64
78
+
79
+ from s3fs .utils import SSEParams
80
+
77
81
login_info = defaultdict (dict )
78
82
79
83
# credentials
@@ -98,8 +102,24 @@ def _prepare_credentials(self, **config):
98
102
99
103
# encryptions
100
104
additional = login_info ["s3_additional_kwargs" ]
101
- additional ["ServerSideEncryption" ] = config .get ("sse" )
102
- additional ["SSEKMSKeyId" ] = config .get ("sse_kms_key_id" )
105
+ sse_customer_key = None
106
+ if config .get ("sse_customer_key" ):
107
+ if config .get ("sse_kms_key_id" ):
108
+ raise ConfigError (
109
+ "`sse_kms_key_id` and `sse_customer_key` AWS S3 config "
110
+ "options are mutually exclusive"
111
+ )
112
+ sse_customer_key = base64 .b64decode (config .get ("sse_customer_key" ))
113
+ sse_customer_algorithm = config .get ("sse_customer_algorithm" )
114
+ if not sse_customer_algorithm and sse_customer_key :
115
+ sse_customer_algorithm = "AES256"
116
+ sse_params = SSEParams (
117
+ server_side_encryption = config .get ("sse" ),
118
+ sse_customer_algorithm = sse_customer_algorithm ,
119
+ sse_customer_key = sse_customer_key ,
120
+ sse_kms_key_id = config .get ("sse_kms_key_id" ),
121
+ )
122
+ additional .update (sse_params .to_kwargs ())
103
123
additional ["ACL" ] = config .get ("acl" )
104
124
for grant_option , grant_key in self ._GRANTS .items ():
105
125
if config .get (grant_option ):
0 commit comments