Libcurl

From Nintendo Switch Brew
Jump to navigation Jump to search

This page documents the libcurl package used by official sw. This is statically linked in the main-codebin, on old versions (~v2.x) this was a subsdk NSO. This page does not apply to the libcurl build included in the browser OSS NRO.

With sdkver 10.x, this is built with support for NGHTTP2 with the relevant Alpn cmds being used for this.

The changes to libcurl compared to the original libcurl are documented below, etc.

CURLOPT

The 50X/900 options are custom, the default values for some of these are set in Curl_init_userdefined.

CINIT name CINIT type CINIT number CURLoption value Default value
#URL STRINGPOINT 2 10002
#SSL_CTX_FUNCTION FUNCTIONPOINT 108 20108
#PROXYAUTOCONFIG LONG 500 500 1
#UNK501 LONG 501 501 0
#UNK502 OBJECTPOINT 502 10502
#UNK503 FUNCTIONPOINT 503 20503
#UNK504 FUNCTIONPOINT 504 20504
#UNK505 OBJECTPOINT 505 10505
#UNK506 LONG 506 506 0
#UNK507 LONG 507 507
#UNK900 LONG 900 900

URL

The following only runs when the #UNK900 flag is not set, otherwise the URL is set directly using the input string.

This was patched to use various string functionality and ResolveEx (only used if needed). sscanf is used twice with the following two format strings, with the input URL. If the first one returns <=1 and the second one returns <=0, the input URL is just copied to state, otherwise this continues with using ResolveEx etc. Format strings:

  • "%15[^\n:]://%[^\n/?:]%[^\n]"
  • "%[^\n/?:]%[^\n]"

Afterwards, ResolveEx is used with the first output string from the latter sscanf as the input. Then the final URL is constructed with the output from ResolveEx.

SSL_CTX_FUNCTION

This funcptr is called with the same params as normal, with the context ptr being {sdknso container object for ISslContext}.

This is only used if #UNK502 is not set, in which case an error is thrown if this funcptr is not set. An error is also thrown afterwards if the context wasn't created.

The user must create the ISslContext using this funcptr, with all required ISslContext initialization - no cmds are used by the caller with ISslContext besides CreateConnection (the caller doesn't use CreateContext, the user must).

PROXYAUTOCONFIG

This option is handled as a bool.

A warning is printed if this option is set when CURLOPT_PROXY is already set - in which case CURLOPT_PROXY is freed.

This option controls whether to load the system proxy from nifm. The code handling this option was added to the start of the inlined create_conn_helper_init_proxy func.

UNK501

This option is handled as a bool.

This controls the value of the DataCheck VerifyOption bit.

UNK502

If set, this is a ptr to a pre-initialized {sdknso container object for ISslContext}, which is used instead of creating a new one via #SSL_CTX_FUNCTION.

UNK503

If set, this funcptr is called at the end of ISslConnection setup, prior to using SetIoMode. If this funcptr returns non-zero, the CURLcode is set to CURLE_ABORTED_BY_CALLBACK.

This funcptr is called with the following params: (Curl_easy*, {sdknso container object for ISslConnection}, #UNK505).

This allows the user to optionally do additional custom ISslConnection setup.

UNK504

If set, this funcptr is called following DoHandshakeGetServerCert usage, if it didn't return error 0x1987B. If this funcptr returns non-zero, the CURLcode is set to CURLE_ABORTED_BY_CALLBACK.

This is essentially a custom version of getting the CERTINFO.

This funcptr is called with the following params: (Curl_easy*, {sdknso container object for ISslConnection}, #UNK505, {struct ptr}).

Where the struct has the following format:

Offset Size Description
0x0 0x1 bool CURLcode==0
0x1 0x7 Padding
0x8 0x8 Output-size from DoHandshakeGetServerCert.
0x10 0x8 Total-certs from DoHandshakeGetServerCert.

UNK505

This option value is used as a param for the #UNK503/#UNK504 funcptrs.

UNK506

This option is handled as a bool.

This is used during Curl_resolver_getaddrinfo.

UNK507

This option is handled as a bool.

This controls the value of the SkipDefaultVerify option flag.

UNK900

This option is handled as a bool.

This is used during Curl_resolver_getaddrinfo. See also #URL.