mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-05 12:27:53 +00:00
Fixed bugs, segfault and signature error at listing.
This commit is contained in:
parent
bb1f1d3faa
commit
0d2f3e2dc4
42
src/curl.cpp
42
src/curl.cpp
@ -1839,8 +1839,7 @@ string S3fsCurl::CalcSignaturev2(string method, string strMD5, string content_ty
|
|||||||
return Signature;
|
return Signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
string S3fsCurl::CalcSignatureReal(string method, string canonical_uri, string query_string , string date2,
|
string S3fsCurl::CalcSignatureReal(string method, string canonical_uri, string query_string, string date2, string canonical_headers, string payload_hash, string signed_headers, string date3)
|
||||||
string canonical_headers, string payload_hash, string signed_headers, string date3)
|
|
||||||
{
|
{
|
||||||
string Signature, StringCQ, StringToSign;
|
string Signature, StringCQ, StringToSign;
|
||||||
string uriencode;
|
string uriencode;
|
||||||
@ -1869,39 +1868,48 @@ string S3fsCurl::CalcSignatureReal(string method, string canonical_uri, string q
|
|||||||
StringCQ += canonical_headers + "\n";
|
StringCQ += canonical_headers + "\n";
|
||||||
StringCQ += signed_headers + "\n";
|
StringCQ += signed_headers + "\n";
|
||||||
StringCQ += payload_hash;
|
StringCQ += payload_hash;
|
||||||
unsigned char * cRequest = (unsigned char *)StringCQ.c_str();
|
|
||||||
unsigned int cRequest_len= StringCQ.size();
|
|
||||||
// DPRN("SHUNDEBUGXXXPUT: %s", cRequest);
|
|
||||||
char kSecret[128];
|
char kSecret[128];
|
||||||
unsigned char *kDate, *kRegion, *kService, *kSigning, *sRequest = NULL;
|
unsigned char *kDate, *kRegion, *kService, *kSigning, *sRequest = NULL;
|
||||||
unsigned int kDate_len,kRegion_len, kService_len, kSigning_len, sRequest_len = 0;
|
unsigned int kDate_len,kRegion_len, kService_len, kSigning_len, sRequest_len = 0;
|
||||||
char hexsRequest[64];
|
char hexsRequest[64 + 1];
|
||||||
int kSecret_len = snprintf(kSecret, sizeof(kSecret), "AWS4%s", S3fsCurl::AWSSecretAccessKey.c_str());
|
int kSecret_len = snprintf(kSecret, sizeof(kSecret), "AWS4%s", S3fsCurl::AWSSecretAccessKey.c_str());
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
s3fs_HMAC(kSecret, kSecret_len, (unsigned char*)date2.data(), date2.size(), &kDate, &kDate_len);
|
s3fs_HMAC(kSecret, kSecret_len, reinterpret_cast<const unsigned char*>(date2.data()), date2.size(), &kDate, &kDate_len);
|
||||||
s3fs_HMAC(kDate, kDate_len, (unsigned char *)endpoint.c_str(), endpoint.size(), &kRegion, &kRegion_len);
|
s3fs_HMAC(kDate, kDate_len, reinterpret_cast<const unsigned char*>(endpoint.c_str()), endpoint.size(), &kRegion, &kRegion_len);
|
||||||
s3fs_HMAC(kRegion, kRegion_len, (unsigned char *)"s3", sizeof("s3")-1, &kService, &kService_len);
|
s3fs_HMAC(kRegion, kRegion_len, reinterpret_cast<const unsigned char*>("s3"), sizeof("s3") - 1, &kService, &kService_len);
|
||||||
s3fs_HMAC(kService, kService_len, (unsigned char *)"aws4_request", sizeof("aws4_request")-1, &kSigning, &kSigning_len);
|
s3fs_HMAC(kService, kService_len, reinterpret_cast<const unsigned char*>("aws4_request"), sizeof("aws4_request") - 1, &kSigning, &kSigning_len);
|
||||||
|
free(kDate);
|
||||||
|
free(kRegion);
|
||||||
|
free(kService);
|
||||||
|
|
||||||
|
const unsigned char* cRequest = reinterpret_cast<const unsigned char*>(StringCQ.c_str());
|
||||||
|
unsigned int cRequest_len = StringCQ.size();
|
||||||
|
// DPRN("SHUNDEBUGXXXPUT: %s", cRequest);
|
||||||
s3fs_sha256(cRequest, cRequest_len, &sRequest, &sRequest_len);
|
s3fs_sha256(cRequest, cRequest_len, &sRequest, &sRequest_len);
|
||||||
//for (i=0;i < sRequest_len;i++) printf("%02x", sRequest[i]);
|
for(i = 0; i < sRequest_len; i++){
|
||||||
|
sprintf(&hexsRequest[i * 2], "%02x", sRequest[i]);
|
||||||
for (i=0;i < sRequest_len;i++) sprintf(hexsRequest+(i*2), "%02x", sRequest[i]);
|
}
|
||||||
|
free(sRequest);
|
||||||
|
|
||||||
StringToSign = "AWS4-HMAC-SHA256\n";
|
StringToSign = "AWS4-HMAC-SHA256\n";
|
||||||
StringToSign += date3+"\n";
|
StringToSign += date3+"\n";
|
||||||
StringToSign += date2+"/" + endpoint + "/s3/aws4_request\n";
|
StringToSign += date2+"/" + endpoint + "/s3/aws4_request\n";
|
||||||
StringToSign += hexsRequest;
|
StringToSign += hexsRequest;
|
||||||
|
|
||||||
|
const unsigned char* cscope = reinterpret_cast<const unsigned char*>(StringToSign.c_str());
|
||||||
unsigned char* cscope = (unsigned char*)StringToSign.c_str();
|
|
||||||
unsigned int cscope_len = StringToSign.size();
|
unsigned int cscope_len = StringToSign.size();
|
||||||
unsigned char* md = NULL;
|
unsigned char* md = NULL;
|
||||||
unsigned int md_len = 0;
|
unsigned int md_len = 0;
|
||||||
char hexSig[64];
|
char hexSig[64 + 1];
|
||||||
|
|
||||||
s3fs_HMAC(kSigning, kSigning_len, cscope, cscope_len, &md, &md_len);
|
s3fs_HMAC(kSigning, kSigning_len, cscope, cscope_len, &md, &md_len);
|
||||||
for (i=0; i < md_len; i++) sprintf(hexSig+(i*2), "%02x", md[i]);
|
for(i = 0; i < md_len; i++){
|
||||||
|
sprintf(&hexSig[i * 2], "%02x", md[i]);
|
||||||
|
}
|
||||||
|
free(kSigning);
|
||||||
|
free(md);
|
||||||
|
|
||||||
Signature = hexSig;
|
Signature = hexSig;
|
||||||
|
|
||||||
|
27
src/s3fs.cpp
27
src/s3fs.cpp
@ -2264,7 +2264,9 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
string s3_realpath;
|
string s3_realpath;
|
||||||
string query;
|
string query_delimiter;;
|
||||||
|
string query_prefix;;
|
||||||
|
string query_maxkey;;
|
||||||
string next_marker = "";
|
string next_marker = "";
|
||||||
bool truncated = true;
|
bool truncated = true;
|
||||||
S3fsCurl s3fscurl;
|
S3fsCurl s3fscurl;
|
||||||
@ -2274,31 +2276,34 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
|
|||||||
FPRNN("[path=%s]", path);
|
FPRNN("[path=%s]", path);
|
||||||
|
|
||||||
if(delimiter && 0 < strlen(delimiter)){
|
if(delimiter && 0 < strlen(delimiter)){
|
||||||
query += "delimiter=";
|
query_delimiter += "delimiter=";
|
||||||
query += delimiter;
|
query_delimiter += delimiter;
|
||||||
query += "&";
|
query_delimiter += "&";
|
||||||
}
|
}
|
||||||
query += "prefix=";
|
|
||||||
|
|
||||||
|
query_prefix += "&prefix=";
|
||||||
s3_realpath = get_realpath(path);
|
s3_realpath = get_realpath(path);
|
||||||
if(0 == s3_realpath.length() || '/' != s3_realpath[s3_realpath.length() - 1]){
|
if(0 == s3_realpath.length() || '/' != s3_realpath[s3_realpath.length() - 1]){
|
||||||
// last word must be "/"
|
// last word must be "/"
|
||||||
query += urlEncode(s3_realpath.substr(1) + "/");
|
query_prefix += urlEncode(s3_realpath.substr(1) + "/");
|
||||||
}else{
|
}else{
|
||||||
query += urlEncode(s3_realpath.substr(1));
|
query_prefix += urlEncode(s3_realpath.substr(1));
|
||||||
}
|
}
|
||||||
if (check_content_only){
|
if (check_content_only){
|
||||||
query += "&max-keys=1";
|
query_maxkey += "max-keys=1";
|
||||||
}else{
|
}else{
|
||||||
query += "&max-keys=1000";
|
query_maxkey += "max-keys=1000";
|
||||||
}
|
}
|
||||||
|
|
||||||
while(truncated){
|
while(truncated){
|
||||||
string each_query = query;
|
string each_query = query_delimiter;
|
||||||
if(next_marker != ""){
|
if(next_marker != ""){
|
||||||
each_query += "&marker=" + urlEncode(next_marker);
|
each_query += "marker=" + urlEncode(next_marker) + "&";
|
||||||
next_marker = "";
|
next_marker = "";
|
||||||
}
|
}
|
||||||
|
each_query += query_maxkey;
|
||||||
|
each_query += query_prefix;
|
||||||
|
|
||||||
// request
|
// request
|
||||||
if(0 != (result = s3fscurl.ListBucketRequest(path, each_query.c_str()))){
|
if(0 != (result = s3fscurl.ListBucketRequest(path, each_query.c_str()))){
|
||||||
DPRN("ListBucketRequest returns with error.");
|
DPRN("ListBucketRequest returns with error.");
|
||||||
|
Loading…
Reference in New Issue
Block a user