forked from status-im/status-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get images over HTTPS with self-signed certificate
Co-Authored-By: andrey <motor4ik@gmail.com> Signed-off-by: Michele Balistreri <michele@bitgamma.com>
- Loading branch information
1 parent
9850dd5
commit 52afbf4
Showing
17 changed files
with
437 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package im.status.ethereum; | ||
|
||
import android.util.Log; | ||
|
||
import com.facebook.react.modules.network.OkHttpClientFactory; | ||
import com.facebook.react.modules.network.OkHttpClientProvider; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.Interceptor; | ||
import okhttp3.tls.HandshakeCertificates; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.lang.RuntimeException; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.X509Certificate; | ||
|
||
import im.status.ethereum.module.StatusPackage; | ||
|
||
class StatusOkHttpClientFactory implements OkHttpClientFactory { | ||
public OkHttpClient createNewNetworkModuleClient() { | ||
String certPem = StatusPackage.getImageTLSCert(); | ||
X509Certificate cert; | ||
|
||
try { | ||
CertificateFactory cf = CertificateFactory.getInstance("X.509"); | ||
cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certPem.getBytes())); | ||
} catch(Exception e) { | ||
Log.e("StatusOkHttpClientFactory", "Could not parse certificate"); | ||
cert = null; | ||
} | ||
|
||
HandshakeCertificates clientCertificates = new HandshakeCertificates.Builder() | ||
.addPlatformTrustedCertificates() | ||
.addTrustedCertificate(cert) | ||
.build(); | ||
|
||
return OkHttpClientProvider.createClientBuilder() | ||
.sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.