I am trying to implement ECIES (using BouncyCastle and FlexiProvider) across mobile app and server communication whereby the mobile app will encrypt a data and server will decrypt the same. Now how should I pass the public key of ECIES to the mobile app for encryption.
-
2$\begingroup$ Is there a reason you are not just establishing a TLS connection with the server? $\endgroup$– mikeazoJul 7, 2017 at 14:59
-
$\begingroup$ Hard-code it into your binary and sign the binary so the OS verifies the integrity of the binary and thus your public key? (or you could push a "CA" public key this way and then distribute certificates at any later point) $\endgroup$– SEJPMJul 7, 2017 at 18:15
1 Answer
I see three options for you, each with strengths and weaknesses.
- Use a PKI with some sort of trusted signing authority and validate that the certificate is signed by a trusted signing authority and that it has some identifier in it that should be present for your app to trust. For example, the certificate could have a Subject field embedded within it that has a value of my-really-cool-app.com. If presented with a certificate signed by the trusted authority with the correct Subject field, you trust the certificate and continue with the connection. This would happen every time you connect.
- Use trust on first use. This means, the first time you connect, you accept whatever certificate you are given. On subsequent connections, you only accept connections that present the same certificate. If a new cert is given, you error out or something. This is similar to how SSH is used most often. In SSH the user is presented with the server's public key certificate fingerprint, but my guess is no one checks that and just trusts it the first time. If it ever changes SSH complains.
- You ship your app with the desired public key certificate (or fingerprint) within it. On making a connection, if the certificate has changed, don't continue the connection. This is pinning.
-
$\begingroup$ the second one is actually TOFU + pinning and the third one is standard pinning? $\endgroup$– SEJPMJul 7, 2017 at 18:16
-
$\begingroup$ @SEJPM, yeah, that is maybe a better terminology than how I put it. $\endgroup$– mikeazoJul 7, 2017 at 18:18
-
$\begingroup$ Actually, I am using TLS but I need to encrypt the JSON payload data which will be encrypted (using ECIES public key) and decrypted in server. Hence we need to pass the public key to the mobile app. I was wondering how that can be achieved. $\endgroup$– SubhapamJul 10, 2017 at 9:08
-
$\begingroup$ If you are using TLS, then why is the data not already encrypted? $\endgroup$– mikeazoJul 10, 2017 at 10:51
-
$\begingroup$ TLS already encrypt payload data. But I want to encrypt certain data within the payload separately using ECIES. $\endgroup$– SubhapamJul 10, 2017 at 16:12