<p> Hello, </p>
<p> I developpe an application on C++. I use an basical AWS bucket for my different test. My question is, how i connect on the bucket. A use "curl" but, i have probelme with the autorization. I suppose, i need create token or other but, i don't understand how a can do make this. </p>
curl_easy_setopt(curl,CURLOPT_URL,"http://<bucket name>.s3.us-east-2.amazonaws.com" );
curl_easy_setopt(curl, CURLOPT_CAINFO, pCertFile);
curl_easy_setopt(curl, CURLOPT_PUT, 1L);
sprintf(autorization,"Authorization: AWS4-HMAC-SHA256 Credential=<key id>/eu-west-3/s3/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=<signature>");");
list = curl_slist_append(list,autorization);
sprintf(autorization,"Date: Wed, 12 Oct 2023 17:50:00 GMT");
list = curl_slist_append(list,autorization);
sprintf(autorization,"Content-Type: text/plain");
list = curl_slist_append(list,autorization);
sprintf(autorization,"Content-Length: 11434");
list = curl_slist_append(list,autorization);
sprintf(autorization,"x-amz-meta-author: Janet");
list = curl_slist_append(list,autorization);
sprintf(autorization,"Expect: 100-continue");
list = curl_slist_append(list,autorization);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(curl, CURLOPT_READDATA,fileToUpload);
res= curl_easy_perform(curl);
printf("%s",res);
curl_easy_cleanup(curl);
fclose(fileToUpload);
[Edit] After reseache, i discover this : https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#UsingTemporarySecurityCredentials
I suppose i do use this, but i don't understand how
[Re-Edit] I supoose, i understand the possible solution but i don't understand how we calcul the signature. i have the message "signatureDoesNotMatch"
for calcul the signature a use this :
import base64
import hmac
from hashlib import sha1
access_key = '<key id>'.encode("UTF-8")
secret_key = '<secret id key>'.encode("UTF-8")
string_to_sign = 'PUT\n\n\nTue, 03 Jan 2022 14:45:00 +0000\n/meropy/'.encode("UTF-8")
signature = base64.b16encode(
hmac.new(
secret_key, string_to_sign, sha1
).digest()
).strip()
print(f"AWS {access_key.decode()}:{signature.decode()}")