Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
f54d8d52
Commit
f54d8d52
authored
Oct 10, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2574 from csware/hostname-for-certificate_check_cb
Provide host name to certificate_check_cb
parents
533da4ea
db3d169c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
7 deletions
+13
-7
include/git2/types.h
+2
-1
src/transports/http.c
+1
-1
src/transports/ssh.c
+1
-1
src/transports/winhttp.c
+1
-1
tests/online/clone.c
+8
-3
No files found.
include/git2/types.h
View file @
f54d8d52
...
@@ -290,9 +290,10 @@ typedef struct {
...
@@ -290,9 +290,10 @@ typedef struct {
* @param len The size of the certificate or host info
* @param len The size of the certificate or host info
* @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
* @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
* this certificate is valid
* this certificate is valid
* @param host Hostname of the host libgit2 connected to
* @param payload Payload provided by the caller
* @param payload Payload provided by the caller
*/
*/
typedef
int
(
*
git_transport_certificate_check_cb
)(
git_cert
*
cert
,
int
valid
,
void
*
payload
);
typedef
int
(
*
git_transport_certificate_check_cb
)(
git_cert
*
cert
,
int
valid
,
const
char
*
host
,
void
*
payload
);
/**
/**
* Opaque structure representing a submodule.
* Opaque structure representing a submodule.
...
...
src/transports/http.c
View file @
f54d8d52
...
@@ -581,7 +581,7 @@ static int http_connect(http_subtransport *t)
...
@@ -581,7 +581,7 @@ static int http_connect(http_subtransport *t)
cert_info
.
cert_type
=
GIT_CERT_X509
;
cert_info
.
cert_type
=
GIT_CERT_X509
;
cert_info
.
data
=
encoded_cert
;
cert_info
.
data
=
encoded_cert
;
cert_info
.
len
=
len
;
cert_info
.
len
=
len
;
error
=
t
->
owner
->
certificate_check_cb
((
git_cert
*
)
&
cert_info
,
is_valid
,
t
->
owner
->
message_cb_payload
);
error
=
t
->
owner
->
certificate_check_cb
((
git_cert
*
)
&
cert_info
,
is_valid
,
t
->
connection_data
.
host
,
t
->
owner
->
message_cb_payload
);
git__free
(
encoded_cert
);
git__free
(
encoded_cert
);
if
(
error
<
0
)
{
if
(
error
<
0
)
{
...
...
src/transports/ssh.c
View file @
f54d8d52
...
@@ -504,7 +504,7 @@ static int _git_ssh_setup_conn(
...
@@ -504,7 +504,7 @@ static int _git_ssh_setup_conn(
/* We don't currently trust any hostkeys */
/* We don't currently trust any hostkeys */
giterr_clear
();
giterr_clear
();
error
=
t
->
owner
->
certificate_check_cb
((
git_cert
*
)
&
cert
,
0
,
t
->
owner
->
message_cb_payload
);
error
=
t
->
owner
->
certificate_check_cb
((
git_cert
*
)
&
cert
,
0
,
host
,
t
->
owner
->
message_cb_payload
);
if
(
error
<
0
)
{
if
(
error
<
0
)
{
if
(
!
giterr_last
())
if
(
!
giterr_last
())
giterr_set
(
GITERR_NET
,
"user cancelled hostkey check"
);
giterr_set
(
GITERR_NET
,
"user cancelled hostkey check"
);
...
...
src/transports/winhttp.c
View file @
f54d8d52
...
@@ -229,7 +229,7 @@ static int certificate_check(winhttp_stream *s, int valid)
...
@@ -229,7 +229,7 @@ static int certificate_check(winhttp_stream *s, int valid)
cert
.
cert_type
=
GIT_CERT_X509
;
cert
.
cert_type
=
GIT_CERT_X509
;
cert
.
data
=
cert_ctx
->
pbCertEncoded
;
cert
.
data
=
cert_ctx
->
pbCertEncoded
;
cert
.
len
=
cert_ctx
->
cbCertEncoded
;
cert
.
len
=
cert_ctx
->
cbCertEncoded
;
error
=
t
->
owner
->
certificate_check_cb
((
git_cert
*
)
&
cert
,
valid
,
t
->
owner
->
cred_acquire_payload
);
error
=
t
->
owner
->
certificate_check_cb
((
git_cert
*
)
&
cert
,
valid
,
t
->
connection_data
.
host
,
t
->
owner
->
cred_acquire_payload
);
CertFreeCertificateContext
(
cert_ctx
);
CertFreeCertificateContext
(
cert_ctx
);
if
(
error
<
0
&&
!
giterr_last
())
if
(
error
<
0
&&
!
giterr_last
())
...
...
tests/online/clone.c
View file @
f54d8d52
...
@@ -473,7 +473,7 @@ void test_online_clone__ssh_cannot_change_username(void)
...
@@ -473,7 +473,7 @@ void test_online_clone__ssh_cannot_change_username(void)
cl_git_fail
(
git_clone
(
&
g_repo
,
"ssh://git@github.com/libgit2/TestGitRepository"
,
"./foo"
,
&
g_options
));
cl_git_fail
(
git_clone
(
&
g_repo
,
"ssh://git@github.com/libgit2/TestGitRepository"
,
"./foo"
,
&
g_options
));
}
}
int
ssh_certificate_check
(
git_cert
*
cert
,
int
valid
,
void
*
payload
)
int
ssh_certificate_check
(
git_cert
*
cert
,
int
valid
,
const
char
*
host
,
void
*
payload
)
{
{
git_cert_hostkey
*
key
;
git_cert_hostkey
*
key
;
git_oid
expected
=
{{
0
}},
actual
=
{{
0
}};
git_oid
expected
=
{{
0
}},
actual
=
{{
0
}};
...
@@ -504,6 +504,8 @@ int ssh_certificate_check(git_cert *cert, int valid, void *payload)
...
@@ -504,6 +504,8 @@ int ssh_certificate_check(git_cert *cert, int valid, void *payload)
cl_assert
(
!
memcmp
(
&
expected
,
&
actual
,
20
));
cl_assert
(
!
memcmp
(
&
expected
,
&
actual
,
20
));
cl_assert_equal_s
(
"localhost"
,
host
);
return
GIT_EUSER
;
return
GIT_EUSER
;
}
}
...
@@ -523,10 +525,11 @@ void test_online_clone__url_with_no_path_returns_EINVALIDSPEC(void)
...
@@ -523,10 +525,11 @@ void test_online_clone__url_with_no_path_returns_EINVALIDSPEC(void)
GIT_EINVALIDSPEC
);
GIT_EINVALIDSPEC
);
}
}
static
int
fail_certificate_check
(
git_cert
*
cert
,
int
valid
,
void
*
payload
)
static
int
fail_certificate_check
(
git_cert
*
cert
,
int
valid
,
const
char
*
host
,
void
*
payload
)
{
{
GIT_UNUSED
(
cert
);
GIT_UNUSED
(
cert
);
GIT_UNUSED
(
valid
);
GIT_UNUSED
(
valid
);
GIT_UNUSED
(
host
);
GIT_UNUSED
(
payload
);
GIT_UNUSED
(
payload
);
return
GIT_ECERTIFICATE
;
return
GIT_ECERTIFICATE
;
...
@@ -545,12 +548,14 @@ void test_online_clone__certificate_invalid(void)
...
@@ -545,12 +548,14 @@ void test_online_clone__certificate_invalid(void)
#endif
#endif
}
}
static
int
succeed_certificate_check
(
git_cert
*
cert
,
int
valid
,
void
*
payload
)
static
int
succeed_certificate_check
(
git_cert
*
cert
,
int
valid
,
const
char
*
host
,
void
*
payload
)
{
{
GIT_UNUSED
(
cert
);
GIT_UNUSED
(
cert
);
GIT_UNUSED
(
valid
);
GIT_UNUSED
(
valid
);
GIT_UNUSED
(
payload
);
GIT_UNUSED
(
payload
);
cl_assert_equal_s
(
"github.com"
,
host
);
return
0
;
return
0
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment