Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > saving a OpenSSL::X509::Certificate as PKCS#12?

Reply
Thread Tools

saving a OpenSSL::X509::Certificate as PKCS#12?

 
 
Magnus Bodin
Guest
Posts: n/a
 
      03-17-2005

I want to create a X.509 certificate and save it as PKCS#12.
All in pure Ruby.

I've looked in the WEBrick and QuickCert sources, waded through
sources of openssl, stunnel and now ruby-1.8.2, but it is a little bit
hazy.

My guess is that I shall create a PKCS12-object of some sort and
initialize this with my already created X.509-cert, right?

How do I save it in PKCS#12-format, readable from e.g. firefox?

I've successfully created a cert and saved it as PEM with the
OpenSSL::X509::Certificate#to_pem, and then *converted* it on the
commandline with the openssl-tool. But I'd like to save it in the right
format directly from ruby.

Please advise or even better:
Please point me to the fine manual, because I cannot find it.

-- magnus


 
Reply With Quote
 
 
 
 
Magnus Bodin
Guest
Posts: n/a
 
      03-19-2005
On Fri, Mar 18, 2005 at 01:48:15AM +0900, Magnus Bodin wrote:
>
> I want to create a X.509 certificate and save it as PKCS#12.
> All in pure Ruby.


I guess I can't?
I guess I have to save it as PEM and then do a
'openssl pkcs12 -inkey mykey.pem -in mycert.pem -out mypair.p12 -export'

?

The sillyness in this is that I will lose simplicity on the
win32 platform as I just want to install the one-click-installer. It
includes the openssl-libraries, but not the commandline tool. A pure
ruby totally independent solution would be much, much nicer.

-- magnus


 
Reply With Quote
 
 
 
 
GOTOU Yuuzou
Guest
Posts: n/a
 
      03-19-2005
Hi,

In message <>,
`Magnus Bodin <>' wrote:
> I want to create a X.509 certificate and save it as PKCS#12.
> All in pure Ruby.


OpenSSL:KCS12.create is a wrapper of PKCS12_create
function.

require "openssl"

pkey = OpenSSL:Key::RSA.new(512)
cert = OpenSSL::X509::Certificate.new
cert.version = 1
cert.subject = cert.issuer = OpenSSL::X509::Name.parse("/C=FOO")
cert.public_key = pkey.public_key
cert.not_before = Time.now
cert.not_after = Time.now+3600*24*365
cert.sign(pkey, OpenSSL:igest::SHA1.new)
p12 = OpenSSL:KCS12.create("passwd", "FriendlyName", pkey, cert)
print p12.to_der

--
gotoyuzo


 
Reply With Quote
 
Magnus Bodin
Guest
Posts: n/a
 
      03-20-2005
On Sun, Mar 20, 2005 at 01:21:22AM +0900, GOTOU Yuuzou wrote:
>
> p12 = OpenSSL:KCS12.create("passwd", "FriendlyName", pkey, cert)
> print p12.to_der


Thanks. This worked perfectly!

-- magnus


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
saving flash files from cache dir? Tom Firefox 4 01-07-2009 11:39 AM
EXCEL question saving a file saving the the first column as read only Luis Esteban Valencia ASP .Net 0 01-06-2005 07:02 PM
Saving DataTable to session vs saving a Custom object. John Kandell ASP .Net 4 12-10-2004 05:08 AM
Saving passwords Moz 1.5 Lambo Firefox 4 12-08-2003 11:33 AM
Saving Images While Saving ASP Pages ! Lovely Angel For You ASP General 1 10-03-2003 12:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57