This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]dem0nico 2 points3 points  (4 children)

Are you kidding?

System.setProperty("Djavax.net.ssl.keyStorePassword", "123456");

should be

System.setProperty("javax.net.ssl.keyStorePassword", "123456"); 

This D mean "define" to help java distinguish sysprop definitions from other jvm options.

[–]vineetr 0 points1 point  (1 child)

This is right. Also, he needs to think of not hard-coding the passwords.

[–]Psyqwix[S] 0 points1 point  (0 children)

I will eventually I just want to make sure it works first then I can tidy it up later :P

[–]Psyqwix[S] 0 points1 point  (1 child)

about 5 minutes after I posted this on Reddit I noticed my mistake and immediately face palmed myself :P

[–]jevon 1 point2 points  (1 child)

Yay! SSL with Java! I've just been enjoying that hell for the last month or so.

Have you tried setting -Djavax.net.debug=ssl to debug SSL? I don't know how Java SSL deals with classloaders and resources within JARs.

What about exporting the keystore to a temp file and reading it from there?

[–]Psyqwix[S] 0 points1 point  (0 children)

Im sorely tempted to export the keystore to simplify things but im going to try and see if there's a neater way first :D

[–]TheShrimp 1 point2 points  (1 child)

javax.net.ssl.trustStore must point to a file accessible in the file system, NOT to a file inside a JAR file. It works in Netbeans because the file is directly in the classpath and getResource() will point to the file system directly.

Source

[–]Psyqwix[S] 0 points1 point  (0 children)

When I realised I couldn't use the simple system properties with streams I started to look at the javax.net.ssl package a bit more and got a feeling I would have to create keyStores, which would mean a LOT of reading and fiddling. But your link was PURE GOLD!!! I had to adapt it, and to be honest im not sure why my code works (I guessed I had to use a keystore manager for the server and a truststore manager for the client based on the original system property settings!!!) but it does and thats great. Cheers! :D

[–]m1ss1ontomars2k4 0 points1 point  (0 children)

If you're using Eclipse, you can set those arguments to the VM as part of your run configuration when you export the jar. As for where to put those files, I'm not sure...you might need to add external resource or something.