I have a Jetty server where I'm opening opening more than one SSL ports and setting the SslContextFactory where I am pointing it to my custom keystore in which I have certificates for all the SSL ports.
public static SslContextFactory getCustomSSLContextFactory() throws IOException {
KeyStoreInfo keyStoreInfo = KeyStoreInfo.getInstance();
SslContextFactory sslContextFactory = new SslContextFactory(mycustomkeystorepath);
sslContextFactory.setKeyStorePassword(mykeystorepassword);
sslContextFactory.setKeyStoreType(keystoretype);
sslContextFactory.setTrustStorePath(defaultcatruststore);
sslContextFactory.setTrustStorePassword(password);
sslContextFactory.setTrustStoreType(truststoretype);
sslContextFactory.setNeedClientAuth(true);
return sslContextFactory;
}
This SslContextFactory I'm setting in ServerConnector SslConnectionFactory. And I have multiple ServerConnectors and all have the same SslContextFactory.
My question is as I have multiple PKI-cert and private key in custom key store. How SslConnectionFactory will know which PKI-cert and private key belongs to which SSL port?
SSL certificate is related to some domain/hostname+port of a server. So the domain/hostname+port data is present in the certificate. When you would make a connection, the SslConnectionFactory will look if a certificate is present for the particular domain/hostname+port and if it is present it will use that certificate and the private key related to the same for doing handshake.
Remember,by default SSL certificates for domain name know that the port is 443. Similarly, it would work for different ports.