|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Headers.php"; |
|
4
|
|
|
require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Utils.class.php"; |
|
5
|
|
|
require_once KS3_API_PATH.DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."Consts.php"; |
|
6
|
|
|
require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
|
7
|
|
|
|
|
8
|
|
|
interface Signer{ |
|
9
|
|
|
public function sign( Ks3Request $request,$args=array()); |
|
10
|
|
|
} |
|
11
|
|
|
class DefaultUserAgentSigner implements Signer{ |
|
12
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
13
|
|
|
$request->addHeader(Headers::$UserAgent,Consts::$UserAgent); |
|
14
|
|
|
} |
|
15
|
|
|
} |
|
16
|
|
|
class DefaultContentTypeSigner implements Signer{ |
|
17
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
18
|
|
|
$contentType = $request->getHeader(Headers::$ContentType); |
|
19
|
|
|
if(empty($contentType)){ |
|
20
|
|
|
$request->addHeader(Headers::$ContentType,"application/xml"); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
class StreamContentTypeSigner implements Signer{ |
|
25
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
26
|
|
|
$contentType = $request->getHeader(Headers::$ContentType); |
|
27
|
|
|
if(empty($contentType)){ |
|
28
|
|
|
$request->addHeader(Headers::$ContentType,"application/ocet-stream"); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
class SuffixContentTypeSigner implements Signer{ |
|
33
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
34
|
|
|
$key = $request->key; |
|
|
|
|
|
|
35
|
|
|
$objArr = explode('/', $key); |
|
36
|
|
|
$basename = array_pop($objArr); |
|
37
|
|
|
$extension = explode ( '.', $basename ); |
|
38
|
|
|
$extension = array_pop ( $extension ); |
|
39
|
|
|
$content_type = Utils::get_mimetype(strtolower($extension)); |
|
40
|
|
|
$request->addHeader(Headers::$ContentType,$content_type); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
class HeaderAuthSigner implements Signer{ |
|
44
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
45
|
|
|
$log = "stringToSing->\r\n"; |
|
46
|
|
|
$date = gmdate('D, d M Y H:i:s \G\M\T'); |
|
47
|
|
|
$request->addHeader(Headers::$Date, $date); |
|
48
|
|
|
|
|
49
|
|
|
$ak = $args["accessKey"]; |
|
50
|
|
|
$sk = $args["secretKey"]; |
|
51
|
|
|
if(empty($ak)){ |
|
52
|
|
|
throw new Ks3ClientException("you should provide accessKey"); |
|
53
|
|
|
} |
|
54
|
|
|
if(empty($sk)){ |
|
55
|
|
|
throw new Ks3ClientException("you should provide secretKey"); |
|
56
|
|
|
} |
|
57
|
|
|
$authration = "KSS "; |
|
58
|
|
|
$signList = array( |
|
59
|
|
|
$request->method, |
|
|
|
|
|
|
60
|
|
|
$request->getHeader(Headers::$ContentMd5), |
|
61
|
|
|
$request->getHeader(Headers::$ContentType), |
|
62
|
|
|
$date |
|
63
|
|
|
); |
|
64
|
|
|
$headers = AuthUtils::canonicalizedKssHeaders($request); |
|
65
|
|
|
$resource = AuthUtils::canonicalizedResource($request); |
|
66
|
|
|
if(!empty($headers)){ |
|
67
|
|
|
array_push($signList,$headers); |
|
68
|
|
|
} |
|
69
|
|
|
array_push($signList,$resource); |
|
70
|
|
|
$stringToSign = join("\n",$signList); |
|
71
|
|
|
$log.= $stringToSign; |
|
72
|
|
|
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true)); |
|
73
|
|
|
|
|
74
|
|
|
$authration.=$ak.":".$signature; |
|
75
|
|
|
$request->addHeader(Headers::$Authorization, $authration); |
|
76
|
|
|
return $log; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
class QueryAuthSigner implements Signer{ |
|
80
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
81
|
|
|
$log = "stringToSing->\r\n"; |
|
82
|
|
|
$ak = $args["accessKey"]; |
|
83
|
|
|
$sk = $args["secretKey"]; |
|
84
|
|
|
$expires = $args["args"]["Options"]["Expires"]; |
|
85
|
|
|
$expiresSencond = time()+$expires; |
|
86
|
|
|
|
|
87
|
|
|
$resource = AuthUtils::canonicalizedResource($request); |
|
|
|
|
|
|
88
|
|
|
$signList = array( |
|
89
|
|
|
$request->method, |
|
|
|
|
|
|
90
|
|
|
$request->getHeader(Headers::$ContentMd5), |
|
91
|
|
|
$request->getHeader(Headers::$ContentType), |
|
92
|
|
|
$expiresSencond |
|
93
|
|
|
); |
|
94
|
|
|
$headers = AuthUtils::canonicalizedKssHeaders($request); |
|
95
|
|
|
$resource = AuthUtils::canonicalizedResource($request); |
|
96
|
|
|
if(!empty($headers)){ |
|
97
|
|
|
array_push($signList,$headers); |
|
98
|
|
|
} |
|
99
|
|
|
array_push($signList,$resource); |
|
100
|
|
|
|
|
101
|
|
|
$stringToSign = join("\n",$signList); |
|
102
|
|
|
$log.= $stringToSign; |
|
103
|
|
|
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true)); |
|
104
|
|
|
$request->addQueryParams("KSSAccessKeyId",$ak); |
|
105
|
|
|
$request->addQueryParams("Signature",$signature); |
|
106
|
|
|
$request->addQueryParams("Expires",$expiresSencond); |
|
107
|
|
|
return $log; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
class ACLSigner implements Signer{ |
|
111
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
112
|
|
|
$args = $args["args"]; |
|
113
|
|
|
if(isset($args["ACL"])){ |
|
114
|
|
|
$acl = $args["ACL"]; |
|
115
|
|
|
if(!in_array($acl, Consts::$Acl)){ |
|
116
|
|
|
throw new Ks3ClientException("unsupport acl :".$acl); |
|
117
|
|
|
}else{ |
|
118
|
|
|
$request->addHeader(Headers::$Acl,$acl); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
if(isset($args["ACP"])){ |
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
class ContentMD5Signer implements Signer{ |
|
127
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
128
|
|
|
$args = $args["args"]; |
|
129
|
|
|
$contentmd5 = ""; |
|
130
|
|
|
if(isset($args["ObjectMeta"][Headers::$ContentMd5])){ |
|
131
|
|
|
$contentmd5 = $args["ObjectMeta"][Headers::$ContentMd5]; |
|
132
|
|
|
} |
|
133
|
|
|
if(empty($contentmd5)){ |
|
134
|
|
|
$body = $request->body; |
|
|
|
|
|
|
135
|
|
|
if(!empty($body)){ |
|
136
|
|
|
$length = $request->getHeader(Headers::$ContentLength); |
|
137
|
|
|
if(empty($length)){ |
|
138
|
|
|
if(isset($args["ObjectMeta"][Headers::$ContentLength])) |
|
139
|
|
|
$length = $args["ObjectMeta"][Headers::$ContentLength]; |
|
140
|
|
|
} |
|
141
|
|
|
if(!empty($length)){ |
|
142
|
|
|
$body = substr($body,0,$length); |
|
143
|
|
|
} |
|
144
|
|
|
$contentmd5 = Utils::hex_to_base64(md5($body)); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
if(!empty($contentmd5)) |
|
148
|
|
|
$request->addHeader(Headers::$ContentMd5,$contentmd5); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
class ContentLengthSigner implements Signer{ |
|
152
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
153
|
|
|
$args = $args["args"]; |
|
154
|
|
|
$contentlength = ""; |
|
155
|
|
|
if(isset($args["ObjectMeta"][Headers::$ContentLength])){ |
|
156
|
|
|
$contentlength = $args["ObjectMeta"][Headers::$ContentLength]; |
|
157
|
|
|
} |
|
158
|
|
|
if(empty($contentlength)){ |
|
159
|
|
|
$body = $request->body; |
|
|
|
|
|
|
160
|
|
|
if(!empty($body)){ |
|
161
|
|
|
$contentlength = strlen($body); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
if(!empty($contentlength)) |
|
165
|
|
|
$request->addHeader(Headers::$ContentLength,$contentlength); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
class ObjectMetaSigner implements Signer{ |
|
169
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
170
|
|
|
$args = $args["args"]; |
|
171
|
|
|
if(isset($args["ObjectMeta"])){ |
|
172
|
|
|
$ObjectMeta = $args["ObjectMeta"]; |
|
173
|
|
|
if(is_array($ObjectMeta)){ |
|
174
|
|
|
foreach ($ObjectMeta as $key => $value) { |
|
175
|
|
|
if(in_array($key,Consts::$ObjectMeta)&&!empty($value)){ |
|
176
|
|
|
$request->addHeader($key,$value); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
class MultipartObjectMetaSigner implements Signer{ |
|
184
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
185
|
|
|
$args = $args["args"]; |
|
186
|
|
|
if(isset($args["ObjectMeta"])){ |
|
187
|
|
|
$ObjectMeta = $args["ObjectMeta"]; |
|
188
|
|
|
if(is_array($ObjectMeta)){ |
|
189
|
|
|
foreach ($ObjectMeta as $key => $value) { |
|
190
|
|
|
if(in_array($key,Consts::$MultipartObjectMeta)&&!empty($value)){ |
|
191
|
|
|
$request->addHeader($key,$value); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
class UserMetaSigner implements Signer{ |
|
199
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
200
|
|
|
$args = $args["args"]; |
|
201
|
|
|
if(isset($args["UserMeta"])){ |
|
202
|
|
|
$UserMeta = $args["UserMeta"]; |
|
203
|
|
|
if(is_array($UserMeta)){ |
|
204
|
|
|
foreach ($UserMeta as $key => $value) { |
|
205
|
|
|
if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){ |
|
206
|
|
|
$request->addHeader($key,$value); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
class CopySourceSigner implements Signer{ |
|
214
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
215
|
|
|
$args = $args["args"]; |
|
216
|
|
|
if(isset($args["CopySource"])){ |
|
217
|
|
|
$CopySource = $args["CopySource"]; |
|
218
|
|
|
if(is_array($CopySource)){ |
|
219
|
|
|
if(!isset($CopySource["Bucket"])) |
|
220
|
|
|
throw new Ks3ClientException("you should provide copy source bucket"); |
|
221
|
|
|
if(!isset($CopySource["Key"])) |
|
222
|
|
|
throw new Ks3ClientException("you should provide copy source key"); |
|
223
|
|
|
$bucket = $CopySource["Bucket"]; |
|
224
|
|
|
$key = Utils::encodeUrl($CopySource["Key"]); |
|
225
|
|
|
$request->addHeader(Headers::$CopySource,"/".$bucket."/".$key); |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
class StreamUploadSigner implements Signer{ |
|
231
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
232
|
|
|
$args = $args["args"]; |
|
233
|
|
|
if(isset($args["Content"])&&is_array($args["Content"])&&isset($args["Content"]["content"])){ |
|
234
|
|
|
$content = $args["Content"]["content"]; |
|
235
|
|
|
$seek_position = 0; |
|
236
|
|
|
$resourceLength = 0; |
|
|
|
|
|
|
237
|
|
|
$length = -1; |
|
238
|
|
|
$isFile = FALSE; |
|
239
|
|
|
|
|
240
|
|
|
if (!is_resource($content)){ |
|
241
|
|
|
$isFile = TRUE; |
|
242
|
|
|
//如果之前用户已经转化为GBK则不转换 |
|
243
|
|
|
if(Utils::chk_chinese($content)&&!Utils::check_char($content)){ |
|
244
|
|
|
$content = iconv('utf-8','gbk',$content); |
|
245
|
|
|
} |
|
246
|
|
|
if(!file_exists($content)) |
|
247
|
|
|
throw new Ks3ClientException("the specified file does not exist "); |
|
248
|
|
|
$length = Utils::getFileSize($content); |
|
249
|
|
|
$content = fopen($content,"r"); |
|
250
|
|
|
}else{ |
|
251
|
|
|
$stats = fstat($content); |
|
252
|
|
|
if ($stats && $stats["size"] >= 0){ |
|
|
|
|
|
|
253
|
|
|
$length = $stats["size"]; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
//之所以取resourceLength是为了防止Content-Length大于实际数据的大小,导致一直等待。 |
|
257
|
|
|
$resourceLength = $length; |
|
258
|
|
|
//优先取用户设置seek_position,没有的话取ftell |
|
259
|
|
|
if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){ |
|
260
|
|
|
$seek_position = $args["Content"]["seek_position"]; |
|
261
|
|
|
}else if(!$isFile){ |
|
262
|
|
|
$seek_position = ftell($content); |
|
263
|
|
|
if($seek_position<0) |
|
264
|
|
|
$seek_position = 0; |
|
265
|
|
|
fseek($content,0); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
$lengthInMeta = -1; |
|
269
|
|
|
if(isset($args["ObjectMeta"]["Content-Length"])){ |
|
270
|
|
|
$lengthInMeta = $args["ObjectMeta"]["Content-Length"]; |
|
271
|
|
|
} |
|
272
|
|
|
if($lengthInMeta > 0){ |
|
273
|
|
|
$length = $lengthInMeta; |
|
274
|
|
|
}else if($resourceLength > 0){ |
|
275
|
|
|
//根据seek_position计算实际长度 |
|
276
|
|
|
$length = $resourceLength - $seek_position; |
|
277
|
|
|
} |
|
278
|
|
|
if($length <= 0) |
|
279
|
|
|
throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length); |
|
280
|
|
|
$request->read_stream = $content; |
|
|
|
|
|
|
281
|
|
|
$request->addHeader(Headers::$ContentLength,$length); |
|
282
|
|
|
$request->seek_position = $seek_position; |
|
|
|
|
|
|
283
|
|
|
}else{ |
|
284
|
|
|
throw new Ks3ClientException("please specifie upload content in args"); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
class RangeSigner{ |
|
289
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
290
|
|
|
$args = $args["args"]; |
|
291
|
|
|
if(isset($args["Range"])){ |
|
292
|
|
|
$Range = $args["Range"]; |
|
293
|
|
|
if(is_array($Range)){ |
|
294
|
|
|
$start = $Range["start"]; |
|
295
|
|
|
$end = $Range["end"]; |
|
296
|
|
|
$range = "bytes=".$start."-".$end; |
|
297
|
|
|
$request->addHeader(Headers::$Range,$range); |
|
298
|
|
|
}else |
|
299
|
|
|
$request->addHeader(Headers::$Range,$Range); |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
class GetObjectSigner{ |
|
304
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
305
|
|
|
$args = $args["args"]; |
|
306
|
|
|
if(isset($args["WriteTo"])){ |
|
307
|
|
|
$WriteTo = $args["WriteTo"]; |
|
308
|
|
|
if(is_resource($WriteTo)){ |
|
309
|
|
|
$request->write_stream = $WriteTo; |
|
|
|
|
|
|
310
|
|
|
}else{ |
|
311
|
|
|
//如果之前用户已经转化为GBK则不转换 |
|
312
|
|
|
if(Utils::chk_chinese($WriteTo)&&!Utils::check_char($WriteTo)){ |
|
313
|
|
|
$WriteTo = iconv('utf-8','gbk',$WriteTo); |
|
314
|
|
|
} |
|
315
|
|
|
$request->write_stream = fopen($WriteTo,"w"); |
|
316
|
|
|
} |
|
317
|
|
|
} |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
class AdpSigner{ |
|
321
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
322
|
|
|
$args = $args["args"]; |
|
323
|
|
|
if(isset($args["Adp"])){ |
|
324
|
|
|
$AdpConf = $args["Adp"]; |
|
325
|
|
|
if(is_array($AdpConf)){ |
|
326
|
|
|
if(isset($AdpConf["NotifyURL"])){ |
|
327
|
|
|
$NotifyURL = $AdpConf["NotifyURL"]; |
|
328
|
|
|
}else{ |
|
329
|
|
|
throw new Ks3ClientException("adp should provide NotifyURL"); |
|
330
|
|
|
} |
|
331
|
|
|
if(isset($AdpConf["Adps"])){ |
|
332
|
|
|
$Adps = $AdpConf["Adps"]; |
|
333
|
|
|
}else{ |
|
334
|
|
|
throw new Ks3ClientException("adp should provide Adps"); |
|
335
|
|
|
} |
|
336
|
|
|
$AdpString = ""; |
|
337
|
|
|
foreach ($Adps as $Adp) { |
|
338
|
|
|
if(is_array($Adp)){ |
|
339
|
|
|
if(!isset($Adp["Command"])){ |
|
340
|
|
|
throw new Ks3ClientException("command is needed in adp"); |
|
341
|
|
|
} |
|
342
|
|
|
$command = $Adp["Command"]; |
|
343
|
|
|
$bucket = NULL; |
|
344
|
|
|
$key = NULL; |
|
345
|
|
|
if(isset($Adp["Bucket"])){ |
|
346
|
|
|
$bucket = $Adp["Bucket"]; |
|
347
|
|
|
} |
|
348
|
|
|
if(isset($Adp["Key"])){ |
|
349
|
|
|
$key = $Adp["Key"]; |
|
350
|
|
|
} |
|
351
|
|
|
$AdpString.=$command; |
|
352
|
|
|
if(!(empty($bucket)&&empty($key))){ |
|
353
|
|
|
if(empty($bucket)){ |
|
354
|
|
|
$AdpString.="|tag=saveas&object=".base64_encode($key); |
|
355
|
|
|
}elseif (empty($key)) { |
|
356
|
|
|
$AdpString.="|tag=saveas&bucket=".$bucket; |
|
357
|
|
|
}else{ |
|
358
|
|
|
$AdpString.="|tag=saveas&bucket=".$bucket."&"."object=".base64_encode($key); |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
$AdpString.=";"; |
|
362
|
|
|
} |
|
363
|
|
|
} |
|
364
|
|
|
if(!empty($AdpString)&&!empty($NotifyURL)){ |
|
365
|
|
|
$request->addHeader(Headers::$AsynchronousProcessingList,$AdpString); |
|
366
|
|
|
$request->addHeader(Headers::$NotifyURL,$NotifyURL); |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
class CallBackSigner{ |
|
373
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
374
|
|
|
$args = $args["args"]; |
|
375
|
|
|
if(isset($args["CallBack"])&&is_array($args["CallBack"])){ |
|
376
|
|
|
$CallBackConf = $args["CallBack"]; |
|
377
|
|
|
$url = NULL; |
|
378
|
|
|
$body = NULL; |
|
379
|
|
|
if(isset($CallBackConf["Url"])){ |
|
380
|
|
|
$url = $CallBackConf["Url"]; |
|
381
|
|
|
} |
|
382
|
|
|
if(empty($url)) |
|
383
|
|
|
throw new Ks3ClientException("Url is needed in CallBack"); |
|
384
|
|
|
if(isset($CallBackConf["BodyMagicVariables"])){ |
|
385
|
|
|
if(is_array($CallBackConf["BodyMagicVariables"])){ |
|
386
|
|
|
$magics = $CallBackConf["BodyMagicVariables"]; |
|
387
|
|
|
foreach ($magics as $key => $value) { |
|
388
|
|
|
if(in_array($value,Consts::$CallBackMagics)) |
|
389
|
|
|
$body.=$key."=\${".$value."}&"; |
|
390
|
|
|
} |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
|
|
if(isset($CallBackConf["BodyVariables"])){ |
|
394
|
|
|
if(is_array($CallBackConf["BodyVariables"])){ |
|
395
|
|
|
$variables = $CallBackConf["BodyVariables"]; |
|
396
|
|
|
foreach ($variables as $key => $value) { |
|
397
|
|
|
$body.=$key."=\${kss-".$key."}&"; |
|
398
|
|
|
$request->addHeader("kss-".$key,$value); |
|
399
|
|
|
} |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
if(!empty($body)){ |
|
403
|
|
|
$body=substr($body,0,strlen($body)-1); |
|
404
|
|
|
$request->addHeader(Headers::$XKssCallbackBody,$body); |
|
405
|
|
|
} |
|
406
|
|
|
$request->addHeader(Headers::$XKssCallbackUrl,$url); |
|
407
|
|
|
} |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
class SSESigner{ |
|
411
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
412
|
|
|
$args = $args["args"]; |
|
413
|
|
|
if(isset($args["SSE"])){ |
|
414
|
|
|
if(isset($args["SSE"]["Algm"])) |
|
415
|
|
|
$algm = $args["SSE"]["Algm"]; |
|
416
|
|
|
if(isset($args["SSE"]["KMSId"])) |
|
417
|
|
|
$id = $args["SSE"]["KMSId"]; |
|
418
|
|
|
if(!empty($algm)){ |
|
419
|
|
|
$request->addHeader(Headers::$SSEAlgm,$algm); |
|
420
|
|
|
if(!empty($id)) |
|
421
|
|
|
$request->addHeader(Headers::$SSEKMSId,$id); |
|
422
|
|
|
} |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
|
|
} |
|
426
|
|
|
class SSECSigner{ |
|
427
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
428
|
|
|
$args = $args["args"]; |
|
429
|
|
|
if(isset($args["SSEC"])){ |
|
430
|
|
|
if(isset($args["SSEC"]["Algm"])) |
|
431
|
|
|
$algm = $args["SSEC"]["Algm"]; |
|
432
|
|
|
if(isset($args["SSEC"]["Key"])) |
|
433
|
|
|
$key = $args["SSEC"]["Key"]; |
|
434
|
|
|
if(isset($args["SSEC"]["KeyBase64"])) |
|
435
|
|
|
$keybase64 = $args["SSEC"]["KeyBase64"]; |
|
436
|
|
|
if(isset($args["SSEC"]["KeyMD5"])) |
|
437
|
|
|
$md5 = $args["SSEC"]["KeyMD5"]; |
|
438
|
|
|
if(!empty($key)||!empty($keybase64)){ |
|
439
|
|
|
if(empty($key)) |
|
440
|
|
|
$key = base64_decode($keybase64); |
|
|
|
|
|
|
441
|
|
|
if(empty($algm)) |
|
442
|
|
|
$algm = Consts::$SSEDefaultAlgm; |
|
443
|
|
|
if(empty($md5)) |
|
444
|
|
|
$md5 = Utils::hex_to_base64(md5($key)); |
|
445
|
|
|
|
|
446
|
|
|
$request->addHeader(Headers::$SSECAlgm,$algm); |
|
447
|
|
|
$request->addHeader(Headers::$SSECKey,base64_encode($key)); |
|
448
|
|
|
$request->addHeader(Headers::$SSECMD5,$md5); |
|
449
|
|
|
} |
|
450
|
|
|
} |
|
451
|
|
|
} |
|
452
|
|
|
} |
|
453
|
|
|
class SSECSourceSigner{ |
|
454
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
455
|
|
|
$args = $args["args"]; |
|
456
|
|
|
if(isset($args["SSECSource"])){ |
|
457
|
|
|
if(isset($args["SSECSource"]["Algm"])) |
|
458
|
|
|
$algm = $args["SSECSource"]["Algm"]; |
|
459
|
|
|
if(isset($args["SSECSource"]["Key"])) |
|
460
|
|
|
$key = $args["SSECSource"]["Key"]; |
|
461
|
|
|
if(isset($args["SSECSource"]["KeyBase64"])) |
|
462
|
|
|
$keybase64 = $args["SSECSource"]["KeyBase64"]; |
|
463
|
|
|
if(isset($args["SSECSource"]["KeyMD5"])) |
|
464
|
|
|
$md5 = $args["SSECSource"]["KeyMD5"]; |
|
465
|
|
|
if(!empty($key)||!empty($keybase64)){ |
|
466
|
|
|
if(empty($key)) |
|
467
|
|
|
$key = base64_decode($keybase64); |
|
|
|
|
|
|
468
|
|
|
if(empty($algm)) |
|
469
|
|
|
$algm = Consts::$SSEDefaultAlgm; |
|
470
|
|
|
if(empty($md5)) |
|
471
|
|
|
$md5 = Utils::hex_to_base64(md5($key)); |
|
472
|
|
|
|
|
473
|
|
|
$request->addHeader(Headers::$SSECSourceAlgm,$algm); |
|
474
|
|
|
$request->addHeader(Headers::$SSECSourceKey,base64_encode($key)); |
|
475
|
|
|
$request->addHeader(Headers::$SSECSourceMD5,$md5); |
|
476
|
|
|
} |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
} |
|
480
|
|
|
class AllHeaderSigner{ |
|
481
|
|
|
public function sign(Ks3Request $request,$args=array()){ |
|
482
|
|
|
$args = $args["args"]; |
|
483
|
|
|
$headers = isset($args["Headers"])?$args["Headers"]:""; |
|
484
|
|
|
if(!empty($headers)&&is_array($headers)){ |
|
485
|
|
|
foreach ($headers as $key => $value) { |
|
486
|
|
|
$request->addHeader($key,$value); |
|
487
|
|
|
} |
|
488
|
|
|
} |
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
class AuthUtils{ |
|
492
|
|
|
public static function canonicalizedKssHeaders(Ks3Request $request){ |
|
493
|
|
|
$header = ""; |
|
494
|
|
|
$headers = $request->headers; |
|
|
|
|
|
|
495
|
|
|
ksort($headers,SORT_STRING); |
|
496
|
|
|
foreach ( $headers as $header_key => $header_value ) { |
|
497
|
|
|
if (substr(strtolower($header_key), 0, 6) === Consts::$KS3HeaderPrefix){ |
|
498
|
|
|
$header .= "\n".strtolower($header_key) . ':' .$header_value; |
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
$header = substr($header, 1); |
|
502
|
|
|
return $header; |
|
503
|
|
|
} |
|
504
|
|
|
public static function canonicalizedResource(Ks3Request $request){ |
|
505
|
|
|
$resource = "/"; |
|
506
|
|
|
$bucket = $request->bucket; |
|
|
|
|
|
|
507
|
|
|
$key = $request->key; |
|
|
|
|
|
|
508
|
|
|
$subResource = $request->subResource; |
|
|
|
|
|
|
509
|
|
|
if(!empty($bucket)){ |
|
510
|
|
|
$resource.=$request->bucket."/"; |
|
511
|
|
|
} |
|
512
|
|
|
if(!empty($key)){ |
|
513
|
|
|
$resource.=Utils::encodeUrl($request->key); |
|
514
|
|
|
} |
|
515
|
|
|
|
|
516
|
|
|
$encodeParams = ""; |
|
517
|
|
|
$querys = $request->queryParams; |
|
|
|
|
|
|
518
|
|
|
if(!empty($subResource)){ |
|
519
|
|
|
$querys[$subResource] = NULL; |
|
520
|
|
|
} |
|
521
|
|
|
ksort($querys,SORT_STRING); |
|
522
|
|
|
foreach ($querys as $key => $value) { |
|
523
|
|
|
if(in_array($key,Consts::$SubResource)||in_array($key,Consts::$QueryParam)){ |
|
524
|
|
|
if(empty($value)){ |
|
525
|
|
|
$encodeParams.="&".$key; |
|
526
|
|
|
}else{ |
|
527
|
|
|
$encodeParams.="&".$key."=".$value; |
|
528
|
|
|
} |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
$encodeParams = substr($encodeParams,1); |
|
532
|
|
|
|
|
533
|
|
|
$resource = str_replace("//","/%2F", $resource); |
|
534
|
|
|
|
|
535
|
|
|
if(!empty($encodeParams)){ |
|
536
|
|
|
$resource.="?".$encodeParams; |
|
537
|
|
|
} |
|
538
|
|
|
return $resource; |
|
539
|
|
|
} |
|
540
|
|
|
} |
|
541
|
|
|
?> |
|
|
|
|
|