MCPcopy Create free account
hub / github.com/OSGeo/gdal / GetSignedURL

Method GetSignedURL

port/cpl_google_cloud.cpp:966–1055  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

964/************************************************************************/
965
966std::string VSIGSHandleHelper::GetSignedURL(CSLConstList papszOptions)
967{
968 if (!((!m_osAccessKeyId.empty() && !m_osSecretAccessKey.empty()) ||
969 m_oManager.GetAuthMethod() == GOA2Manager::SERVICE_ACCOUNT))
970 {
971 CPLError(CE_Failure, CPLE_NotSupported,
972 "Signed URL for Google Cloud Storage is only available with "
973 "AWS style authentication with "
974 "GS_ACCESS_KEY_ID+GS_SECRET_ACCESS_KEY, "
975 "or with service account authentication");
976 return std::string();
977 }
978
979 GIntBig nStartDate = static_cast<GIntBig>(time(nullptr));
980 const char *pszStartDate = CSLFetchNameValue(papszOptions, "START_DATE");
981 if (pszStartDate)
982 {
983 int nYear, nMonth, nDay, nHour, nMin, nSec;
984 if (sscanf(pszStartDate, "%04d%02d%02dT%02d%02d%02dZ", &nYear, &nMonth,
985 &nDay, &nHour, &nMin, &nSec) == 6)
986 {
987 struct tm brokendowntime;
988 brokendowntime.tm_year = nYear - 1900;
989 brokendowntime.tm_mon = nMonth - 1;
990 brokendowntime.tm_mday = nDay;
991 brokendowntime.tm_hour = nHour;
992 brokendowntime.tm_min = nMin;
993 brokendowntime.tm_sec = nSec;
994 nStartDate = CPLYMDHMSToUnixTime(&brokendowntime);
995 }
996 }
997 GIntBig nExpiresIn =
998 nStartDate +
999 atoi(CSLFetchNameValueDef(papszOptions, "EXPIRATION_DELAY", "3600"));
1000 std::string osExpires(CSLFetchNameValueDef(
1001 papszOptions, "EXPIRES", CPLSPrintf(CPL_FRMT_GIB, nExpiresIn)));
1002
1003 std::string osVerb(CSLFetchNameValueDef(papszOptions, "VERB", "GET"));
1004
1005 std::string osCanonicalizedResource(
1006 "/" + CPLAWSURLEncode(m_osBucketObjectKey, false));
1007
1008 std::string osStringToSign;
1009 osStringToSign += osVerb + "\n";
1010 osStringToSign += "\n"; // Content_MD5
1011 osStringToSign += "\n"; // Content_Type
1012 osStringToSign += osExpires + "\n";
1013 // osStringToSign += // Canonicalized_Extension_Headers
1014 osStringToSign += osCanonicalizedResource;
1015#ifdef DEBUG_VERBOSE
1016 CPLDebug("GS", "osStringToSign = %s", osStringToSign.c_str());
1017#endif
1018
1019 if (!m_osAccessKeyId.empty())
1020 {
1021 // No longer documented but actually works !
1022 GByte abySignature[CPL_SHA1_HASH_SIZE] = {};
1023 CPL_HMAC_SHA1(m_osSecretAccessKey.c_str(), m_osSecretAccessKey.size(),

Callers

nothing calls this directly

Calls 15

CPLErrorFunction · 0.85
CSLFetchNameValueFunction · 0.85
CPLYMDHMSToUnixTimeFunction · 0.85
CSLFetchNameValueDefFunction · 0.85
CPLSPrintfFunction · 0.85
CPLAWSURLEncodeFunction · 0.85
CPLDebugFunction · 0.85
CPL_HMAC_SHA1Function · 0.85
CPLBase64EncodeFunction · 0.85
CPL_RSA_SHA256_SignFunction · 0.85
GetAuthMethodMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected