|
|
@@ -57,10 +57,9 @@ public class ObjectBasicController {
|
|
|
String date = servletRequest.getHeader("x-amz-date");
|
|
|
|
|
|
FileInputStream fis = new FileInputStream(file);
|
|
|
- byte[] md5 = DigestUtil.md5sum(fis.readAllBytes());
|
|
|
- String md5Hex = ByteHex.bytes2Hex(md5);
|
|
|
- String md5Base64 = Base64Util.encode(md5);
|
|
|
- if (!contentMd5.equals(md5Base64)) {
|
|
|
+ String sha256sum1 = DigestUtil.sha256sum(fis);
|
|
|
+
|
|
|
+ if (!sha256sum.equals(sha256sum1)) {
|
|
|
return ResponseEntity.status(500).body("md5 不匹配");
|
|
|
}
|
|
|
|
|
|
@@ -73,53 +72,12 @@ public class ObjectBasicController {
|
|
|
return ResponseEntity.status(500).body("签名不正确2");
|
|
|
}
|
|
|
|
|
|
- boolean matched = OssUtil.matchSignature(secretKey, file);
|
|
|
+ boolean matched = OssUtil.matchSignature(secretKey, sha256sum1);
|
|
|
if (!matched) {
|
|
|
return ResponseEntity.status(500).body("签名不正确3");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*String authorization = servletRequest.getHeader("authorization");
|
|
|
- String[] auths = authorization.split(",");
|
|
|
- String credential = auths[0].replace("AWS4-HMAC-SHA256 ", "").split("=")[1];
|
|
|
- String[] strs = credential.split("/");
|
|
|
- String accessKey = strs[0];
|
|
|
- String date1 = strs[1];
|
|
|
- String region = strs[2];
|
|
|
- String service = strs[3];
|
|
|
- String version = strs[4];
|
|
|
-
|
|
|
- String[] signedHeaders = auths[1].split("=")[1].split(";");
|
|
|
- String signature = auths[2].split("=")[1];
|
|
|
-
|
|
|
- String xAmzDate = servletRequest.getHeader("x-amz-date");
|
|
|
- TreeMap<String, String> awsHeaders = new TreeMap<>();
|
|
|
- for (String name : signedHeaders) {
|
|
|
- servletRequest.getHeader(name);
|
|
|
- awsHeaders.put(name, servletRequest.getHeader(name));
|
|
|
- }
|
|
|
-
|
|
|
- String method = servletRequest.getMethod();
|
|
|
- String uri = servletRequest.getRequestURI();
|
|
|
- //String accessKey = "accesskey123456";
|
|
|
- String secretKey = "secretKey123456";
|
|
|
- AWS4Signer aWSV4Signer = new AWS4Signer.Builder(accessKey, secretKey)
|
|
|
- .regionName("cd")
|
|
|
- .serviceName("s3")
|
|
|
- .xAmzDate(xAmzDate)
|
|
|
- .httpMethodName(method)
|
|
|
- .canonicalURI(uri)
|
|
|
- .queryParametes(null)
|
|
|
- .awsHeaders(awsHeaders)
|
|
|
- .payload(fis.readAllBytes())
|
|
|
- .build();
|
|
|
-
|
|
|
- String signature1 = aWSV4Signer.getSignature();
|
|
|
- if (!signature.equals(signature1)) {
|
|
|
- log.error("签名不正确");
|
|
|
- return ResponseEntity.status(500).body("签名不正确");
|
|
|
- }*/
|
|
|
-
|
|
|
String objectName = OssUtil.getObjectName();
|
|
|
objectBasicService.putObject(objectName, file, contentType, sha256sum);
|
|
|
|
|
|
@@ -132,7 +90,7 @@ public class ObjectBasicController {
|
|
|
.header("Content-Length", "1")
|
|
|
.header("Connection", "close")
|
|
|
.header("Server", "TNBCloudOSS")
|
|
|
- .eTag(md5Hex)
|
|
|
+ .eTag(sha256sum1)
|
|
|
.build();
|
|
|
}
|
|
|
|