title: Using a self-signed certificate to create a secure client-server connection in android
body: <p>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).  </p>
  
  <p>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 <a href="http://developer.android.com/training/articles/security-ssl.html#UnknownCa" rel="nofollow">google's suggestion for creating an HTTPS environment in this scenario</a> almost verbatim.  </p>
  
  <p>The problem I'm currently facing is that I can't access my <code>.crt</code> file as in this line from google's example:</p>
  
  <pre><code>InputStream caInput = new BufferedInputStream(
      new FileInputStream("load-der.crt"));
  </code></pre>
  
  <p>In place of the above, I am using: </p>
  
  <pre><code>InputStream caInput = new BufferedInputStream(
  getResources().openRawResource(R.raw.mycrtfile));
  </code></pre>
  
  <p>to open the <code>InputStream</code> derived from <code>mycrtfile.crt</code>, where the <code>.crt</code> file exists in <code>/res/raw/mycrtfile.crt</code>.  However, I get a <code>NullPointerException</code> on that line.   </p>
  
  <p>Is there a better way to store and access the cert file which I need to load as an <code>InputStream</code> or <code>FileInputStream</code> than as a raw resource stored inside the <code>res</code> directory?</p>