Commit Graph

120 Commits

Author SHA1 Message Date
Carlos Martín Nieto
4e01741390 netops: make the path optional in URLs
When we're dealing with proxy addresses, we only want a hostname and
port, and the user would not provide a path, so make it optional so we
can use this same function to parse git as well as proxy URLs.
2016-04-19 13:54:19 +02:00
Patrick Steinhardt
8a62bf1180 netops: fix memory leak when an error occurs 2016-02-18 20:50:33 +01:00
Edward Thomson
75a4636f50 git__tolower: a tolower() that isn't dumb
Some brain damaged tolower() implementations appear to want to
take the locale into account, and this may require taking some
insanely aggressive lock on the locale and slowing down what should
be the most trivial of trivial calls for people who just want to
downcase ASCII.
2015-05-29 18:16:46 -04: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
02b4c1e2a4 Port the TCP transport to the new stream API 2014-12-10 01:39:09 +01:00
Carlos Martín Nieto
22fbb2656e netops: return GIT_ECERTIFICATE when it fails the basic tests
When we first ask OpenSSL to verify the certfiicate itself (rather
than the HTTPS specifics), we should also return
GIT_ECERTIFICATE. Otherwise, the caller would consider this as a failed
operation rather than a failed validation and not call the user's own
validation.
2014-11-02 16:12:10 +01:00
William Swanson
d0cf1040c7 Correctly handle getaddrinfo return result
The getaddrinfo function indicates failure with a non-zero return code,
but this code is not necessarily negative. On platforms like Android
where the code is positive, a failed call causes libgit2 to segfault.
2014-09-24 12:01:14 -07:00
Carlos Martín Nieto
41698f22f6 net: remove support for outright ignoring certificates
This option make it easy to ignore anything about the server we're
connecting to, which is bad security practice. This was necessary as we
didn't use to expose detailed information about the certificate, but now
that we do, we should get rid of this.

If the user wants to ignore everything, they can still provide a
callback which ignores all the information passed.
2014-09-16 17:01:32 +02:00
Carlos Martín Nieto
9b9405865e Provide a callback for certificate validation
If the certificate validation fails (or always in the case of ssh),
let the user decide whether to allow the connection.

The data structure passed to the user is the native certificate
information from the underlying implementation, namely OpenSSL or
WinHTTP.
2014-09-16 17:01:30 +02:00
Jacques Germishuys
90c2b37fd7 in_addr is defined in <Winsock2.h>, include before <ws2tcpip.h> 2014-07-06 09:22:24 +02:00
Carlos Martín Nieto
1380e7c6b1 netops: error out on url without a path
In order to connect to a remote server, we need to provide a path to the
repository we're interested in. Consider the lack of path in the url an
error.
2014-07-03 02:34:32 +02:00
Carlos Martín Nieto
081e76bac2 ssl: init everything all the time
Bring together all of the OpenSSL initialization to
git_threads_init() so it's together and doesn't need locks.

Moving it here also gives us libssh2 thread safety (when built against
openssl).
2014-06-12 16:58:25 +02:00
Carlos Martín Nieto
cf15ac8aa9 ssl: cargo-cult thread safety
OpenSSL's tests init everything in the main thread, so let's do that.
2014-06-12 14:37:03 +02:00
Carlos Martín Nieto
5fa0494328 ssl: use locking
When using in a multithreaded context, OpenSSL needs to lock, and leaves
it up to application to provide said locks.

We were not doing this, and it's just luck that's kept us from crashing
up to now.
2014-06-11 23:19:48 +02:00
Carlos Martín Nieto
1d3364ac9d netops: init OpenSSL once under lock
The OpenSSL init functions are not reentrant, which means that running
multiple fetches in parallel can cause us to crash.

Use a mutex to init OpenSSL, and since we're adding this extra checks,
init it only once.
2014-06-11 20:54:42 +02:00
Albert Meltzer
7c57cd97d8 Win32 fix for #2300.
The code doesn't use SSL and a test requires it.
2014-05-12 20:51:03 -07:00
Carlos Martín Nieto
783555d8e1 netops: catch the server not sending a certificate
It's possible for an encrypted connection not have a certificate. In
this case, SSL_get_verify_result() will return OK because no error
happened (as it never even tried to validate anything).

SSL_get_peer_certificate() will return NULL in this case so we need to
catch that. On the upside, the current code would segfault in this
situation instead of letting it through as a valid cert.
2014-04-26 17:27:43 +02:00
Carlos Martín Nieto
51d3f6f5f2 netops: provide more specific error for cert failure
Specify what we do not like about the certificate. In this case, we do
not like the name.
2014-04-26 17:27:43 +02:00
Carlos Martín Nieto
1f0d4f3d8d netops: unit-test the cert host-name pattern matching
This kind of stuff should have unit tests, even if it's just to show
what we expect to match successfully.
2014-04-26 17:27:42 +02:00
Carlos Martín Nieto
e1ce5249e5 netops: fix leak 2013-11-18 21:40:19 +01:00
Russell Belfer
98eaf39a87 Fix warnings 2013-11-13 11:12:31 -08:00
Linquize
fb190bbbd0 Fix warnings 2013-11-12 19:46:25 +08:00
Ben Straub
79c443425b Make url decoding more bulletproof 2013-11-05 11:35:57 -08:00
Ben Straub
d6eb3f9ce7 Remove unnecessary check 2013-11-05 10:54:44 -08:00
Ben Straub
fe294b95d1 Incorporate feedback 2013-11-05 10:37:50 -08:00
Ben Straub
16bffd1c26 Unescape url-encoded usernames and passwords 2013-11-04 12:04:17 -08:00
Ben Straub
c227c173b8 Use http_parser_parse_url to parse urls 2013-11-04 11:42:14 -08:00
Ben Straub
56c1cda28a Clarify parsing issues and errors 2013-11-01 19:22:43 -07:00
Ben Straub
7e0359084e Streamline url-parsing logic. 2013-11-01 15:29:25 -07:00
Ben Straub
048f837b2f Prevent another segfault from bad URL 2013-10-31 13:30:22 -07:00
Ben Straub
151b321898 Prevent segfault with a badly-formed URL 2013-10-31 13:16:04 -07:00
Ben Straub
41a6de289f HTTP: handle "relative" redirects 2013-10-02 14:45:57 -07:00
Ben Straub
b59344bf83 Tighten up url-connection utility 2013-09-26 16:48:46 -07:00
Ben Straub
ea59f65977 Deploy gitno_connection_data into transport (winhttp)
...and have that call manage replaced memory in the output structure.
2013-09-26 16:20:30 -07:00
Ben Straub
8988688c47 Migrate redirect URL handling to common utility 2013-09-25 20:41:56 -07:00
Russell Belfer
eb0ff13071 Disconnect path string to preserve after redirect
The subtransport path was relying on pointing to data owned by
the remote which meant that after a redirect, the updated path
was getting lost for future requests.  This updates the http
transport to strdup the path and maintain its own lifetime.

This also pulls responsibility for parsing the URL back into the
http transport and isolates the functions that parse and free that
connection data so that they can be reused between the initial
parsing and the redirect parsing.
2013-09-24 14:07:08 -07:00
Ben Straub
c91444055a Properly parse urls that include protocol:// 2013-09-24 11:18:43 -07:00
Fraser Tweedale
e52963080a netops: remove duplicate include
9e9aee6 added an include <netinet/in.h> to fix the build on FreeBSD.
Sometime since then the same header is included ifndef _WIN32, so
remove the duplicate include.
2013-08-24 20:15:22 +10:00
Russell Belfer
de81aee390 Merge pull request #1298 from ben/user-at
Handle "user@" prefix for credentials partially included in URLs
2013-02-04 14:49:28 -08:00
Sven Strickroth
c70455c75e Deduplicate FormatMessage UTF-16 to UTF-8 conversion code
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-02-02 00:55:32 +01:00
Sven Strickroth
bd25a302d3 Improved error handling
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-02-02 00:52:23 +01:00
Sven Strickroth
89ad1c57a3 Get utf8_size from WideCharToMultiByte instead of guessing it
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-02-01 22:17:34 +01:00
Sven Strickroth
b0dc81f055 Win32: Make sure error messages are consistently UTF-8 encoded
W/o this a libgit2 error message could have a mixed encoding:
e.g. a filename in UTF-8 combined with a native Windows error message
encoded with the local code page.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-02-01 21:54:32 +01:00
Ben Straub
c4beee7681 Introduce git__substrdup 2013-02-01 10:00:55 -08:00
Ben Straub
cf7038a65c Enhance url parsing to include passwords 2013-01-31 14:04:21 -08:00
Ben Straub
2234b2b031 Stash username from url (but don't use it yet) 2013-01-30 19:03:58 -08:00
Ben Straub
5f10853e90 Skip "user@" when finding hostname in url 2013-01-30 18:52:47 -08:00
Philip Kelley
cfc39f5078 Fix 3 memory leaks 2013-01-25 22:43:52 -05:00
Carlos Martín Nieto
7a2cf780d1 Fix compilation on OpenBSD 2013-01-20 01:57:32 +01:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00