switchbrew / switch-examples

Switch examples for devkitA64 and libnx.
https://devkitpro.org/viewforum.php?f=42
559 stars 99 forks source link

curl_example: SSL connect error #87

Closed xfangfang closed 3 years ago

xfangfang commented 3 years ago

I can't access HTTPS using curl, even the default sample program can't access it normally, but when I change it to HTTP, I can access it normally. Is there a problem with my environment configuration or does curl not support HTTPS on Switch? Thank you for someone who can solve my problem~

and by the way,is it possible for ffmpeg to support HTTPS?

yellows8 commented 3 years ago

Add curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); and post output. Also check what dkp-pacman -Sl returns for switch-curl.

xfangfang commented 3 years ago

@yellows8 thanks~

Here is:

sudo dkp-pacman -Sl | grep switch-curl
dkp-libs switch-curl 7.69.1-3 [installed]
void network_request(void) {
    CURL *curl;
    CURLcode res;

    printf("curl init\n");
    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "libnx curl example/1.0");
        // Add any other options here.

        printf("curl_easy_perform\n");
        consoleUpdate(NULL);

        res = curl_easy_perform(curl);
        if (res != CURLE_OK) printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

        // In an actual app you should return an error on failure, following cleanup.

        printf("cleanup\n");
        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();
}

the screen shows:

curl example curl init curl_easy_perform curl_easy_perform() failed: SSL connect error cleanup

yellows8 commented 3 years ago

Displayed output should've changed with CURLOPT_VERBOSE....

xfangfang commented 3 years ago

use curl_easy_setopt(curl, CURLOPT_STDERR, fopen("sdmc://curl.txt", "w+")); output the log to file.

log for https :

* timeout on name lookup is not supported
*   Trying 93.184.216.34:443...
* Connected to example.com (93.184.216.34) port 443 (#0)
* Closing connection 0

log for http:

* timeout on name lookup is not supported
*   Trying 93.184.216.34:80...
* Connected to example.com (93.184.216.34) port 80 (#0)
> GET / HTTP/1.1
Host: example.com
User-Agent: libnx curl example/1.0
Accept: */*

* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Age: 549857
< Cache-Control: max-age=604800
< Content-Type: text/html; charset=UTF-8
< Date: Wed, 20 Jan 2021 15:37:52 GMT
< Etag: "3147526947"
< Expires: Wed, 27 Jan 2021 15:37:52 GMT
< Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
< Server: ECS (sjc/4E76)
< Vary: Accept-Encoding
< X-Cache: HIT
< Content-Length: 1256
< 
* Connection #0 to host example.com left intact
yellows8 commented 3 years ago

Try other HTTPS URLs? What's your system-version?

That log isn't really useful :/

xfangfang commented 3 years ago

try other urls, get the same problems.

11.0.0 sxos 3.1.0

(I don't find openssl upder /opt/devkitpro/portlibs/switch/lib)

make outputs

make
linking curl.elf
aarch64-none-elf-g++ -specs=/opt/devkitpro/libnx/switch.specs -g -march=armv8-a+crc+crypto -mtune=cortex-a5
7 -mtp=soft -fPIE -Wl,-Map,curl.map main.o -L/opt/devkitpro/portlibs/switch/lib -L/opt/devkitpro/libnx/lib
-L/opt/devkitpro/portlibs/switch/lib -lcurl -lnx -lz -lnx -o /Users/fang/project/ns/sw
itch-examples/network/curl/curl.elf
built ... curl.nacp
built ... curl.nro
yellows8 commented 3 years ago

Can you try vanilla AMS?

xfangfang commented 3 years ago

It may take some time to switch the system. I'll update it when I'm done.

And my previous build file : curl.nro

xfangfang commented 3 years ago

thank you very much. After change to AMS, https is good.