@@ -23,7 +23,6 @@ public abstract class HttpRequestor : IDisposable
2323
2424 private readonly ProductInfoHeaderValue userAgentHeader ;
2525
26- private HttpClient client ;
2726 private readonly GitAuthentication authentication ;
2827
2928 private readonly Lazy < X509Store > store = new Lazy < X509Store > ( ( ) =>
@@ -33,6 +32,8 @@ public abstract class HttpRequestor : IDisposable
3332 return s ;
3433 } ) ;
3534
35+ private HttpClient client ;
36+
3637 static HttpRequestor ( )
3738 {
3839 ServicePointManager . SecurityProtocol = ServicePointManager . SecurityProtocol | SecurityProtocolType . Tls12 ;
@@ -63,9 +64,10 @@ protected HttpRequestor(ITracer tracer, RetryConfig retryConfig, Enlistment enli
6364 string certificatePassword = null ;
6465 if ( enlistment . GitSslSettings . SslCertPasswordProtected )
6566 {
66- certificatePassword = LoadCertificatePassword ( enlistment . GitSslSettings . SslCertificate , enlistment . CreateGitProcess ( ) ) ;
67+ certificatePassword = this . LoadCertificatePassword ( enlistment . GitSslSettings . SslCertificate , enlistment . CreateGitProcess ( ) ) ;
6768 }
68- var cert = LoadCertificate ( enlistment . GitSslSettings . SslCertificate , certificatePassword ) ;
69+
70+ var cert = this . LoadCertificate ( enlistment . GitSslSettings . SslCertificate , certificatePassword ) ;
6971 if ( cert != null )
7072 {
7173 httpClientHandler . ClientCertificates . Add ( cert ) ;
@@ -80,38 +82,6 @@ protected HttpRequestor(ITracer tracer, RetryConfig retryConfig, Enlistment enli
8082 this . userAgentHeader = new ProductInfoHeaderValue ( ProcessHelper . GetEntryClassName ( ) , ProcessHelper . GetCurrentProcessVersion ( ) ) ;
8183 }
8284
83- private string LoadCertificatePassword ( string certId , GitProcess git )
84- {
85- if ( git . TryGetCertificatePassword ( this . Tracer , certId , out var password , out var error ) )
86- {
87- return password ;
88- }
89-
90- return null ;
91- }
92-
93- private X509Certificate2 LoadCertificate ( string certId , string certificatePassword )
94- {
95- if ( File . Exists ( certId ) )
96- {
97- return new X509Certificate2 ( certId , certificatePassword ) ;
98- }
99- #if DEBUG
100- // Allow invalid (self-signed) client certificates while debugging
101- var onlyValidCertificates = false ;
102- #else
103- var onlyValidCertificates = true ;
104- #endif
105- var findResults = store . Value . Certificates . Find ( X509FindType . FindBySubjectName , certId , onlyValidCertificates ) ;
106- if ( findResults ? . Count > 0 )
107- {
108- return findResults [ 0 ] ;
109- }
110-
111- this . Tracer . RelatedError ( "Certificate {0} not found" , certId ) ;
112- return null ;
113- }
114-
11585 public RetryConfig RetryConfig { get ; }
11686
11787 protected ITracer Tracer { get ; }
@@ -129,9 +99,9 @@ public void Dispose()
12999 this . client = null ;
130100 }
131101
132- if ( store . IsValueCreated )
102+ if ( this . store . IsValueCreated )
133103 {
134- store . Value . Close ( ) ;
104+ this . store . Value . Close ( ) ;
135105 }
136106 }
137107
@@ -157,6 +127,7 @@ protected GitEndPointResponseData SendRequest(
157127 }
158128
159129 HttpRequestMessage request = new HttpRequestMessage ( httpMethod , requestUri ) ;
130+
160131 // By default, VSTS auth failures result in redirects to SPS to reauthenticate.
161132 // To provide more consistent behavior when using the GCM, have them send us 401s instead
162133 request . Headers . Add ( "X-TFS-FedAuthRedirect" , "Suppress" ) ;
@@ -311,8 +282,8 @@ protected GitEndPointResponseData SendRequest(
311282 }
312283
313284 return gitEndPointResponseData ;
314- }
315-
285+ }
286+
316287 private static bool ShouldRetry ( HttpStatusCode statusCode )
317288 {
318289 // Retry timeout, Unauthorized, and 5xx errors
@@ -337,5 +308,37 @@ private static string GetSingleHeaderOrEmpty(HttpHeaders headers, string headerN
337308
338309 return string . Empty ;
339310 }
311+
312+ private string LoadCertificatePassword ( string certId , GitProcess git )
313+ {
314+ if ( git . TryGetCertificatePassword ( this . Tracer , certId , out var password , out var error ) )
315+ {
316+ return password ;
317+ }
318+
319+ return null ;
320+ }
321+
322+ private X509Certificate2 LoadCertificate ( string certId , string certificatePassword )
323+ {
324+ if ( File . Exists ( certId ) )
325+ {
326+ return new X509Certificate2 ( certId , certificatePassword ) ;
327+ }
328+ #if DEBUG
329+ // Allow invalid (self-signed) client certificates while debugging
330+ var onlyValidCertificates = false ;
331+ #else
332+ var onlyValidCertificates = true ;
333+ #endif
334+ var findResults = this . store . Value . Certificates . Find ( X509FindType . FindBySubjectName , certId , onlyValidCertificates ) ;
335+ if ( findResults ? . Count > 0 )
336+ {
337+ return findResults [ 0 ] ;
338+ }
339+
340+ this . Tracer . RelatedError ( "Certificate {0} not found" , certId ) ;
341+ return null ;
342+ }
340343 }
341344}
0 commit comments