Commit Graph

42 Commits

Author SHA1 Message Date
Patrick Steinhardt
88520151fd openssl_stream: use new initialization function on OpenSSL version >=1.1
Previous to OpenSSL version 1.1, the user had to initialize at least the error
strings as well as the SSL algorithms by himself. OpenSSL version 1.1 instead
provides a new function `OPENSSL_init_ssl`, which handles initialization of all
subsystems. As the new API call will by default load error strings and
initialize the SSL algorithms, we can safely replace these calls when compiling
against version 1.1 or later.

This fixes a compiler error when compiling against OpenSSL version 1.1 which has
been built without stubs for deprecated syntax.
2017-04-10 11:29:07 +02:00
Patrick Steinhardt
29081c2fd4 openssl_stream: remove locking initialization on OpenSSL version >=1.1
Up to version 1.0, OpenSSL required us to provide a callback which implements
a locking mechanism. Due to problems in the API design though this mechanism was
inherently broken, especially regarding that the locking callback cannot report
errors in an obvious way. Due to this shortcoming, the locking initialization
has been completely removed in OpenSSL version 1.1. As the library has also been
refactored to not make any use of these callback functions, we can safely remove
all initialization of the locking subsystem if compiling against OpenSSL version
1.1 or higher.

This fixes a compilation error when compiling against OpenSSL version 1.1 which
has been built without stubs for deprecated syntax.
2017-04-10 11:29:07 +02:00
Patrick Steinhardt
dd0b1e8cb6 openssl_stream: fix releasing OpenSSL locks
The OpenSSL library may require multiple locks to work correctly, where
it is the caller's responsibility to initialize and release the locks.
While we correctly initialized up to `n` locks, as determined by
`CRYPTO_num_locks`, we were repeatedly freeing the same mutex in our
shutdown procedure.

Fix the issue by freeing locks at the correct index.
2017-03-20 12:36:14 +01:00
Edward Thomson
909d549436 giterr_set: consistent error messages
Error messages should be sentence fragments, and therefore:

1. Should not begin with a capital letter,
2. Should not conclude with punctuation, and
3. Should not end a sentence and begin a new one
2016-12-29 12:26:03 +00:00
Carlos Martín Nieto
7175222ce6 Merge pull request #3960 from ignatenkobrain/openssl-1.1.0
add support for OpenSSL 1.1.0 for BIO filter
2016-11-02 14:50:59 +01:00
Carlos Martín Nieto
2f3adf9513 openssl: use ASN1_STRING_get0_data when compiling against 1.1
For older versions we can fall back on the deprecated ASN1_STRING_data.
2016-11-02 13:02:13 +01:00
Carlos Martín Nieto
f15eedb3a3 openssl: recreate the OpenSSL 1.1 BIO interface for older versions
We want to program against the interface, so recreate it when we compile
against pre-1.1 versions.
2016-11-02 13:00:30 +01:00
Patrick Steinhardt
dc98cb28db openssl_stream: fix typo 2016-10-31 13:50:23 +01:00
Igor Gnatenko
feb330d50d add support for OpenSSL 1.1.0 for BIO filter
Closes: https://github.com/libgit2/libgit2/issues/3959
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2016-10-12 12:41:43 +02:00
Christian Schlack
568c5a9fc1 Fix style: no braces 2016-04-27 13:56:16 +02:00
Christian Schlack
4734c52ab2 Fix return value of openssl_read (infinite loop)
openssl_read should return -1 in case of error.

SSL_read returns values <= 0 in case of error.

A return value of 0 can lead to an infinite loop, so the return value
of ssl_set_error will be returned if SSL_read is not successful (analog
to openssl_write).
2016-04-26 18:04:03 +02:00
Carlos Martín Nieto
b373e9a6ba net: use proxy options struct in the stream config 2016-04-19 13:54:19 +02:00
Dirkjan Bussink
fa72d6daf8 Setup better defaults for OpenSSL ciphers
This ensures that when using OpenSSL a safe default set of ciphers
is selected. This is done so that the client communicates securely
and we don't accidentally enable unsafe ciphers like RC4, or even
worse some old export ciphers.

Implements the first part of https://github.com/libgit2/libgit2/issues/3682
2016-03-14 12:07:13 +00:00
Edward Thomson
0d9a7498c5 Merge pull request #3628 from pks-t/pks/coverity-fixes
Coverity fixes
2016-02-25 12:09:49 -05:00
Carlos Martín Nieto
68ad3156a0 openssl: we already had the function, just needed the header 2016-02-24 17:17:57 +01:00
Carlos Martín Nieto
f3d1be7d62 openssl: export the locking function when building without OpenSSL
This got lost duing the move and it lets the users call this function
just in case.
2016-02-24 16:38:22 +01:00
Patrick Steinhardt
05bf67b901 openssl_stream: fix NULL pointer dereference 2016-02-23 12:07:37 +01:00
Patrick Steinhardt
2baf854e97 openssl_stream: fix memory leak when creating new stream 2016-02-23 12:07:36 +01:00
Carlos Martín Nieto
c8fe6c0975 openssl: re-export the last-resort locking function
We need to include the header where we define the function. Otherwise it
won't be available on the DLL.
2016-02-19 16:23:14 +01:00
Carlos Martín Nieto
deecaa2ece openssl: free the context even if we don't connect 2016-02-19 13:34:52 +01:00
Edward Thomson
8a6d667763 global: make openssl registration like the rest 2016-02-08 16:30:39 -08:00
Carlos Martín Nieto
146a96de82 openssl: don't try to teardown an unconnected SSL context
SSL_shutdown() does not like it when we pass an unitialized ssl context
to it. This means that when we fail to connect to a host, we hide the
error message saying so with OpenSSL's indecipherable error message.
2015-09-30 09:41:25 +02:00
Carlos Martín Nieto
a1687f7855 Merge pull request #3297 from tkelman/patch-2
Fix undefined reference with old versions of openssl
2015-07-10 19:07:41 +02:00
Edward Thomson
79698030b0 git_cert: child types use proper base type 2015-07-10 09:28:33 -05:00
Tony Kelman
febc8c4612 Fix undefined reference with old versions of openssl
Versions prior to 0.9.8f  did not have this function, rhel/centos5 are still on a
heavily backported version of 0.9.8e and theoretically supported until March 2017

Without this ifdef, I get the following link failure:
```
CMakeFiles/libgit2_clar.dir/src/openssl_stream.c.o: In function `openssl_connect':
openssl_stream.c:(.text+0x45a): undefined reference to `SSL_set_tlsext_host_name'
collect2: error: ld returned 1 exit status
make[6]: *** [libgit2_clar] Error 1
```
2015-07-07 06:55:05 -04:00
Edward Thomson
3ca84ac0ed openssl: free hostname 2015-06-29 21:23:09 +00:00
Pierre-Olivier Latour
cae2a55552 Fixed build failure if GIT_CURL is not defined 2015-06-26 08:17:56 -07:00
Carlos Martín Nieto
8443f492dd curl: remove the encrypted param to the constructor
We do not want libcurl to perform the TLS negotiation for us, so we
don't need to pass this option.
2015-06-24 17:26:36 +02:00
Carlos Martín Nieto
e247649dfa openssl: use the curl stream if available
When linking against libcurl, use it as the underlying transport instead
of straight sockets. We can't quite just give over the file descriptor,
as curl puts it into non-blocking mode, so we build a custom BIO so
OpenSSL sends the data through our stream, be it the socket or curl
streams.
2015-06-24 17:26:36 +02:00
Edward Thomson
2540487fcd Merge pull request #3108 from libgit2/cmn/ssl-no-want
openssl: don't try to handle WANT_READ or WANT_WRITE
2015-05-22 12:53:52 -04:00
Carlos Martín Nieto
a6ea108b56 Merge branch 'sni' 2015-05-21 14:04:46 +02:00
Cristian Oneț
987045c74a Call the openssl API to be able to work with SNI servers. 2015-05-21 14:03:44 +02:00
Carlos Martín Nieto
1396c38178 errors: add GIT_EEOF to indicate early EOF
This can be used by tools to show mesages about failing to communicate
with the server. The error message in this case will often contain the
server's error message, as far as it managed to send anything.
2015-05-20 15:08:39 +02:00
Carlos Martín Nieto
77bffc2cd6 openssl: don't try to handle WANT_READ or WANT_WRITE
We use a blocking socket and set the mode to AUTO_RETRY which means that
`SSL_write` and `SSL_read` will only return once the read or write has
been completed. We therefore don't need to handle partial writes or
re-try read due to a regenotiation.

While here, consider that a zero also indicates an error condition.
2015-05-09 13:21:39 +02:00
Carlos Martín Nieto
24e53d2fba Rename GIT_SSL to GIT_OPENSSL
This is what it's meant all along, but now we actually have multiple
implementations, it's clearer to use the name of the library.
2015-04-23 17:39:51 +02:00
Carlos Martín Nieto
70b852cee2 Silence unused warnings when not using OpenSSL 2015-04-23 17:39:51 +02:00
Aki Koskinen
ec03244227 Include openssl headers last
Windows headers #define some names that openssl uses too. Openssl
headers #undef the offending names before reusing them. But if those
offending Windows headers get included after the openssl headers the
namespace is polluted and nothing good happens.

Fixes issue #2850.
2015-03-02 11:15:13 +02:00
Aki Koskinen
a944c6cc40 Don't include headers on windows that aren't available
This mainly concerns mingw build.
2015-03-02 11:14:07 +02:00
Raphael Kubo da Costa
3cda6be76b openssl: Add all required includes for AF_INET6 and in6_addr.
This fixes the build at least on FreeBSD, where those types were not
defined indirectly:

src/openssl_stream.c💯18: error: variable has incomplete type 'struct in6_addr'
        struct in6_addr addr6;
                        ^
src/openssl_stream.c💯9: note: forward declaration of 'struct in6_addr'
        struct in6_addr addr6;
               ^
src/openssl_stream.c:111:18: error: use of undeclared identifier 'AF_INET'
        if (p_inet_pton(AF_INET, host, &addr4)) {
                        ^
src/unix/posix.h:31:40: note: expanded from macro 'p_inet_pton'
                                       ^
src/openssl_stream.c:115:18: error: use of undeclared identifier 'AF_INET6'
                if(p_inet_pton(AF_INET6, host, &addr6)) {
                               ^
src/unix/posix.h:31:40: note: expanded from macro 'p_inet_pton'
                                       ^
2015-01-24 16:19:43 +02:00
Carlos Martín Nieto
49ae22baac stream: constify the write buffer 2014-12-10 16:20:52 +01:00
Carlos Martín Nieto
1b75c29e3e gitno: remove code which is no longer needed
Most of the network-facing facilities have been copied to the socket and
openssl streams. No code now uses these functions directly anymore, so
we can now remove them.
2014-12-10 01:39:09 +01:00
Carlos Martín Nieto
468d7b11f9 Add an OpenSSL IO stream
This unfortunately isn't as stackable as could be possible, as it
hard-codes the socket stream. This is because the method of using a
custom openssl BIO is not clear, and we do not need this for now. We can
still bring this in if and as we need it.
2014-12-10 01:17:41 +01:00