35 _(
"Remote asset URL" ) ) )
43 const bool originAllowed =
44 ( !apiOrigin.IsEmpty() && assetOrigin == apiOrigin )
45 || ( !panelOrigin.IsEmpty() && assetOrigin == panelOrigin );
47 if( assetOrigin.IsEmpty() || !originAllowed )
49 aError =
_(
"Remote asset URL origin must match the selected provider." );
64 if( !curl.
SetURL( aUrl.ToStdString() ) )
66 aError = wxString::Format(
_(
"Unable to set download URL '%s'." ), aUrl );
80 char* contentType =
nullptr;
81 curl_easy_getinfo(
static_cast<CURL*
>( curl.
GetCurl() ), CURLINFO_CONTENT_TYPE, &contentType );
84 aResponse.
content_type = wxString::FromUTF8( contentType );
86 const std::string& buffer = curl.
GetBuffer();
87 aResponse.
payload.assign( buffer.begin(), buffer.end() );
92wxString sha256Hex(
const std::vector<uint8_t>& aPayload )
95 picosha2::hash256_hex_string( aPayload.begin(), aPayload.end(), hashHex );
96 return wxString::FromUTF8( hashHex.c_str() );
115 long long aRemainingBudget,
117 wxString& aError )
const
124 aError =
_(
"Remote asset manifest declared an invalid size." );
128 if( aAsset.
sha256.IsEmpty() )
130 aError =
_(
"Remote asset manifest must declare sha256 for URL-based downloads." );
134 if( !validateAssetUrl( aProvider, aAsset.
download_url, aError ) )
137 if( aRemainingBudget >= 0 && aAsset.
size_bytes > aRemainingBudget )
139 aError =
_(
"Remote asset exceeds the provider download limit." );
150 aError = wxString::Format(
_(
"Remote download failed with HTTP %d." ), response.
status_code );
156 aError =
_(
"Remote asset content type did not match the manifest." );
162 aError =
_(
"Remote asset size did not match the manifest." );
166 if( aRemainingBudget >= 0 &&
static_cast<long long>( response.
payload.size() ) > aRemainingBudget )
168 aError =
_(
"Remote asset exceeds the remaining download limit." );
172 if( !aAsset.
sha256.IsEmpty() && !sha256Hex( response.
payload ).IsSameAs( aAsset.
sha256,
false ) )
174 aError =
_(
"Remote asset digest did not match the manifest." );
int Perform()
Equivalent to curl_easy_perform.
bool SetUserAgent(const std::string &aAgent)
Set the request user agent.
int GetResponseStatusCode()
const std::string & GetBuffer()
Return a reference to the received data buffer.
bool SetURL(const std::string &aURL)
Set the request URL.
bool SetFollowRedirects(bool aFollow)
Enable the following of HTTP(s) and other redirects, by default curl does not follow redirects.
bool SetConnectTimeout(long aTimeoutSecs)
Set the connection timeout in seconds.
const std::string GetErrorText(int aCode)
Fetch CURL's "friendly" error string for a given error code.
std::function< bool(const wxString &, REMOTE_SYMBOL_FETCH_RESPONSE &, wxString &)> FETCH_HANDLER
REMOTE_SYMBOL_DOWNLOAD_MANAGER()
bool DownloadAndVerify(const REMOTE_PROVIDER_METADATA &aProvider, const REMOTE_PROVIDER_PART_ASSET &aAsset, long long aRemainingBudget, REMOTE_SYMBOL_FETCHED_ASSET &aFetched, wxString &aError) const
wxString NormalizedUrlOrigin(const wxString &aUrl)
Return a normalized scheme://host:port origin string for aUrl.
bool ValidateRemoteUrlSecurity(const wxString &aUrl, bool aAllowInsecureLocalhost, wxString &aError, const wxString &aLabel)
Validate that aUrl uses HTTPS, or HTTP on a loopback address when aAllowInsecureLocalhost is true.
std::vector< uint8_t > payload
std::vector< uint8_t > payload
wxString result
Test unit parsing edge cases and error handling.