File: net/ftptls.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Net#30
  class: FTPTLS#31
inherits from
  FTP ( Net )
has properties
method: connect / 2 #32
method: login / 3 #37

Class Hierarchy

Object ( Builtin-Module )
FTP ( Net )
  FTPTLS    #31

Code

   1  =begin
   2  = $RCSfile$ -- SSL/TLS enhancement for Net::HTTP.
   3 
   4  = Info
   5    'OpenSSL for Ruby 2' project
   6    Copyright (C) 2003 Blaz Grilc <farmer@gmx.co.uk>
   7    All rights reserved.
   8 
   9  = Licence
  10    This program is licenced under the same licence as Ruby.
  11    (See the file 'LICENCE'.)
  12 
  13  = Requirements
  14 
  15  = Version
  16    $Id: ftptls.rb 13657 2007-10-08 11:16:54Z gotoyuzo $
  17    
  18  = Notes
  19    Tested on FreeBSD 5-CURRENT and 4-STABLE
  20    - ruby 1.6.8 (2003-01-17) [i386-freebsd5]
  21    - OpenSSL 0.9.7a Feb 19 2003
  22    - ruby-openssl-0.2.0.p0
  23    tested on ftp server: glftpd 1.30
  24  =end
  25 
  26  require 'socket'
  27  require 'openssl'
  28  require 'net/ftp'
  29 
  30  module Net
  31    class FTPTLS < FTP
  32      def connect(host, port=FTP_PORT)
  33        @hostname = host
  34        super
  35      end
  36 
  37      def login(user = "anonymous", passwd = nil, acct = nil)
  38         store = OpenSSL::X509::Store.new
  39         store.set_default_paths
  40         ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
  41         ctx.cert_store = store
  42         ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
  43         ctx.key = nil
  44         ctx.cert = nil
  45         voidcmd("AUTH TLS")
  46         @sock = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
  47         @sock.connect
  48         @sock.post_connection_check(@hostname)
  49         super(user, passwd, acct)
  50         voidcmd("PBSZ 0")
  51      end
  52    end
  53  end