title: error reading X.509 key or certificate file: Error in parsing
body: <p>I'm setting certificate auth to my <a href="https://nifi.apache.org/" rel="nofollow noreferrer">nifi</a> server.</p>
  
  <p>I have used <a href="https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#tls-generation-toolkit" rel="nofollow noreferrer">nifi-tools/tls-toolkit</a> from <a href="https://nifi.apache.org/" rel="nofollow noreferrer">nifi project</a> to generate a keystore, truststore, client certificate and so on.</p>
  
  <p>I have added the client certificate generated by <a href="https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#tls-generation-toolkit" rel="nofollow noreferrer">tls-toolkit</a> in p12 format to my browser and configured my nifi server property. All works fine.</p>
  
  <p>Now I want to use the client certificate within ruby script. </p>
  
  <p>To do that I have converted the certificate from p12 format to pem format like that...</p>
  
  <p><code>openssl pkcs12 -in CN=admin_DC=nifi_DC=com.p12 -passin pass:26V+Hs1qupglToDlVqO+oKW0yWR2jG3uXjuFTUus76o -out a.pem
  MAC verified OK
  Enter PEM pass phrase:
  </code></p>
  
  <p>PEM pass phrase in blank.</p>
  
  <p>To test it I tried</p>
  
  <p><code>curl --insecure --cert-type pem --cert "a.pem" "https://127.0.0.1:9443/nifi"
  curl: (35) error reading X.509 key or certificate file: Error in parsing.
  </code></p>
  
  <p>Error in parsing? I haven't found any info about it.</p>
  
  <p>Let's to verify...</p>
  
  <p><code>openssl verify a.pem
  a.pem: DC = com, DC = nifi, CN = admin
  error 20 at 0 depth lookup:unable to get local issuer certificate
  </code></p>
  
  <p>Verify with tha CA file...</p>
  
  <p><code>openssl verify -verbose -x509_strict -issuer_checks -CAfile nifi-cert.pem a.pem
  a.pem: OK
  </code></p>
  
  <p>With my ruby script fails too (obviously)</p>
  
  <pre class="lang-rb prettyprint-override"><code>require 'rest_client'
  
  a = RestClient::Resource.new(
    'https://127.0.0.1:9443/nifi',
    :ssl_client_cert  =&gt; OpenSSL::X509::Certificate.new(File.read("a.pem")),
    :verify_ssl       =&gt;  OpenSSL::SSL::VERIFY_NONE
  ).get
  
  pp a
  </code></pre>
  
  <p>`</p>
  
  <p>I get...</p>
  
  <pre class="lang-sh prettyprint-override"><code>/usr/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock': SSL_connect returned=1 errno=0 state=unknown state: sslv3 alert bad certificate (OpenSSL::SSL::SSLError)
  from /usr/lib/ruby/2.3.0/net/http.rb:933:in `connect'
  from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
  from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
  from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:in `transmit'
  from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in `execute'
  from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:in `execute'
  from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/resource.rb:51:in `get'
  from test.rb:8:in `&lt;main&gt;'
  </code></pre>
  
  <p>Whats wrong?</p>
  
  <p>Thanks.</p>