Java
Java
Enumerate Server-Advertised Acceptable Client CAs
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetSslAcceptableClientCaDn, which returns a certificate-authority distinguished name advertised by a TLS server when it requests a client certificate.
Background. Valid indexes range from 0 through
NumSslAcceptableClientCAs minus one. A client can use these names to select an appropriate client certificate.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkSocket socket = new CkSocket();
// Connect to the server using TLS.
boolean bTls = true;
int maxWaitMs = 5000;
success = socket.Connect("example.com",5000,bTls,maxWaitMs);
if (success == false) {
System.out.println(socket.lastErrorText());
return;
}
// After connecting to a server that requests a client certificate, enumerate the certificate-
// authority distinguished names the server advertised as acceptable.
int numCAs = socket.get_NumSslAcceptableClientCAs();
int i;
for (i = 0; i <= numCAs - 1; i++) {
String caDn = socket.getSslAcceptableClientCaDn(i);
if (socket.get_LastMethodSuccess() == false) {
System.out.println(socket.lastErrorText());
return;
}
System.out.println(caDn);
}
}
}