mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-22 16:58:55 +00:00
commit
1520ca6220
@ -70,20 +70,16 @@ std::string s3fs_md5sum(int fd, off_t start, off_t size)
|
||||
std::string s3fs_sha256sum(int fd, off_t start, off_t size)
|
||||
{
|
||||
size_t digestlen = get_sha256_digest_length();
|
||||
char sha256[2 * digestlen + 1];
|
||||
unsigned char* sha256hex;
|
||||
|
||||
if(NULL == (sha256hex = s3fs_sha256hexsum(fd, start, size))){
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
memset(sha256, 0, 2 * digestlen + 1);
|
||||
for(size_t pos = 0; pos < digestlen; pos++){
|
||||
snprintf(sha256 + 2 * pos, 3, "%02x", sha256hex[pos]);
|
||||
}
|
||||
std::string sha256 = s3fs_hex(sha256hex, digestlen);
|
||||
delete[] sha256hex;
|
||||
|
||||
return std::string(sha256);
|
||||
return sha256;
|
||||
}
|
||||
|
||||
/*
|
||||
|
25
src/curl.cpp
25
src/curl.cpp
@ -2492,9 +2492,7 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
|
||||
char kSecret[128];
|
||||
unsigned char *kDate, *kRegion, *kService, *kSigning, *sRequest = NULL;
|
||||
unsigned int kDate_len,kRegion_len, kService_len, kSigning_len, sRequest_len = 0;
|
||||
char hexsRequest[64 + 1];
|
||||
int kSecret_len = snprintf(kSecret, sizeof(kSecret), "AWS4%s", S3fsCurl::AWSSecretAccessKey.c_str());
|
||||
unsigned int cnt;
|
||||
|
||||
s3fs_HMAC256(kSecret, kSecret_len, reinterpret_cast<const unsigned char*>(strdate.data()), strdate.size(), &kDate, &kDate_len);
|
||||
s3fs_HMAC256(kDate, kDate_len, reinterpret_cast<const unsigned char*>(endpoint.c_str()), endpoint.size(), &kRegion, &kRegion_len);
|
||||
@ -2507,15 +2505,12 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
|
||||
const unsigned char* cRequest = reinterpret_cast<const unsigned char*>(StringCQ.c_str());
|
||||
unsigned int cRequest_len = StringCQ.size();
|
||||
s3fs_sha256(cRequest, cRequest_len, &sRequest, &sRequest_len);
|
||||
for(cnt = 0; cnt < sRequest_len; cnt++){
|
||||
sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]);
|
||||
}
|
||||
delete[] sRequest;
|
||||
|
||||
StringToSign = "AWS4-HMAC-SHA256\n";
|
||||
StringToSign += date8601 + "\n";
|
||||
StringToSign += strdate + "/" + endpoint + "/s3/aws4_request\n";
|
||||
StringToSign += hexsRequest;
|
||||
StringToSign += s3fs_hex(sRequest, sRequest_len);
|
||||
delete[] sRequest;
|
||||
|
||||
const unsigned char* cscope = reinterpret_cast<const unsigned char*>(StringToSign.c_str());
|
||||
unsigned int cscope_len = StringToSign.size();
|
||||
@ -2523,15 +2518,10 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
|
||||
unsigned int md_len = 0;
|
||||
|
||||
s3fs_HMAC256(kSigning, kSigning_len, cscope, cscope_len, &md, &md_len);
|
||||
char *hexSig = new char[2 * md_len + 1];
|
||||
for(cnt = 0; cnt < md_len; cnt++){
|
||||
sprintf(&hexSig[cnt * 2], "%02x", md[cnt]);
|
||||
}
|
||||
delete[] kSigning;
|
||||
delete[] md;
|
||||
|
||||
Signature = hexSig;
|
||||
delete[] hexSig;
|
||||
Signature = s3fs_hex(md, md_len);
|
||||
delete[] md;
|
||||
|
||||
return Signature;
|
||||
}
|
||||
@ -2550,14 +2540,9 @@ void S3fsCurl::insertV4Headers()
|
||||
unsigned int cRequest_len = strlen(reinterpret_cast<const char *>(b_postdata));
|
||||
unsigned char* sRequest = NULL;
|
||||
unsigned int sRequest_len = 0;
|
||||
char hexsRequest[64 + 1];
|
||||
unsigned int cnt;
|
||||
s3fs_sha256(b_postdata, cRequest_len, &sRequest, &sRequest_len);
|
||||
for(cnt = 0; cnt < sRequest_len; cnt++){
|
||||
sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]);
|
||||
}
|
||||
payload_hash = s3fs_hex(sRequest, sRequest_len);
|
||||
delete[] sRequest;
|
||||
payload_hash.assign(hexsRequest, &hexsRequest[sRequest_len * 2]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -38,14 +38,8 @@ template <> void assert_equals(const std::string &x, const std::string &y, const
|
||||
{
|
||||
if (x != y) {
|
||||
std::cerr << x << " != " << y << " at " << file << ":" << line << std::endl;
|
||||
for (unsigned i=0; i<x.length(); i++) {
|
||||
fprintf(stderr, "%02x ", (unsigned char)x[i]);
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
for (unsigned i=0; i<y.length(); i++) {
|
||||
fprintf(stderr, "%02x ", (unsigned char)y[i]);
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
@ -63,14 +57,8 @@ template <> void assert_nequals(const std::string &x, const std::string &y, cons
|
||||
{
|
||||
if (x == y) {
|
||||
std::cerr << x << " == " << y << " at " << file << ":" << line << std::endl;
|
||||
for (unsigned i=0; i<x.length(); i++) {
|
||||
fprintf(stderr, "%02x ", (unsigned char)x[i]);
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
for (unsigned i=0; i<y.length(); i++) {
|
||||
fprintf(stderr, "%02x ", (unsigned char)y[i]);
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user