System.setProperty() doesn't seem to take new keystore

Hi,
I've spent a few hours hunting around on google and can't seem to find a solution to my problem so hopefully someone here can help.
I've written a simulator for people at work that tests HTTPS connections using .jks keystores. Each time they make a request they pass in a few basic variables like IP Address and Port number etc but also the keystore file to use.
The first HTTPS request always works fine, assuming they've passed in the correct keystore, but if they then change the keystore and point to another server it fails even if using the correct keystore. Here is the part of the code where the keystore is set.
public HttpsURLConnection getHTTPSRequest(URL url) throws IOException {
          System.setProperty("javax.net.ssl.trustStore", ToolWindow.sHTTPSKeystoreLocation);
          System.setProperty("javax.net.ssl.keyStoreType", "JKS");
          System.out.println(ToolWindow.sHTTPSKeystoreLocation);
          System.out.println(System.getProperty("javax.net.ssl.trustStore"));
          HttpsURLConnection httpsURL = (HttpsURLConnection)url.openConnection();
          httpsURL.setHostnameVerifier(new HostnameVerifier()
               public boolean verify(String hostname, SSLSession session)
                    return true;
          httpsURL.setRequestProperty("Content-Type","text/xml");
          httpsURL.setDoOutput(true);
          httpsURL.setDoInput(true);
          httpsURL.setConnectTimeout(iConnectTimeout);
          httpsURL.setReadTimeout(iReadTimeout);
          return httpsURL;
     }The System.out.println output always shows the correct keystore that's being passed in but the following exception gets thrown:
nested exception is:
     javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I know the path and certificate are good because if I restart the application and put in the same values it works but each time I change the keystore it stops working. It seems like System.setProperty() isn't using the new keystore supplied when making the connection but then my System.out.println output would show that surely.
Any help would be appreciated.
Thanks.

Hi ejp,
Thanks for pointing me in the right direction. I eventually found a solution which I will share here in case anyone else has a similar problem. The reason why I couldn't put all private keys into a single keystore is that the tool I'm writing is for our Operations team to be able to test keystores that we give out to individual customers. From a security point of view it wouldn't be a good idea to give out every customers keystore to everyone else.
Here is how I did my implementation.
In my original class that creates the HttpsURLConnection only line changed as follows:
public HttpsURLConnection getHTTPSRequest(URL url, SSLSocketFactory sslSF) throws IOException { // pass in SSLSocketFactory
     HttpsURLConnection httpsURL = (HttpsURLConnection)url.openConnection();
     httpsURL.setSSLSocketFactory(sslSF); // set SSLSocketFactory
     httpsURL.setHostnameVerifier(new HostnameVerifier()
          public boolean verify(String hostname, SSLSession session)
               return true;
     httpsURL.setRequestProperty("Content-Type","text/xml");
     httpsURL.setDoOutput(true);
     httpsURL.setDoInput(true);
     httpsURL.setConnectTimeout(iConnectTimeout);
     httpsURL.setReadTimeout(iReadTimeoutDefault);
     return httpsURL;
}and here is the code I added to build the SSLSocketFactory...
KeyStore ks = KeyStore.getInstance("JKS"); // create new KeyStore object and pass in instance to constructor
ks.load(new FileInputStream(ToolWindow.getHTTPSKeystoreFile()), ToolWindow.getKeystorePassword()); // load keystore file and password in to KeyStore instance
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); // create a new KeyManagerFactory object and pass in instance to constructor
kmf.init(ks, ToolWindow.getKeystorePassword()); // initialize the KeyManagerFactory and pass in the KeyStore object and keystore password as variables
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); // create a new TrustManagerFactory object and pass in instance to constructor
tmf.init(ks); // initialize the TrustManagerFactory and pass in the KeyManagerFactory object as a variable
SSLContext c = SSLContext.getInstance("SSL"); // create a new SSLContext object and pass in instace to constructor
c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); // initialize SSLContext and pass in Trust/KeyManagerFactory as variables
SSLSocketFactory sf = c.getSocketFactory(); // create my SSLSocketFactory to be passed in to HttpsURLConnection
HttpsURLConnection urlc = getHTTPSRequest(url,sf); // create a HttpsURLConnection by calling my method listed at the top of this post and passing in the variables I have herby described.Hope this helps someone else who runs into the same problem as me!

Similar Messages

  • I have 3dparty software wirelessly with a cryptographic authentication system without my consent (seems to be new technology developed by stanford) obtaining ownership of my iPhone 4s software and controlling it with remote device to jail break. Now what?

    I have 3rd party software wirelessly injected and used on my iphone with a cryptographic authentication system without my consent (seems to be new technology developed by stanford and apple security is not updated for this technology) obtaining ownership of my iPhone 4s software and controlling it with remote device to jail breaking my phone, adding and removing software, changing settings all from a remotely controled device from different location (I have a Mac address I'd of this device to know for sure). Almost undetectable. When I look at the legal section of my phone it shows a list of all the unauthorized 3rd party software "as is" copyright encrypted on the phone.  This is the most basic way to legally steal software of any kind.  Because of this legalality 3rd party ownership have total control of certain software correlated with hardware use including visualization technology, etc.  most people luckily will never have this happen to them so it's unlikely many readers have not a clue of what I'm saying currently.  Either way, without needing to obtain specific warranty of any kind "as is" copyright control makes system restores not a solution because the source code is not directly encrypted on the actual hardware device only a copy right notice must appear on the specific device 3rd party software validation making it extremely difficult for me to take control of the situation. Apple claims their iOS technology prevents this type copyright obstruction from being possible, however, according to my phone a new form of technology was used developed by Tom wu of Stanford university called the STANFORD SRP AUTHENTICATION TECHNOLOGY which uses Some form of cryptographic authentication system and uses quote "secure remote password" which seems to suceed in hacking iOS apple technology apple claims is not possible to jailbreak an unstolen phone or without the owners consent As well as loading the device with 3rd party copyright Notices to make all of this legalized. My phone shows atleast 30 pages worth of legalized 3rd party copyright permissions! Yesterday my apple care provider labeled me a jailbreaker and refused to look at my legal documented proof which completely blew my mind because it voides my apple care contract I spent 100 on. This employee did not take all factors into consideration and made quick assumptions as well as verbally speaking to me as I'm an automatic criminal. I left the store yesterday with no payed insurance help on a problem I had no control over and couldn't prevent, leaving with voided contracts. This is an apple users worst nightmare and I have spent days researching all of this like i am some kind of lawyer only to be able to use my phone the way it should and spent alot of money on.  I can legally backup any claim I have just wrote above currently and have a large source of data collected to prove apple is wrong in voiding insurance support on this issue. The problem lies in apple avoiding and not wanting to believe their software can legally be obtained ot "hacked". Yet still labeled a jailbreaker basically.. What should I do????? Been to local apple store 3 times and rebooted my phone as well sprint service restore 4 times and spoke with reps twiice on the phone. Spoke with my phone provider who said apple has full control over these matters so they can't help me.  My case is according to apple "still open"...Anyone else heard of this or of Stanford's office of technology licensing? Maybe I need to buy a blackberry again or just use a landline so I can stop being my own lawyer and focus on other productive areas in life instead of this horrible mess. I shouldn't have to prove to apple I not a jailbreaker they should have to prove I'm one before voiding support I desperately need!!

    Mullaly75 wrote:
    I assume u guys don't understand what open source software is
    Yes, I think most of us do understand what open source software is. It sounds as if you don't. Here's some information:
    Open-source software (OSS) is computer software that is available in source code form: the source code and certain other rights normally reserved forcopyright holders are provided under an open-source license that permits users to study, change, improve and at times also to distribute the software.
    Open source software is very often developed in a public, collaborative manner. Open-source software is the most prominent example of open-sourcedevelopment and often compared to (technically defined) user-generated content or (legally defined) open content movements.
    from http://en.wikipedia.org/wiki/Open_source_software
    Yes, Tom Wu of Stanford wrote a paper on something called Secure Remote Access Protocol. It's a form of Asymetric Key Exchange and has nothing to do with hacking anything. It's actually intended to protect data.

  • TS1474 ive just bought a new ipod and used it on my gf's computer using my existing apple id. it doesn't seem to take across the songs correctly, even though i've permitted it for authorisation on this computer- any ideas please?

    Please can anyone help me with my problem as shwn in the title? thanks

    Try using the manual method of syncing. You can only sync music and vides from other than your one syncing computer if you use the manual method. The manual method is included here:
    iTunes: Syncing media content to iOS devices and iPod

  • It doesn't seem like my new macbook pro has a battery

    I got my new MacBook Pro 13-inch LED-backit widescreen notebook about a week ago. The first time i tried it, I plugged the Power Adapter in the whole time i used it. The next morning i tried using it, but this time i didn't have it plugged in. It wouldn't turn on. So, i plugged it in and then it worked fine. I searched for the problem and then i noticed that on the top right corner, the battery sign had an X on it. I clicked it and it said "No Batteries Available | Power Source: Power Adapter". i did a little experiment. i plugged off the Power Adapter during the middle of me using it and it completely shut down. I figured that it didn't come with a battery when i bought it. Is this normal and do i have to buy the battery seperately?

    Absolutely not normal - check one more thing:
    Go to the Apple in the menu bar and click on About this Mac, then on more info. Click on System Report. In the resulting window, click on Power and see what is listed there (hopefully the battery) - post the results here. If there is something wrong with the battery, call Apple - you have 90 day phone support (and a year hardware warranty) and/or book an appointment at your nearest Genius Bar.
    FWIW, the new laptops have batteries built in (not accessible by user).

  • When I click "configure" in Synch Contacts with Google, I enter my google ID and PW, but it doesn't seem to take.  I tried the same thing with Yahoo, and nothing happens.  What is the problem?

    This issue is similar to a question that was asked in Dec 2010, but was not answered, and has not been archived.
    I'm hoping someone might have an idea.
    OS: Vista
    iTunes:  10.3.1.55
    iPhone 4: 4.2.8
    Problem with iPhone contacts synchronization settings
    I am having problems with iPhone contacts synchronization settings in iTunes 10. I have: - iPhone 4 - OS 4.2.1 - Windows Vista PC When I view the device in iTunes and click on "Info" at the top of the screen, I see a box to "Synch contacts with"...in iTunes for Windows,by lindsacl,Dec 4, 2010

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).<br />
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]<br />
    <br />
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.<br />
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.<br />
    You have to close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")<br />
    See also http://kb.mozillazine.org/Java#Multiple_Java_Console_extensions

  • Authorisation doesn't seem to take

    Hello all, I am looking for some help with ADE. Each time I start up the program, it asks me to authorise the computer , which it reassures me is a one time process. Each time. Obviously something is not working correctly. I can't find anyone else discussing the same problem... no idea where to start to sort it out. Cheers, Jane

    Jane, in order to know what to do now, it would be nice to know what you
    did before.
    Did you go to the Adobe website, register and get an Adobe ID and password
    before you downloaded and installed ADE?  It's possible to download ADE and
    install it without registering first with Adobe, and when that happens, ADE
    may not install correctly.
    Did you change computers after you installed ADE - or change ID's?
    Are you running a Windows 7 PC?  It's security might not be set up to allow
    you to use ADE as intended.
    =============

  • URLConnection setRequestProperty doesn't seem to work

    G'day, I am trying to set a URLConnection property for proxy authentication. Here's a simple test I've created:
    import java.net.*;
    public class ProxyTest {
        public static void main(String[] args) {
            try {
                System.setProperty("http.proxyHost", "192.168.107.24");
                System.setProperty("http.proxyPort", "3128");
                URL url=new URL("http://google.com");
                URLConnection uc = url.openConnection ();
                uc.setRequestProperty( "Proxy-Authorization", "foobar");
                System.out.println("Proxy-Authorization is: " + uc.getRequestProperty("Proxy-Authorization"));
                uc.connect();
            } catch (Exception e) {
                e.printStackTrace();
    }This always gives my "Proxy-Authorization is null". I have tested this on java 1.6 and 1.5, on a linux system and a windows xp system. In my real app the url connection always gives me 407 unauthorized, I have used tcpdump to check just in case the Proxy-Authorization is being sent, but it isn't.
    I am probably missing something simple - can anyone see what it might be? Cheers.

    Try the below.
    package test;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    * @author asiri_godage
    public class Main {
    public static void main(String[] args) {
    System.out.println("HHHHH");
    String message;
    System.out.println(System.getProperty("proxySet"));
    System.getProperties().put( "proxySet", "true" );
    System.getProperties().put( "proxyHost", "proxy.server.com" );
    System.getProperties().put( "proxyPort", "8080" );
    String password = "UserName:LoginPassword";
    String encodedPassword = base64Encode( password );
    try{
    URL u = new URL("[http://www.rarlab.com/rar/wrar390.exe]");
    URLConnection uc = u.openConnection();
    {color:#000000}uc.setRequestProperty( "Proxy-Authorization", " Basic " + encodedPassword );{color}
    String contentType = uc.getContentType();
    int contentLength = uc.getContentLength();
    if (contentType.startsWith("text/") || contentLength == -1) {
    throw new IOException("This is not a binary file.");
    InputStream raw = uc.getInputStream();
    InputStream in = new BufferedInputStream(raw);
    byte[] data = new byte[contentLength];
    int bytesRead = 0;
    int offset = 0;
    while (offset < contentLength) {
    bytesRead = in.read(data, offset, data.length - offset);
    if (bytesRead == -1) {
    break;
    offset += bytesRead;
    in.close();
    if (offset != contentLength) {
    throw new IOException("Only read " + offset + " bytes; Expected " + contentLength + " bytes");
    String filename = "";
    filename = "C:" + u.getFile().substring(filename.lastIndexOf('/') + 1);
    FileOutputStream out = new FileOutputStream(filename);
    out.write(data);
    out.flush();
    out.close();
    }catch(Exception e){
    e.printStackTrace();
    private static String base64Encode(String password) {
    char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
    char [] data= password.toCharArray();
    char[] out = new char[((data.length + 2) / 3) * 4];
    // 3 bytes encode to 4 chars. Output is always an even
    // multiple of 4 characters.
    for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
    boolean quad = false;
    boolean triple = false;
    //convert to unsigned byte
    int val = (0xFF & (int) data);
    val <<= 8;
    if ((i + 1) < data.length) {
    val |= (0xFF & (int) data[i + 1]);
    triple = true;
    val <<= 8;
    if ((i + 2) < data.length) {
    val |= (0xFF & (int) data[i + 2]);
    quad = true;
    out[index + 3] = alphabet[(quad ? (val & 0x3F) : 64)];
    val >>= 6;
    out[index + 2] = alphabet[(triple ? (val & 0x3F) : 64)];
    val >>= 6;
    out[index + 1] = alphabet[val & 0x3F];
    val >>= 6;
    out[index + 0] = alphabet[val & 0x3F];
    String sout=new String(out);
    return sout;

  • I'm travelling and trying to back up my new iPhone to iCloud. I have sufficient storage, am connected to wifi and it's plugged into a power source and yet it doesn't seem to work. Can anyone suggest what I'm doing wrong?

    I'm travelling and trying to back up my new iPhone to iCloud. I have sufficient storage, am connected to wifi and it's plugged into a power source and yet it doesn't seem to work at all. I'm currently in India. Could that be the cause or can anyone suggest any reason why this wouldn't work?

    "gets stuck" - are there any error messages?
    If you get the error "Backup not successful" and you've tried deleting the last backup and trying to back up manually without luck, try the following test:   Go to...
    Settings>iCloud>Storage & Backup>manage Storage, tap your device name in the Backups section, then look under Backup options.  Turn off all apps from backup and then do a manual backup.  If that doesn't work, then this post will not help.  If the backup works, then go back to the app list and turn some on and try another backup.  If successful, keep repeating these steps.  If it fails at some point, then try to zero in on the one app that seems to make the backup fail.  (I had this problem and found one app failing, probably due to a corrupt data file.)
    This process will take time, but if a backup works with no app data being used but clearly fails with the original settings, then somewhere in the mix of apps is a "bad" one.

  • I  have a Mac Pro running OS X 10.8.2. Frequently the system fails detect a CD. Doesn't seem to make a difference if it contains music or is blank. I am unable to eject the CD. The system just doesn't recognize that a CD has been loaded.

    I  have a Mac Pro running OS X 10.8.2. Frequently the system fails detect a CD. Doesn't seem to make a difference if it contains music or is blank. I am unable to eject the CD. The system just doesn't recognize that a CD has been loaded.

    Step one, boot the new MBA into recovery mode (CMD+R on startup), launch Disk Utility, wipe the HD, and restore the OS. On reboot, use the Setup Assistant to do the migration. Details in Pondini's Setup New Mac guide.

  • New Vault - but doesn't seem to be updating

    Many thanks in advance for your attention.
    1. Have been having trouble with backups to my Vault, so after trying various things, I deleted it. And tried to start over with a new Vault.
    2. Before starting New Vault, I ran Aperture Repair Permissions and Aperture Repair Library as a precaution.
    3. Setup a new Vault. I deleted old Vault on an External Hard Drive to make room for this new Vault.
    4. Aperture Library is about 400GB - about 11, 000 Raw Managed images. Have my Aperture Library all by itself on a separate External Hard Drive. Have Vault on a second External Hard Drive (with 700GB of free space). Use Firewire 800 for connections.
    5. Started the backup to Vault so it would run overnight, but next morning, little seemed to have changed.
    Progress bar was still on - but seemed to be at about the same point (from 8 hours earlier). The word "Copying", at the bottom of the Aperture window, was still on - as it was 8 hours before.
    I can see where it might take longer than overnight, but would also expect some progress.
    If anyone knows what I may be doing wrong, let me know.
    Or - perhaps, when backing up 400GB of Raw files to a new Vault, it just is going to take a long time (days?)
    Macbook Pro 750GB   2.9 Intel Core i7

    This seems to be new in 10.8.2  From the article I linked to
    This issue happens because Apple has implemented some changes to the latest versions of OS X that result in different requirements for the system to determine if it can go to sleep, and one of these is a new dependence on applications to invoke a "power assertion" to keep the system from going to sleep.
    Unless a program invokes a power assertion, the system may go to sleep if left idling, even though the program is running.
    So perhaps some of the programs you are running that don;t seem to have this problem have been updated to include this. As I said for me Aperture does not do the vaults like it use to.
    So when you returned to the system and saw the vault hadn't finished did it continue once you cheked on it? If so I'd say it is this problem. If the vault operation stayed hung even after you got back on the machine then it is possible that you have a different problem.
    You can see for certain by either installing the app i linked to Caffeine or doing the steps listed in the article. Not sure if just changing the settings in Energy Saver will keep this from happening.
    regards

  • Search doesn't seem to be searching system files

    I'm trying out 10.7 for the first time (was using 10.6). I notice that in Finder, when I do shift-apple-F, to Find files by name, it doesn't seem to be searching system files like it did on 10.6.  Is this configurable - how do I make it search and show me EVERY file on the disk matching criteria?  I did a terminal command to show "hidden files" and now the Desktop has .localized and .SD_Store files (which I didn't want to see necessarily) but this hasn't seemed to help me find files below /Library and so on. What am I missing?

    By default, System files are not included in a Finder search.
    While in Finder, press Command-F. In that window, click the button that shows "Kind" in the criteria area of the window's header. In the menu that appears, select "Other...". In the new list that appears, select "System".
    Doing this will add "System" to the array selectable from the button initially labelled "Kind". You can add several criteria lines to the window's second sub-toolbar area to narrow or broaden the search. Once satisfied, you can save the criteria settings by clicking the "Save" button on the right end of the first sub-toolbar.

  • My New HP P2015d Printer ($400) doesn't seem to work with New Pavilion Slimeline 64 bit PC !

    My New HP P2015d Printer ($400) doesn't seem to work with New Pavilion Slimeline 64 bit PC ! I need some suggestions. Any help would be appreciated.
    The printer worked for a while and then out of the blue stopped working. We have a virus protection system, so I doubt it is a virus issue.
    *** We already tried to download the latest drivers and that doesn't seem to work ***

    Hi
    Are you trying to find your printer's email address? If so, check out details below
    http://h30434.www3.hp.com/t5/ePrint-Print-Apps-Mobile/how-do-I-find-my-printer-s-email-address/td-p/...
    Although I am an HP employee, I am speaking for myself and not for HP.
    Twitter: @Ciara_B_HP

  • My apple tv is registering on my tv - i can see it on my system info screen but the apple tv doesn't show up, as well my imac doesn't seem to let me share - so i don't know whats wrong, why my apple tv isn't working

    anybody able to help me with my setup for apple tv.  i've followed the directions in the guide and my tv doesn't seem to register in part.  it's weird because my tv system info identifies the apple tv but the screen never went black and it doesn't show anything, too, my imac doesn't seem to register the apple tv unit either

    I would try connecting it to another tv to see if it works there if it does
    then likely your tv can't handle the default resolution and you should lower it on the other tv
    if not then you should connect it by usb to the computer and use itunes to restore it's firmware

  • How do I open my itunes account on a new computer without having to buy all new songs? It doesn't seem fair to have to buy all the same songs a second time if they are already purchased by me and I just want them on my new computer!

    How do I open my itunes account on a new computer without having to buy all new songs? It doesn't seem fair to have to buy all the same songs a second time if they are already purchased by me and I just want them on my new computer!

    There's a few different ways. The following document is worth checking through:
    iTunes: How to move your music to a new computer

  • Hi,  I've just purchased and installed an upgrade from Lightroom 4 to 5.  It doesn't seem to handle raw files authored with a new Nikon D750 camera.  I spoke to the sales rep about this and he gave me a link to the 8.6 DNG converter page with instructions

    Hi,  I've just purchased and installed an upgrade from Lightroom 4 to 5.  It doesn't seem to handle raw files authored with a new Nikon D750 camera.  I spoke to the sales rep about this and he gave me a link to the 8.6 DNG converter page with instructions to download.  8.6 only works with Mac OS 10.7-10.9, according to the page.  I'm running Yosemite, Mac 10.10.  Please can you tell me my options?  Lightroom 4 worked beautifully with my older cameras' raw files so I would like to continue using the application.  What should I do?  How soon will Lightroom 5 be able to deal with raw files from a D750.  Many thanks, Adam.

    Until the next version of Lightroom is released, you need to use the DNG Converter version 8.7RC to convert your RAW photos to DNG and then import the DNGs into Lightroom.

Maybe you are looking for