A recommendation has been made by the team penetration testing our Android app that we should pin the IP address of the server along with the already pinned certificate to add a layer defense against man in the middle attacks. My question is how could I pin the server IP address on an android app in addition to the already pinned certificate.
Currently I am using okhttp
. I already have certificate pinning implemented, this is done when creating a singleton okhttpClient
using okhttpClientBuilder
. Code shown below. I would like to add backend server IP address pinning to this builder somehow.
val client = OkHttpClient.Builder()
.addInterceptor { chain ->
val request = chain.request().newBuilder()
.addHeader(apiKeyHeader, apiKey)
.header("Content-Type", "application/json")
.build()
chain.proceed(request)
}.addInterceptor(loggingInterceptor)
.certificatePinner(CertificatePinUtil.createOkHttpCertPinner())
.build()
Any recommendations around how to implement IP pinning would be helpful.
Ideally we would do this using OkhttpClientBuilder
or the android security configs. I do not want to implement any manual checking of the responses.