wget-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wget2 | OpenSSL on Windows (#468)


From: Gisle Vanem
Subject: Re: wget2 | OpenSSL on Windows (#468)
Date: Wed, 13 Nov 2019 19:14:49 +0000



Gisle Vanem commented:


This was still bugging me, so I came up with patch that works for me:
```diff
--- a/libwget/ssl_openssl.c 2019-11-13 11:27:58
+++ b/libwget/ssl_openssl.c 2019-11-13 18:17:05
@@ -800,15 +800,22 @@
 {
        SSL *ssl = NULL;
        X509_STORE *store;
-       int retval, error, resumed;
+       int retval, error, resumed, fd;

        if (!tcp || tcp->sockfd < 0)
                return WGET_E_INVALID;
        if (!init)
                wget_ssl_init();

+#if defined(_WIN32)
+       /* Get a Winsock handle from a POSIX fd */
+       fd = _get_osfhandle(tcp->sockfd);
+#else
+       fd = tcp->sockfd;
+#endif
+
        /* Initiate a new TLS connection from an existing OpenSSL context */
-       if (!(ssl = SSL_new(_ctx)) || !SSL_set_fd(ssl, tcp->sockfd)) {
+       if (!(ssl = SSL_new(_ctx)) || !SSL_set_fd(ssl, fd)) {
                retval = WGET_E_UNKNOWN;
                goto bail;
        }
@@ -853,6 +860,7 @@
        else
                error_printf(_("Could not get cached TLS session"));

+       error = 0;
        do {
                /* Wait for socket to become ready */
                if (tcp->connect_timeout &&
@@ -941,9 +949,15 @@
                return 0;
        if ((ssl = session) == NULL)
                return WGET_E_INVALID;
+
        if ((fd = SSL_get_fd(ssl)) < 0)
                return WGET_E_UNKNOWN;

+#ifdef _WIN32
+       /* Map Winsock's handle to a POSIX handle */
+       fd = _open_osfhandle ((intptr_t)fd, O_RDWR | O_BINARY);
+#endif
+
        /* SSL_read() and SSL_write() take ints, so we'd rather play safe here 
*/
        if (count > INT_MAX)
                count = INT_MAX;
```

(the `error = 0;` was just to squelch a warning).


With the above (similar to what `tests/libtest.c` does) and a 
`check-certificate = off`in my `wget2rc`, a https-link seems to work fine.
(Win-10, clang-cl 32-bit).

-- 
Reply to this email directly or view it on GitLab: 
https://gitlab.com/gnuwget/wget2/issues/468#note_244239762
You're receiving this email because of your account on gitlab.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]