Sha256: 9ee573e2a5a2215a6174ccec6d3becb7fb183e30875a2d6df62dc4c794b72e1a

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

#!/usr/bin/env ruby
# Usage: generate_certs
# Generate test certs for testing Faraday with SSL

require 'openssl'
require 'fileutils'

$shell = ARGV.include? '-s'

# 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

def write(file, contents, env_var)
  FileUtils.mkdir_p(File.dirname(file))
  File.open(file, 'w') {|f| f.puts(contents) }
  puts %(export #{env_var}="#{file}") if $shell
end


# One cert / CA for ease of testing when ignoring verification
cert, key = create_self_signed_cert(1024, [['CN', 'localhost']], 'Faraday Test CA')
write 'tmp/faraday-cert.key', key,  'SSL_KEY'
write 'tmp/faraday-cert.crt', cert, 'SSL_FILE'

# And a second CA to prove that verification can fail
cert, key = create_self_signed_cert(1024, [['CN', 'real-ca.com']], 'A different CA')
write 'tmp/faraday-different-ca-cert.key', key,  'SSL_KEY_ALT'
write 'tmp/faraday-different-ca-cert.crt', cert, 'SSL_FILE_ALT'

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
faraday-0.8.11 script/generate_certs
faraday-0.8.10 script/generate_certs
faraday-0.9.1 script/generate_certs
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/faraday-0.8.9/script/generate_certs
whos_dated_who-0.1.0 vendor/bundle/gems/faraday-0.9.0/script/generate_certs
whos_dated_who-0.0.1 vendor/bundle/gems/faraday-0.9.0/script/generate_certs
faraday-0.9.0 script/generate_certs
faraday-0.9.0.rc7 script/generate_certs
faraday-0.8.9 script/generate_certs
faraday-0.9.0.rc6 script/generate_certs
faraday-0.8.8 script/generate_certs
faraday-0.9.0.rc5 script/generate_certs
faraday-0.9.0.rc4 script/generate_certs
faraday-0.9.0.rc3 script/generate_certs
faraday-0.9.0.rc2 script/generate_certs
faraday-0.9.0.rc1 script/generate_certs