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
86a1cdd3
Unverified
Commit
86a1cdd3
authored
Dec 13, 2020
by
Edward Thomson
Committed by
GitHub
Dec 13, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5384 from ianhattendorf/fix/winhttp-client-cert
winhttp: support optional client cert
parents
21fe183e
6a10b802
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
26 deletions
+49
-26
src/transports/winhttp.c
+49
-26
No files found.
src/transports/winhttp.c
View file @
86a1cdd3
...
...
@@ -874,42 +874,65 @@ static int do_send_request(winhttp_stream *s, size_t len, bool chunked)
static
int
send_request
(
winhttp_stream
*
s
,
size_t
len
,
bool
chunked
)
{
int
request_failed
=
0
,
cert_valid
=
1
,
error
=
0
;
DWORD
ignore_flags
;
int
request_failed
=
1
,
error
,
attempts
=
0
;
DWORD
ignore_flags
,
send_request_error
;
git_error_clear
();
if
((
error
=
do_send_request
(
s
,
len
,
chunked
))
<
0
)
{
if
(
GetLastError
()
!=
ERROR_WINHTTP_SECURE_FAILURE
)
{
git_error_set
(
GIT_ERROR_OS
,
"failed to send request"
);
return
-
1
;
while
(
request_failed
&&
attempts
++
<
3
)
{
int
cert_valid
=
1
;
int
client_cert_requested
=
0
;
request_failed
=
0
;
if
((
error
=
do_send_request
(
s
,
len
,
chunked
))
<
0
)
{
send_request_error
=
GetLastError
();
request_failed
=
1
;
switch
(
send_request_error
)
{
case
ERROR_WINHTTP_SECURE_FAILURE
:
cert_valid
=
0
;
break
;
case
ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED
:
client_cert_requested
=
1
;
break
;
default:
git_error_set
(
GIT_ERROR_OS
,
"failed to send request"
);
return
-
1
;
}
}
request_failed
=
1
;
cert_valid
=
0
;
}
if
(
!
request_failed
||
!
cert_valid
)
{
git_error_clear
();
if
((
error
=
certificate_check
(
s
,
cert_valid
))
<
0
)
{
if
(
!
git_error_last
())
git_error_set
(
GIT_ERROR_OS
,
"user cancelled certificate check"
);
git_error_clear
();
if
((
error
=
certificate_check
(
s
,
cert_valid
))
<
0
)
{
if
(
!
git_error_last
())
git_error_set
(
GIT_ERROR_OS
,
"user cancelled certificate check"
);
return
error
;
}
return
error
;
}
}
/* if neither the request nor the certificate check returned errors, we're done */
if
(
!
request_failed
)
return
0
;
/* if neither the request nor the certificate check returned errors, we're done */
if
(
!
request_failed
)
return
0
;
ignore_flags
=
no_check_cert_flags
;
if
(
!
cert_valid
)
{
ignore_flags
=
no_check_cert_flags
;
if
(
!
WinHttpSetOption
(
s
->
request
,
WINHTTP_OPTION_SECURITY_FLAGS
,
&
ignore_flags
,
sizeof
(
ignore_flags
)))
{
git_error_set
(
GIT_ERROR_OS
,
"failed to set security options"
);
return
-
1
;
}
}
if
(
!
WinHttpSetOption
(
s
->
request
,
WINHTTP_OPTION_SECURITY_FLAGS
,
&
ignore_flags
,
sizeof
(
ignore_flags
)))
{
git_error_set
(
GIT_ERROR_OS
,
"failed to set security options"
);
return
-
1
;
if
(
client_cert_requested
)
{
/*
* Client certificates are not supported, explicitly tell the server that
* (it's possible a client certificate was requested but is not required)
*/
if
(
!
WinHttpSetOption
(
s
->
request
,
WINHTTP_OPTION_CLIENT_CERT_CONTEXT
,
WINHTTP_NO_CLIENT_CERT_CONTEXT
,
0
))
{
git_error_set
(
GIT_ERROR_OS
,
"failed to set client cert context"
);
return
-
1
;
}
}
}
if
((
error
=
do_send_request
(
s
,
len
,
chunked
))
<
0
)
git_error_set
(
GIT_ERROR_OS
,
"failed to send request with unchecked certificate"
);
return
error
;
}
...
...
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