Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ android {
// package-specific config fields
buildConfigField("String", "RNAS_PINNING_CONFIG", "\"${safeExtGet("RNAS_PINNING_CONFIG", "{}")}\"")
buildConfigField("boolean", "RNAS_PREVENT_RECENT_SCREENSHOTS", safeExtGet("RNAS_PREVENT_RECENT_SCREENSHOTS", "false"))
buildConfigField("boolean", "RNAS_CT_FAIL_ON_ERROR", safeExtGet("RNAS_CT_FAIL_ON_ERROR", "true"))
}
lintOptions {
abortOnError false
Expand Down
6 changes: 5 additions & 1 deletion android/src/main/java/tech/bam/rnas/HttpClientOverride.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public class SSLPinning : OkHttpClientFactory {
* See more : https://github.com/appmattus/certificatetransparency#getting-started
*/
if (Build.VERSION.SDK_INT >= 26) {
clientBuilder.addNetworkInterceptor(CTInterceptorBuilder().build())
clientBuilder.addNetworkInterceptor(
CTInterceptorBuilder()
.failOnError(BuildConfig.RNAS_CT_FAIL_ON_ERROR)
.build()
)
}

return clientBuilder.build()
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigPlugin } from "@expo/config-plugins";
import { RNASConfig } from "./types";
import withCertificateTransparency from "./withCertificateTransparency";
import withDisableCache from "./withDisableCache";
import withpreventRecentScreenshots from "./withPreventRecentScreenshots";
import withSSLPinning from "./withSSLPinning";
Expand All @@ -9,6 +10,7 @@ const withRNAS: ConfigPlugin<RNASConfig> = (config, props) => {

config = withpreventRecentScreenshots(config, props.preventRecentScreenshots);
config = withDisableCache(config, props.disableCache);
config = withCertificateTransparency(config, props.certificateTransparency);

return config;
};
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export type RNASConfig = {
disableCache?: {
ios?: { enabled: boolean };
};
certificateTransparency?: {
android?: { failOnError?: boolean };
};
};
32 changes: 32 additions & 0 deletions plugin/src/withCertificateTransparency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ConfigPlugin, withGradleProperties } from "@expo/config-plugins";
import { RNASConfig } from "./types";

type Props = RNASConfig["certificateTransparency"];

const withCertificateTransparency: ConfigPlugin<Props> = (config, props) => {
config = withGradleProperties(config, (config) => {
const gradleProperties = config.modResults;

const failOnError = props?.android?.failOnError ?? true;

const existingIndex = gradleProperties.findIndex(
(prop) =>
prop.type === "property" && prop.key === "RNAS_CT_FAIL_ON_ERROR"
);
if (existingIndex !== -1) {
gradleProperties.splice(existingIndex, 1);
}

gradleProperties.push({
type: "property",
key: "RNAS_CT_FAIL_ON_ERROR",
value: String(failOnError),
});

return config;
});

return config;
};

export default withCertificateTransparency;