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