httpclient 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/httpclient.rb CHANGED
@@ -52,9 +52,9 @@ require 'httpclient/cookie'
52
52
  #
53
53
  class HTTPClient
54
54
 
55
- VERSION = '2.1.1'
55
+ VERSION = '2.1.2'
56
56
  RUBY_VERSION_STRING = "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
57
- s = %w$Id: httpclient.rb 178 2007-08-28 13:47:27Z nahi $
57
+ s = %w$Id: httpclient.rb 187 2007-09-22 14:15:42Z nahi $
58
58
  RCS_FILE, RCS_REVISION = s[1][/.*(?=,v$)/], s[2]
59
59
 
60
60
  SSLEnabled = begin
@@ -64,6 +64,13 @@ class HTTPClient
64
64
  false
65
65
  end
66
66
 
67
+ NTLMEnabled = begin
68
+ require 'net/ntlm'
69
+ true
70
+ rescue LoadError
71
+ false
72
+ end
73
+
67
74
  SSPIEnabled = begin
68
75
  require 'win32/sspi'
69
76
  true
@@ -152,7 +159,7 @@ class SSLConfig # :nodoc:
152
159
  @timeout = nil
153
160
  @options = defined?(OpenSSL::SSL::OP_ALL) ?
154
161
  OpenSSL::SSL::OP_ALL | OpenSSL::SSL::OP_NO_SSLv2 : nil
155
- @ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"
162
+ @ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:+SSLv2:@STRENGTH"
156
163
  load_cacerts
157
164
  end
158
165
 
@@ -357,9 +364,9 @@ private
357
364
  require 'openssl'
358
365
  dist_cert =<<__DIST_CERT__
359
366
  -----BEGIN CERTIFICATE-----
360
- MIIC/jCCAmegAwIBAgIBADANBgkqhkiG9w0BAQUFADBNMQswCQYDVQQGEwJKUDER
367
+ MIIC/jCCAmegAwIBAgIBATANBgkqhkiG9w0BAQUFADBNMQswCQYDVQQGEwJKUDER
361
368
  MA8GA1UECgwIY3Rvci5vcmcxFDASBgNVBAsMC0RldmVsb3BtZW50MRUwEwYD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iG/
381
+ UeQkOZk/P1TxB6Ozn2htJ1srqDpUsncFVZ/ecP19GkeOZ6BmIhppcHhE5WyLBcPX
382
+ It5q1BW0PiAzT9LlEGoaiW0nw39so0Pr1whJDfc1t4fjdk+kSiMIzRHbTDvHWfpV
383
+ nTA=
377
384
  -----END CERTIFICATE-----
378
385
  __DIST_CERT__
379
386
  p7 = OpenSSL::PKCS7.read_smime(File.open(file) { |f| f.read })
@@ -517,6 +524,79 @@ end
517
524
  #
518
525
  class NegotiateAuth # :nodoc:
519
526
  attr_reader :scheme
527
+ attr_reader :ntlm_opt
528
+
529
+ def initialize
530
+ @auth = {}
531
+ @auth_default = nil
532
+ @challenge = {}
533
+ @scheme = "Negotiate"
534
+ @ntlm_opt = {
535
+ :ntlmv2 => true
536
+ }
537
+ end
538
+
539
+ def reset_challenge
540
+ @challenge.clear
541
+ end
542
+
543
+ def set(uri, user, passwd)
544
+ if uri
545
+ uri = Util.uri_dirname(uri)
546
+ @auth[uri] = [user, passwd]
547
+ else
548
+ @auth_default = [user, passwd]
549
+ end
550
+ end
551
+
552
+ def get(req)
553
+ return nil unless NTLMEnabled
554
+ target_uri = req.header.request_uri
555
+ param = Util.hash_find_value(@challenge) { |uri, param|
556
+ Util.uri_part_of(target_uri, uri)
557
+ }
558
+ return nil unless param
559
+ user, passwd = Util.hash_find_value(@auth) { |uri, auth_data|
560
+ Util.uri_part_of(target_uri, uri)
561
+ }
562
+ unless user
563
+ user, passwd = @auth_default
564
+ end
565
+ return nil unless user
566
+ state = param[:state]
567
+ authphrase = param[:authphrase]
568
+ case state
569
+ when :init
570
+ t1 = Net::NTLM::Message::Type1.new
571
+ return t1.encode64
572
+ when :response
573
+ t2 = Net::NTLM::Message.decode64(authphrase)
574
+ t3 = t2.response({:user => user, :password => passwd}, @ntlm_opt)
575
+ return t3.encode64
576
+ end
577
+ nil
578
+ end
579
+
580
+ def challenge(uri, param_str)
581
+ return false unless NTLMEnabled
582
+ if param_str.nil? or @challenge[uri].nil?
583
+ c = @challenge[uri] = {}
584
+ c[:state] = :init
585
+ c[:authphrase] = ""
586
+ else
587
+ c = @challenge[uri]
588
+ c[:state] = :response
589
+ c[:authphrase] = param_str
590
+ end
591
+ true
592
+ end
593
+ end
594
+
595
+
596
+ # HTTPClient::SSPINegotiateAuth
597
+ #
598
+ class SSPINegotiateAuth # :nodoc:
599
+ attr_reader :scheme
520
600
 
521
601
  def initialize
522
602
  @challenge = {}
@@ -607,6 +687,7 @@ class WWWAuth < AuthFilterBase # :nodoc:
607
687
  def set_auth(uri, user, passwd)
608
688
  @basic_auth.set(uri, user, passwd)
609
689
  @digest_auth.set(uri, user, passwd)
690
+ @negotiate_auth.set(uri, user, passwd)
610
691
  end
611
692
 
612
693
  def filter_request(req)
@@ -642,12 +723,14 @@ end
642
723
  class ProxyAuth < AuthFilterBase # :nodoc:
643
724
  attr_reader :basic_auth
644
725
  attr_reader :negotiate_auth
726
+ attr_reader :sspi_negotiate_auth
645
727
 
646
728
  def initialize
647
729
  @basic_auth = BasicAuth.new
648
730
  @negotiate_auth = NegotiateAuth.new
731
+ @sspi_negotiate_auth = SSPINegotiateAuth.new
649
732
  # sort authenticators by priority
650
- @authenticator = [@negotiate_auth, @basic_auth]
733
+ @authenticator = [@negotiate_auth, @sspi_negotiate_auth, @basic_auth]
651
734
  end
652
735
 
653
736
  def reset_challenge
@@ -658,6 +741,7 @@ class ProxyAuth < AuthFilterBase # :nodoc:
658
741
 
659
742
  def set_auth(user, passwd)
660
743
  @basic_auth.set(nil, user, passwd)
744
+ @negotiate_auth.set(nil, user, passwd)
661
745
  end
662
746
 
663
747
  def filter_request(req)
@@ -1093,11 +1177,10 @@ end
1093
1177
 
1094
1178
  # HTTPClient::DebugSocket -- debugging support
1095
1179
  #
1096
- class DebugSocket
1097
- include SocketWrap
1180
+ module DebugSocket
1181
+ extend SocketWrap
1098
1182
 
1099
- def initialize(socket, debug_dev)
1100
- super(socket)
1183
+ def debug_dev=(debug_dev)
1101
1184
  @debug_dev = debug_dev
1102
1185
  end
1103
1186
 
@@ -1415,7 +1498,8 @@ private
1415
1498
  end
1416
1499
  if @debug_dev
1417
1500
  @debug_dev << "! CONNECTION ESTABLISHED\n"
1418
- socket = DebugSocket.new(socket, @debug_dev)
1501
+ socket.extend(DebugSocket)
1502
+ socket.debug_dev = @debug_dev
1419
1503
  end
1420
1504
  rescue SystemCallError => e
1421
1505
  e.message << " (#{site})"
@@ -1489,7 +1573,7 @@ private
1489
1573
  return [@version, @status, @reason]
1490
1574
  end
1491
1575
 
1492
- StatusParseRegexp = %r(\AHTTP/(\d+\.\d+)\s+(\d+)(?:\s+([^\r\n]+))?\r?\n\z)
1576
+ StatusParseRegexp = %r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?\r?\n\z)
1493
1577
  def parse_header(socket)
1494
1578
  begin
1495
1579
  timeout(@receive_timeout) do
@@ -1,9 +1,9 @@
1
1
  MIME-Version: 1.0
2
- Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="----5D1564AD4B7AA41C792F4EA6897F9BBC"
2
+ Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="----8B5C3F7F4B46AC7A36EDE5247D3D6E76"
3
3
 
4
4
  This is an S/MIME signed message
5
5
 
6
- ------5D1564AD4B7AA41C792F4EA6897F9BBC
6
+ ------8B5C3F7F4B46AC7A36EDE5247D3D6E76
7
7
  -----BEGIN CERTIFICATE-----
8
8
  MIIEGDCCAwCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBlMQswCQYDVQQGEwJTRTEU
9
9
  MBIGA1UEChMLQWRkVHJ1c3QgQUIxHTAbBgNVBAsTFEFkZFRydXN0IFRUUCBOZXR3
@@ -420,19 +420,6 @@ T9oT95mvPtDPjqZyorPDBZrJJ32SzH5SjbOrcG2eiZ9N6xp1wpiq1QIW1wyKvyXk
420
420
  ysiUFnZflGEo8IWnObvXi9moshMdVAk0JH0ggX1mfqKQdFwQxr3sqxvC
421
421
  -----END CERTIFICATE-----
422
422
  -----BEGIN CERTIFICATE-----
423
- MIIB+jCCAWMCAgGjMA0GCSqGSIb3DQEBBAUAMEUxCzAJBgNVBAYTAlVTMRgwFgYD
424
- VQQKEw9HVEUgQ29ycG9yYXRpb24xHDAaBgNVBAMTE0dURSBDeWJlclRydXN0IFJv
425
- b3QwHhcNOTYwMjIzMjMwMTAwWhcNMDYwMjIzMjM1OTAwWjBFMQswCQYDVQQGEwJV
426
- UzEYMBYGA1UEChMPR1RFIENvcnBvcmF0aW9uMRwwGgYDVQQDExNHVEUgQ3liZXJU
427
- cnVzdCBSb290MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC45k+625h8cXyv
428
- RLfTD0bZZOWTwUKOx7pJjTUteueLveUFMVnGsS8KDPufpz+iCWaEVh43KRuH6X4M
429
- ypqfpX/1FZSj1aJGgthoTNE3FQZor734sLPwKfWVWgkWYXcKIiXUT0Wqx73llt/5
430
- 1KiOQswkwB6RJ0q1bQaAYznEol44AwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBABKz
431
- dcZfHeFhVYAA1IFLezEPI2PnPfMD+fQ2qLvZ46WXTeorKeDWanOB5sCJo9Px4KWl
432
- IjeaY8JIILTbcuPI9tl8vrGvU9oUtCG41tWW4/5ODFlitppK+ULdjG+BqXH/9Apy
433
- bW1EDp3zdHSo1TRJ6V6e6bR64eVaH4QwnNOfpSXY
434
- -----END CERTIFICATE-----
435
- -----BEGIN CERTIFICATE-----
436
423
  MIICWjCCAcMCAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzAJBgNVBAYTAlVTMRgwFgYD
437
424
  VQQKEw9HVEUgQ29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNv
438
425
  bHV0aW9ucywgSW5jLjEjMCEGA1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJv
@@ -915,16 +902,16 @@ YQO2WxZpO8ZECAyIUwxrl0nHPjXcbLm7qt9cuzovk2C2qUtN8iD3zV9/ZHuO3ABc
915
902
  1/p3yjkWWW8O6tO1g39NTUJWdrTJXwT4OPjr0l91X817/OWOgHz8UA==
916
903
  -----END CERTIFICATE-----
917
904
 
918
- ------5D1564AD4B7AA41C792F4EA6897F9BBC
905
+ ------8B5C3F7F4B46AC7A36EDE5247D3D6E76
919
906
  Content-Type: application/x-pkcs7-signature; name="smime.p7s"
920
907
  Content-Transfer-Encoding: base64
921
908
  Content-Disposition: attachment; filename="smime.p7s"
922
909
 
923
910
  MIIE5gYJKoZIhvcNAQcCoIIE1zCCBNMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3
924
- DQEHAaCCAwIwggL+MIICZ6ADAgECAgEAMA0GCSqGSIb3DQEBBQUAME0xCzAJBgNV
911
+ DQEHAaCCAwIwggL+MIICZ6ADAgECAgEBMA0GCSqGSIb3DQEBBQUAME0xCzAJBgNV
925
912
  BAYTAkpQMREwDwYDVQQKDAhjdG9yLm9yZzEUMBIGA1UECwwLRGV2ZWxvcG1lbnQx
926
- FTATBgNVBAMMDGh0dHAtYWNjZXNzMjAeFw0wNzA0MjgyMzU1MjRaFw0wOTA0Mjcy
927
- MzU1MjRaME0xCzAJBgNVBAYTAkpQMREwDwYDVQQKDAhjdG9yLm9yZzEUMBIGA1UE
913
+ FTATBgNVBAMMDGh0dHAtYWNjZXNzMjAeFw0wNzA5MTExMzU4MzFaFw0wOTA5MTAx
914
+ MzU4MzFaME0xCzAJBgNVBAYTAkpQMREwDwYDVQQKDAhjdG9yLm9yZzEUMBIGA1UE
928
915
  CwwLRGV2ZWxvcG1lbnQxFTATBgNVBAMMDGh0dHAtYWNjZXNzMjCBnzANBgkqhkiG
929
916
  9w0BAQEFAAOBjQAwgYkCgYEAuLrq6Na1QJCbkekxLKv8AAgVhVcL92afsLxNH8cy
930
917
  JS5bfBpji5csWoIMAY5fiB/Xvulf5v323ealqICMm6pzznwP3EQQLOENaBd0tuFG
@@ -934,19 +921,19 @@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JMCbxFOqj+trGj6/dwwUgYJKoZIhvcNAQkPMUUwQzAKBggqhkiG9w0D
929
+ Y2Nlc3MyAgEBMAkGBSsOAwIaBQCggbEwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEH
930
+ ATAcBgkqhkiG9w0BCQUxDxcNMDcwOTExMTQwNjUwWjAjBgkqhkiG9w0BCQQxFgQU
931
+ LDo4zNjnYqZsbuf5cQiMPYoKaq4wUgYJKoZIhvcNAQkPMUUwQzAKBggqhkiG9w0D
945
932
  BzAOBggqhkiG9w0DAgICAIAwDQYIKoZIhvcNAwICAUAwBwYFKw4DAgcwDQYIKoZI
946
- hvcNAwICASgwDQYJKoZIhvcNAQEBBQAEgYA8jASc7wiTM6dcogoMCs8n7rvS/5a9
947
- 9DQgtaV2lQp3ZjbxmHzN/8KuaCXMTYmxd4kpCk/z/xuYTRJk1zRB5wHbxWeCqSw+
948
- Bagm6uvrW+QGlFuewia+vL8FI5tS1xDpQj+8H8XMgwx5tRCHKG0eTLGCEuBtbqeN
949
- TfBhCVMhdFhblg==
933
+ hvcNAwICASgwDQYJKoZIhvcNAQEBBQAEgYBATRqB7vtE7yjSfNYaV6urEPN9ewKx
934
+ VS7lZVuCWjbC7Yt2XIRMLWq+CgPy+FNfCGH6DIDzN6HnfsRuCSB25mTtInTopJAb
935
+ hG5SpJ1GScCjmVoJIGXvXDejKQPo9rz2WK0ZEj7NRtpNyfv0BwG+bRozgq54Cnq/
936
+ yNXneHi9dCn1KQ==
950
937
 
951
- ------5D1564AD4B7AA41C792F4EA6897F9BBC--
938
+ ------8B5C3F7F4B46AC7A36EDE5247D3D6E76--
952
939
 
@@ -196,14 +196,16 @@ class Message
196
196
 
197
197
  def dump(dev = '')
198
198
  set_header
199
+ str = nil
199
200
  if @is_request
200
- dev << request_line
201
+ str = request_line
201
202
  else
202
- dev << response_status_line
203
+ str = response_status_line
203
204
  end
204
- dev << @header_item.collect { |key, value|
205
+ str += @header_item.collect { |key, value|
205
206
  dump_line("#{ key }: #{ value }")
206
207
  }.join
208
+ dev << str
207
209
  dev
208
210
  end
209
211
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: httpclient
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.1.1
7
- date: 2007-08-28 00:00:00 +09:00
6
+ version: 2.1.2
7
+ date: 2007-09-22 00:00:00 +09:00
8
8
  summary: gives something like the functionality of libwww-perl (LWP) in Ruby
9
9
  require_paths:
10
10
  - lib