@@ -220,21 +220,29 @@ public static File loadCert(String name) throws IOException {
220220 }
221221
222222 /**
223- * Returns a SSLSocketFactory which uses the certificate specified in certChainFile .
223+ * Deprecated, please use {@link #newSslSocketFactoryForCa(File)} instead .
224224 */
225+ @ Deprecated
225226 public static SSLSocketFactory getSslSocketFactoryForCertainCert (File certChainFile )
226227 throws Exception {
228+ return newSslSocketFactoryForCa (certChainFile );
229+ }
230+
231+ /**
232+ * Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate.
233+ */
234+ public static SSLSocketFactory newSslSocketFactoryForCa (File certChainFile ) throws Exception {
227235 KeyStore ks = KeyStore .getInstance ("JKS" );
228236 ks .load (null , null );
229237 CertificateFactory cf = CertificateFactory .getInstance ("X.509" );
230238 X509Certificate cert = (X509Certificate ) cf .generateCertificate (
231- new BufferedInputStream (new FileInputStream (certChainFile )));
239+ new BufferedInputStream (new FileInputStream (certChainFile )));
232240 X500Principal principal = cert .getSubjectX500Principal ();
233241 ks .setCertificateEntry (principal .getName ("RFC2253" ), cert );
234242
235243 // Set up trust manager factory to use our key store.
236244 TrustManagerFactory trustManagerFactory =
237- TrustManagerFactory .getInstance (TrustManagerFactory .getDefaultAlgorithm ());
245+ TrustManagerFactory .getInstance (TrustManagerFactory .getDefaultAlgorithm ());
238246 trustManagerFactory .init (ks );
239247 SSLContext context = SSLContext .getInstance ("TLS" );
240248 context .init (null , trustManagerFactory .getTrustManagers (), null );
0 commit comments