Close Menu
InfovistarInfovistar
  • AI & ML
  • Cybersecurity
  • Money
    • Personal Finance
  • Insights
    • Tech News
    • Tech Tips
    • Startup
    • Web Development
    • AWS and Cloud
    • Technology
  • Courses
    • Machine Learning
      • Python Tutorial
      • TensorFlow Tutorial
      • OpenCV
    • DSA
      • Data Structures
    • Web Development
      • PHP Tutorial
      • CodeIgniter Tutorial
      • CodeIgniter 4 Tutorial
      • CodeIgniter 4 AJAX
      • JavaScript
    • Mobile App Development
      • Android Tutorial
  • Tools
    • Beautifier
      • HTML Beautifier
      • JavaScript Beautifier
      • CSS Beautifier
    • Online Compilers
      • Python Compiler
      • Java Compiler
      • JavaScript Editor
      • PHP Compiler
      • C++ Compiler
      • C Compiler
    • Image Optimization
      • Image Compressor
      • JPEG to PNG
      • PNG to JPEG
      • WebP to PNG
Trending News
US Outage Wave_ Microsoft, FAA, Banks, Apple-compressed

US Outages Explained: What Happened to Microsoft, FAA and Banks

November 18, 2026
Microsoft 365 Outage_ Outlook, Teams and Copilot Down. What We Know

Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know

November 13, 2026
Diwali online shopping scams warning for shoppers in India

Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe

November 7, 2026
Facebook X (Twitter) Instagram
Friday, November 20
Trending
  • US Outages Explained: What Happened to Microsoft, FAA and Banks
  • Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know
  • Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe
  • 10 Best DDoS Protection Services for 2027
  • 12 Best Web Application Firewalls (WAF) for 2027
  • Best Ethical Hacking Tools in 2027: Free & Paid Picks
  • Software supply chain attacks 2026: Timeline and developer checklist
  • Binance Hack: $6.3 Billion Drained in the Largest Crypto Theft Ever. What We Know So Far
Facebook X (Twitter) Instagram Pinterest LinkedIn WhatsApp
InfovistarInfovistar
  • AI & ML
  • Cybersecurity
  • Money
    • Personal Finance
  • Insights
    • Tech News
    • Tech Tips
    • Startup
    • Web Development
    • AWS and Cloud
    • Technology
  • Courses
    • Machine Learning
      • Python Tutorial
      • TensorFlow Tutorial
      • OpenCV
    • DSA
      • Data Structures
    • Web Development
      • PHP Tutorial
      • CodeIgniter Tutorial
      • CodeIgniter 4 Tutorial
      • CodeIgniter 4 AJAX
      • JavaScript
    • Mobile App Development
      • Android Tutorial
  • Tools
    • Beautifier
      • HTML Beautifier
      • JavaScript Beautifier
      • CSS Beautifier
    • Online Compilers
      • Python Compiler
      • Java Compiler
      • JavaScript Editor
      • PHP Compiler
      • C++ Compiler
      • C Compiler
    • Image Optimization
      • Image Compressor
      • JPEG to PNG
      • PNG to JPEG
      • WebP to PNG
InfovistarInfovistar
Home » Retrofit – SSLHandshakeException Android
Android

Retrofit – SSLHandshakeException Android

InfovistarBy InfovistarMay 2, 2022Updated:January 17, 20253 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Retrofit – SSLHandshakeException Android
Share
Facebook Twitter LinkedIn Pinterest Email

Recently, I worked on a remote-networking implementation for an Android eCommerce application, and everything went smoothly. I used the Retrofit networking library and the base URL was http://api.infovistar.in without SSL (an HTTP scheme).

As soon as we finished the MVP, we acquired a domain name and enabled SSL on the server. Consequently, the base URL scheme became HTTPS (example: https://api.infovistar.in).

The change to a secured URL in the app caused chaos in the entire app. All the endpoints were not connecting to the server successfully. There was a problem with the network handshake between the client and server.

HTTP FAILED: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Solution 1:

In doing some research, I found out the Android system didn’t trust the server certificate. There are several possible reasons for this:

  • The Certificate Authority (CA) that issued the server certificate was unknown.
  • The server certificate wasn’t signed by a CA but was self-signed.
  • The server configuration is missing an intermediate CA.

In my case, this issue occurred because the server certificate was self-signed.

The Android documentation describes a simple way to set it up to trust self-signed certificates, which I will outline in three steps.

Step 1

Add the .crt or .pem file to the raw folder.

The digital certificate will be obtained from the server or you can request it from the backend engineer.

Step 2

Create an XML network security configuration file (network_security_config.xml) as follows:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">api.infovistar.in</domain>
        <trust-anchors>
            <certificates src="@raw/certificate" />
        </trust-anchors>
    </domain-config>
</network-security-config>

Step 3

Provide the application’s network configuration settings in the Manifest.xml file.

Solution 2:

In your Retrofit request, you need to modify your OKHttpClient.Builder object so that your request will create a certificate that can be trusted by your server. Only then can your server allow access to your request.

    public static Retrofit getUnsafeApiClient(Context ctx) {
        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(getUnsafeOkHttpClient().build())
                .build();
    }

    public static OkHttpClient.Builder getUnsafeOkHttpClient() {
        try {
            // Create a trust manager that does not validate certificate chains
            final TrustManager[] trustAllCerts = new TrustManager[]{
                    new X509TrustManager() {
                        @SuppressLint("TrustAllX509TrustManager")
                        @Override
                        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                        }

                        @SuppressLint("TrustAllX509TrustManager")
                        @Override
                        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                        }

                        @Override
                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                            return new java.security.cert.X509Certificate[]{};
                        }
                    }
            };

            // Install the all-trusting trust manager
            final SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());

            // Create an ssl socket factory with our all-trusting manager
            final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

            OkHttpClient.Builder builder = new OkHttpClient.Builder();
            builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
            return builder;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

These two solutions should allow you to connect seamlessly with the backend.

Android retrofit SSLHandshakeException
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleIs Blockchain Secure? in Hindi
Next Article Metaverse- the new reality
Infovistar
  • Website
  • Facebook
  • X (Twitter)
  • Instagram
  • LinkedIn

Related Posts

What Is Google Partner Setup and How Does It Work
Tech Tips

What Is Google Partner Setup and How Does It Work?

February 28, 2025
Google is rolling out Identity Check Feature to Android 15
Tech News

Google is rolling out Identity Check Feature to Android 15

January 25, 2025
Google Restore Credentials Effortless account restoration for Android apps
Cybersecurity

Google’s New Restore Credentials Tool Simplifies App Login

November 26, 2024
Add A Comment

Comments are closed.

Blog Categories
  • AI and ML (106)
  • Android (4)
  • AWS and Cloud (9)
  • Cybersecurity (84)
  • Money (12)
  • Personal Finance (6)
  • Startup (37)
  • Tech News (82)
  • Tech Tips (28)
  • Technology (73)
  • Web Development (25)
Top Posts
Google is rolling out Identity Check Feature to Android 15

Google is rolling out Identity Check Feature to Android 15

January 25, 20252,375 Views
How to Integrate Google Gemini to WhatsApp

How to Use Google Gemini with WhatsApp in 2026

February 16, 20241,913 Views
OpenAI Unveils Web-Based AI Agent Operator for Task Automation

OpenAI Unveils Web-Based AI Agent Operator for Task Automation

January 24, 20251,508 Views
Stay In Touch
  • Facebook
  • YouTube
  • WhatsApp
  • Twitter
  • Instagram
  • Pinterest
  • LinkedIn
Latest Articles

Subscribe to Updates

Get the latest tech news from FooBar about tech, design and biz.

About Us

Infovistar is a technology blog offering practical tutorials, programming guides, and the latest updates on AI, cybersecurity, software development, and digital technology.

Contact Information

Address: Nashik, Maharashtra, India – 422004
Email: infovistarindia@gmail.com
Phone: +91 89990 59150

Contact Us | About Us

DMCA.com Protection Status
Most Popular
US Outage Wave_ Microsoft, FAA, Banks, Apple-compressed

US Outages Explained: What Happened to Microsoft, FAA and Banks

Microsoft 365 Outage_ Outlook, Teams and Copilot Down. What We Know

Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know

Diwali online shopping scams warning for shoppers in India

Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe

Our Picks
Binance Hack: $6.3 Billion Stolen, Largest Crypto Heist Ever

This Site Uses XSLT Chrome Warning Explained: How to Fix It

iPad mini OLED Price in India

iPad mini OLED Price in India: Wi-Fi & Cellular Variants, Offers

iMac M6 Price in India

iMac M6 Price in India: All Variants, Colors, Offers and Release Date

Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
  • About Us
  • Contact Us
  • Tools
  • Terms & Conditions
  • Privacy Policy
  • AdSense Disclaimer
© 2026 Infovistar. Designed and Developed by Infovistar.

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.