rugged 0.27.10.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (297) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +23 -2
  3. data/ext/rugged/rugged.c +48 -2
  4. data/ext/rugged/rugged.h +5 -0
  5. data/ext/rugged/rugged_allocator.c +89 -0
  6. data/ext/rugged/rugged_blob.c +3 -3
  7. data/ext/rugged/rugged_branch.c +1 -1
  8. data/ext/rugged/rugged_commit.c +8 -8
  9. data/ext/rugged/rugged_config.c +1 -1
  10. data/ext/rugged/rugged_diff.c +24 -4
  11. data/ext/rugged/rugged_note.c +1 -1
  12. data/ext/rugged/rugged_repo.c +10 -10
  13. data/ext/rugged/rugged_settings.c +1 -1
  14. data/lib/rugged/version.rb +1 -1
  15. data/vendor/libgit2/CMakeLists.txt +69 -47
  16. data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +15 -1
  17. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -8
  18. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
  19. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +2 -0
  20. data/vendor/libgit2/deps/http-parser/{LICENSE-MIT → COPYING} +0 -0
  21. data/vendor/libgit2/deps/regex/COPYING +502 -0
  22. data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
  23. data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
  24. data/vendor/libgit2/deps/zlib/CMakeLists.txt +1 -0
  25. data/vendor/libgit2/deps/zlib/COPYING +27 -0
  26. data/vendor/libgit2/include/git2.h +3 -0
  27. data/vendor/libgit2/include/git2/annotated_commit.h +9 -0
  28. data/vendor/libgit2/include/git2/apply.h +129 -0
  29. data/vendor/libgit2/include/git2/attr.h +19 -8
  30. data/vendor/libgit2/include/git2/blame.h +41 -24
  31. data/vendor/libgit2/include/git2/blob.h +1 -1
  32. data/vendor/libgit2/include/git2/branch.h +1 -1
  33. data/vendor/libgit2/include/git2/buffer.h +2 -2
  34. data/vendor/libgit2/include/git2/checkout.h +20 -19
  35. data/vendor/libgit2/include/git2/cherrypick.h +6 -4
  36. data/vendor/libgit2/include/git2/clone.h +11 -9
  37. data/vendor/libgit2/include/git2/commit.h +30 -2
  38. data/vendor/libgit2/include/git2/common.h +54 -4
  39. data/vendor/libgit2/include/git2/config.h +18 -7
  40. data/vendor/libgit2/include/git2/deprecated.h +253 -0
  41. data/vendor/libgit2/include/git2/describe.h +30 -7
  42. data/vendor/libgit2/include/git2/diff.h +193 -143
  43. data/vendor/libgit2/include/git2/errors.h +54 -46
  44. data/vendor/libgit2/include/git2/ignore.h +2 -2
  45. data/vendor/libgit2/include/git2/index.h +72 -51
  46. data/vendor/libgit2/include/git2/indexer.h +30 -4
  47. data/vendor/libgit2/include/git2/mailmap.h +115 -0
  48. data/vendor/libgit2/include/git2/merge.h +29 -8
  49. data/vendor/libgit2/include/git2/net.h +1 -1
  50. data/vendor/libgit2/include/git2/notes.h +1 -1
  51. data/vendor/libgit2/include/git2/object.h +16 -16
  52. data/vendor/libgit2/include/git2/odb.h +10 -10
  53. data/vendor/libgit2/include/git2/odb_backend.h +7 -7
  54. data/vendor/libgit2/include/git2/oid.h +1 -1
  55. data/vendor/libgit2/include/git2/pack.h +2 -2
  56. data/vendor/libgit2/include/git2/proxy.h +9 -5
  57. data/vendor/libgit2/include/git2/rebase.h +7 -4
  58. data/vendor/libgit2/include/git2/refs.h +14 -15
  59. data/vendor/libgit2/include/git2/refspec.h +17 -0
  60. data/vendor/libgit2/include/git2/remote.h +92 -16
  61. data/vendor/libgit2/include/git2/repository.h +52 -37
  62. data/vendor/libgit2/include/git2/revert.h +5 -3
  63. data/vendor/libgit2/include/git2/revwalk.h +7 -7
  64. data/vendor/libgit2/include/git2/signature.h +2 -2
  65. data/vendor/libgit2/include/git2/stash.h +13 -10
  66. data/vendor/libgit2/include/git2/status.h +8 -4
  67. data/vendor/libgit2/include/git2/submodule.h +11 -10
  68. data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
  69. data/vendor/libgit2/include/git2/sys/commit.h +1 -1
  70. data/vendor/libgit2/include/git2/sys/config.h +13 -13
  71. data/vendor/libgit2/include/git2/sys/filter.h +6 -6
  72. data/vendor/libgit2/include/git2/sys/index.h +3 -0
  73. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  74. data/vendor/libgit2/include/git2/sys/merge.h +9 -4
  75. data/vendor/libgit2/include/git2/sys/odb_backend.h +19 -19
  76. data/vendor/libgit2/include/git2/sys/path.h +64 -0
  77. data/vendor/libgit2/include/git2/sys/refdb_backend.h +19 -19
  78. data/vendor/libgit2/include/git2/sys/stream.h +92 -12
  79. data/vendor/libgit2/include/git2/sys/transport.h +127 -81
  80. data/vendor/libgit2/include/git2/tag.h +2 -2
  81. data/vendor/libgit2/include/git2/trace.h +1 -1
  82. data/vendor/libgit2/include/git2/transaction.h +1 -0
  83. data/vendor/libgit2/include/git2/transport.h +47 -18
  84. data/vendor/libgit2/include/git2/tree.h +3 -3
  85. data/vendor/libgit2/include/git2/types.h +35 -28
  86. data/vendor/libgit2/include/git2/version.h +4 -4
  87. data/vendor/libgit2/include/git2/worktree.h +47 -12
  88. data/vendor/libgit2/src/CMakeLists.txt +87 -26
  89. data/vendor/libgit2/src/alloc.c +55 -0
  90. data/vendor/libgit2/src/alloc.h +40 -0
  91. data/vendor/libgit2/src/annotated_commit.c +15 -8
  92. data/vendor/libgit2/src/apply.c +490 -14
  93. data/vendor/libgit2/src/apply.h +3 -1
  94. data/vendor/libgit2/src/array.h +2 -2
  95. data/vendor/libgit2/src/attr.c +11 -11
  96. data/vendor/libgit2/src/attr_file.c +20 -15
  97. data/vendor/libgit2/src/attrcache.c +11 -11
  98. data/vendor/libgit2/src/blame.c +30 -15
  99. data/vendor/libgit2/src/blame.h +1 -0
  100. data/vendor/libgit2/src/blame_git.c +16 -13
  101. data/vendor/libgit2/src/blob.c +50 -28
  102. data/vendor/libgit2/src/blob.h +18 -1
  103. data/vendor/libgit2/src/branch.c +38 -38
  104. data/vendor/libgit2/src/buf_text.c +7 -6
  105. data/vendor/libgit2/src/buffer.c +55 -50
  106. data/vendor/libgit2/src/buffer.h +1 -1
  107. data/vendor/libgit2/src/cache.c +16 -16
  108. data/vendor/libgit2/src/cache.h +2 -2
  109. data/vendor/libgit2/src/cc-compat.h +15 -3
  110. data/vendor/libgit2/src/checkout.c +83 -74
  111. data/vendor/libgit2/src/cherrypick.c +6 -6
  112. data/vendor/libgit2/src/clone.c +20 -20
  113. data/vendor/libgit2/src/commit.c +53 -33
  114. data/vendor/libgit2/src/commit.h +1 -0
  115. data/vendor/libgit2/src/commit_list.c +6 -10
  116. data/vendor/libgit2/src/common.h +32 -30
  117. data/vendor/libgit2/src/config.c +167 -147
  118. data/vendor/libgit2/src/config.h +1 -14
  119. data/vendor/libgit2/src/config_backend.h +84 -0
  120. data/vendor/libgit2/src/config_cache.c +7 -1
  121. data/vendor/libgit2/src/config_entries.c +259 -0
  122. data/vendor/libgit2/src/config_entries.h +23 -0
  123. data/vendor/libgit2/src/config_file.c +167 -439
  124. data/vendor/libgit2/src/config_mem.c +224 -0
  125. data/vendor/libgit2/src/config_parse.c +69 -38
  126. data/vendor/libgit2/src/config_parse.h +4 -4
  127. data/vendor/libgit2/src/crlf.c +215 -186
  128. data/vendor/libgit2/src/delta.c +25 -18
  129. data/vendor/libgit2/src/describe.c +23 -23
  130. data/vendor/libgit2/src/diff.c +12 -12
  131. data/vendor/libgit2/src/diff_driver.c +14 -15
  132. data/vendor/libgit2/src/diff_file.c +10 -10
  133. data/vendor/libgit2/src/diff_generate.c +29 -23
  134. data/vendor/libgit2/src/diff_generate.h +1 -1
  135. data/vendor/libgit2/src/diff_parse.c +3 -3
  136. data/vendor/libgit2/src/diff_print.c +17 -17
  137. data/vendor/libgit2/src/diff_stats.c +22 -7
  138. data/vendor/libgit2/src/diff_tform.c +12 -12
  139. data/vendor/libgit2/src/diff_xdiff.c +15 -3
  140. data/vendor/libgit2/src/errors.c +42 -20
  141. data/vendor/libgit2/src/features.h.in +2 -1
  142. data/vendor/libgit2/src/fetch.c +3 -3
  143. data/vendor/libgit2/src/fetchhead.c +16 -16
  144. data/vendor/libgit2/src/filebuf.c +28 -28
  145. data/vendor/libgit2/src/fileops.c +54 -54
  146. data/vendor/libgit2/src/fileops.h +1 -1
  147. data/vendor/libgit2/src/filter.c +30 -30
  148. data/vendor/libgit2/src/filter.h +0 -10
  149. data/vendor/libgit2/src/global.c +36 -23
  150. data/vendor/libgit2/src/hash.h +4 -1
  151. data/vendor/libgit2/src/hash/hash_collisiondetect.h +6 -2
  152. data/vendor/libgit2/src/hash/hash_common_crypto.h +5 -1
  153. data/vendor/libgit2/src/hash/hash_generic.h +5 -1
  154. data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
  155. data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
  156. data/vendor/libgit2/src/hash/hash_openssl.h +8 -4
  157. data/vendor/libgit2/src/hash/hash_win32.c +13 -13
  158. data/vendor/libgit2/src/hashsig.c +4 -4
  159. data/vendor/libgit2/src/idxmap.c +25 -5
  160. data/vendor/libgit2/src/idxmap.h +4 -18
  161. data/vendor/libgit2/src/ignore.c +9 -9
  162. data/vendor/libgit2/src/index.c +280 -198
  163. data/vendor/libgit2/src/index.h +16 -0
  164. data/vendor/libgit2/src/indexer.c +311 -139
  165. data/vendor/libgit2/src/integer.h +32 -22
  166. data/vendor/libgit2/src/iterator.c +116 -49
  167. data/vendor/libgit2/src/iterator.h +15 -0
  168. data/vendor/libgit2/src/khash.h +3 -1
  169. data/vendor/libgit2/src/mailmap.c +485 -0
  170. data/vendor/libgit2/src/mailmap.h +35 -0
  171. data/vendor/libgit2/src/merge.c +89 -59
  172. data/vendor/libgit2/src/merge_driver.c +7 -7
  173. data/vendor/libgit2/src/merge_file.c +1 -1
  174. data/vendor/libgit2/src/mwindow.c +8 -8
  175. data/vendor/libgit2/src/netops.c +22 -13
  176. data/vendor/libgit2/src/netops.h +2 -0
  177. data/vendor/libgit2/src/notes.c +15 -10
  178. data/vendor/libgit2/src/object.c +118 -67
  179. data/vendor/libgit2/src/object.h +20 -9
  180. data/vendor/libgit2/src/object_api.c +8 -8
  181. data/vendor/libgit2/src/odb.c +72 -72
  182. data/vendor/libgit2/src/odb.h +7 -7
  183. data/vendor/libgit2/src/odb_loose.c +46 -46
  184. data/vendor/libgit2/src/odb_mempack.c +14 -14
  185. data/vendor/libgit2/src/odb_pack.c +14 -10
  186. data/vendor/libgit2/src/offmap.c +30 -0
  187. data/vendor/libgit2/src/offmap.h +20 -11
  188. data/vendor/libgit2/src/oid.c +6 -6
  189. data/vendor/libgit2/src/oidmap.c +20 -0
  190. data/vendor/libgit2/src/oidmap.h +9 -12
  191. data/vendor/libgit2/src/pack-objects.c +71 -63
  192. data/vendor/libgit2/src/pack-objects.h +1 -7
  193. data/vendor/libgit2/src/pack.c +58 -58
  194. data/vendor/libgit2/src/pack.h +6 -6
  195. data/vendor/libgit2/src/parse.h +1 -1
  196. data/vendor/libgit2/src/patch.c +3 -3
  197. data/vendor/libgit2/src/patch_generate.c +18 -18
  198. data/vendor/libgit2/src/patch_parse.c +13 -13
  199. data/vendor/libgit2/src/path.c +93 -225
  200. data/vendor/libgit2/src/path.h +2 -84
  201. data/vendor/libgit2/src/pathspec.c +6 -6
  202. data/vendor/libgit2/src/posix.c +3 -3
  203. data/vendor/libgit2/src/proxy.c +1 -1
  204. data/vendor/libgit2/src/push.c +27 -26
  205. data/vendor/libgit2/src/push.h +2 -1
  206. data/vendor/libgit2/src/reader.c +265 -0
  207. data/vendor/libgit2/src/reader.h +107 -0
  208. data/vendor/libgit2/src/rebase.c +49 -52
  209. data/vendor/libgit2/src/refdb.c +3 -3
  210. data/vendor/libgit2/src/refdb_fs.c +181 -103
  211. data/vendor/libgit2/src/reflog.c +3 -3
  212. data/vendor/libgit2/src/refs.c +98 -74
  213. data/vendor/libgit2/src/refs.h +5 -3
  214. data/vendor/libgit2/src/refspec.c +47 -21
  215. data/vendor/libgit2/src/refspec.h +1 -1
  216. data/vendor/libgit2/src/remote.c +219 -166
  217. data/vendor/libgit2/src/remote.h +9 -0
  218. data/vendor/libgit2/src/repository.c +173 -133
  219. data/vendor/libgit2/src/repository.h +6 -3
  220. data/vendor/libgit2/src/reset.c +8 -8
  221. data/vendor/libgit2/src/revert.c +6 -6
  222. data/vendor/libgit2/src/revparse.c +30 -30
  223. data/vendor/libgit2/src/revwalk.c +60 -30
  224. data/vendor/libgit2/src/revwalk.h +2 -1
  225. data/vendor/libgit2/src/settings.c +42 -10
  226. data/vendor/libgit2/src/signature.c +11 -11
  227. data/vendor/libgit2/src/sortedcache.c +13 -13
  228. data/vendor/libgit2/src/stash.c +91 -45
  229. data/vendor/libgit2/src/status.c +13 -13
  230. data/vendor/libgit2/src/stdalloc.c +120 -0
  231. data/vendor/libgit2/src/{streams/curl.h → stdalloc.h} +6 -6
  232. data/vendor/libgit2/src/stream.h +17 -2
  233. data/vendor/libgit2/src/streams/mbedtls.c +483 -0
  234. data/vendor/libgit2/src/streams/mbedtls.h +23 -0
  235. data/vendor/libgit2/src/streams/openssl.c +204 -114
  236. data/vendor/libgit2/src/streams/openssl.h +4 -108
  237. data/vendor/libgit2/src/streams/registry.c +118 -0
  238. data/vendor/libgit2/src/streams/registry.h +19 -0
  239. data/vendor/libgit2/src/streams/socket.c +54 -29
  240. data/vendor/libgit2/src/streams/stransport.c +57 -32
  241. data/vendor/libgit2/src/streams/stransport.h +5 -0
  242. data/vendor/libgit2/src/streams/tls.c +50 -19
  243. data/vendor/libgit2/src/streams/tls.h +12 -4
  244. data/vendor/libgit2/src/strmap.c +22 -2
  245. data/vendor/libgit2/src/strmap.h +18 -15
  246. data/vendor/libgit2/src/submodule.c +179 -155
  247. data/vendor/libgit2/src/sysdir.c +18 -18
  248. data/vendor/libgit2/src/tag.c +31 -26
  249. data/vendor/libgit2/src/tag.h +2 -1
  250. data/vendor/libgit2/src/trace.c +1 -1
  251. data/vendor/libgit2/src/trace.h +1 -1
  252. data/vendor/libgit2/src/trailer.c +6 -6
  253. data/vendor/libgit2/src/transaction.c +23 -23
  254. data/vendor/libgit2/src/transport.c +5 -5
  255. data/vendor/libgit2/src/transports/auth.c +7 -4
  256. data/vendor/libgit2/src/transports/auth.h +1 -1
  257. data/vendor/libgit2/src/transports/auth_negotiate.c +12 -11
  258. data/vendor/libgit2/src/transports/cred.c +18 -18
  259. data/vendor/libgit2/src/transports/git.c +15 -15
  260. data/vendor/libgit2/src/transports/http.c +606 -216
  261. data/vendor/libgit2/src/transports/http.h +2 -0
  262. data/vendor/libgit2/src/transports/local.c +26 -26
  263. data/vendor/libgit2/src/transports/smart.c +54 -31
  264. data/vendor/libgit2/src/transports/smart.h +1 -2
  265. data/vendor/libgit2/src/transports/smart_pkt.c +43 -40
  266. data/vendor/libgit2/src/transports/smart_protocol.c +61 -57
  267. data/vendor/libgit2/src/transports/ssh.c +34 -33
  268. data/vendor/libgit2/src/transports/winhttp.c +99 -119
  269. data/vendor/libgit2/src/tree-cache.c +5 -5
  270. data/vendor/libgit2/src/tree.c +96 -121
  271. data/vendor/libgit2/src/tree.h +1 -12
  272. data/vendor/libgit2/src/unix/map.c +2 -2
  273. data/vendor/libgit2/src/util.c +22 -6
  274. data/vendor/libgit2/src/util.h +12 -135
  275. data/vendor/libgit2/src/vector.c +4 -4
  276. data/vendor/libgit2/src/win32/dir.c +3 -3
  277. data/vendor/libgit2/src/win32/findfile.c +3 -3
  278. data/vendor/libgit2/src/win32/map.c +6 -6
  279. data/vendor/libgit2/src/win32/msvc-compat.h +6 -0
  280. data/vendor/libgit2/src/win32/path_w32.c +101 -7
  281. data/vendor/libgit2/src/win32/path_w32.h +18 -0
  282. data/vendor/libgit2/src/win32/posix_w32.c +24 -43
  283. data/vendor/libgit2/src/win32/w32_buffer.c +2 -2
  284. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +96 -2
  285. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +28 -75
  286. data/vendor/libgit2/src/win32/w32_stack.c +2 -2
  287. data/vendor/libgit2/src/win32/w32_util.c +1 -69
  288. data/vendor/libgit2/src/win32/w32_util.h +1 -19
  289. data/vendor/libgit2/src/worktree.c +75 -54
  290. data/vendor/libgit2/src/worktree.h +2 -0
  291. data/vendor/libgit2/src/xdiff/xdiffi.c +7 -5
  292. data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
  293. data/vendor/libgit2/src/xdiff/xmerge.c +15 -15
  294. data/vendor/libgit2/src/zstream.c +4 -4
  295. metadata +33 -7
  296. data/vendor/libgit2/src/config_file.h +0 -73
  297. data/vendor/libgit2/src/streams/curl.c +0 -385
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_steams_mbedtls_h__
8
+ #define INCLUDE_steams_mbedtls_h__
9
+
10
+ #include "common.h"
11
+
12
+ #include "git2/sys/stream.h"
13
+
14
+ extern int git_mbedtls_stream_global_init(void);
15
+
16
+ #ifdef GIT_MBEDTLS
17
+ extern int git_mbedtls__set_cert_location(const char *path, int is_dir);
18
+
19
+ extern int git_mbedtls_stream_new(git_stream **out, const char *host, const char *port);
20
+ extern int git_mbedtls_stream_wrap(git_stream **out, git_stream *in, const char *host);
21
+ #endif
22
+
23
+ #endif
@@ -19,10 +19,6 @@
19
19
  #include "git2/transport.h"
20
20
  #include "git2/sys/openssl.h"
21
21
 
22
- #ifdef GIT_CURL
23
- # include "streams/curl.h"
24
- #endif
25
-
26
22
  #ifndef GIT_WIN32
27
23
  # include <sys/types.h>
28
24
  # include <sys/socket.h>
@@ -38,8 +34,115 @@ SSL_CTX *git__ssl_ctx;
38
34
 
39
35
  #define GIT_SSL_DEFAULT_CIPHERS "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES128-SHA256:DHE-DSS-AES256-SHA256:DHE-DSS-AES128-SHA:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA"
40
36
 
41
- #if defined(GIT_THREADS) && OPENSSL_VERSION_NUMBER < 0x10100000L
37
+ #if (defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L) || \
38
+ (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
39
+ # define OPENSSL_LEGACY_API
40
+ #endif
41
+
42
+ /*
43
+ * OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it
44
+ * which do not exist in previous versions. We define these inline functions so
45
+ * we can program against the interface instead of littering the implementation
46
+ * with ifdefs. We do the same for OPENSSL_init_ssl.
47
+ */
48
+ #if defined(OPENSSL_LEGACY_API)
49
+ static int OPENSSL_init_ssl(int opts, void *settings)
50
+ {
51
+ GIT_UNUSED(opts);
52
+ GIT_UNUSED(settings);
53
+ SSL_load_error_strings();
54
+ OpenSSL_add_ssl_algorithms();
55
+ return 0;
56
+ }
57
+
58
+ static BIO_METHOD* BIO_meth_new(int type, const char *name)
59
+ {
60
+ BIO_METHOD *meth = git__calloc(1, sizeof(BIO_METHOD));
61
+ if (!meth) {
62
+ return NULL;
63
+ }
64
+
65
+ meth->type = type;
66
+ meth->name = name;
67
+
68
+ return meth;
69
+ }
70
+
71
+ static void BIO_meth_free(BIO_METHOD *biom)
72
+ {
73
+ git__free(biom);
74
+ }
75
+
76
+ static int BIO_meth_set_write(BIO_METHOD *biom, int (*write) (BIO *, const char *, int))
77
+ {
78
+ biom->bwrite = write;
79
+ return 1;
80
+ }
81
+
82
+ static int BIO_meth_set_read(BIO_METHOD *biom, int (*read) (BIO *, char *, int))
83
+ {
84
+ biom->bread = read;
85
+ return 1;
86
+ }
87
+
88
+ static int BIO_meth_set_puts(BIO_METHOD *biom, int (*puts) (BIO *, const char *))
89
+ {
90
+ biom->bputs = puts;
91
+ return 1;
92
+ }
93
+
94
+ static int BIO_meth_set_gets(BIO_METHOD *biom, int (*gets) (BIO *, char *, int))
95
+
96
+ {
97
+ biom->bgets = gets;
98
+ return 1;
99
+ }
100
+
101
+ static int BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *))
102
+ {
103
+ biom->ctrl = ctrl;
104
+ return 1;
105
+ }
106
+
107
+ static int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
108
+ {
109
+ biom->create = create;
110
+ return 1;
111
+ }
112
+
113
+ static int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
114
+ {
115
+ biom->destroy = destroy;
116
+ return 1;
117
+ }
118
+
119
+ static int BIO_get_new_index(void)
120
+ {
121
+ /* This exists as of 1.1 so before we'd just have 0 */
122
+ return 0;
123
+ }
124
+
125
+ static void BIO_set_init(BIO *b, int init)
126
+ {
127
+ b->init = init;
128
+ }
129
+
130
+ static void BIO_set_data(BIO *a, void *ptr)
131
+ {
132
+ a->ptr = ptr;
133
+ }
134
+
135
+ static void *BIO_get_data(BIO *a)
136
+ {
137
+ return a->ptr;
138
+ }
139
+
140
+ static const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)
141
+ {
142
+ return ASN1_STRING_data((ASN1_STRING *)x);
143
+ }
42
144
 
145
+ # if defined(GIT_THREADS)
43
146
  static git_mutex *openssl_locks;
44
147
 
45
148
  static void openssl_locking_function(
@@ -70,8 +173,8 @@ static void shutdown_ssl_locking(void)
70
173
  git_mutex_free(&openssl_locks[i]);
71
174
  git__free(openssl_locks);
72
175
  }
73
-
74
- #endif /* GIT_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L */
176
+ # endif /* GIT_THREADS */
177
+ #endif /* OPENSSL_LEGACY_API */
75
178
 
76
179
  static BIO_METHOD *git_stream_bio_method;
77
180
  static int init_bio_method(void);
@@ -95,7 +198,6 @@ static void shutdown_ssl(void)
95
198
 
96
199
  int git_openssl_stream_global_init(void)
97
200
  {
98
- #ifdef GIT_OPENSSL
99
201
  long ssl_opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
100
202
  const char *ciphers = git_libgit2__ssl_ciphers();
101
203
 
@@ -104,13 +206,7 @@ int git_openssl_stream_global_init(void)
104
206
  ssl_opts |= SSL_OP_NO_COMPRESSION;
105
207
  #endif
106
208
 
107
- #if OPENSSL_VERSION_NUMBER < 0x10100000L || \
108
- (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
109
- SSL_load_error_strings();
110
- OpenSSL_add_ssl_algorithms();
111
- #else
112
209
  OPENSSL_init_ssl(0, NULL);
113
- #endif
114
210
 
115
211
  /*
116
212
  * Load SSLv{2,3} and TLSv1 so that we can talk with servers
@@ -118,60 +214,58 @@ int git_openssl_stream_global_init(void)
118
214
  * compatibility. We then disable SSL so we only allow OpenSSL
119
215
  * to speak TLSv1 to perform the encryption itself.
120
216
  */
121
- git__ssl_ctx = SSL_CTX_new(SSLv23_method());
217
+ if (!(git__ssl_ctx = SSL_CTX_new(SSLv23_method())))
218
+ goto error;
219
+
122
220
  SSL_CTX_set_options(git__ssl_ctx, ssl_opts);
123
221
  SSL_CTX_set_mode(git__ssl_ctx, SSL_MODE_AUTO_RETRY);
124
222
  SSL_CTX_set_verify(git__ssl_ctx, SSL_VERIFY_NONE, NULL);
125
- if (!SSL_CTX_set_default_verify_paths(git__ssl_ctx)) {
126
- SSL_CTX_free(git__ssl_ctx);
127
- git__ssl_ctx = NULL;
128
- return -1;
129
- }
223
+ if (!SSL_CTX_set_default_verify_paths(git__ssl_ctx))
224
+ goto error;
130
225
 
131
- if (!ciphers) {
226
+ if (!ciphers)
132
227
  ciphers = GIT_SSL_DEFAULT_CIPHERS;
133
- }
134
228
 
135
- if(!SSL_CTX_set_cipher_list(git__ssl_ctx, ciphers)) {
136
- SSL_CTX_free(git__ssl_ctx);
137
- git__ssl_ctx = NULL;
138
- return -1;
139
- }
229
+ if(!SSL_CTX_set_cipher_list(git__ssl_ctx, ciphers))
230
+ goto error;
140
231
 
141
- if (init_bio_method() < 0) {
142
- SSL_CTX_free(git__ssl_ctx);
143
- git__ssl_ctx = NULL;
144
- return -1;
145
- }
146
-
147
- #endif
232
+ if (init_bio_method() < 0)
233
+ goto error;
148
234
 
149
235
  git__on_shutdown(shutdown_ssl);
150
236
 
151
237
  return 0;
238
+
239
+ error:
240
+ git_error_set(GIT_ERROR_NET, "could not initialize openssl: %s",
241
+ ERR_error_string(ERR_get_error(), NULL));
242
+ SSL_CTX_free(git__ssl_ctx);
243
+ git__ssl_ctx = NULL;
244
+ return -1;
152
245
  }
153
246
 
154
- #if defined(GIT_THREADS)
247
+ #if defined(GIT_THREADS) && defined(OPENSSL_LEGACY_API)
155
248
  static void threadid_cb(CRYPTO_THREADID *threadid)
156
249
  {
157
- CRYPTO_THREADID_set_numeric(threadid, git_thread_currentid());
250
+ GIT_UNUSED(threadid);
251
+ CRYPTO_THREADID_set_numeric(threadid, git_thread_currentid());
158
252
  }
159
253
  #endif
160
254
 
161
255
  int git_openssl_set_locking(void)
162
256
  {
163
- #if defined(GIT_THREADS) && OPENSSL_VERSION_NUMBER < 0x10100000L
257
+ #if defined(GIT_THREADS) && defined(OPENSSL_LEGACY_API)
164
258
  int num_locks, i;
165
259
 
166
260
  CRYPTO_THREADID_set_callback(threadid_cb);
167
261
 
168
262
  num_locks = CRYPTO_num_locks();
169
263
  openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
170
- GITERR_CHECK_ALLOC(openssl_locks);
264
+ GIT_ERROR_CHECK_ALLOC(openssl_locks);
171
265
 
172
266
  for (i = 0; i < num_locks; i++) {
173
267
  if (git_mutex_init(&openssl_locks[i]) != 0) {
174
- giterr_set(GITERR_SSL, "failed to initialize openssl locks");
268
+ git_error_set(GIT_ERROR_SSL, "failed to initialize openssl locks");
175
269
  return -1;
176
270
  }
177
271
  }
@@ -179,10 +273,10 @@ int git_openssl_set_locking(void)
179
273
  CRYPTO_set_locking_callback(openssl_locking_function);
180
274
  git__on_shutdown(shutdown_ssl_locking);
181
275
  return 0;
182
- #elif OPENSSL_VERSION_NUMBER >= 0x10100000L
276
+ #elif !defined(OPENSSL_LEGACY_API)
183
277
  return 0;
184
278
  #else
185
- giterr_set(GITERR_THREAD, "libgit2 was not built with threads");
279
+ git_error_set(GIT_ERROR_THREAD, "libgit2 was not built with threads");
186
280
  return -1;
187
281
  #endif
188
282
  }
@@ -249,7 +343,7 @@ static int init_bio_method(void)
249
343
  {
250
344
  /* Set up the BIO_METHOD we use for wrapping our own stream implementations */
251
345
  git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream");
252
- GITERR_CHECK_ALLOC(git_stream_bio_method);
346
+ GIT_ERROR_CHECK_ALLOC(git_stream_bio_method);
253
347
 
254
348
  BIO_meth_set_write(git_stream_bio_method, bio_write);
255
349
  BIO_meth_set_read(git_stream_bio_method, bio_read);
@@ -275,23 +369,23 @@ static int ssl_set_error(SSL *ssl, int error)
275
369
  switch (err) {
276
370
  case SSL_ERROR_WANT_CONNECT:
277
371
  case SSL_ERROR_WANT_ACCEPT:
278
- giterr_set(GITERR_NET, "SSL error: connection failure");
372
+ git_error_set(GIT_ERROR_SSL, "SSL error: connection failure");
279
373
  break;
280
374
  case SSL_ERROR_WANT_X509_LOOKUP:
281
- giterr_set(GITERR_NET, "SSL error: x509 error");
375
+ git_error_set(GIT_ERROR_SSL, "SSL error: x509 error");
282
376
  break;
283
377
  case SSL_ERROR_SYSCALL:
284
378
  e = ERR_get_error();
285
379
  if (e > 0) {
286
380
  char errmsg[256];
287
381
  ERR_error_string_n(e, errmsg, sizeof(errmsg));
288
- giterr_set(GITERR_NET, "SSL error: %s", errmsg);
382
+ git_error_set(GIT_ERROR_NET, "SSL error: %s", errmsg);
289
383
  break;
290
384
  } else if (error < 0) {
291
- giterr_set(GITERR_OS, "SSL error: syscall failure");
385
+ git_error_set(GIT_ERROR_OS, "SSL error: syscall failure");
292
386
  break;
293
387
  }
294
- giterr_set(GITERR_NET, "SSL error: received early EOF");
388
+ git_error_set(GIT_ERROR_SSL, "SSL error: received early EOF");
295
389
  return GIT_EEOF;
296
390
  break;
297
391
  case SSL_ERROR_SSL:
@@ -299,13 +393,13 @@ static int ssl_set_error(SSL *ssl, int error)
299
393
  char errmsg[256];
300
394
  e = ERR_get_error();
301
395
  ERR_error_string_n(e, errmsg, sizeof(errmsg));
302
- giterr_set(GITERR_NET, "SSL error: %s", errmsg);
396
+ git_error_set(GIT_ERROR_SSL, "SSL error: %s", errmsg);
303
397
  break;
304
398
  }
305
399
  case SSL_ERROR_NONE:
306
400
  case SSL_ERROR_ZERO_RETURN:
307
401
  default:
308
- giterr_set(GITERR_NET, "SSL error: unknown error");
402
+ git_error_set(GIT_ERROR_SSL, "SSL error: unknown error");
309
403
  break;
310
404
  }
311
405
  return -1;
@@ -349,7 +443,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
349
443
  int i = -1, j, error = 0;
350
444
 
351
445
  if (SSL_get_verify_result(ssl) != X509_V_OK) {
352
- giterr_set(GITERR_SSL, "the SSL certificate is invalid");
446
+ git_error_set(GIT_ERROR_SSL, "the SSL certificate is invalid");
353
447
  return GIT_ECERTIFICATE;
354
448
  }
355
449
 
@@ -368,7 +462,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
368
462
  cert = SSL_get_peer_certificate(ssl);
369
463
  if (!cert) {
370
464
  error = -1;
371
- giterr_set(GITERR_SSL, "the server did not provide a certificate");
465
+ git_error_set(GIT_ERROR_SSL, "the server did not provide a certificate");
372
466
  goto cleanup;
373
467
  }
374
468
 
@@ -435,7 +529,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
435
529
 
436
530
  if (size > 0) {
437
531
  peer_cn = OPENSSL_malloc(size + 1);
438
- GITERR_CHECK_ALLOC(peer_cn);
532
+ GIT_ERROR_CHECK_ALLOC(peer_cn);
439
533
  memcpy(peer_cn, ASN1_STRING_get0_data(str), size);
440
534
  peer_cn[size] = '\0';
441
535
  } else {
@@ -443,7 +537,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
443
537
  }
444
538
  } else {
445
539
  int size = ASN1_STRING_to_UTF8(&peer_cn, str);
446
- GITERR_CHECK_ALLOC(peer_cn);
540
+ GIT_ERROR_CHECK_ALLOC(peer_cn);
447
541
  if (memchr(peer_cn, '\0', size))
448
542
  goto cert_fail_name;
449
543
  }
@@ -455,7 +549,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
455
549
 
456
550
  cert_fail_name:
457
551
  error = GIT_ECERTIFICATE;
458
- giterr_set(GITERR_SSL, "hostname does not match certificate");
552
+ git_error_set(GIT_ERROR_SSL, "hostname does not match certificate");
459
553
  goto cleanup;
460
554
 
461
555
  on_error:
@@ -471,27 +565,24 @@ cleanup:
471
565
  typedef struct {
472
566
  git_stream parent;
473
567
  git_stream *io;
568
+ int owned;
474
569
  bool connected;
475
570
  char *host;
476
571
  SSL *ssl;
477
572
  git_cert_x509 cert_info;
478
573
  } openssl_stream;
479
574
 
480
- int openssl_close(git_stream *stream);
481
-
482
- int openssl_connect(git_stream *stream)
575
+ static int openssl_connect(git_stream *stream)
483
576
  {
484
577
  int ret;
485
578
  BIO *bio;
486
579
  openssl_stream *st = (openssl_stream *) stream;
487
580
 
488
- if ((ret = git_stream_connect(st->io)) < 0)
581
+ if (st->owned && (ret = git_stream_connect(st->io)) < 0)
489
582
  return ret;
490
583
 
491
- st->connected = true;
492
-
493
584
  bio = BIO_new(git_stream_bio_method);
494
- GITERR_CHECK_ALLOC(bio);
585
+ GIT_ERROR_CHECK_ALLOC(bio);
495
586
 
496
587
  BIO_set_data(bio, st->io);
497
588
  SSL_set_bio(st->ssl, bio, bio);
@@ -504,10 +595,12 @@ int openssl_connect(git_stream *stream)
504
595
  if ((ret = SSL_connect(st->ssl)) <= 0)
505
596
  return ssl_set_error(st->ssl, ret);
506
597
 
598
+ st->connected = true;
599
+
507
600
  return verify_server_cert(st->ssl, st->host);
508
601
  }
509
602
 
510
- int openssl_certificate(git_cert **out, git_stream *stream)
603
+ static int openssl_certificate(git_cert **out, git_stream *stream)
511
604
  {
512
605
  openssl_stream *st = (openssl_stream *) stream;
513
606
  int len;
@@ -517,19 +610,19 @@ int openssl_certificate(git_cert **out, git_stream *stream)
517
610
  /* Retrieve the length of the certificate first */
518
611
  len = i2d_X509(cert, NULL);
519
612
  if (len < 0) {
520
- giterr_set(GITERR_NET, "failed to retrieve certificate information");
613
+ git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information");
521
614
  return -1;
522
615
  }
523
616
 
524
617
  encoded_cert = git__malloc(len);
525
- GITERR_CHECK_ALLOC(encoded_cert);
618
+ GIT_ERROR_CHECK_ALLOC(encoded_cert);
526
619
  /* i2d_X509 makes 'guard' point to just after the data */
527
620
  guard = encoded_cert;
528
621
 
529
622
  len = i2d_X509(cert, &guard);
530
623
  if (len < 0) {
531
624
  git__free(encoded_cert);
532
- giterr_set(GITERR_NET, "failed to retrieve certificate information");
625
+ git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information");
533
626
  return -1;
534
627
  }
535
628
 
@@ -549,21 +642,20 @@ static int openssl_set_proxy(git_stream *stream, const git_proxy_options *proxy_
549
642
  return git_stream_set_proxy(st->io, proxy_opts);
550
643
  }
551
644
 
552
- ssize_t openssl_write(git_stream *stream, const char *data, size_t len, int flags)
645
+ static ssize_t openssl_write(git_stream *stream, const char *data, size_t data_len, int flags)
553
646
  {
554
647
  openssl_stream *st = (openssl_stream *) stream;
555
- int ret;
648
+ int ret, len = min(data_len, INT_MAX);
556
649
 
557
650
  GIT_UNUSED(flags);
558
651
 
559
- if ((ret = SSL_write(st->ssl, data, len)) <= 0) {
652
+ if ((ret = SSL_write(st->ssl, data, len)) <= 0)
560
653
  return ssl_set_error(st->ssl, ret);
561
- }
562
654
 
563
655
  return ret;
564
656
  }
565
657
 
566
- ssize_t openssl_read(git_stream *stream, void *data, size_t len)
658
+ static ssize_t openssl_read(git_stream *stream, void *data, size_t len)
567
659
  {
568
660
  openssl_stream *st = (openssl_stream *) stream;
569
661
  int ret;
@@ -574,7 +666,7 @@ ssize_t openssl_read(git_stream *stream, void *data, size_t len)
574
666
  return ret;
575
667
  }
576
668
 
577
- int openssl_close(git_stream *stream)
669
+ static int openssl_close(git_stream *stream)
578
670
  {
579
671
  openssl_stream *st = (openssl_stream *) stream;
580
672
  int ret;
@@ -584,47 +676,47 @@ int openssl_close(git_stream *stream)
584
676
 
585
677
  st->connected = false;
586
678
 
587
- return git_stream_close(st->io);
679
+ return st->owned ? git_stream_close(st->io) : 0;
588
680
  }
589
681
 
590
- void openssl_free(git_stream *stream)
682
+ static void openssl_free(git_stream *stream)
591
683
  {
592
684
  openssl_stream *st = (openssl_stream *) stream;
593
685
 
686
+ if (st->owned)
687
+ git_stream_free(st->io);
688
+
594
689
  SSL_free(st->ssl);
595
690
  git__free(st->host);
596
691
  git__free(st->cert_info.data);
597
- git_stream_free(st->io);
598
692
  git__free(st);
599
693
  }
600
694
 
601
- int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
695
+ static int openssl_stream_wrap(
696
+ git_stream **out,
697
+ git_stream *in,
698
+ const char *host,
699
+ int owned)
602
700
  {
603
- int error;
604
701
  openssl_stream *st;
605
702
 
606
- st = git__calloc(1, sizeof(openssl_stream));
607
- GITERR_CHECK_ALLOC(st);
703
+ assert(out && in && host);
608
704
 
609
- st->io = NULL;
610
- #ifdef GIT_CURL
611
- error = git_curl_stream_new(&st->io, host, port);
612
- #else
613
- error = git_socket_stream_new(&st->io, host, port);
614
- #endif
705
+ st = git__calloc(1, sizeof(openssl_stream));
706
+ GIT_ERROR_CHECK_ALLOC(st);
615
707
 
616
- if (error < 0)
617
- goto out_err;
708
+ st->io = in;
709
+ st->owned = owned;
618
710
 
619
711
  st->ssl = SSL_new(git__ssl_ctx);
620
712
  if (st->ssl == NULL) {
621
- giterr_set(GITERR_SSL, "failed to create ssl object");
622
- error = -1;
623
- goto out_err;
713
+ git_error_set(GIT_ERROR_SSL, "failed to create ssl object");
714
+ git__free(st);
715
+ return -1;
624
716
  }
625
717
 
626
718
  st->host = git__strdup(host);
627
- GITERR_CHECK_ALLOC(st->host);
719
+ GIT_ERROR_CHECK_ALLOC(st->host);
628
720
 
629
721
  st->parent.version = GIT_STREAM_VERSION;
630
722
  st->parent.encrypted = 1;
@@ -639,10 +731,27 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
639
731
 
640
732
  *out = (git_stream *) st;
641
733
  return 0;
734
+ }
642
735
 
643
- out_err:
644
- git_stream_free(st->io);
645
- git__free(st);
736
+ int git_openssl_stream_wrap(git_stream **out, git_stream *in, const char *host)
737
+ {
738
+ return openssl_stream_wrap(out, in, host, 0);
739
+ }
740
+
741
+ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
742
+ {
743
+ git_stream *stream = NULL;
744
+ int error;
745
+
746
+ assert(out && host && port);
747
+
748
+ if ((error = git_socket_stream_new(&stream, host, port)) < 0)
749
+ return error;
750
+
751
+ if ((error = openssl_stream_wrap(out, stream, host, 1)) < 0) {
752
+ git_stream_close(stream);
753
+ git_stream_free(stream);
754
+ }
646
755
 
647
756
  return error;
648
757
  }
@@ -653,7 +762,7 @@ int git_openssl__set_cert_location(const char *file, const char *path)
653
762
  char errmsg[256];
654
763
 
655
764
  ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
656
- giterr_set(GITERR_SSL, "OpenSSL error: failed to load certificates: %s",
765
+ git_error_set(GIT_ERROR_SSL, "OpenSSL error: failed to load certificates: %s",
657
766
  errmsg);
658
767
 
659
768
  return -1;
@@ -673,26 +782,7 @@ int git_openssl_stream_global_init(void)
673
782
 
674
783
  int git_openssl_set_locking(void)
675
784
  {
676
- giterr_set(GITERR_SSL, "libgit2 was not built with OpenSSL support");
677
- return -1;
678
- }
679
-
680
- int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
681
- {
682
- GIT_UNUSED(out);
683
- GIT_UNUSED(host);
684
- GIT_UNUSED(port);
685
-
686
- giterr_set(GITERR_SSL, "openssl is not supported in this version");
687
- return -1;
688
- }
689
-
690
- int git_openssl__set_cert_location(const char *file, const char *path)
691
- {
692
- GIT_UNUSED(file);
693
- GIT_UNUSED(path);
694
-
695
- giterr_set(GITERR_SSL, "openssl is not supported in this version");
785
+ git_error_set(GIT_ERROR_SSL, "libgit2 was not built with OpenSSL support");
696
786
  return -1;
697
787
  }
698
788