Network security configuration
The Network Security Configuration in Android is used to customize the behavior of your app's network stack. It allows you to define specific rules and security policies for handling network connections, such as which domains to trust, handling cleartext traffic, or setting up custom Certificate Authorities (CAs).
Here are the key reasons to use Network Security Configuration in an Android Kotlin app:
1. Control Over Cleartext Traffic
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">example.com</domain>
</domain-config>
2. Custom Certificate Authority (CA) Trust
<domain-config>
<domain includeSubdomains="true">example.com</domain>
<trust-anchors>
<certificates src="user" />
<certificates src="system" />
</trust-anchors>
</domain-config>
3. Improved Security for Specific Domains
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">secure.example.com</domain>
</domain-config>
4. Debugging and Development Flexibility
领英推荐
<debug-overrides>
<trust-anchors>
<certificates src="raw/debug_ca" />
</trust-anchors>
</debug-overrides>
The Network Security Configuration in Android is used to customize the behavior of your app's network stack. It allows you to define specific rules and security policies for handling network connections, such as which domains to trust, handling cleartext traffic, or setting up custom Certificate Authorities (CAs).
Here are the key reasons to use Network Security Configuration in an Android Kotlin app:
5. Granular Control Over Security Policies
<network-security-config>
<domain-config>
<domain includeSubdomains="true">api.example.com</domain>
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</domain-config>
</network-security-config>
6. Compliance with Security Standards
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">secure.example.com</domain>
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</domain-config>
<debug-overrides>
<trust-anchors>
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
Conclusion
The Network Security Configuration provides flexibility, granular control, and security for network communication in your Kotlin Android app. It simplifies the process of enforcing secure connections and managing custom requirements without modifying your app's code.
Senior Android Engineer @Clicks Egypt
3 个月https://developer.android.com/privacy-and-security/security-config