Skip to content

Commit 98da5f8

Browse files
author
Matthieu Gicquel
committed
certificate transparency
1 parent 1a7ae4e commit 98da5f8

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p align="center">Easily implement usual security measures in React Native Expo apps</p>
44

55
- [SSL public key pinning](#ssl-pinning)
6-
- [🚧 Certificate transparency](#certificate-transparency)
6+
- [Certificate transparency](#certificate-transparency)
77
- [🚧 "Recent screenshots" prevention](#recent-screenshots-prevention)
88

99
> **⚠️ Disclaimer**<br/>
@@ -84,7 +84,14 @@ To test that SSL pinning is working as expected, you can:
8484

8585
## Certificate transparency
8686

87-
TODO
87+
> **🥷 What's the threat?** Compromised certificate authorities. [More details](https://certificate.transparency.dev)
88+
89+
- On iOS, [certificate transparency is enabled by default](https://developer.apple.com/documentation/ios-ipados-release-notes/ios-12_1_1-release-notes) since _iOS 12.1.1_
90+
- On Android, this package enables it using [appmatus/certificatetransparency](https://github.com/appmattus/certificatetransparency) for _Android >= 8.0_
91+
92+
### Configuration
93+
94+
None, enabled by default.
8895

8996
## "Recent screenshots" prevention
9097

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ dependencies {
9292

9393
// package-specific dependencies
9494
implementation("com.facebook.react:react-native:+")
95+
implementation("com.appmattus.certificatetransparency:certificatetransparency-android:2.5+") // using `+` because minors are mostly automated updates of logs_list
9596
}

android/src/main/java/tech/bam/rnas/HttpClientOverride.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package tech.bam.rnas
22

3+
import android.os.Build
34
import com.facebook.react.modules.network.OkHttpClientFactory;
45
import com.facebook.react.modules.network.OkHttpClientProvider;
56

67
import okhttp3.CertificatePinner;
78
import okhttp3.OkHttpClient;
89

10+
import com.appmattus.certificatetransparency.CTInterceptorBuilder
11+
912
import org.json.JSONObject
1013

1114
public class SSLPinning : OkHttpClientFactory {
1215
override fun createNewNetworkModuleClient(): OkHttpClient {
1316
val config = parseConfig()
1417

18+
val clientBuilder = OkHttpClientProvider.createClientBuilder()
19+
20+
// -- SSL pinning --
21+
1522
val certificatePinnerBuilder = CertificatePinner.Builder()
1623

1724
for((hostName, certificates) in config) {
@@ -21,13 +28,19 @@ public class SSLPinning : OkHttpClientFactory {
2128
}
2229
}
2330

24-
val certificatePinner = certificatePinnerBuilder.build()
31+
clientBuilder.certificatePinner(certificatePinnerBuilder.build())
2532

26-
val clientBuilder = OkHttpClientProvider.createClientBuilder()
33+
// -- Certificate Transparency --
34+
35+
/*
36+
* The library for certificate transparency does not support Android sdk version < 26 (Android 8.0) without setting up "desugaring"
37+
* See more : https://github.com/appmattus/certificatetransparency#getting-started
38+
*/
39+
if (Build.VERSION.SDK_INT >= 26) {
40+
clientBuilder.addNetworkInterceptor(CTInterceptorBuilder().build())
41+
}
2742

28-
return clientBuilder
29-
.certificatePinner(certificatePinner)
30-
.build()
43+
return clientBuilder.build()
3144
}
3245

3346
}
@@ -48,5 +61,5 @@ fun parseConfig() : Map<String, List<String>> {
4861
resultMap[key] = valuesList
4962
}
5063

51-
return resultMap // Map<String, List<String>>
64+
return resultMap
5265
}

0 commit comments

Comments
 (0)