Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:16:05+00:00 2026-05-28T04:16:05+00:00

The basic components of my question are (context follows code snippet) Is the following

  • 0

The basic components of my question are (context follows code snippet)

  1. Is the following code a valid alternative to setting the default Java keystore via the -Djavax.net.ssl.keystore?
  2. What impact, other than changing the default key and trust managers, might this code have on the behavior of SSL within the affected JVM
  3. Is there a better alternative to setting the default trust/key stores, at run-time, from a resource?

    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(testService.class.getClassLoader().getResourceAsStream("resources/.keystore"), "changeit".toCharArray());
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(ks, "changeit".toCharArray());
    SSLContext ctx = SSLContext.getInstance("TLS");
    ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    SSLContext.setDefault(ctx); 
    

The context surrounding this question is as follows. I am currently developing a CXF client for a web service with mutual certificate authentication. For various reasons, adding the client certificate and key to the default keystore is not a desirable option. Ideally, I was looking for a way include a keystore as a resource file in the JAR, and set it as the default at run-time, as the need arose. I also wanted to avoid configuring each client and/or connection on a per-object basis, and also support the operation of things such as JaxWsDynamicClientFactory (mostly for the sake of “completeness”).

I scoured the internet and SO for relevant material and found these (one, two) related questions, but none of the solutions offered were exactly what I was looking for (although I did use them as a springboard to develop the code above).

Now, I realize that other solutions could be made to work, but I was/am specifically looking for a solution that would meet all of these requirements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:16:05+00:00Added an answer on May 28, 2026 at 4:16 am

    Your code will use the same keystore (loaded from the classloader) as the default key store and the default trust store. That’s effectively equivalent to setting both -Djavax.net.ssl.keystore* and -Djavax.net.ssl.truststore* with the same value.

    This is fine if that’s what you want to do. (You may want to close the InputStream once you’ve loaded the keystore, though.)

    This will affect the entire JVM, and everything that uses SSLContext.getDefault(), in particular everything that relies on the default SSLSocketFactory (URLConnection and so on).

    Since this will be your default trust store, the default trusted CA certificates from the major CAs won’t be in your trust store unless you’ve also explicitly imported them into the copy you load from the classloader.

    Presumably, you won’t have a large number of new CA (or self-signed) certificates to trust. It might be more convenient to keep the keystore and truststore separated, since your truststore might be common to most of your clients, and it would usually just be a one-off configuration step at the beginning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic question about MVC web applications in Java. Since the
I have a basic layout where different components can be selected using a tree
Basic question : How to I create a bidirectional one-to-many map in Fluent NHibernate?
Basic question: How do I load an Excel template for use with POI and
Basic doubt...If QTP generates vbscript code as we record actions, can't we directly write
Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
Basic question - is it possible to access the current Page from a static
Basic array question: $string = The quick brown cat; $check1 = apple; $check2 =
I have a question that might seem basic but I just cannot figure out
Basic question: Including a page, that contains a component with component id, multiple times

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.