Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Generate Self-Signed Certificate
    primarykey
    data
    text
    <p>I'm trying to generate a self-signed certificate in ruby, but am running into trouble. This is what I currently have right now:</p> <pre><code>require 'openssl' if ARGV.length != 3 then puts "USAGE: #{__FILE__} &lt;type[der|pem]&gt; &lt;private-out&gt; &lt;public-out&gt;" exit end type = ARGV[0].downcase privateKeyFile = ARGV[1] publicKeyFile = ARGV[2] values = [{ 'C' =&gt; 'US'}, {'ST' =&gt; 'SomeState'}, { 'L' =&gt; 'SomeCity'}, { 'O' =&gt; 'Organization'}, {'OU' =&gt; 'Organizational Unit'}, {'CN' =&gt; "somesite.com"}] name = values.collect{ |l| l.collect { |k, v| "/#{k}=#{v}" }.join }.join key = OpenSSL::PKey::RSA.generate(1024) pub = key.public_key ca = OpenSSL::X509::Name.parse(name) cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = 1 cert.subject = ca cert.issuer = ca cert.public_key = pub cert.not_before = Time.now cert.not_before = Time.now + (360 * 24 * 3600) File.open(privateKeyFile + "." + type, "w") {|f| f.write key.send("to_#{type}") } File.open(publicKeyFile + "." + type, "w") {|f| f.write cert.send("to_#{type}") } </code></pre> <p>When I try to use the generated private key and certificate in apache, I get this error:</p> <pre><code>[Thu Mar 04 10:58:44 2010] [error] Init: Unable to read server certificate from file /etc/ssl/certs/gnarly.pem [Thu Mar 04 10:58:44 2010] [error] SSL Library Error: 218529960 error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag [Thu Mar 04 10:58:44 2010] [error] SSL Library Error: 218595386 error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error </code></pre> <p>This is what my certificate says:</p> <pre><code>-----BEGIN CERTIFICATE----- &lt;lots of stuff&gt; -----END CERTIFICATE----- </code></pre> <p>It calls itself a certificate instead of a CSR, which is what most of the things I've found online say about that apache2 error (that I might have gotten the CSR and CERT mixed up). My guess is that I'm not generating the right type of certificate. Maybe I have to change the serial or version attributes. Also, I'm not doing any self-signing anywhere, not that I know of anyways. I know you can do something like this though:</p> <pre><code>require "openssl" key = OpenSSL::PKey::RSA.generate(1024) signature = key.sign(OpenSSL::Digest::SHA1.new, "data to sign") </code></pre> <p>Reminder: My goal is to generate a self-signed certificate, in case my long-ish question lost focus on the way.</p> <p>EDIT: I guess the real question is how to sign a certificate with a key</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload