diff --git a/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java b/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java index f2b5c36e5089..625dc348fccc 100644 --- a/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java +++ b/android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java @@ -23,7 +23,9 @@ class StatusOkHttpClientFactory implements OkHttpClientFactory { public OkHttpClient createNewNetworkModuleClient() { String certPem = StatusPackage.getImageTLSCert(); X509Certificate cert; + HandshakeCertificates clientCertificates; + // Convert PEM certificate string to X509Certificate object try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certPem.getBytes())); @@ -32,13 +34,25 @@ public OkHttpClient createNewNetworkModuleClient() { cert = null; } - HandshakeCertificates clientCertificates = new HandshakeCertificates.Builder() - .addPlatformTrustedCertificates() - .addTrustedCertificate(cert) - .build(); + // Create HandshakeCertificates object with our certificate + try { + clientCertificates = new HandshakeCertificates.Builder() + .addPlatformTrustedCertificates() + .addTrustedCertificate(cert) + .build(); + } catch(Exception e) { + Log.e("StatusOkHttpClientFactory", "Could not build HandshakeCertificates", e); + return null; + } - return OkHttpClientProvider.createClientBuilder() - .sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager()) - .build(); + // Create OkHttpClient with custom SSL socket factory and trust manager + try { + return OkHttpClientProvider.createClientBuilder() + .sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager()) + .build(); + } catch(Exception e) { + Log.e("StatusOkHttpClientFactory", "Could not create OkHttpClient", e); + return null; + } } }