Using a self-signed certificate to create a secure client-server
connection in android
I am developing an enterprise android application, thus it is necessary to
create a secure connection between the client (android emulator / test
phone) and server during my testing phase, even though the server's
certificate is self-signed while a legitimate certificate is being bought
by the company (something outside my control for now).
I need to trust the server's self-signed certificate and its
certificate-authority, which is not trusted by the android OS natively, of
course. I am following google's suggestion for creating an HTTPS
environment in this scenario almost verbatim.
The problem I'm currently facing is that I can't access my .crt file as in
this line from google's example:
InputStream caInput = new BufferedInputStream(
new FileInputStream("load-der.crt"));
In place of the above, I am using:
InputStream caInput = new BufferedInputStream(
getResources().openRawResource(R.raw.mycrtfile));
to open the InputStream derived from mycrtfile.crt, where the .crt file
exists in /res/raw/mycrtfile.crt. However, I get a NullPointerException on
that line.
Is there a better way to store and access the cert file which I need to
load as an InputStream or FileInputStream than as a raw resource stored
inside the res directory?
No comments:
Post a Comment