~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/net/https.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
  You can get it from RAA or Ruby's CVS repository.
17
17
 
18
18
== Version
19
 
  $Id: https.rb 11708 2007-02-12 23:01:19Z shyouhei $
 
19
  $Id: https.rb 14371 2007-12-20 16:21:22Z gotoyuzo $
20
20
  
21
21
  2001-11-06: Contiributed to Ruby/OpenSSL project.
22
22
  2004-03-06: Some code is merged in to net/http.
102
102
require 'openssl'
103
103
 
104
104
module Net
105
 
 
106
105
  class HTTP
107
106
    remove_method :use_ssl?
108
107
    def use_ssl?
109
108
      @use_ssl
110
109
    end
111
110
 
112
 
    alias use_ssl use_ssl?   # for backward compatibility
113
 
 
114
111
    # Turn on/off SSL.
115
112
    # This flag must be set before starting session.
116
113
    # If you change use_ssl value after session started,
117
114
    # a Net::HTTP object raises IOError.
118
115
    def use_ssl=(flag)
119
116
      flag = (flag ? true : false)
120
 
      raise IOError, "use_ssl value changed, but session already started" \
121
 
          if started? and @use_ssl != flag
122
 
      if flag and not @ssl_context
123
 
        @ssl_context = OpenSSL::SSL::SSLContext.new
 
117
      if started? and @use_ssl != flag
 
118
        raise IOError, "use_ssl value changed, but session already started"
124
119
      end
125
120
      @use_ssl = flag
126
121
    end
127
122
 
128
 
    def self.ssl_context_accessor(name)
129
 
      module_eval(<<-End, __FILE__, __LINE__ + 1)
130
 
        def #{name}
131
 
          return nil unless @ssl_context
132
 
          @ssl_context.#{name}
133
 
        end
134
 
 
135
 
        def #{name}=(val)
136
 
          @ssl_context ||= OpenSSL::SSL::SSLContext.new
137
 
          @ssl_context.#{name} = val
138
 
        end
139
 
      End
140
 
    end
141
 
 
142
 
    ssl_context_accessor :key
143
 
    ssl_context_accessor :cert
144
 
    ssl_context_accessor :ca_file
145
 
    ssl_context_accessor :ca_path
146
 
    ssl_context_accessor :verify_mode
147
 
    ssl_context_accessor :verify_callback
148
 
    ssl_context_accessor :verify_depth
149
 
    ssl_context_accessor :cert_store
150
 
 
151
 
    def ssl_timeout
152
 
      return nil unless @ssl_context
153
 
      @ssl_context.timeout
154
 
    end
155
 
 
156
 
    def ssl_timeout=(sec)
157
 
      raise ArgumentError, 'Net::HTTP#ssl_timeout= called but use_ssl=false' \
158
 
          unless use_ssl?
159
 
      @ssl_context ||= OpenSSL::SSL::SSLContext.new
160
 
      @ssl_context.timeout = sec
161
 
    end
162
 
 
163
 
    alias timeout= ssl_timeout=   # for backward compatibility
 
123
    SSL_ATTRIBUTES = %w(
 
124
      ssl_version key cert ca_file ca_path cert_store ciphers
 
125
      verify_mode verify_callback verify_depth ssl_timeout
 
126
    )
 
127
    attr_accessor *SSL_ATTRIBUTES
164
128
 
165
129
    def peer_cert
166
 
      return nil if not use_ssl? or not @socket
 
130
      if not use_ssl? or not @socket
 
131
        return nil
 
132
      end
167
133
      @socket.io.peer_cert
168
134
    end
169
135
  end
170
 
 
171
136
end