line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 "git2/errors.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "common.h" |
11
|
|
|
|
|
|
|
#include "streams/registry.h" |
12
|
|
|
|
|
|
|
#include "streams/tls.h" |
13
|
|
|
|
|
|
|
#include "streams/mbedtls.h" |
14
|
|
|
|
|
|
|
#include "streams/openssl.h" |
15
|
|
|
|
|
|
|
#include "streams/stransport.h" |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
int git_tls_stream_new(git_stream **out, const char *host, const char *port) |
18
|
|
|
|
|
|
|
{ |
19
|
0
|
|
|
|
|
|
int (*init)(git_stream **, const char *, const char *) = NULL; |
20
|
0
|
|
|
|
|
|
git_stream_registration custom = {0}; |
21
|
|
|
|
|
|
|
int error; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(out); |
24
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(host); |
25
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(port); |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) { |
28
|
0
|
|
|
|
|
|
init = custom.init; |
29
|
0
|
0
|
|
|
|
|
} else if (error == GIT_ENOTFOUND) { |
30
|
|
|
|
|
|
|
#ifdef GIT_SECURE_TRANSPORT |
31
|
|
|
|
|
|
|
init = git_stransport_stream_new; |
32
|
|
|
|
|
|
|
#elif defined(GIT_OPENSSL) |
33
|
0
|
|
|
|
|
|
init = git_openssl_stream_new; |
34
|
|
|
|
|
|
|
#elif defined(GIT_MBEDTLS) |
35
|
|
|
|
|
|
|
init = git_mbedtls_stream_new; |
36
|
|
|
|
|
|
|
#endif |
37
|
|
|
|
|
|
|
} else { |
38
|
0
|
|
|
|
|
|
return error; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if (!init) { |
42
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_SSL, "there is no TLS stream available"); |
43
|
0
|
|
|
|
|
|
return -1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return init(out, host, port); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host) |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
|
|
|
int (*wrap)(git_stream **, git_stream *, const char *) = NULL; |
52
|
0
|
|
|
|
|
|
git_stream_registration custom = {0}; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(out); |
55
|
0
|
0
|
|
|
|
|
GIT_ASSERT_ARG(in); |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) { |
58
|
0
|
|
|
|
|
|
wrap = custom.wrap; |
59
|
|
|
|
|
|
|
} else { |
60
|
|
|
|
|
|
|
#ifdef GIT_SECURE_TRANSPORT |
61
|
|
|
|
|
|
|
wrap = git_stransport_stream_wrap; |
62
|
|
|
|
|
|
|
#elif defined(GIT_OPENSSL) |
63
|
0
|
|
|
|
|
|
wrap = git_openssl_stream_wrap; |
64
|
|
|
|
|
|
|
#elif defined(GIT_MBEDTLS) |
65
|
|
|
|
|
|
|
wrap = git_mbedtls_stream_wrap; |
66
|
|
|
|
|
|
|
#endif |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if (!wrap) { |
70
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_SSL, "there is no TLS stream available"); |
71
|
0
|
|
|
|
|
|
return -1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return wrap(out, in, host); |
75
|
|
|
|
|
|
|
} |