0

I'm developing an Android application (Jetpack Compose with Ktor) that communicates with a server I am building in Go (with Gin).

While I have checked that everything works locally between the application and the server, I am at a stage where I want to make my server only respond to requests from my application (when it goes live). These requests should also be secure as much as they can be so I learned I need to use SSL with a client certificate.

This is something where I lack knowledge in, so please forgive my ignorance.

I have read many SO questions (some of them are outdated or don't refer to current libraries) and other resources online, and since this is a personal project, I have understood that I can:

I am still unsure on what needs to be done server side, but we will get to that later in this question.

After creating the certificate, I put it inside the res/raw resource folder (certificate has a .der file extension) and I am unfamiliar with the configuration I need to make for the Ktor client.

I currently have this in place for the Ktor client:

HttpClient(Android) {
        install(ContentNegotiation) {
            json(
                Json {
                    ignoreUnknownKeys = true
                }
            )
        }
    }

and I read about the different engines in Ktor client, but it seems like I need to use the Android one. On one part of the official documentation, it says to use the network security config XML file to configure SSL in Ktor, but a bit down the page, the official documentation talks about the sslManager property, which kind of confuses me.

  1. What do I need to do in order to setup the Ktor client to use the certificate in requests?
  2. What do I need to do on the server side to accept only the requests which are valid?

I know this is a two-part question and it involves two different languages, but you actually can't just do the client part without the server side.

References:

4
  • Did I understand correctly that you need to enable mutual TLS (cloudflare.com/learning/access-management/what-is-mutual-tls) to be able to protect the server from other clients? Commented Jan 8, 2025 at 9:48
  • @AlekseiTirman - My goal is to make my Go server accept requests only from my application. Commented Jan 8, 2025 at 10:16
  • I understand it. Can you explain how you would like to achieve that goal? Commented Jan 8, 2025 at 10:21
  • @AlekseiTirman - I am seeking answers to allow me to do this. I have very little knowledge in doing so. I read that I generate a self signed certificate for the client. Commented Jan 8, 2025 at 11:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.