class Aspera::WebAuth

Public Class Methods

new(endpoint_url) click to toggle source
# File lib/aspera/web_auth.rb, line 52
def initialize(endpoint_url)
  uri=URI.parse(endpoint_url)
  webrick_options = {
    :app                => WebAuth,
    :Port               => uri.port,
    :Logger             => Log.log
  }
  uri_path=uri.path.empty? ? '/' : uri.path
  case uri.scheme
  when 'http'
    Log.log.debug('HTTP mode')
  when 'https'
    webrick_options[:SSLEnable]=true
    webrick_options[:SSLVerifyClient]=OpenSSL::SSL::VERIFY_NONE
    case 0
    when 0
      # generate self signed cert
      fill_self_signed_cert(webrick_options)
    when 1
      # short
      webrick_options[:SSLCertName]    = [ [ 'CN',WEBrick::Utils::getservername ] ]
      Log.log.error(">>>#{webrick_options[:SSLCertName]}")
    when 2
      # good cert
      webrick_options[:SSLPrivateKey] =OpenSSL::PKey::RSA.new(File.read('/Users/laurent/workspace/Tools/certificate/myserver.key'))
      webrick_options[:SSLCertificate] = OpenSSL::X509::Certificate.new(File.read('/Users/laurent/workspace/Tools/certificate/myserver.crt'))
    end
  end
  # parameters for servlet
  @shared_info={
    expected_path: uri_path,
    mutex: Mutex.new,
    cond: ConditionVariable.new
  }
  @server = WEBrick::HTTPServer.new(webrick_options)
  @server.mount(uri_path, FxGwServlet, @shared_info) # additional args provided to constructor
  Thread.new { @server.start }
end

Public Instance Methods

fill_self_signed_cert(options) click to toggle source

generates and adds self signed cert to provided webrick options

# File lib/aspera/web_auth.rb, line 29
def fill_self_signed_cert(options)
  key = OpenSSL::PKey::RSA.new(4096)
  cert = OpenSSL::X509::Certificate.new
  cert.subject = cert.issuer = OpenSSL::X509::Name.parse('/C=FR/O=Test/OU=Test/CN=Test')
  cert.not_before = Time.now
  cert.not_after = Time.now + 365 * 24 * 60 * 60
  cert.public_key = key.public_key
  cert.serial = 0x0
  cert.version = 2
  ef = OpenSSL::X509::ExtensionFactory.new
  ef.issuer_certificate = cert
  ef.subject_certificate = cert
  cert.extensions = [
    ef.create_extension('basicConstraints','CA:TRUE', true),
    ef.create_extension('subjectKeyIdentifier', 'hash'),
    # ef.create_extension('keyUsage', 'cRLSign,keyCertSign', true),
  ]
  cert.add_extension(ef.create_extension('authorityKeyIdentifier','keyid:always,issuer:always'))
  cert.sign(key, OpenSSL::Digest::SHA256.new)
  options[:SSLPrivateKey]  = key
  options[:SSLCertificate] = cert
end
get_request() click to toggle source

wait for request on web server @return Hash the query

# File lib/aspera/web_auth.rb, line 93
def get_request
  Log.log.debug('get_request')
  # called only once
  raise "error, called twice ?" if @server.nil?
  @shared_info[:mutex].synchronize do
    @shared_info[:cond].wait(@shared_info[:mutex])
  end
  @server.shutdown
  @server=nil
  return @shared_info[:query]
end