ssl - How to load multiple certificate files in Java? -


i'm trying create ssl connection certificates loaded 2 files (.p12 , .p7b).
have tried following code load .p12 file

char []passwkey = "1234567".tochararray();         keystore ts = keystore.getinstance("pkcs12");         ts.load(new fileinputstream("/home/user/desktop/file.p12"), passwkey);         keymanagerfactory tmf = keymanagerfactory.getinstance("sunx509");         tmf.init(ts,passwkey);         sslcontext sslcontext = sslcontext.getinstance("tls");         sslcontext.init(tmf.getkeymanagers(), null, null);         sslsocketfactory factory =sslcontext.getsocketfactory();         httpsurlconnection.setdefaultsslsocketfactory(factory);         sslsocket socket = (sslsocket) factory.createsocket("www.host.com", 8883); // create serversocket         string[] suites = socket.getsupportedciphersuites();         socket.setenabledciphersuites(suites);         socket.starthandshake(); 

but receive exception:

javax.net.ssl.sslhandshakeexception: sun.security.validator.validatorexception: pkix path building failed: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target

i believe must create .jks file form .p12 , .p7b files (that contains whole ca chain), i'm noob @ , have no idea how that. examples found based on single file/certificate.

update:

i used certification files create single keystore (i believe needed .p12 file) no luck. accessed site directly , exported certificate .pem , added keystore. in debug information receive "serverhello" @ end, still

handling exception: javax.net.ssl.sslhandshakeexception: received fatal alert: handshake_failure 

i tried several solutions, ex. java client certificates on https/ssl or getting javax.net.ssl.sslhandshakeexception: received fatal alert: handshake_failure error certificate .p12 file received , 1 exported browser none of them work...

update 2:

i tried this: https://stackoverflow.com/a/11908693/1215791 , managed serverhellodone (and found trusted certificate ...).

but, i'm trying login soap request , this:

com.sun.xml.internal.messaging.saaj.soap.messageimpl identifycontenttype severe: saaj0537: invalid content-type. error message instead of soap message exception in thread "main" com.sun.xml.internal.messaging.saaj.soapexceptionimpl: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: invalid content-type:text/html. error message instead of soap response?     @ com.sun.xml.internal.messaging.saaj.client.p2p.httpsoapconnection.call(httpsoapconnection.java:148)     @ soapt.login(soapt.java:241)     @ soapt.main(soapt.java:75) 

i believe not problem attached certificates, error when creating soap request or error (html) server.

try not-yet-commons-ssl.

very easy use ssl-library. create sslclient , add trust material

example webpage:

client example:  sslclient client = new sslclient();  // let's trust usual "cacerts" come java.  plus, let's trust self-signed cert // know of.  have additional certs trust inside java keystore file. client.addtrustmaterial( trustmaterial.default ); client.addtrustmaterial( new trustmaterial( "/path/to/self-signed.pem" ) ); client.addtrustmaterial( new keymaterial( "/path/to/keystore.jks", "changeit".tochararray() ) );  // different, let's allow expired certificates (not recommended). client.setcheckhostname( true );  // default setting "true" sslclient client.setcheckexpiry( false );   // default setting "true" sslclient client.setcheckcrl( true );       // default setting "true" sslclient  // let's load client certificate (max: 1 per sslclient instance). client.setkeymaterial( new keymaterial( "/path/to/client.pfx", "secret".tochararray() ) ); sslsocket s = (sslsocket) client.createsocket( "www.cucbc.com", 443 ); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -