Permalink
Browse files

add script/generate_certs

  • Loading branch information...
1 parent 6faf149 commit 306ed766dcd47666b864d8aae26a56d7d70a4676 @technoweenie committed Dec 28, 2012
Showing with 27 additions and 1 deletion.
  1. +26 −0 script/generate_certs
  2. +1 −1 script/test
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+require File.expand_path("../ruby", __FILE__)
+require 'openssl'
+require 'fileutils'
+
+# Adapted from WEBrick::Utils. Skips cert extensions so it
+# can be used as a CA bundle
+def create_self_signed_cert(bits, cn, comment)
+ rsa = OpenSSL::PKey::RSA.new(bits)
+ cert = OpenSSL::X509::Certificate.new
+ cert.version = 2
+ cert.serial = 1
+ name = OpenSSL::X509::Name.new(cn)
+ cert.subject = name
+ cert.issuer = name
+ cert.not_before = Time.now
+ cert.not_after = Time.now + (365*24*60*60)
+ cert.public_key = rsa.public_key
+ cert.sign(rsa, OpenSSL::Digest::SHA1.new)
+ return [cert, rsa]
+end
+
+cert, key = create_self_signed_cert(1024, [['CN', 'localhost']], 'Faraday Test CA')
+FileUtils.mkdir_p 'tmp'
+File.open('tmp/faraday-cert.key', 'w') {|f| f.puts(key) }
+File.open('tmp/faraday-cert.crt', 'w') {|f| f.puts(cert.to_s) }
View
@@ -33,7 +33,7 @@ if ssl_mode = ENV['SSL'] == 'yes'
unless ENV['SSL_KEY'] and ENV['SSL_FILE']
key_file = ENV['SSL_KEY'] = 'tmp/faraday-cert.key'
cert_file = ENV['SSL_FILE'] = 'tmp/faraday-cert.crt'
- system 'rake', key_file, cert_file
+ system 'script/generate_certs'
abort unless $?.success?
end
end

0 comments on commit 306ed76

Please sign in to comment.