1

I'm writing an Android library which is a REST API client to an HTTPS endpoint. This library will be used by apps to abstract access to the REST service.

I'd like to use certificate pinning and cleartext opt-out to keep my traffic secure, but I don't want to stop the consuming app from talking to other services or managing its own security configuration. I'd like to make sure that even if the app is set up wrong and communicates insecurely with other services, all the traffic coming from my library will always be secure. (To be clear: I'm not so much worried about a malicious app trying to read my network traffic. I'm just worried about a badly written app breaking my security policy and accepting bad HTTPS connections, exposing user data from my web service.)

The library is delivered as an AAR. If it makes a difference, I'm using OkHttp3 as my HTTP client. One extra complexity: I need minSdkVersion 21, so to use Network Security Config, I'd have to use CommonsWare's backport anyway.

What's the easiest way for me to set up a network security policy for my library that can't be broken by the app and doesn't affect the app's other traffic?

1 Answer 1

1

There's no way to ensure that an app embedding your library can't mess with the network traffic used by your library. The reason is that Android Application Sandbox doesn't distinguish between the app and a library embedded in that app. Their code runs in the same process, they can access (read/write) each other's state, they share global state (e.g., default SSLSocketFactory, HostnameVerifier and X509TrustManager), and so forth.

The best you can do is assume app developer is not malicious and provide them with guidance about what to add to their app's Network Security Config to secure the traffic emitted by your library.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.