javax.net.ssl.SSLHandshakeException: PKIX path building failed: : unable to find valid certification path to requested target

I’m working on a mini Java XMPP project using Vysper server and Smack client, I have two modules one for the server and the other for the client similar to a microservice architecture but a pure Java project with no Springboot. I have my configuration setup on the server side and running but when I try to establish a connection on the Client side I get the below exception

Exception in thread "main" java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I have generated an SSL/TSL certificate on my Keystore using shell scripting and imported the same on the client module but the exception persists. Below is my code

XmppServerConfig-Server Module

public class XmppServerConfig {

    private final StorageRegistry storageRegistry;
    private static final Logger log = LoggerFactory.getLogger(XmppServerConfig.class);

    public XmppServerConfig(StorageRegistry storageRegistry) {
        this.storageRegistry = storageRegistry;
    }

    public void config() throws Exception {
        WebSocketEndpoint wsEndpoint = new WebSocketEndpoint();
        wsEndpoint.setContextPath("/xmpp");
        wsEndpoint.setPort(9000);
        XMPPServer server = new XMPPServer("domain.com");
        TCPEndpoint endpoint = new TCPEndpoint();
        endpoint.setPort(7000);
        server.addEndpoint(wsEndpoint);
        server.addEndpoint(endpoint);
        server.setStorageProviderRegistry(storageRegistry.get());
        server.setTLSCertificateInfo(new File("part-to/tls-cert/cleaned_myserver.p12"), "password");

        try {
            server.start();
            System.out.println("server is running...");
            log.info("server is running... on port {}", server.getServerRuntimeContext());
        } catch (Exception e) {
            System.out.println("error occurred while starting server" + e.getLocalizedMessage());
            throw  new RuntimeException( "error occurred while starting server", e);
        }
    }
}

TCPConnectionConfiguration – Client Module

public class TCPConnectionConfiguration {

    public ModularXmppClientToServerConnectionConfiguration connectXmppServer() {
        try {
            System.out.println("ConnectingXMPP server connected.");
            return ModularXmppClientToServerConnectionConfiguration.builder()
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.required)
                    .setPort(7000)
                    .setHost("127.0.0.1")
                    .setSendPresence(true)
                    .setResource("Smack")
                    .setXmppDomain("domain.com")
                    .setCustomSSLContext(SSLConfig.getSSLContext())
                    .build();
        } catch (Exception e) {
            String causeMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
            System.out.println("Unable to connect to XMPP server: " + causeMessage);
            throw new RuntimeException("Unable to connect to XMPP server", e);
        }
    }
}

SSLContextConfig-Client Module

public class SSLContextConfig {
    public static SSLContext getSSLContext() throws Exception {
            String keystorePath = "part-to/tls-cert/client_keystore.p12";
            String keystorePassword = "aspace@1234";
            String truststorePath = "part-to/tls-cert/client_keystore.p12";
            String truststorePassword = "aspace@1234";

            KeyStore keystore = KeyStore.getInstance("PKCS12");
            keystore.load(new FileInputStream(keystorePath), keystorePassword.toCharArray());

            KeyStore truststore = KeyStore.getInstance("PKCS12");
            truststore.load(new FileInputStream(truststorePath), truststorePassword.toCharArray());

            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(truststore);

            SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
            sslContext.init(null, trustManagerFactory.getTrustManagers(), null);

            return sslContext;
        }
}

What am I missing and how can this bug be resolved?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật