39
39
import com .cloudbees .jenkins .plugins .bitbucket .client .repository .UserRoleInRepository ;
40
40
import com .cloudbees .jenkins .plugins .bitbucket .filesystem .BitbucketSCMFile ;
41
41
import com .cloudbees .jenkins .plugins .bitbucket .impl .client .AbstractBitbucketApi ;
42
- import com .cloudbees .jenkins .plugins .bitbucket .impl .client .BitbucketTlsSocketStrategy ;
43
42
import com .cloudbees .jenkins .plugins .bitbucket .impl .credentials .BitbucketAccessTokenAuthenticator ;
44
43
import com .cloudbees .jenkins .plugins .bitbucket .impl .credentials .BitbucketClientCertificateAuthenticator ;
45
44
import com .cloudbees .jenkins .plugins .bitbucket .impl .credentials .BitbucketUsernamePasswordAuthenticator ;
75
74
import java .io .InputStream ;
76
75
import java .lang .reflect .ParameterizedType ;
77
76
import java .nio .charset .StandardCharsets ;
77
+ import java .nio .file .Paths ;
78
78
import java .util .ArrayList ;
79
79
import java .util .Arrays ;
80
80
import java .util .Collections ;
88
88
import jenkins .scm .api .SCMFile ;
89
89
import jenkins .scm .api .SCMFile .Type ;
90
90
import jenkins .scm .impl .avatars .AvatarImage ;
91
+ import nl .altindag .ssl .SSLFactory ;
92
+ import nl .altindag .ssl .SSLFactory .Builder ;
91
93
import org .apache .commons .codec .digest .DigestUtils ;
92
94
import org .apache .commons .io .IOUtils ;
93
95
import org .apache .commons .lang3 .StringUtils ;
94
96
import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
97
+ import org .apache .hc .client5 .http .impl .classic .HttpClientBuilder ;
95
98
import org .apache .hc .client5 .http .io .HttpClientConnectionManager ;
99
+ import org .apache .hc .client5 .http .ssl .DefaultClientTlsStrategy ;
96
100
import org .apache .hc .core5 .http .HttpHost ;
97
101
import org .apache .hc .core5 .http .HttpStatus ;
98
102
import org .apache .hc .core5 .http .message .BasicNameValuePair ;
@@ -140,10 +144,24 @@ public class BitbucketServerAPIClient extends AbstractBitbucketApi implements Bi
140
144
private static final String API_MIRRORS_PATH = "/rest/mirroring/1.0/mirrorServers" ;
141
145
private static final Integer DEFAULT_PAGE_LIMIT = 200 ;
142
146
147
+ private static Builder sslFactoryBuilder () {
148
+ Builder builder = SSLFactory .builder ()
149
+ .withSystemTrustMaterial ()
150
+ .withDefaultTrustMaterial ()
151
+ .withTrustMaterial (Paths .get ("D:\\ Download\\ JENKINS-75676\\ jenkins\\ trustStore.jks" ), "JENKINS-75676" .toCharArray ())
152
+ .withDummyIdentityMaterial ()
153
+ .withInflatableIdentityMaterial ();
154
+ if (System .getProperty ("javax.net.ssl.trustStore" ) != null ) {
155
+ builder .withSystemPropertyDerivedTrustMaterial ();
156
+ }
157
+ return builder ;
158
+ }
159
+
160
+ private static final SSLFactory sslFactory = sslFactoryBuilder ().build ();
143
161
private static final HttpClientConnectionManager connectionManager = connectionManagerBuilder ()
144
- .setMaxConnPerRoute (20 )
145
- .setMaxConnTotal (40 /* should be 20 * number of server instances */ )
146
- .setTlsSocketStrategy (new BitbucketTlsSocketStrategy ( ))
162
+ .setMaxConnPerRoute (1 ) // FIXME restore to 20
163
+ .setMaxConnTotal (1 /* should be 20 * number of server instances */ ) // FIXME restore to 40
164
+ .setTlsSocketStrategy (new DefaultClientTlsStrategy ( sslFactory . getSslContext () ))
147
165
.build ();
148
166
149
167
/**
@@ -162,6 +180,7 @@ public class BitbucketServerAPIClient extends AbstractBitbucketApi implements Bi
162
180
private final BitbucketServerWebhookImplementation webhookImplementation ;
163
181
private final CloseableHttpClient client ;
164
182
183
+
165
184
public BitbucketServerAPIClient (@ NonNull String baseURL , @ NonNull String owner , @ CheckForNull String repositoryName ,
166
185
@ CheckForNull BitbucketAuthenticator authenticator , boolean userCentric ) {
167
186
this (baseURL , owner , repositoryName , authenticator , userCentric , BitbucketServerEndpoint .findWebhookImplementation (baseURL ));
@@ -182,6 +201,14 @@ public BitbucketServerAPIClient(@NonNull String baseURL, @NonNull String owner,
182
201
this .client = setupClientBuilder ().build ();
183
202
}
184
203
204
+ @ Override
205
+ protected HttpClientBuilder setupClientBuilder () {
206
+ if (getAuthenticator () instanceof BitbucketClientCertificateAuthenticator certificateAuthenticator ) {
207
+ certificateAuthenticator .configureContext (sslFactory , getHost ());
208
+ }
209
+ return super .setupClientBuilder ();
210
+ }
211
+
185
212
@ Override
186
213
protected boolean isSupportedAuthenticator (@ CheckForNull BitbucketAuthenticator authenticator ) {
187
214
return authenticator == null
0 commit comments