rugged 0.27.7 → 0.27.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +6 -2
  4. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
  5. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
  6. data/vendor/libgit2/cmake/Modules/FindIconv.cmake +11 -6
  7. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -2
  8. data/vendor/libgit2/include/git2.h +0 -1
  9. data/vendor/libgit2/include/git2/attr.h +7 -18
  10. data/vendor/libgit2/include/git2/blame.h +22 -39
  11. data/vendor/libgit2/include/git2/blob.h +1 -1
  12. data/vendor/libgit2/include/git2/branch.h +1 -1
  13. data/vendor/libgit2/include/git2/buffer.h +2 -14
  14. data/vendor/libgit2/include/git2/checkout.h +12 -13
  15. data/vendor/libgit2/include/git2/cherrypick.h +4 -6
  16. data/vendor/libgit2/include/git2/clone.h +6 -8
  17. data/vendor/libgit2/include/git2/commit.h +0 -28
  18. data/vendor/libgit2/include/git2/common.h +0 -27
  19. data/vendor/libgit2/include/git2/config.h +0 -1
  20. data/vendor/libgit2/include/git2/describe.h +7 -30
  21. data/vendor/libgit2/include/git2/diff.h +22 -32
  22. data/vendor/libgit2/include/git2/errors.h +0 -1
  23. data/vendor/libgit2/include/git2/ignore.h +2 -2
  24. data/vendor/libgit2/include/git2/merge.h +8 -10
  25. data/vendor/libgit2/include/git2/proxy.h +5 -9
  26. data/vendor/libgit2/include/git2/rebase.h +4 -7
  27. data/vendor/libgit2/include/git2/refs.h +1 -1
  28. data/vendor/libgit2/include/git2/refspec.h +0 -17
  29. data/vendor/libgit2/include/git2/remote.h +10 -12
  30. data/vendor/libgit2/include/git2/repository.h +5 -7
  31. data/vendor/libgit2/include/git2/revert.h +3 -5
  32. data/vendor/libgit2/include/git2/stash.h +8 -11
  33. data/vendor/libgit2/include/git2/status.h +3 -7
  34. data/vendor/libgit2/include/git2/submodule.h +7 -8
  35. data/vendor/libgit2/include/git2/sys/index.h +0 -3
  36. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  37. data/vendor/libgit2/include/git2/sys/merge.h +1 -6
  38. data/vendor/libgit2/include/git2/transaction.h +0 -1
  39. data/vendor/libgit2/include/git2/types.h +5 -8
  40. data/vendor/libgit2/include/git2/version.h +2 -2
  41. data/vendor/libgit2/include/git2/worktree.h +11 -46
  42. data/vendor/libgit2/src/CMakeLists.txt +28 -91
  43. data/vendor/libgit2/src/annotated_commit.c +4 -4
  44. data/vendor/libgit2/src/apply.c +6 -5
  45. data/vendor/libgit2/src/attr.c +4 -4
  46. data/vendor/libgit2/src/attr_file.c +5 -5
  47. data/vendor/libgit2/src/attrcache.c +2 -2
  48. data/vendor/libgit2/src/blame.c +4 -11
  49. data/vendor/libgit2/src/blame.h +0 -1
  50. data/vendor/libgit2/src/blame_git.c +5 -8
  51. data/vendor/libgit2/src/blob.c +5 -5
  52. data/vendor/libgit2/src/branch.c +20 -20
  53. data/vendor/libgit2/src/buffer.c +4 -9
  54. data/vendor/libgit2/src/buffer.h +1 -1
  55. data/vendor/libgit2/src/checkout.c +24 -33
  56. data/vendor/libgit2/src/cherrypick.c +3 -3
  57. data/vendor/libgit2/src/clone.c +13 -13
  58. data/vendor/libgit2/src/commit.c +5 -18
  59. data/vendor/libgit2/src/commit_list.c +9 -3
  60. data/vendor/libgit2/src/common.h +1 -3
  61. data/vendor/libgit2/src/config.c +15 -6
  62. data/vendor/libgit2/src/config_file.c +249 -193
  63. data/vendor/libgit2/src/config_parse.c +66 -89
  64. data/vendor/libgit2/src/config_parse.h +2 -2
  65. data/vendor/libgit2/src/crlf.c +3 -9
  66. data/vendor/libgit2/src/diff.c +2 -2
  67. data/vendor/libgit2/src/diff_driver.c +3 -3
  68. data/vendor/libgit2/src/diff_file.c +3 -3
  69. data/vendor/libgit2/src/diff_generate.c +3 -4
  70. data/vendor/libgit2/src/diff_print.c +8 -8
  71. data/vendor/libgit2/src/diff_tform.c +4 -2
  72. data/vendor/libgit2/src/diff_xdiff.c +0 -12
  73. data/vendor/libgit2/src/features.h.in +0 -2
  74. data/vendor/libgit2/src/fetch.c +2 -2
  75. data/vendor/libgit2/src/fetchhead.c +5 -5
  76. data/vendor/libgit2/src/filebuf.c +4 -4
  77. data/vendor/libgit2/src/fileops.c +10 -10
  78. data/vendor/libgit2/src/filter.c +9 -3
  79. data/vendor/libgit2/src/global.c +12 -17
  80. data/vendor/libgit2/src/hash.h +0 -2
  81. data/vendor/libgit2/src/ignore.c +5 -5
  82. data/vendor/libgit2/src/index.c +40 -80
  83. data/vendor/libgit2/src/index.h +0 -10
  84. data/vendor/libgit2/src/indexer.c +9 -9
  85. data/vendor/libgit2/src/iterator.c +8 -8
  86. data/vendor/libgit2/src/khash.h +1 -3
  87. data/vendor/libgit2/src/merge.c +7 -7
  88. data/vendor/libgit2/src/netops.c +5 -5
  89. data/vendor/libgit2/src/notes.c +2 -2
  90. data/vendor/libgit2/src/odb.c +9 -9
  91. data/vendor/libgit2/src/odb_loose.c +22 -18
  92. data/vendor/libgit2/src/odb_pack.c +3 -3
  93. data/vendor/libgit2/src/pack-objects.c +3 -3
  94. data/vendor/libgit2/src/pack.c +5 -5
  95. data/vendor/libgit2/src/pack.h +1 -1
  96. data/vendor/libgit2/src/parse.c +7 -4
  97. data/vendor/libgit2/src/patch.c +1 -1
  98. data/vendor/libgit2/src/patch_generate.c +2 -2
  99. data/vendor/libgit2/src/patch_parse.c +4 -24
  100. data/vendor/libgit2/src/path.c +140 -39
  101. data/vendor/libgit2/src/path.h +84 -2
  102. data/vendor/libgit2/src/pathspec.c +1 -1
  103. data/vendor/libgit2/src/push.c +2 -2
  104. data/vendor/libgit2/src/rebase.c +23 -20
  105. data/vendor/libgit2/src/refdb_fs.c +34 -65
  106. data/vendor/libgit2/src/refs.c +16 -13
  107. data/vendor/libgit2/src/refspec.c +5 -30
  108. data/vendor/libgit2/src/refspec.h +1 -1
  109. data/vendor/libgit2/src/remote.c +43 -43
  110. data/vendor/libgit2/src/repository.c +56 -56
  111. data/vendor/libgit2/src/reset.c +1 -1
  112. data/vendor/libgit2/src/revert.c +3 -3
  113. data/vendor/libgit2/src/revparse.c +7 -6
  114. data/vendor/libgit2/src/revwalk.c +20 -48
  115. data/vendor/libgit2/src/revwalk.h +1 -2
  116. data/vendor/libgit2/src/settings.c +1 -25
  117. data/vendor/libgit2/src/signature.c +4 -2
  118. data/vendor/libgit2/src/stash.c +34 -80
  119. data/vendor/libgit2/src/status.c +1 -1
  120. data/vendor/libgit2/src/streams/curl.c +1 -1
  121. data/vendor/libgit2/src/streams/openssl.c +34 -132
  122. data/vendor/libgit2/src/streams/openssl.h +107 -0
  123. data/vendor/libgit2/src/streams/tls.c +0 -3
  124. data/vendor/libgit2/src/submodule.c +83 -118
  125. data/vendor/libgit2/src/sysdir.c +4 -4
  126. data/vendor/libgit2/src/tag.c +12 -12
  127. data/vendor/libgit2/src/trace.h +1 -1
  128. data/vendor/libgit2/src/trailer.c +6 -6
  129. data/vendor/libgit2/src/transport.c +2 -2
  130. data/vendor/libgit2/src/transports/auth.c +1 -1
  131. data/vendor/libgit2/src/transports/auth_negotiate.c +2 -2
  132. data/vendor/libgit2/src/transports/git.c +1 -1
  133. data/vendor/libgit2/src/transports/http.c +15 -12
  134. data/vendor/libgit2/src/transports/local.c +7 -7
  135. data/vendor/libgit2/src/transports/smart.c +15 -20
  136. data/vendor/libgit2/src/transports/smart.h +5 -5
  137. data/vendor/libgit2/src/transports/smart_pkt.c +131 -123
  138. data/vendor/libgit2/src/transports/smart_protocol.c +38 -48
  139. data/vendor/libgit2/src/transports/ssh.c +1 -1
  140. data/vendor/libgit2/src/transports/winhttp.c +26 -21
  141. data/vendor/libgit2/src/tree-cache.c +2 -2
  142. data/vendor/libgit2/src/tree.c +69 -23
  143. data/vendor/libgit2/src/tree.h +12 -0
  144. data/vendor/libgit2/src/util.c +99 -52
  145. data/vendor/libgit2/src/util.h +138 -14
  146. data/vendor/libgit2/src/vector.c +13 -8
  147. data/vendor/libgit2/src/win32/findfile.c +2 -2
  148. data/vendor/libgit2/src/win32/posix_w32.c +1 -1
  149. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -94
  150. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +75 -28
  151. data/vendor/libgit2/src/worktree.c +44 -65
  152. data/vendor/libgit2/src/worktree.h +0 -2
  153. data/vendor/libgit2/src/xdiff/xdiffi.c +1 -3
  154. metadata +5 -17
  155. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +0 -93
  156. data/vendor/libgit2/include/git2/mailmap.h +0 -115
  157. data/vendor/libgit2/include/git2/sys/alloc.h +0 -101
  158. data/vendor/libgit2/include/git2/sys/path.h +0 -55
  159. data/vendor/libgit2/src/alloc.c +0 -47
  160. data/vendor/libgit2/src/alloc.h +0 -40
  161. data/vendor/libgit2/src/hash/hash_mbedtls.c +0 -38
  162. data/vendor/libgit2/src/hash/hash_mbedtls.h +0 -20
  163. data/vendor/libgit2/src/mailmap.c +0 -485
  164. data/vendor/libgit2/src/mailmap.h +0 -35
  165. data/vendor/libgit2/src/stdalloc.c +0 -120
  166. data/vendor/libgit2/src/stdalloc.h +0 -17
  167. data/vendor/libgit2/src/streams/mbedtls.c +0 -463
  168. data/vendor/libgit2/src/streams/mbedtls.h +0 -20
@@ -1,35 +0,0 @@
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_mailmap_h__
8
- #define INCLUDE_mailmap_h__
9
-
10
- #include "git2/mailmap.h"
11
- #include "vector.h"
12
-
13
- /*
14
- * A mailmap is stored as a sorted vector of 'git_mailmap_entry's. These entries
15
- * are sorted first by 'replace_email', and then by 'replace_name'. NULL
16
- * replace_names are ordered first.
17
- *
18
- * Looking up a name and email in the mailmap is done with a binary search.
19
- */
20
- struct git_mailmap {
21
- git_vector entries;
22
- };
23
-
24
- /* Single entry parsed from a mailmap */
25
- typedef struct git_mailmap_entry {
26
- char *real_name; /**< the real name (may be NULL) */
27
- char *real_email; /**< the real email (may be NULL) */
28
- char *replace_name; /**< the name to replace (may be NULL) */
29
- char *replace_email; /**< the email to replace */
30
- } git_mailmap_entry;
31
-
32
- const git_mailmap_entry *git_mailmap_entry_lookup(
33
- const git_mailmap *mm, const char *name, const char *email);
34
-
35
- #endif
@@ -1,120 +0,0 @@
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
-
8
- #include "stdalloc.h"
9
-
10
- static void *stdalloc__malloc(size_t len, const char *file, int line)
11
- {
12
- void *ptr = malloc(len);
13
-
14
- GIT_UNUSED(file);
15
- GIT_UNUSED(line);
16
-
17
- if (!ptr) giterr_set_oom();
18
- return ptr;
19
- }
20
-
21
- static void *stdalloc__calloc(size_t nelem, size_t elsize, const char *file, int line)
22
- {
23
- void *ptr = calloc(nelem, elsize);
24
-
25
- GIT_UNUSED(file);
26
- GIT_UNUSED(line);
27
-
28
- if (!ptr) giterr_set_oom();
29
- return ptr;
30
- }
31
-
32
- static char *stdalloc__strdup(const char *str, const char *file, int line)
33
- {
34
- char *ptr = strdup(str);
35
-
36
- GIT_UNUSED(file);
37
- GIT_UNUSED(line);
38
-
39
- if (!ptr) giterr_set_oom();
40
- return ptr;
41
- }
42
-
43
- static char *stdalloc__strndup(const char *str, size_t n, const char *file, int line)
44
- {
45
- size_t length = 0, alloclength;
46
- char *ptr;
47
-
48
- length = p_strnlen(str, n);
49
-
50
- if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
51
- !(ptr = stdalloc__malloc(alloclength, file, line)))
52
- return NULL;
53
-
54
- if (length)
55
- memcpy(ptr, str, length);
56
-
57
- ptr[length] = '\0';
58
-
59
- return ptr;
60
- }
61
-
62
- static char *stdalloc__substrdup(const char *start, size_t n, const char *file, int line)
63
- {
64
- char *ptr;
65
- size_t alloclen;
66
-
67
- if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
68
- !(ptr = stdalloc__malloc(alloclen, file, line)))
69
- return NULL;
70
-
71
- memcpy(ptr, start, n);
72
- ptr[n] = '\0';
73
- return ptr;
74
- }
75
-
76
- static void *stdalloc__realloc(void *ptr, size_t size, const char *file, int line)
77
- {
78
- void *new_ptr = realloc(ptr, size);
79
-
80
- GIT_UNUSED(file);
81
- GIT_UNUSED(line);
82
-
83
- if (!new_ptr) giterr_set_oom();
84
- return new_ptr;
85
- }
86
-
87
- static void *stdalloc__reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
88
- {
89
- size_t newsize;
90
-
91
- GIT_UNUSED(file);
92
- GIT_UNUSED(line);
93
-
94
- return GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize) ?
95
- NULL : realloc(ptr, newsize);
96
- }
97
-
98
- static void *stdalloc__mallocarray(size_t nelem, size_t elsize, const char *file, int line)
99
- {
100
- return stdalloc__reallocarray(NULL, nelem, elsize, file, line);
101
- }
102
-
103
- static void stdalloc__free(void *ptr)
104
- {
105
- free(ptr);
106
- }
107
-
108
- int git_stdalloc_init_allocator(git_allocator *allocator)
109
- {
110
- allocator->gmalloc = stdalloc__malloc;
111
- allocator->gcalloc = stdalloc__calloc;
112
- allocator->gstrdup = stdalloc__strdup;
113
- allocator->gstrndup = stdalloc__strndup;
114
- allocator->gsubstrdup = stdalloc__substrdup;
115
- allocator->grealloc = stdalloc__realloc;
116
- allocator->greallocarray = stdalloc__reallocarray;
117
- allocator->gmallocarray = stdalloc__mallocarray;
118
- allocator->gfree = stdalloc__free;
119
- return 0;
120
- }
@@ -1,17 +0,0 @@
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
-
8
- #ifndef INCLUDE_stdalloc_h__
9
- #define INCLUDE_stdalloc_h__
10
-
11
- #include "alloc.h"
12
-
13
- #include "common.h"
14
-
15
- int git_stdalloc_init_allocator(git_allocator *allocator);
16
-
17
- #endif
@@ -1,463 +0,0 @@
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
-
8
- #include "streams/mbedtls.h"
9
-
10
- #ifdef GIT_MBEDTLS
11
-
12
- #include <ctype.h>
13
-
14
- #include "global.h"
15
- #include "stream.h"
16
- #include "streams/socket.h"
17
- #include "netops.h"
18
- #include "git2/transport.h"
19
- #include "util.h"
20
-
21
- #ifdef GIT_CURL
22
- # include "streams/curl.h"
23
- #endif
24
-
25
- #ifndef GIT_DEFAULT_CERT_LOCATION
26
- #define GIT_DEFAULT_CERT_LOCATION NULL
27
- #endif
28
-
29
- /* Work around C90-conformance issues */
30
- #if defined(_MSC_VER)
31
- # define inline __inline
32
- #elif defined(__GNUC__)
33
- # define inline __inline__
34
- #else
35
- # define inline
36
- #endif
37
-
38
- #include <mbedtls/config.h>
39
- #include <mbedtls/ssl.h>
40
- #include <mbedtls/error.h>
41
- #include <mbedtls/entropy.h>
42
- #include <mbedtls/ctr_drbg.h>
43
-
44
- #undef inline
45
-
46
- mbedtls_ssl_config *git__ssl_conf;
47
- mbedtls_entropy_context *mbedtls_entropy;
48
-
49
- #define GIT_SSL_DEFAULT_CIPHERS "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384:TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-DSS-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-DSS-WITH-AES-256-GCM-SHA384:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-CBC-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-128-CBC-SHA:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-128-CBC-SHA256:TLS-DHE-DSS-WITH-AES-256-CBC-SHA256:TLS-DHE-DSS-WITH-AES-128-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-128-GCM-SHA256:TLS-RSA-WITH-AES-256-GCM-SHA384:TLS-RSA-WITH-AES-128-CBC-SHA256:TLS-RSA-WITH-AES-256-CBC-SHA256:TLS-RSA-WITH-AES-128-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA"
50
- #define GIT_SSL_DEFAULT_CIPHERS_COUNT 30
51
-
52
- /**
53
- * This function aims to clean-up the SSL context which
54
- * we allocated.
55
- */
56
- static void shutdown_ssl(void)
57
- {
58
- if (git__ssl_conf) {
59
- mbedtls_x509_crt_free(git__ssl_conf->ca_chain);
60
- git__free(git__ssl_conf->ca_chain);
61
- mbedtls_ctr_drbg_free(git__ssl_conf->p_rng);
62
- git__free(git__ssl_conf->p_rng);
63
- mbedtls_ssl_config_free(git__ssl_conf);
64
- git__free(git__ssl_conf);
65
- git__ssl_conf = NULL;
66
- }
67
- if (mbedtls_entropy) {
68
- mbedtls_entropy_free(mbedtls_entropy);
69
- git__free(mbedtls_entropy);
70
- mbedtls_entropy = NULL;
71
- }
72
- }
73
-
74
- int git_mbedtls__set_cert_location(const char *path, int is_dir);
75
-
76
- int git_mbedtls_stream_global_init(void)
77
- {
78
- int loaded = 0;
79
- char *crtpath = GIT_DEFAULT_CERT_LOCATION;
80
- struct stat statbuf;
81
- mbedtls_ctr_drbg_context *ctr_drbg = NULL;
82
-
83
- int *ciphers_list = NULL;
84
- int ciphers_known = 0;
85
- char *cipher_name = NULL;
86
- char *cipher_string = NULL;
87
- char *cipher_string_tmp = NULL;
88
-
89
- mbedtls_x509_crt *cacert = NULL;
90
-
91
- git__ssl_conf = git__malloc(sizeof(mbedtls_ssl_config));
92
- mbedtls_ssl_config_init(git__ssl_conf);
93
- if (mbedtls_ssl_config_defaults(git__ssl_conf,
94
- MBEDTLS_SSL_IS_CLIENT,
95
- MBEDTLS_SSL_TRANSPORT_STREAM,
96
- MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
97
- giterr_set(GITERR_SSL, "failed to initialize mbedTLS");
98
- goto cleanup;
99
- }
100
-
101
- /* configure TLSv1 */
102
- mbedtls_ssl_conf_min_version(git__ssl_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0);
103
-
104
- /* verify_server_cert is responsible for making the check.
105
- * OPTIONAL because REQUIRED drops the certificate as soon as the check
106
- * is made, so we can never see the certificate and override it. */
107
- mbedtls_ssl_conf_authmode(git__ssl_conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
108
-
109
- /* set the list of allowed ciphersuites */
110
- ciphers_list = calloc(GIT_SSL_DEFAULT_CIPHERS_COUNT, sizeof(int));
111
- ciphers_known = 0;
112
- cipher_string = cipher_string_tmp = git__strdup(GIT_SSL_DEFAULT_CIPHERS);
113
- while ((cipher_name = git__strtok(&cipher_string_tmp, ":")) != NULL) {
114
- int cipherid = mbedtls_ssl_get_ciphersuite_id(cipher_name);
115
- if (cipherid == 0) continue;
116
-
117
- ciphers_list[ciphers_known++] = cipherid;
118
- }
119
- git__free(cipher_string);
120
-
121
- if (!ciphers_known) {
122
- giterr_set(GITERR_SSL, "no cipher could be enabled");
123
- goto cleanup;
124
- }
125
- mbedtls_ssl_conf_ciphersuites(git__ssl_conf, ciphers_list);
126
-
127
- /* Seeding the random number generator */
128
- mbedtls_entropy = git__malloc(sizeof(mbedtls_entropy_context));
129
- mbedtls_entropy_init(mbedtls_entropy);
130
-
131
- ctr_drbg = git__malloc(sizeof(mbedtls_ctr_drbg_context));
132
- mbedtls_ctr_drbg_init(ctr_drbg);
133
- if (mbedtls_ctr_drbg_seed(ctr_drbg,
134
- mbedtls_entropy_func,
135
- mbedtls_entropy, NULL, 0) != 0) {
136
- giterr_set(GITERR_SSL, "failed to initialize mbedTLS entropy pool");
137
- goto cleanup;
138
- }
139
-
140
- mbedtls_ssl_conf_rng(git__ssl_conf, mbedtls_ctr_drbg_random, ctr_drbg);
141
-
142
- /* load default certificates */
143
- if (crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
144
- loaded = (git_mbedtls__set_cert_location(crtpath, 0) == 0);
145
- if (!loaded && crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
146
- loaded = (git_mbedtls__set_cert_location(crtpath, 1) == 0);
147
-
148
- git__on_shutdown(shutdown_ssl);
149
-
150
- return 0;
151
-
152
- cleanup:
153
- mbedtls_x509_crt_free(cacert);
154
- git__free(cacert);
155
- mbedtls_ctr_drbg_free(ctr_drbg);
156
- git__free(ctr_drbg);
157
- mbedtls_ssl_config_free(git__ssl_conf);
158
- git__free(git__ssl_conf);
159
- git__ssl_conf = NULL;
160
-
161
- return -1;
162
- }
163
-
164
- mbedtls_ssl_config *git__ssl_conf;
165
-
166
- static int bio_read(void *b, unsigned char *buf, size_t len)
167
- {
168
- git_stream *io = (git_stream *) b;
169
- return (int) git_stream_read(io, buf, len);
170
- }
171
-
172
- static int bio_write(void *b, const unsigned char *buf, size_t len)
173
- {
174
- git_stream *io = (git_stream *) b;
175
- return (int) git_stream_write(io, (const char *)buf, len, 0);
176
- }
177
-
178
- static int ssl_set_error(mbedtls_ssl_context *ssl, int error)
179
- {
180
- char errbuf[512];
181
- int ret = -1;
182
-
183
- assert(error != MBEDTLS_ERR_SSL_WANT_READ);
184
- assert(error != MBEDTLS_ERR_SSL_WANT_WRITE);
185
-
186
- if (error != 0)
187
- mbedtls_strerror( error, errbuf, 512 );
188
-
189
- switch(error) {
190
- case 0:
191
- giterr_set(GITERR_SSL, "SSL error: unknown error");
192
- break;
193
-
194
- case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:
195
- giterr_set(GITERR_SSL, "SSL error: %#04x [%x] - %s", error, ssl->session_negotiate->verify_result, errbuf);
196
- ret = GIT_ECERTIFICATE;
197
- break;
198
-
199
- default:
200
- giterr_set(GITERR_SSL, "SSL error: %#04x - %s", error, errbuf);
201
- }
202
-
203
- return ret;
204
- }
205
-
206
- static int ssl_teardown(mbedtls_ssl_context *ssl)
207
- {
208
- int ret = 0;
209
-
210
- ret = mbedtls_ssl_close_notify(ssl);
211
- if (ret < 0)
212
- ret = ssl_set_error(ssl, ret);
213
-
214
- mbedtls_ssl_free(ssl);
215
- return ret;
216
- }
217
-
218
- static int verify_server_cert(mbedtls_ssl_context *ssl)
219
- {
220
- int ret = -1;
221
-
222
- if ((ret = mbedtls_ssl_get_verify_result(ssl)) != 0) {
223
- char vrfy_buf[512];
224
- int len = mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), "", ret);
225
- if (len >= 1) vrfy_buf[len - 1] = '\0'; /* Remove trailing \n */
226
- giterr_set(GITERR_SSL, "the SSL certificate is invalid: %#04x - %s", ret, vrfy_buf);
227
- return GIT_ECERTIFICATE;
228
- }
229
-
230
- return 0;
231
- }
232
-
233
- typedef struct {
234
- git_stream parent;
235
- git_stream *io;
236
- bool connected;
237
- char *host;
238
- mbedtls_ssl_context *ssl;
239
- git_cert_x509 cert_info;
240
- } mbedtls_stream;
241
-
242
-
243
- int mbedtls_connect(git_stream *stream)
244
- {
245
- int ret;
246
- mbedtls_stream *st = (mbedtls_stream *) stream;
247
-
248
- if ((ret = git_stream_connect(st->io)) < 0)
249
- return ret;
250
-
251
- st->connected = true;
252
-
253
- mbedtls_ssl_set_hostname(st->ssl, st->host);
254
-
255
- mbedtls_ssl_set_bio(st->ssl, st->io, bio_write, bio_read, NULL);
256
-
257
- if ((ret = mbedtls_ssl_handshake(st->ssl)) != 0)
258
- return ssl_set_error(st->ssl, ret);
259
-
260
- return verify_server_cert(st->ssl);
261
- }
262
-
263
- int mbedtls_certificate(git_cert **out, git_stream *stream)
264
- {
265
- unsigned char *encoded_cert;
266
- mbedtls_stream *st = (mbedtls_stream *) stream;
267
-
268
- const mbedtls_x509_crt *cert = mbedtls_ssl_get_peer_cert(st->ssl);
269
- if (!cert) {
270
- giterr_set(GITERR_SSL, "the server did not provide a certificate");
271
- return -1;
272
- }
273
-
274
- /* Retrieve the length of the certificate first */
275
- if (cert->raw.len == 0) {
276
- giterr_set(GITERR_NET, "failed to retrieve certificate information");
277
- return -1;
278
- }
279
-
280
- encoded_cert = git__malloc(cert->raw.len);
281
- GITERR_CHECK_ALLOC(encoded_cert);
282
- memcpy(encoded_cert, cert->raw.p, cert->raw.len);
283
-
284
- st->cert_info.parent.cert_type = GIT_CERT_X509;
285
- st->cert_info.data = encoded_cert;
286
- st->cert_info.len = cert->raw.len;
287
-
288
- *out = &st->cert_info.parent;
289
-
290
- return 0;
291
- }
292
-
293
- static int mbedtls_set_proxy(git_stream *stream, const git_proxy_options *proxy_options)
294
- {
295
- mbedtls_stream *st = (mbedtls_stream *) stream;
296
-
297
- return git_stream_set_proxy(st->io, proxy_options);
298
- }
299
-
300
- ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t len, int flags)
301
- {
302
- size_t read = 0;
303
- mbedtls_stream *st = (mbedtls_stream *) stream;
304
-
305
- GIT_UNUSED(flags);
306
-
307
- do {
308
- int error = mbedtls_ssl_write(st->ssl, (const unsigned char *)data + read, len - read);
309
- if (error <= 0) {
310
- return ssl_set_error(st->ssl, error);
311
- }
312
- read += error;
313
- } while (read < len);
314
-
315
- return read;
316
- }
317
-
318
- ssize_t mbedtls_stream_read(git_stream *stream, void *data, size_t len)
319
- {
320
- mbedtls_stream *st = (mbedtls_stream *) stream;
321
- int ret;
322
-
323
- if ((ret = mbedtls_ssl_read(st->ssl, (unsigned char *)data, len)) <= 0)
324
- ssl_set_error(st->ssl, ret);
325
-
326
- return ret;
327
- }
328
-
329
- int mbedtls_stream_close(git_stream *stream)
330
- {
331
- mbedtls_stream *st = (mbedtls_stream *) stream;
332
- int ret = 0;
333
-
334
- if (st->connected && (ret = ssl_teardown(st->ssl)) != 0)
335
- return -1;
336
-
337
- st->connected = false;
338
-
339
- return git_stream_close(st->io);
340
- }
341
-
342
- void mbedtls_stream_free(git_stream *stream)
343
- {
344
- mbedtls_stream *st = (mbedtls_stream *) stream;
345
-
346
- git__free(st->host);
347
- git__free(st->cert_info.data);
348
- git_stream_free(st->io);
349
- git__free(st->ssl);
350
- git__free(st);
351
- }
352
-
353
- int git_mbedtls_stream_new(git_stream **out, const char *host, const char *port)
354
- {
355
- int error;
356
- mbedtls_stream *st;
357
-
358
- st = git__calloc(1, sizeof(mbedtls_stream));
359
- GITERR_CHECK_ALLOC(st);
360
-
361
- #ifdef GIT_CURL
362
- error = git_curl_stream_new(&st->io, host, port);
363
- #else
364
- error = git_socket_stream_new(&st->io, host, port);
365
- #endif
366
-
367
- if (error < 0)
368
- goto out_err;
369
-
370
- st->ssl = git__malloc(sizeof(mbedtls_ssl_context));
371
- GITERR_CHECK_ALLOC(st->ssl);
372
- mbedtls_ssl_init(st->ssl);
373
- if (mbedtls_ssl_setup(st->ssl, git__ssl_conf)) {
374
- giterr_set(GITERR_SSL, "failed to create ssl object");
375
- error = -1;
376
- goto out_err;
377
- }
378
-
379
- st->host = git__strdup(host);
380
- GITERR_CHECK_ALLOC(st->host);
381
-
382
- st->parent.version = GIT_STREAM_VERSION;
383
- st->parent.encrypted = 1;
384
- st->parent.proxy_support = git_stream_supports_proxy(st->io);
385
- st->parent.connect = mbedtls_connect;
386
- st->parent.certificate = mbedtls_certificate;
387
- st->parent.set_proxy = mbedtls_set_proxy;
388
- st->parent.read = mbedtls_stream_read;
389
- st->parent.write = mbedtls_stream_write;
390
- st->parent.close = mbedtls_stream_close;
391
- st->parent.free = mbedtls_stream_free;
392
-
393
- *out = (git_stream *) st;
394
- return 0;
395
-
396
- out_err:
397
- mbedtls_ssl_free(st->ssl);
398
- git_stream_free(st->io);
399
- git__free(st);
400
-
401
- return error;
402
- }
403
-
404
- int git_mbedtls__set_cert_location(const char *path, int is_dir)
405
- {
406
- int ret = 0;
407
- char errbuf[512];
408
- mbedtls_x509_crt *cacert;
409
-
410
- assert(path != NULL);
411
-
412
- cacert = git__malloc(sizeof(mbedtls_x509_crt));
413
- mbedtls_x509_crt_init(cacert);
414
- if (is_dir) {
415
- ret = mbedtls_x509_crt_parse_path(cacert, path);
416
- } else {
417
- ret = mbedtls_x509_crt_parse_file(cacert, path);
418
- }
419
- /* mbedtls_x509_crt_parse_path returns the number of invalid certs on success */
420
- if (ret < 0) {
421
- mbedtls_x509_crt_free(cacert);
422
- git__free(cacert);
423
- mbedtls_strerror( ret, errbuf, 512 );
424
- giterr_set(GITERR_SSL, "failed to load CA certificates: %#04x - %s", ret, errbuf);
425
- return -1;
426
- }
427
-
428
- mbedtls_x509_crt_free(git__ssl_conf->ca_chain);
429
- git__free(git__ssl_conf->ca_chain);
430
- mbedtls_ssl_conf_ca_chain(git__ssl_conf, cacert, NULL);
431
-
432
- return 0;
433
- }
434
-
435
- #else
436
-
437
- #include "stream.h"
438
-
439
- int git_mbedtls_stream_global_init(void)
440
- {
441
- return 0;
442
- }
443
-
444
- int git_mbedtls_stream_new(git_stream **out, const char *host, const char *port)
445
- {
446
- GIT_UNUSED(out);
447
- GIT_UNUSED(host);
448
- GIT_UNUSED(port);
449
-
450
- giterr_set(GITERR_SSL, "mbedTLS is not supported in this version");
451
- return -1;
452
- }
453
-
454
- int git_mbedtls__set_cert_location(const char *path, int is_dir)
455
- {
456
- GIT_UNUSED(path);
457
- GIT_UNUSED(is_dir);
458
-
459
- giterr_set(GITERR_SSL, "mbedTLS is not supported in this version");
460
- return -1;
461
- }
462
-
463
- #endif