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
7bcced44
Commit
7bcced44
authored
May 12, 2014
by
Russell Belfer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2300 from libgit2/cmn/match-host-tests
Some improvements to the cert checking
parents
d2c4d1c6
783555d8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
9 deletions
+39
-9
src/netops.c
+13
-9
src/netops.h
+13
-0
tests/network/matchhost.c
+13
-0
No files found.
src/netops.c
View file @
7bcced44
...
...
@@ -207,7 +207,7 @@ static int gitno_ssl_teardown(gitno_ssl *ssl)
}
/* Match host names according to RFC 2818 rules */
static
int
match_host
(
const
char
*
pattern
,
const
char
*
host
)
int
gitno__
match_host
(
const
char
*
pattern
,
const
char
*
host
)
{
for
(;;)
{
char
c
=
tolower
(
*
pattern
++
);
...
...
@@ -230,9 +230,9 @@ static int match_host(const char *pattern, const char *host)
while
(
*
host
)
{
char
h
=
tolower
(
*
host
);
if
(
c
==
h
)
return
match_host
(
pattern
,
host
++
);
return
gitno__
match_host
(
pattern
,
host
++
);
if
(
h
==
'.'
)
return
match_host
(
pattern
,
host
);
return
gitno__
match_host
(
pattern
,
host
);
host
++
;
}
return
-
1
;
...
...
@@ -250,7 +250,7 @@ static int check_host_name(const char *name, const char *host)
if
(
!
strcasecmp
(
name
,
host
))
return
0
;
if
(
match_host
(
name
,
host
)
<
0
)
if
(
gitno__
match_host
(
name
,
host
)
<
0
)
return
-
1
;
return
0
;
...
...
@@ -287,6 +287,10 @@ static int verify_server_cert(gitno_ssl *ssl, const char *host)
cert
=
SSL_get_peer_certificate
(
ssl
->
ssl
);
if
(
!
cert
)
{
giterr_set
(
GITERR_SSL
,
"the server did not provide a certificate"
);
return
-
1
;
}
/* Check the alternative names */
alts
=
X509_get_ext_d2i
(
cert
,
NID_subject_alt_name
,
NULL
,
NULL
);
...
...
@@ -321,7 +325,7 @@ static int verify_server_cert(gitno_ssl *ssl, const char *host)
GENERAL_NAMES_free
(
alts
);
if
(
matched
==
0
)
goto
cert_fail
;
goto
cert_fail
_name
;
if
(
matched
==
1
)
return
0
;
...
...
@@ -358,11 +362,11 @@ static int verify_server_cert(gitno_ssl *ssl, const char *host)
int
size
=
ASN1_STRING_to_UTF8
(
&
peer_cn
,
str
);
GITERR_CHECK_ALLOC
(
peer_cn
);
if
(
memchr
(
peer_cn
,
'\0'
,
size
))
goto
cert_fail
;
goto
cert_fail
_name
;
}
if
(
check_host_name
((
char
*
)
peer_cn
,
host
)
<
0
)
goto
cert_fail
;
goto
cert_fail
_name
;
OPENSSL_free
(
peer_cn
);
...
...
@@ -372,9 +376,9 @@ on_error:
OPENSSL_free
(
peer_cn
);
return
ssl_set_error
(
ssl
,
0
);
cert_fail:
cert_fail
_name
:
OPENSSL_free
(
peer_cn
);
giterr_set
(
GITERR_SSL
,
"
Certificate host name check failed
"
);
giterr_set
(
GITERR_SSL
,
"
hostname does not match certificate
"
);
return
-
1
;
}
...
...
src/netops.h
View file @
7bcced44
...
...
@@ -54,6 +54,19 @@ enum {
GITNO_CONNECT_SSL_NO_CHECK_CERT
=
2
,
};
/**
* Check if the name in a cert matches the wanted hostname
*
* Check if a pattern from a certificate matches the hostname we
* wanted to connect to according to RFC2818 rules (which specifies
* HTTP over TLS). Mainly, an asterisk matches anything, but is
* limited to a single url component.
*
* Note that this does not set an error message. It expects the user
* to provide the message for the user.
*/
int
gitno__match_host
(
const
char
*
pattern
,
const
char
*
host
);
void
gitno_buffer_setup
(
gitno_socket
*
t
,
gitno_buffer
*
buf
,
char
*
data
,
size_t
len
);
void
gitno_buffer_setup_callback
(
gitno_socket
*
t
,
gitno_buffer
*
buf
,
char
*
data
,
size_t
len
,
int
(
*
recv
)(
gitno_buffer
*
buf
),
void
*
cb_data
);
int
gitno_recv
(
gitno_buffer
*
buf
);
...
...
tests/network/matchhost.c
0 → 100644
View file @
7bcced44
#include "clar_libgit2.h"
#include "netops.h"
void
test_network_matchhost__match
(
void
)
{
cl_git_pass
(
gitno__match_host
(
"*.example.org"
,
"www.example.org"
));
cl_git_pass
(
gitno__match_host
(
"*.foo.example.org"
,
"www.foo.example.org"
));
cl_git_fail
(
gitno__match_host
(
"*.foo.example.org"
,
"foo.example.org"
));
cl_git_fail
(
gitno__match_host
(
"*.foo.example.org"
,
"www.example.org"
));
cl_git_fail
(
gitno__match_host
(
"*.example.org"
,
"example.org"
));
cl_git_fail
(
gitno__match_host
(
"*.example.org"
,
"www.foo.example.org"
));
cl_git_fail
(
gitno__match_host
(
"*.example.org"
,
"blah.www.www.example.org"
));
}
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