97 const std::string& trace_config) {
98 EnableDebugHttpTransportMetadata();
100 curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, &SilentWriteCallback);
101 curl_easy_setopt(easy, CURLOPT_HEADERFUNCTION, &SilentWriteCallback);
103 const bool user_requested_verbose = std::getenv(kVerboseEnvVar) !=
nullptr;
104 if (!trace_config.empty()) {
107 (void)curl_global_trace(trace_config.c_str());
112 if (trace_ids || !trace_config.empty()) {
117 curl_easy_setopt(easy, CURLOPT_DEBUGFUNCTION, &SilentDebugCallback);
118 curl_easy_setopt(easy, CURLOPT_DEBUGDATA, easy);
119 curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
120 }
else if (scheme == curl::fuzzer::proto::SCHEME_TELNET && !user_requested_verbose) {
126 curl_easy_setopt(easy, CURLOPT_DEBUGFUNCTION, &SilentDebugCallback);
127 curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
134 const char* direct_protocols = kEventDrivenProtocolsAllowed;
136 case curl::fuzzer::proto::SCHEME_TELNET:
137 direct_protocols = kTelnetProtocolAllowed;
139 case curl::fuzzer::proto::SCHEME_FTP:
140 case curl::fuzzer::proto::SCHEME_FTPS:
141 direct_protocols = kFtpProtocolAllowed;
143 case curl::fuzzer::proto::SCHEME_TFTP:
144 direct_protocols = kTftpProtocolAllowed;
146 case curl::fuzzer::proto::SCHEME_SMTP:
147 case curl::fuzzer::proto::SCHEME_SMTPS:
148 direct_protocols = kSmtpProtocolAllowed;
150 case curl::fuzzer::proto::SCHEME_IMAP:
151 case curl::fuzzer::proto::SCHEME_IMAPS:
152 direct_protocols = kImapProtocolAllowed;
154 case curl::fuzzer::proto::SCHEME_POP3:
155 case curl::fuzzer::proto::SCHEME_POP3S:
156 direct_protocols = kPop3ProtocolAllowed;
158 case curl::fuzzer::proto::SCHEME_MQTT:
159 case curl::fuzzer::proto::SCHEME_MQTTS:
160 direct_protocols = kMqttProtocolAllowed;
162 case curl::fuzzer::proto::SCHEME_DICT:
163 direct_protocols = kDictProtocolAllowed;
165 case curl::fuzzer::proto::SCHEME_GOPHER:
166 direct_protocols =
"gopher";
168 case curl::fuzzer::proto::SCHEME_GOPHERS:
169 direct_protocols =
"gophers";
171 case curl::fuzzer::proto::SCHEME_FILE:
172 direct_protocols = kFileProtocolAllowed;
174 case curl::fuzzer::proto::SCHEME_LDAP:
175 case curl::fuzzer::proto::SCHEME_LDAPS:
176 direct_protocols = kLdapProtocolAllowed;
178 case curl::fuzzer::proto::SCHEME_RTSP:
179 direct_protocols = kRtspProtocolAllowed;
181 case curl::fuzzer::proto::SCHEME_HTTP:
182 case curl::fuzzer::proto::SCHEME_HTTPS:
183 case curl::fuzzer::proto::SCHEME_WS:
184 case curl::fuzzer::proto::SCHEME_WSS:
185 case curl::fuzzer::proto::SCHEME_IPFS:
186 case curl::fuzzer::proto::SCHEME_IPNS:
187 case curl::fuzzer::proto::SCHEME_UNSPECIFIED:
191 curl_easy_setopt(easy, CURLOPT_PROTOCOLS_STR, direct_protocols);
192 curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS_STR, kEventDrivenProtocolsAllowed);
198 curl_easy_setopt(easy, CURLOPT_PROXY,
"");
204 curl_easy_setopt(easy, CURLOPT_SSL_VERIFYPEER, 0L);
208 CurlSlistPtr connect_to(curl_slist_append(
nullptr, kConnectToOverride));
209 curl_easy_setopt(easy, CURLOPT_CONNECT_TO, connect_to.get());
215 curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT_MS, kConnectTimeoutMs);
216 curl_easy_setopt(easy, CURLOPT_TIMEOUT_MS, kTimeoutMs);
223 curl_easy_setopt(easy, CURLOPT_COOKIEJAR, kDevNull);
224 curl_easy_setopt(easy, CURLOPT_COOKIEFILE, kDevNull);
225 curl_easy_setopt(easy, CURLOPT_ALTSVC, kDevNull);
226 curl_easy_setopt(easy, CURLOPT_HSTS, kDevNull);
227 curl_easy_setopt(easy, CURLOPT_NETRC_FILE, kDevNull);
236 if (user_requested_verbose) {
237 curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
248 if (easy ==
nullptr) {
249 return CURLE_BAD_FUNCTION_ARGUMENT;
252 const auto set_string = [easy](CURLoption option,
const char* value) {
253 return curl_easy_setopt(easy, option, value);
256 case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_NONE:
259 case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_MALFORMED_PKCS12: {
260 CURLcode result = set_string(CURLOPT_SSLCERTTYPE, kPkcs12CertificateType);
261 if (result != CURLE_OK) {
264 const curl_blob blob = {
const_cast<unsigned char*
>(kMalformedPkcs12),
sizeof(kMalformedPkcs12), CURL_BLOB_COPY};
265 return curl_easy_setopt(easy, CURLOPT_SSLCERT_BLOB, &blob);
268 case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_ENGINE_DEV_NULL: {
269 CURLcode result = set_string(CURLOPT_SSLCERTTYPE, kEngineCertificateType);
270 if (result != CURLE_OK) {
273 return set_string(CURLOPT_SSLCERT, kDevNull);
276 case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_DEFAULT_PROVIDER_DEV_NULL: {
277 CURLcode result = set_string(CURLOPT_SSLENGINE, kDefaultProvider);
278 if (result != CURLE_OK) {
281 result = set_string(CURLOPT_SSLCERTTYPE, kProviderCertificateType);
282 if (result != CURLE_OK) {
285 return set_string(CURLOPT_SSLCERT, kDevNull);
288 case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_UNLOADED_PROVIDER_DEV_NULL: {
289 CURLcode result = set_string(CURLOPT_SSLCERTTYPE, kProviderCertificateType);
290 if (result != CURLE_OK) {
293 return set_string(CURLOPT_SSLCERT, kDevNull);
297 return CURLE_BAD_FUNCTION_ARGUMENT;
310CURLcode
ApplySetOption(CURL* easy,
const curl::fuzzer::proto::SetOption& option) {
312 if (desc ==
nullptr) {
313 return CURLE_UNKNOWN_OPTION;
315 const CURLoption curlopt =
static_cast<CURLoption
>(desc->
curlopt);
317 switch (desc->
kind) {
319 const std::string& value = option.string_value();
325 if (desc->
curlopt == CURLOPT_COPYPOSTFIELDS) {
326 CURLcode result = curl_easy_setopt(easy, CURLOPT_POSTFIELDS, value.c_str());
327 if (result != CURLE_OK) {
336 if (desc->
curlopt == CURLOPT_POSTFIELDS || desc->
curlopt == CURLOPT_COPYPOSTFIELDS) {
337 CURLcode result = curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE_LARGE,
static_cast<curl_off_t
>(value.size()));
338 if (result != CURLE_OK) {
343 if (desc->
curlopt == CURLOPT_COPYPOSTFIELDS) {
347 return curl_easy_setopt(easy, CURLOPT_COPYPOSTFIELDS, value.c_str());
356 std::string constrained = value;
358 return curl_easy_setopt(easy, curlopt, constrained.c_str());
361 return curl_easy_setopt(easy, curlopt, value.c_str());
369 if (
static_cast<int>(desc->
curlopt) >= 30000) {
370 return curl_easy_setopt(easy, curlopt,
static_cast<curl_off_t
>(raw));
372 return curl_easy_setopt(easy, curlopt,
static_cast<long>(raw));
378 return curl_easy_setopt(easy, curlopt, flag);
381 return CURLE_UNKNOWN_OPTION;