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.
- checksums.yaml +4 -4
- data/ext/rugged/extconf.rb +23 -2
- data/ext/rugged/rugged.c +48 -2
- data/ext/rugged/rugged.h +5 -0
- data/ext/rugged/rugged_allocator.c +89 -0
- data/ext/rugged/rugged_blob.c +3 -3
- data/ext/rugged/rugged_branch.c +1 -1
- data/ext/rugged/rugged_commit.c +8 -8
- data/ext/rugged/rugged_config.c +1 -1
- data/ext/rugged/rugged_diff.c +24 -4
- data/ext/rugged/rugged_note.c +1 -1
- data/ext/rugged/rugged_repo.c +10 -10
- data/ext/rugged/rugged_settings.c +1 -1
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +69 -47
- data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +15 -1
- data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -8
- data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
- data/vendor/libgit2/deps/http-parser/CMakeLists.txt +2 -0
- data/vendor/libgit2/deps/http-parser/{LICENSE-MIT → COPYING} +0 -0
- data/vendor/libgit2/deps/regex/COPYING +502 -0
- data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
- data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
- data/vendor/libgit2/deps/zlib/CMakeLists.txt +1 -0
- data/vendor/libgit2/deps/zlib/COPYING +27 -0
- data/vendor/libgit2/include/git2.h +3 -0
- data/vendor/libgit2/include/git2/annotated_commit.h +9 -0
- data/vendor/libgit2/include/git2/apply.h +129 -0
- data/vendor/libgit2/include/git2/attr.h +19 -8
- data/vendor/libgit2/include/git2/blame.h +41 -24
- data/vendor/libgit2/include/git2/blob.h +1 -1
- data/vendor/libgit2/include/git2/branch.h +1 -1
- data/vendor/libgit2/include/git2/buffer.h +2 -2
- data/vendor/libgit2/include/git2/checkout.h +20 -19
- data/vendor/libgit2/include/git2/cherrypick.h +6 -4
- data/vendor/libgit2/include/git2/clone.h +11 -9
- data/vendor/libgit2/include/git2/commit.h +30 -2
- data/vendor/libgit2/include/git2/common.h +54 -4
- data/vendor/libgit2/include/git2/config.h +18 -7
- data/vendor/libgit2/include/git2/deprecated.h +253 -0
- data/vendor/libgit2/include/git2/describe.h +30 -7
- data/vendor/libgit2/include/git2/diff.h +193 -143
- data/vendor/libgit2/include/git2/errors.h +54 -46
- data/vendor/libgit2/include/git2/ignore.h +2 -2
- data/vendor/libgit2/include/git2/index.h +72 -51
- data/vendor/libgit2/include/git2/indexer.h +30 -4
- data/vendor/libgit2/include/git2/mailmap.h +115 -0
- data/vendor/libgit2/include/git2/merge.h +29 -8
- data/vendor/libgit2/include/git2/net.h +1 -1
- data/vendor/libgit2/include/git2/notes.h +1 -1
- data/vendor/libgit2/include/git2/object.h +16 -16
- data/vendor/libgit2/include/git2/odb.h +10 -10
- data/vendor/libgit2/include/git2/odb_backend.h +7 -7
- data/vendor/libgit2/include/git2/oid.h +1 -1
- data/vendor/libgit2/include/git2/pack.h +2 -2
- data/vendor/libgit2/include/git2/proxy.h +9 -5
- data/vendor/libgit2/include/git2/rebase.h +7 -4
- data/vendor/libgit2/include/git2/refs.h +14 -15
- data/vendor/libgit2/include/git2/refspec.h +17 -0
- data/vendor/libgit2/include/git2/remote.h +92 -16
- data/vendor/libgit2/include/git2/repository.h +52 -37
- data/vendor/libgit2/include/git2/revert.h +5 -3
- data/vendor/libgit2/include/git2/revwalk.h +7 -7
- data/vendor/libgit2/include/git2/signature.h +2 -2
- data/vendor/libgit2/include/git2/stash.h +13 -10
- data/vendor/libgit2/include/git2/status.h +8 -4
- data/vendor/libgit2/include/git2/submodule.h +11 -10
- data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
- data/vendor/libgit2/include/git2/sys/commit.h +1 -1
- data/vendor/libgit2/include/git2/sys/config.h +13 -13
- data/vendor/libgit2/include/git2/sys/filter.h +6 -6
- data/vendor/libgit2/include/git2/sys/index.h +3 -0
- data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
- data/vendor/libgit2/include/git2/sys/merge.h +9 -4
- data/vendor/libgit2/include/git2/sys/odb_backend.h +19 -19
- data/vendor/libgit2/include/git2/sys/path.h +64 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +19 -19
- data/vendor/libgit2/include/git2/sys/stream.h +92 -12
- data/vendor/libgit2/include/git2/sys/transport.h +127 -81
- data/vendor/libgit2/include/git2/tag.h +2 -2
- data/vendor/libgit2/include/git2/trace.h +1 -1
- data/vendor/libgit2/include/git2/transaction.h +1 -0
- data/vendor/libgit2/include/git2/transport.h +47 -18
- data/vendor/libgit2/include/git2/tree.h +3 -3
- data/vendor/libgit2/include/git2/types.h +35 -28
- data/vendor/libgit2/include/git2/version.h +4 -4
- data/vendor/libgit2/include/git2/worktree.h +47 -12
- data/vendor/libgit2/src/CMakeLists.txt +87 -26
- data/vendor/libgit2/src/alloc.c +55 -0
- data/vendor/libgit2/src/alloc.h +40 -0
- data/vendor/libgit2/src/annotated_commit.c +15 -8
- data/vendor/libgit2/src/apply.c +490 -14
- data/vendor/libgit2/src/apply.h +3 -1
- data/vendor/libgit2/src/array.h +2 -2
- data/vendor/libgit2/src/attr.c +11 -11
- data/vendor/libgit2/src/attr_file.c +20 -15
- data/vendor/libgit2/src/attrcache.c +11 -11
- data/vendor/libgit2/src/blame.c +30 -15
- data/vendor/libgit2/src/blame.h +1 -0
- data/vendor/libgit2/src/blame_git.c +16 -13
- data/vendor/libgit2/src/blob.c +50 -28
- data/vendor/libgit2/src/blob.h +18 -1
- data/vendor/libgit2/src/branch.c +38 -38
- data/vendor/libgit2/src/buf_text.c +7 -6
- data/vendor/libgit2/src/buffer.c +55 -50
- data/vendor/libgit2/src/buffer.h +1 -1
- data/vendor/libgit2/src/cache.c +16 -16
- data/vendor/libgit2/src/cache.h +2 -2
- data/vendor/libgit2/src/cc-compat.h +15 -3
- data/vendor/libgit2/src/checkout.c +83 -74
- data/vendor/libgit2/src/cherrypick.c +6 -6
- data/vendor/libgit2/src/clone.c +20 -20
- data/vendor/libgit2/src/commit.c +53 -33
- data/vendor/libgit2/src/commit.h +1 -0
- data/vendor/libgit2/src/commit_list.c +6 -10
- data/vendor/libgit2/src/common.h +32 -30
- data/vendor/libgit2/src/config.c +167 -147
- data/vendor/libgit2/src/config.h +1 -14
- data/vendor/libgit2/src/config_backend.h +84 -0
- data/vendor/libgit2/src/config_cache.c +7 -1
- data/vendor/libgit2/src/config_entries.c +259 -0
- data/vendor/libgit2/src/config_entries.h +23 -0
- data/vendor/libgit2/src/config_file.c +167 -439
- data/vendor/libgit2/src/config_mem.c +224 -0
- data/vendor/libgit2/src/config_parse.c +69 -38
- data/vendor/libgit2/src/config_parse.h +4 -4
- data/vendor/libgit2/src/crlf.c +215 -186
- data/vendor/libgit2/src/delta.c +25 -18
- data/vendor/libgit2/src/describe.c +23 -23
- data/vendor/libgit2/src/diff.c +12 -12
- data/vendor/libgit2/src/diff_driver.c +14 -15
- data/vendor/libgit2/src/diff_file.c +10 -10
- data/vendor/libgit2/src/diff_generate.c +29 -23
- data/vendor/libgit2/src/diff_generate.h +1 -1
- data/vendor/libgit2/src/diff_parse.c +3 -3
- data/vendor/libgit2/src/diff_print.c +17 -17
- data/vendor/libgit2/src/diff_stats.c +22 -7
- data/vendor/libgit2/src/diff_tform.c +12 -12
- data/vendor/libgit2/src/diff_xdiff.c +15 -3
- data/vendor/libgit2/src/errors.c +42 -20
- data/vendor/libgit2/src/features.h.in +2 -1
- data/vendor/libgit2/src/fetch.c +3 -3
- data/vendor/libgit2/src/fetchhead.c +16 -16
- data/vendor/libgit2/src/filebuf.c +28 -28
- data/vendor/libgit2/src/fileops.c +54 -54
- data/vendor/libgit2/src/fileops.h +1 -1
- data/vendor/libgit2/src/filter.c +30 -30
- data/vendor/libgit2/src/filter.h +0 -10
- data/vendor/libgit2/src/global.c +36 -23
- data/vendor/libgit2/src/hash.h +4 -1
- data/vendor/libgit2/src/hash/hash_collisiondetect.h +6 -2
- data/vendor/libgit2/src/hash/hash_common_crypto.h +5 -1
- data/vendor/libgit2/src/hash/hash_generic.h +5 -1
- data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
- data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +8 -4
- data/vendor/libgit2/src/hash/hash_win32.c +13 -13
- data/vendor/libgit2/src/hashsig.c +4 -4
- data/vendor/libgit2/src/idxmap.c +25 -5
- data/vendor/libgit2/src/idxmap.h +4 -18
- data/vendor/libgit2/src/ignore.c +9 -9
- data/vendor/libgit2/src/index.c +280 -198
- data/vendor/libgit2/src/index.h +16 -0
- data/vendor/libgit2/src/indexer.c +311 -139
- data/vendor/libgit2/src/integer.h +32 -22
- data/vendor/libgit2/src/iterator.c +116 -49
- data/vendor/libgit2/src/iterator.h +15 -0
- data/vendor/libgit2/src/khash.h +3 -1
- data/vendor/libgit2/src/mailmap.c +485 -0
- data/vendor/libgit2/src/mailmap.h +35 -0
- data/vendor/libgit2/src/merge.c +89 -59
- data/vendor/libgit2/src/merge_driver.c +7 -7
- data/vendor/libgit2/src/merge_file.c +1 -1
- data/vendor/libgit2/src/mwindow.c +8 -8
- data/vendor/libgit2/src/netops.c +22 -13
- data/vendor/libgit2/src/netops.h +2 -0
- data/vendor/libgit2/src/notes.c +15 -10
- data/vendor/libgit2/src/object.c +118 -67
- data/vendor/libgit2/src/object.h +20 -9
- data/vendor/libgit2/src/object_api.c +8 -8
- data/vendor/libgit2/src/odb.c +72 -72
- data/vendor/libgit2/src/odb.h +7 -7
- data/vendor/libgit2/src/odb_loose.c +46 -46
- data/vendor/libgit2/src/odb_mempack.c +14 -14
- data/vendor/libgit2/src/odb_pack.c +14 -10
- data/vendor/libgit2/src/offmap.c +30 -0
- data/vendor/libgit2/src/offmap.h +20 -11
- data/vendor/libgit2/src/oid.c +6 -6
- data/vendor/libgit2/src/oidmap.c +20 -0
- data/vendor/libgit2/src/oidmap.h +9 -12
- data/vendor/libgit2/src/pack-objects.c +71 -63
- data/vendor/libgit2/src/pack-objects.h +1 -7
- data/vendor/libgit2/src/pack.c +58 -58
- data/vendor/libgit2/src/pack.h +6 -6
- data/vendor/libgit2/src/parse.h +1 -1
- data/vendor/libgit2/src/patch.c +3 -3
- data/vendor/libgit2/src/patch_generate.c +18 -18
- data/vendor/libgit2/src/patch_parse.c +13 -13
- data/vendor/libgit2/src/path.c +93 -225
- data/vendor/libgit2/src/path.h +2 -84
- data/vendor/libgit2/src/pathspec.c +6 -6
- data/vendor/libgit2/src/posix.c +3 -3
- data/vendor/libgit2/src/proxy.c +1 -1
- data/vendor/libgit2/src/push.c +27 -26
- data/vendor/libgit2/src/push.h +2 -1
- data/vendor/libgit2/src/reader.c +265 -0
- data/vendor/libgit2/src/reader.h +107 -0
- data/vendor/libgit2/src/rebase.c +49 -52
- data/vendor/libgit2/src/refdb.c +3 -3
- data/vendor/libgit2/src/refdb_fs.c +181 -103
- data/vendor/libgit2/src/reflog.c +3 -3
- data/vendor/libgit2/src/refs.c +98 -74
- data/vendor/libgit2/src/refs.h +5 -3
- data/vendor/libgit2/src/refspec.c +47 -21
- data/vendor/libgit2/src/refspec.h +1 -1
- data/vendor/libgit2/src/remote.c +219 -166
- data/vendor/libgit2/src/remote.h +9 -0
- data/vendor/libgit2/src/repository.c +173 -133
- data/vendor/libgit2/src/repository.h +6 -3
- data/vendor/libgit2/src/reset.c +8 -8
- data/vendor/libgit2/src/revert.c +6 -6
- data/vendor/libgit2/src/revparse.c +30 -30
- data/vendor/libgit2/src/revwalk.c +60 -30
- data/vendor/libgit2/src/revwalk.h +2 -1
- data/vendor/libgit2/src/settings.c +42 -10
- data/vendor/libgit2/src/signature.c +11 -11
- data/vendor/libgit2/src/sortedcache.c +13 -13
- data/vendor/libgit2/src/stash.c +91 -45
- data/vendor/libgit2/src/status.c +13 -13
- data/vendor/libgit2/src/stdalloc.c +120 -0
- data/vendor/libgit2/src/{streams/curl.h → stdalloc.h} +6 -6
- data/vendor/libgit2/src/stream.h +17 -2
- data/vendor/libgit2/src/streams/mbedtls.c +483 -0
- data/vendor/libgit2/src/streams/mbedtls.h +23 -0
- data/vendor/libgit2/src/streams/openssl.c +204 -114
- data/vendor/libgit2/src/streams/openssl.h +4 -108
- data/vendor/libgit2/src/streams/registry.c +118 -0
- data/vendor/libgit2/src/streams/registry.h +19 -0
- data/vendor/libgit2/src/streams/socket.c +54 -29
- data/vendor/libgit2/src/streams/stransport.c +57 -32
- data/vendor/libgit2/src/streams/stransport.h +5 -0
- data/vendor/libgit2/src/streams/tls.c +50 -19
- data/vendor/libgit2/src/streams/tls.h +12 -4
- data/vendor/libgit2/src/strmap.c +22 -2
- data/vendor/libgit2/src/strmap.h +18 -15
- data/vendor/libgit2/src/submodule.c +179 -155
- data/vendor/libgit2/src/sysdir.c +18 -18
- data/vendor/libgit2/src/tag.c +31 -26
- data/vendor/libgit2/src/tag.h +2 -1
- data/vendor/libgit2/src/trace.c +1 -1
- data/vendor/libgit2/src/trace.h +1 -1
- data/vendor/libgit2/src/trailer.c +6 -6
- data/vendor/libgit2/src/transaction.c +23 -23
- data/vendor/libgit2/src/transport.c +5 -5
- data/vendor/libgit2/src/transports/auth.c +7 -4
- data/vendor/libgit2/src/transports/auth.h +1 -1
- data/vendor/libgit2/src/transports/auth_negotiate.c +12 -11
- data/vendor/libgit2/src/transports/cred.c +18 -18
- data/vendor/libgit2/src/transports/git.c +15 -15
- data/vendor/libgit2/src/transports/http.c +606 -216
- data/vendor/libgit2/src/transports/http.h +2 -0
- data/vendor/libgit2/src/transports/local.c +26 -26
- data/vendor/libgit2/src/transports/smart.c +54 -31
- data/vendor/libgit2/src/transports/smart.h +1 -2
- data/vendor/libgit2/src/transports/smart_pkt.c +43 -40
- data/vendor/libgit2/src/transports/smart_protocol.c +61 -57
- data/vendor/libgit2/src/transports/ssh.c +34 -33
- data/vendor/libgit2/src/transports/winhttp.c +99 -119
- data/vendor/libgit2/src/tree-cache.c +5 -5
- data/vendor/libgit2/src/tree.c +96 -121
- data/vendor/libgit2/src/tree.h +1 -12
- data/vendor/libgit2/src/unix/map.c +2 -2
- data/vendor/libgit2/src/util.c +22 -6
- data/vendor/libgit2/src/util.h +12 -135
- data/vendor/libgit2/src/vector.c +4 -4
- data/vendor/libgit2/src/win32/dir.c +3 -3
- data/vendor/libgit2/src/win32/findfile.c +3 -3
- data/vendor/libgit2/src/win32/map.c +6 -6
- data/vendor/libgit2/src/win32/msvc-compat.h +6 -0
- data/vendor/libgit2/src/win32/path_w32.c +101 -7
- data/vendor/libgit2/src/win32/path_w32.h +18 -0
- data/vendor/libgit2/src/win32/posix_w32.c +24 -43
- data/vendor/libgit2/src/win32/w32_buffer.c +2 -2
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +96 -2
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +28 -75
- data/vendor/libgit2/src/win32/w32_stack.c +2 -2
- data/vendor/libgit2/src/win32/w32_util.c +1 -69
- data/vendor/libgit2/src/win32/w32_util.h +1 -19
- data/vendor/libgit2/src/worktree.c +75 -54
- data/vendor/libgit2/src/worktree.h +2 -0
- data/vendor/libgit2/src/xdiff/xdiffi.c +7 -5
- data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
- data/vendor/libgit2/src/xdiff/xmerge.c +15 -15
- data/vendor/libgit2/src/zstream.c +4 -4
- metadata +33 -7
- data/vendor/libgit2/src/config_file.h +0 -73
- data/vendor/libgit2/src/streams/curl.c +0 -385
data/vendor/libgit2/src/status.c
CHANGED
@@ -174,7 +174,7 @@ static int status_collect(
|
|
174
174
|
return 0;
|
175
175
|
|
176
176
|
status_entry = git__malloc(sizeof(git_status_entry));
|
177
|
-
|
177
|
+
GIT_ERROR_CHECK_ALLOC(status_entry);
|
178
178
|
|
179
179
|
status_entry->status = status_compute(status, head2idx, idx2wd);
|
180
180
|
status_entry->head_to_index = head2idx;
|
@@ -240,16 +240,16 @@ static int status_validate_options(const git_status_options *opts)
|
|
240
240
|
if (!opts)
|
241
241
|
return 0;
|
242
242
|
|
243
|
-
|
243
|
+
GIT_ERROR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options");
|
244
244
|
|
245
245
|
if (opts->show > GIT_STATUS_SHOW_WORKDIR_ONLY) {
|
246
|
-
|
246
|
+
git_error_set(GIT_ERROR_INVALID, "unknown status 'show' option");
|
247
247
|
return -1;
|
248
248
|
}
|
249
249
|
|
250
250
|
if ((opts->flags & GIT_STATUS_OPT_NO_REFRESH) != 0 &&
|
251
251
|
(opts->flags & GIT_STATUS_OPT_UPDATE_INDEX) != 0) {
|
252
|
-
|
252
|
+
git_error_set(GIT_ERROR_INVALID, "updating index from status "
|
253
253
|
"is not allowed when index refresh is disabled");
|
254
254
|
return -1;
|
255
255
|
}
|
@@ -288,17 +288,17 @@ int git_status_list_new(
|
|
288
288
|
if ((error = git_repository_head_tree(&head, repo)) < 0) {
|
289
289
|
if (error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH)
|
290
290
|
goto done;
|
291
|
-
|
291
|
+
git_error_clear();
|
292
292
|
}
|
293
293
|
}
|
294
294
|
|
295
295
|
/* refresh index from disk unless prevented */
|
296
296
|
if ((flags & GIT_STATUS_OPT_NO_REFRESH) == 0 &&
|
297
|
-
|
298
|
-
|
297
|
+
git_index_read_safely(index) < 0)
|
298
|
+
git_error_clear();
|
299
299
|
|
300
300
|
status = git_status_list_alloc(index);
|
301
|
-
|
301
|
+
GIT_ERROR_CHECK_ALLOC(status);
|
302
302
|
|
303
303
|
if (opts) {
|
304
304
|
memcpy(&status->opts, opts, sizeof(git_status_options));
|
@@ -437,7 +437,7 @@ int git_status_foreach_ext(
|
|
437
437
|
status_entry->index_to_workdir->old_file.path;
|
438
438
|
|
439
439
|
if ((error = cb(path, status_entry->status, payload)) != 0) {
|
440
|
-
|
440
|
+
git_error_set_after_callback(error);
|
441
441
|
break;
|
442
442
|
}
|
443
443
|
}
|
@@ -475,7 +475,7 @@ static int get_one_status(const char *path, unsigned int status, void *data)
|
|
475
475
|
p_fnmatch(sfi->expected, path, sfi->fnm_flags) != 0))
|
476
476
|
{
|
477
477
|
sfi->ambiguous = true;
|
478
|
-
return GIT_EAMBIGUOUS; /*
|
478
|
+
return GIT_EAMBIGUOUS; /* git_error_set will be done by caller */
|
479
479
|
}
|
480
480
|
|
481
481
|
return 0;
|
@@ -514,13 +514,13 @@ int git_status_file(
|
|
514
514
|
error = git_status_foreach_ext(repo, &opts, get_one_status, &sfi);
|
515
515
|
|
516
516
|
if (error < 0 && sfi.ambiguous) {
|
517
|
-
|
517
|
+
git_error_set(GIT_ERROR_INVALID,
|
518
518
|
"ambiguous path '%s' given to git_status_file", sfi.expected);
|
519
519
|
error = GIT_EAMBIGUOUS;
|
520
520
|
}
|
521
521
|
|
522
522
|
if (!error && !sfi.count) {
|
523
|
-
|
523
|
+
git_error_set(GIT_ERROR_INVALID,
|
524
524
|
"attempt to get status of nonexistent file '%s'", path);
|
525
525
|
error = GIT_ENOTFOUND;
|
526
526
|
}
|
@@ -551,7 +551,7 @@ int git_status_list_get_perfdata(
|
|
551
551
|
git_diff_perfdata *out, const git_status_list *status)
|
552
552
|
{
|
553
553
|
assert(out);
|
554
|
-
|
554
|
+
GIT_ERROR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
|
555
555
|
|
556
556
|
out->stat_calls = 0;
|
557
557
|
out->oid_calculations = 0;
|
@@ -0,0 +1,120 @@
|
|
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) git_error_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) git_error_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) git_error_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) git_error_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
|
+
}
|
@@ -4,14 +4,14 @@
|
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
6
6
|
*/
|
7
|
-
#ifndef INCLUDE_streams_curl_h__
|
8
|
-
#define INCLUDE_streams_curl_h__
|
9
7
|
|
10
|
-
#
|
8
|
+
#ifndef INCLUDE_stdalloc_h__
|
9
|
+
#define INCLUDE_stdalloc_h__
|
10
|
+
|
11
|
+
#include "alloc.h"
|
11
12
|
|
12
|
-
#include "
|
13
|
+
#include "common.h"
|
13
14
|
|
14
|
-
|
15
|
-
extern int git_curl_stream_new(git_stream **out, const char *host, const char *port);
|
15
|
+
int git_stdalloc_init_allocator(git_allocator *allocator);
|
16
16
|
|
17
17
|
#endif
|
data/vendor/libgit2/src/stream.h
CHANGED
@@ -23,7 +23,7 @@ GIT_INLINE(int) git_stream_is_encrypted(git_stream *st)
|
|
23
23
|
GIT_INLINE(int) git_stream_certificate(git_cert **out, git_stream *st)
|
24
24
|
{
|
25
25
|
if (!st->encrypted) {
|
26
|
-
|
26
|
+
git_error_set(GIT_ERROR_INVALID, "an unencrypted stream does not have a certificate");
|
27
27
|
return -1;
|
28
28
|
}
|
29
29
|
|
@@ -38,7 +38,7 @@ GIT_INLINE(int) git_stream_supports_proxy(git_stream *st)
|
|
38
38
|
GIT_INLINE(int) git_stream_set_proxy(git_stream *st, const git_proxy_options *proxy_opts)
|
39
39
|
{
|
40
40
|
if (!st->proxy_support) {
|
41
|
-
|
41
|
+
git_error_set(GIT_ERROR_INVALID, "proxy not supported on this stream");
|
42
42
|
return -1;
|
43
43
|
}
|
44
44
|
|
@@ -55,6 +55,21 @@ GIT_INLINE(ssize_t) git_stream_write(git_stream *st, const char *data, size_t le
|
|
55
55
|
return st->write(st, data, len, flags);
|
56
56
|
}
|
57
57
|
|
58
|
+
GIT_INLINE(int) git_stream__write_full(git_stream *st, const char *data, size_t len, int flags)
|
59
|
+
{
|
60
|
+
size_t total_written = 0;
|
61
|
+
|
62
|
+
while (total_written < len) {
|
63
|
+
ssize_t written = git_stream_write(st, data + total_written, len - total_written, flags);
|
64
|
+
if (written <= 0)
|
65
|
+
return -1;
|
66
|
+
|
67
|
+
total_written += written;
|
68
|
+
}
|
69
|
+
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
|
58
73
|
GIT_INLINE(int) git_stream_close(git_stream *st)
|
59
74
|
{
|
60
75
|
return st->close(st);
|
@@ -0,0 +1,483 @@
|
|
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
|
+
#ifndef GIT_DEFAULT_CERT_LOCATION
|
22
|
+
#define GIT_DEFAULT_CERT_LOCATION NULL
|
23
|
+
#endif
|
24
|
+
|
25
|
+
/* Work around C90-conformance issues */
|
26
|
+
#if defined(_MSC_VER)
|
27
|
+
# define inline __inline
|
28
|
+
#elif defined(__GNUC__)
|
29
|
+
# define inline __inline__
|
30
|
+
#else
|
31
|
+
# define inline
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#include <mbedtls/config.h>
|
35
|
+
#include <mbedtls/ssl.h>
|
36
|
+
#include <mbedtls/error.h>
|
37
|
+
#include <mbedtls/entropy.h>
|
38
|
+
#include <mbedtls/ctr_drbg.h>
|
39
|
+
|
40
|
+
#undef inline
|
41
|
+
|
42
|
+
#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"
|
43
|
+
#define GIT_SSL_DEFAULT_CIPHERS_COUNT 30
|
44
|
+
|
45
|
+
static mbedtls_ssl_config *git__ssl_conf;
|
46
|
+
static int ciphers_list[GIT_SSL_DEFAULT_CIPHERS_COUNT];
|
47
|
+
static mbedtls_entropy_context *mbedtls_entropy;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* This function aims to clean-up the SSL context which
|
51
|
+
* we allocated.
|
52
|
+
*/
|
53
|
+
static void shutdown_ssl(void)
|
54
|
+
{
|
55
|
+
if (git__ssl_conf) {
|
56
|
+
mbedtls_x509_crt_free(git__ssl_conf->ca_chain);
|
57
|
+
git__free(git__ssl_conf->ca_chain);
|
58
|
+
mbedtls_ctr_drbg_free(git__ssl_conf->p_rng);
|
59
|
+
git__free(git__ssl_conf->p_rng);
|
60
|
+
mbedtls_ssl_config_free(git__ssl_conf);
|
61
|
+
git__free(git__ssl_conf);
|
62
|
+
git__ssl_conf = NULL;
|
63
|
+
}
|
64
|
+
if (mbedtls_entropy) {
|
65
|
+
mbedtls_entropy_free(mbedtls_entropy);
|
66
|
+
git__free(mbedtls_entropy);
|
67
|
+
mbedtls_entropy = NULL;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
int git_mbedtls__set_cert_location(const char *path, int is_dir);
|
72
|
+
|
73
|
+
int git_mbedtls_stream_global_init(void)
|
74
|
+
{
|
75
|
+
int loaded = 0;
|
76
|
+
char *crtpath = GIT_DEFAULT_CERT_LOCATION;
|
77
|
+
struct stat statbuf;
|
78
|
+
mbedtls_ctr_drbg_context *ctr_drbg = NULL;
|
79
|
+
|
80
|
+
size_t ciphers_known = 0;
|
81
|
+
char *cipher_name = NULL;
|
82
|
+
char *cipher_string = NULL;
|
83
|
+
char *cipher_string_tmp = NULL;
|
84
|
+
|
85
|
+
git__ssl_conf = git__malloc(sizeof(mbedtls_ssl_config));
|
86
|
+
GIT_ERROR_CHECK_ALLOC(git__ssl_conf);
|
87
|
+
|
88
|
+
mbedtls_ssl_config_init(git__ssl_conf);
|
89
|
+
if (mbedtls_ssl_config_defaults(git__ssl_conf,
|
90
|
+
MBEDTLS_SSL_IS_CLIENT,
|
91
|
+
MBEDTLS_SSL_TRANSPORT_STREAM,
|
92
|
+
MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
|
93
|
+
git_error_set(GIT_ERROR_SSL, "failed to initialize mbedTLS");
|
94
|
+
goto cleanup;
|
95
|
+
}
|
96
|
+
|
97
|
+
/* configure TLSv1 */
|
98
|
+
mbedtls_ssl_conf_min_version(git__ssl_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0);
|
99
|
+
|
100
|
+
/* verify_server_cert is responsible for making the check.
|
101
|
+
* OPTIONAL because REQUIRED drops the certificate as soon as the check
|
102
|
+
* is made, so we can never see the certificate and override it. */
|
103
|
+
mbedtls_ssl_conf_authmode(git__ssl_conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
|
104
|
+
|
105
|
+
/* set the list of allowed ciphersuites */
|
106
|
+
ciphers_known = 0;
|
107
|
+
cipher_string = cipher_string_tmp = git__strdup(GIT_SSL_DEFAULT_CIPHERS);
|
108
|
+
GIT_ERROR_CHECK_ALLOC(cipher_string);
|
109
|
+
|
110
|
+
while ((cipher_name = git__strtok(&cipher_string_tmp, ":")) != NULL) {
|
111
|
+
int cipherid = mbedtls_ssl_get_ciphersuite_id(cipher_name);
|
112
|
+
if (cipherid == 0) continue;
|
113
|
+
|
114
|
+
if (ciphers_known >= ARRAY_SIZE(ciphers_list)) {
|
115
|
+
git_error_set(GIT_ERROR_SSL, "out of cipher list space");
|
116
|
+
goto cleanup;
|
117
|
+
}
|
118
|
+
|
119
|
+
ciphers_list[ciphers_known++] = cipherid;
|
120
|
+
}
|
121
|
+
git__free(cipher_string);
|
122
|
+
|
123
|
+
if (!ciphers_known) {
|
124
|
+
git_error_set(GIT_ERROR_SSL, "no cipher could be enabled");
|
125
|
+
goto cleanup;
|
126
|
+
}
|
127
|
+
mbedtls_ssl_conf_ciphersuites(git__ssl_conf, ciphers_list);
|
128
|
+
|
129
|
+
/* Seeding the random number generator */
|
130
|
+
mbedtls_entropy = git__malloc(sizeof(mbedtls_entropy_context));
|
131
|
+
GIT_ERROR_CHECK_ALLOC(mbedtls_entropy);
|
132
|
+
|
133
|
+
mbedtls_entropy_init(mbedtls_entropy);
|
134
|
+
|
135
|
+
ctr_drbg = git__malloc(sizeof(mbedtls_ctr_drbg_context));
|
136
|
+
GIT_ERROR_CHECK_ALLOC(ctr_drbg);
|
137
|
+
|
138
|
+
mbedtls_ctr_drbg_init(ctr_drbg);
|
139
|
+
|
140
|
+
if (mbedtls_ctr_drbg_seed(ctr_drbg,
|
141
|
+
mbedtls_entropy_func,
|
142
|
+
mbedtls_entropy, NULL, 0) != 0) {
|
143
|
+
git_error_set(GIT_ERROR_SSL, "failed to initialize mbedTLS entropy pool");
|
144
|
+
goto cleanup;
|
145
|
+
}
|
146
|
+
|
147
|
+
mbedtls_ssl_conf_rng(git__ssl_conf, mbedtls_ctr_drbg_random, ctr_drbg);
|
148
|
+
|
149
|
+
/* load default certificates */
|
150
|
+
if (crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
|
151
|
+
loaded = (git_mbedtls__set_cert_location(crtpath, 0) == 0);
|
152
|
+
if (!loaded && crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
|
153
|
+
loaded = (git_mbedtls__set_cert_location(crtpath, 1) == 0);
|
154
|
+
|
155
|
+
git__on_shutdown(shutdown_ssl);
|
156
|
+
|
157
|
+
return 0;
|
158
|
+
|
159
|
+
cleanup:
|
160
|
+
mbedtls_ctr_drbg_free(ctr_drbg);
|
161
|
+
git__free(ctr_drbg);
|
162
|
+
mbedtls_ssl_config_free(git__ssl_conf);
|
163
|
+
git__free(git__ssl_conf);
|
164
|
+
git__ssl_conf = NULL;
|
165
|
+
|
166
|
+
return -1;
|
167
|
+
}
|
168
|
+
|
169
|
+
static int bio_read(void *b, unsigned char *buf, size_t len)
|
170
|
+
{
|
171
|
+
git_stream *io = (git_stream *) b;
|
172
|
+
return (int) git_stream_read(io, buf, min(len, INT_MAX));
|
173
|
+
}
|
174
|
+
|
175
|
+
static int bio_write(void *b, const unsigned char *buf, size_t len)
|
176
|
+
{
|
177
|
+
git_stream *io = (git_stream *) b;
|
178
|
+
return (int) git_stream_write(io, (const char *)buf, min(len, INT_MAX), 0);
|
179
|
+
}
|
180
|
+
|
181
|
+
static int ssl_set_error(mbedtls_ssl_context *ssl, int error)
|
182
|
+
{
|
183
|
+
char errbuf[512];
|
184
|
+
int ret = -1;
|
185
|
+
|
186
|
+
assert(error != MBEDTLS_ERR_SSL_WANT_READ);
|
187
|
+
assert(error != MBEDTLS_ERR_SSL_WANT_WRITE);
|
188
|
+
|
189
|
+
if (error != 0)
|
190
|
+
mbedtls_strerror( error, errbuf, 512 );
|
191
|
+
|
192
|
+
switch(error) {
|
193
|
+
case 0:
|
194
|
+
git_error_set(GIT_ERROR_SSL, "SSL error: unknown error");
|
195
|
+
break;
|
196
|
+
|
197
|
+
case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:
|
198
|
+
git_error_set(GIT_ERROR_SSL, "SSL error: %#04x [%x] - %s", error, ssl->session_negotiate->verify_result, errbuf);
|
199
|
+
ret = GIT_ECERTIFICATE;
|
200
|
+
break;
|
201
|
+
|
202
|
+
default:
|
203
|
+
git_error_set(GIT_ERROR_SSL, "SSL error: %#04x - %s", error, errbuf);
|
204
|
+
}
|
205
|
+
|
206
|
+
return ret;
|
207
|
+
}
|
208
|
+
|
209
|
+
static int ssl_teardown(mbedtls_ssl_context *ssl)
|
210
|
+
{
|
211
|
+
int ret = 0;
|
212
|
+
|
213
|
+
ret = mbedtls_ssl_close_notify(ssl);
|
214
|
+
if (ret < 0)
|
215
|
+
ret = ssl_set_error(ssl, ret);
|
216
|
+
|
217
|
+
mbedtls_ssl_free(ssl);
|
218
|
+
return ret;
|
219
|
+
}
|
220
|
+
|
221
|
+
static int verify_server_cert(mbedtls_ssl_context *ssl)
|
222
|
+
{
|
223
|
+
int ret = -1;
|
224
|
+
|
225
|
+
if ((ret = mbedtls_ssl_get_verify_result(ssl)) != 0) {
|
226
|
+
char vrfy_buf[512];
|
227
|
+
int len = mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), "", ret);
|
228
|
+
if (len >= 1) vrfy_buf[len - 1] = '\0'; /* Remove trailing \n */
|
229
|
+
git_error_set(GIT_ERROR_SSL, "the SSL certificate is invalid: %#04x - %s", ret, vrfy_buf);
|
230
|
+
return GIT_ECERTIFICATE;
|
231
|
+
}
|
232
|
+
|
233
|
+
return 0;
|
234
|
+
}
|
235
|
+
|
236
|
+
typedef struct {
|
237
|
+
git_stream parent;
|
238
|
+
git_stream *io;
|
239
|
+
int owned;
|
240
|
+
bool connected;
|
241
|
+
char *host;
|
242
|
+
mbedtls_ssl_context *ssl;
|
243
|
+
git_cert_x509 cert_info;
|
244
|
+
} mbedtls_stream;
|
245
|
+
|
246
|
+
|
247
|
+
static int mbedtls_connect(git_stream *stream)
|
248
|
+
{
|
249
|
+
int ret;
|
250
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
251
|
+
|
252
|
+
if (st->owned && (ret = git_stream_connect(st->io)) < 0)
|
253
|
+
return ret;
|
254
|
+
|
255
|
+
st->connected = true;
|
256
|
+
|
257
|
+
mbedtls_ssl_set_hostname(st->ssl, st->host);
|
258
|
+
|
259
|
+
mbedtls_ssl_set_bio(st->ssl, st->io, bio_write, bio_read, NULL);
|
260
|
+
|
261
|
+
if ((ret = mbedtls_ssl_handshake(st->ssl)) != 0)
|
262
|
+
return ssl_set_error(st->ssl, ret);
|
263
|
+
|
264
|
+
return verify_server_cert(st->ssl);
|
265
|
+
}
|
266
|
+
|
267
|
+
static int mbedtls_certificate(git_cert **out, git_stream *stream)
|
268
|
+
{
|
269
|
+
unsigned char *encoded_cert;
|
270
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
271
|
+
|
272
|
+
const mbedtls_x509_crt *cert = mbedtls_ssl_get_peer_cert(st->ssl);
|
273
|
+
if (!cert) {
|
274
|
+
git_error_set(GIT_ERROR_SSL, "the server did not provide a certificate");
|
275
|
+
return -1;
|
276
|
+
}
|
277
|
+
|
278
|
+
/* Retrieve the length of the certificate first */
|
279
|
+
if (cert->raw.len == 0) {
|
280
|
+
git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information");
|
281
|
+
return -1;
|
282
|
+
}
|
283
|
+
|
284
|
+
encoded_cert = git__malloc(cert->raw.len);
|
285
|
+
GIT_ERROR_CHECK_ALLOC(encoded_cert);
|
286
|
+
memcpy(encoded_cert, cert->raw.p, cert->raw.len);
|
287
|
+
|
288
|
+
st->cert_info.parent.cert_type = GIT_CERT_X509;
|
289
|
+
st->cert_info.data = encoded_cert;
|
290
|
+
st->cert_info.len = cert->raw.len;
|
291
|
+
|
292
|
+
*out = &st->cert_info.parent;
|
293
|
+
|
294
|
+
return 0;
|
295
|
+
}
|
296
|
+
|
297
|
+
static int mbedtls_set_proxy(git_stream *stream, const git_proxy_options *proxy_options)
|
298
|
+
{
|
299
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
300
|
+
|
301
|
+
return git_stream_set_proxy(st->io, proxy_options);
|
302
|
+
}
|
303
|
+
|
304
|
+
static ssize_t mbedtls_stream_write(git_stream *stream, const char *data, size_t len, int flags)
|
305
|
+
{
|
306
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
307
|
+
int written;
|
308
|
+
|
309
|
+
GIT_UNUSED(flags);
|
310
|
+
|
311
|
+
/*
|
312
|
+
* `mbedtls_ssl_write` can only represent INT_MAX bytes
|
313
|
+
* written via its return value. We thus need to clamp
|
314
|
+
* the maximum number of bytes written.
|
315
|
+
*/
|
316
|
+
len = min(len, INT_MAX);
|
317
|
+
|
318
|
+
if ((written = mbedtls_ssl_write(st->ssl, (const unsigned char *)data, len)) <= 0)
|
319
|
+
return ssl_set_error(st->ssl, written);
|
320
|
+
|
321
|
+
return written;
|
322
|
+
}
|
323
|
+
|
324
|
+
static ssize_t mbedtls_stream_read(git_stream *stream, void *data, size_t len)
|
325
|
+
{
|
326
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
327
|
+
int ret;
|
328
|
+
|
329
|
+
if ((ret = mbedtls_ssl_read(st->ssl, (unsigned char *)data, len)) <= 0)
|
330
|
+
ssl_set_error(st->ssl, ret);
|
331
|
+
|
332
|
+
return ret;
|
333
|
+
}
|
334
|
+
|
335
|
+
static int mbedtls_stream_close(git_stream *stream)
|
336
|
+
{
|
337
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
338
|
+
int ret = 0;
|
339
|
+
|
340
|
+
if (st->connected && (ret = ssl_teardown(st->ssl)) != 0)
|
341
|
+
return -1;
|
342
|
+
|
343
|
+
st->connected = false;
|
344
|
+
|
345
|
+
return st->owned ? git_stream_close(st->io) : 0;
|
346
|
+
}
|
347
|
+
|
348
|
+
static void mbedtls_stream_free(git_stream *stream)
|
349
|
+
{
|
350
|
+
mbedtls_stream *st = (mbedtls_stream *) stream;
|
351
|
+
|
352
|
+
if (st->owned)
|
353
|
+
git_stream_free(st->io);
|
354
|
+
|
355
|
+
git__free(st->host);
|
356
|
+
git__free(st->cert_info.data);
|
357
|
+
mbedtls_ssl_free(st->ssl);
|
358
|
+
git__free(st->ssl);
|
359
|
+
git__free(st);
|
360
|
+
}
|
361
|
+
|
362
|
+
static int mbedtls_stream_wrap(
|
363
|
+
git_stream **out,
|
364
|
+
git_stream *in,
|
365
|
+
const char *host,
|
366
|
+
int owned)
|
367
|
+
{
|
368
|
+
mbedtls_stream *st;
|
369
|
+
int error;
|
370
|
+
|
371
|
+
st = git__calloc(1, sizeof(mbedtls_stream));
|
372
|
+
GIT_ERROR_CHECK_ALLOC(st);
|
373
|
+
|
374
|
+
st->io = in;
|
375
|
+
st->owned = owned;
|
376
|
+
|
377
|
+
st->ssl = git__malloc(sizeof(mbedtls_ssl_context));
|
378
|
+
GIT_ERROR_CHECK_ALLOC(st->ssl);
|
379
|
+
mbedtls_ssl_init(st->ssl);
|
380
|
+
if (mbedtls_ssl_setup(st->ssl, git__ssl_conf)) {
|
381
|
+
git_error_set(GIT_ERROR_SSL, "failed to create ssl object");
|
382
|
+
error = -1;
|
383
|
+
goto out_err;
|
384
|
+
}
|
385
|
+
|
386
|
+
st->host = git__strdup(host);
|
387
|
+
GIT_ERROR_CHECK_ALLOC(st->host);
|
388
|
+
|
389
|
+
st->parent.version = GIT_STREAM_VERSION;
|
390
|
+
st->parent.encrypted = 1;
|
391
|
+
st->parent.proxy_support = git_stream_supports_proxy(st->io);
|
392
|
+
st->parent.connect = mbedtls_connect;
|
393
|
+
st->parent.certificate = mbedtls_certificate;
|
394
|
+
st->parent.set_proxy = mbedtls_set_proxy;
|
395
|
+
st->parent.read = mbedtls_stream_read;
|
396
|
+
st->parent.write = mbedtls_stream_write;
|
397
|
+
st->parent.close = mbedtls_stream_close;
|
398
|
+
st->parent.free = mbedtls_stream_free;
|
399
|
+
|
400
|
+
*out = (git_stream *) st;
|
401
|
+
return 0;
|
402
|
+
|
403
|
+
out_err:
|
404
|
+
mbedtls_ssl_free(st->ssl);
|
405
|
+
git_stream_close(st->io);
|
406
|
+
git_stream_free(st->io);
|
407
|
+
git__free(st);
|
408
|
+
|
409
|
+
return error;
|
410
|
+
}
|
411
|
+
|
412
|
+
int git_mbedtls_stream_wrap(
|
413
|
+
git_stream **out,
|
414
|
+
git_stream *in,
|
415
|
+
const char *host)
|
416
|
+
{
|
417
|
+
return mbedtls_stream_wrap(out, in, host, 0);
|
418
|
+
}
|
419
|
+
|
420
|
+
int git_mbedtls_stream_new(
|
421
|
+
git_stream **out,
|
422
|
+
const char *host,
|
423
|
+
const char *port)
|
424
|
+
{
|
425
|
+
git_stream *stream;
|
426
|
+
int error;
|
427
|
+
|
428
|
+
assert(out && host && port);
|
429
|
+
|
430
|
+
if ((error = git_socket_stream_new(&stream, host, port)) < 0)
|
431
|
+
return error;
|
432
|
+
|
433
|
+
if ((error = mbedtls_stream_wrap(out, stream, host, 1)) < 0) {
|
434
|
+
git_stream_close(stream);
|
435
|
+
git_stream_free(stream);
|
436
|
+
}
|
437
|
+
|
438
|
+
return error;
|
439
|
+
}
|
440
|
+
|
441
|
+
int git_mbedtls__set_cert_location(const char *path, int is_dir)
|
442
|
+
{
|
443
|
+
int ret = 0;
|
444
|
+
char errbuf[512];
|
445
|
+
mbedtls_x509_crt *cacert;
|
446
|
+
|
447
|
+
assert(path != NULL);
|
448
|
+
|
449
|
+
cacert = git__malloc(sizeof(mbedtls_x509_crt));
|
450
|
+
GIT_ERROR_CHECK_ALLOC(cacert);
|
451
|
+
|
452
|
+
mbedtls_x509_crt_init(cacert);
|
453
|
+
if (is_dir) {
|
454
|
+
ret = mbedtls_x509_crt_parse_path(cacert, path);
|
455
|
+
} else {
|
456
|
+
ret = mbedtls_x509_crt_parse_file(cacert, path);
|
457
|
+
}
|
458
|
+
/* mbedtls_x509_crt_parse_path returns the number of invalid certs on success */
|
459
|
+
if (ret < 0) {
|
460
|
+
mbedtls_x509_crt_free(cacert);
|
461
|
+
git__free(cacert);
|
462
|
+
mbedtls_strerror( ret, errbuf, 512 );
|
463
|
+
git_error_set(GIT_ERROR_SSL, "failed to load CA certificates: %#04x - %s", ret, errbuf);
|
464
|
+
return -1;
|
465
|
+
}
|
466
|
+
|
467
|
+
mbedtls_x509_crt_free(git__ssl_conf->ca_chain);
|
468
|
+
git__free(git__ssl_conf->ca_chain);
|
469
|
+
mbedtls_ssl_conf_ca_chain(git__ssl_conf, cacert, NULL);
|
470
|
+
|
471
|
+
return 0;
|
472
|
+
}
|
473
|
+
|
474
|
+
#else
|
475
|
+
|
476
|
+
#include "stream.h"
|
477
|
+
|
478
|
+
int git_mbedtls_stream_global_init(void)
|
479
|
+
{
|
480
|
+
return 0;
|
481
|
+
}
|
482
|
+
|
483
|
+
#endif
|