简体   繁体   中英

How to write a generic java client handling both 1-way and 2-way ssl?

Here is a sample code I am referring to. https://sites.google.com/site/ssljavaguide/example-code/2-way-ssl

Can I not set the keystore-related properties and wait for some exception to be thrown and then depending upon the occurrence of exception decide whether it is a 1-way or 2-way ssl connection?

Apologies if the question seems stupid.

It's up to the server to request a client certificate (the client cannot send it if it's not requested).

Your client keystore will only be used if the server makes such a request. Setting a keystore when no client certificate is requested is not a problem: it just won't be used. The side effect is that the client will send a suitable cert whenever it's requested. If you need a bit more control, you'll need a custom KeyManager .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM