~ubuntu-branches/ubuntu/saucy/amsn/saucy

« back to all changes in this revision

Viewing changes to proxy.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-13 23:21:29 UTC
  • mfrom: (1.1.11 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100413232129-vgpx20brdd2qavs7
Tags: 0.98.3-0ubuntu1
* Merge from Debian unstable (LP: #449072), remaining Ubuntu changes:
  - add 08_use_aplay_for_sound.dpatch patch by Festor Wailon Dacoba to use
    aplay to play sounds
  + debian/control:
    - modify iceweasel to firefox | abrowser in amsn Suggests field
    - add xdg-utils and gstreamer0.10-nice to amsn Depends field
    - mofify sox to alsa-utils in amsn Suggests field as we are now using
      aplay
* New upstream release (LP: #562619), tarball repacked according to
  debian/README.source.
* Fix missing-debian-source-format lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#       SOCKS5 support (integration) is experimental!!!
7
7
#
8
8
 
9
 
::Version::setSubversionId {$Id: proxy.tcl 11344 2009-07-12 21:18:51Z kakaroto $}
 
9
::Version::setSubversionId {$Id: proxy.tcl 11886 2010-01-11 01:43:13Z kakaroto $}
10
10
 
11
11
package provide Proxy 0.1
12
 
package require -exact http 2.4.4
 
12
package require http
 
13
package require SASL::NTLM;
 
14
package require uri;
 
15
package require base64;
13
16
 
14
17
# This should be converted to a proper package, to use with package require
15
18
source socks.tcl        ;# SOCKS5 proxy support
170
173
        return [socket -async $thost $tport]
171
174
}
172
175
 
 
176
####################################################
 
177
# All NTLM stuff adapted from autoproxy
 
178
####################################################
 
179
 
 
180
proc NTLMsecureSocket { args } {
 
181
 
 
182
  upvar host thost
 
183
  upvar port tport
 
184
 
 
185
  set s [NTLMauthenticate $thost $tport]
 
186
  return [::tls::import $socket]
 
187
 
 
188
}
 
189
 
 
190
proc NTLMsocket { args } {
 
191
 
 
192
  upvar host thost
 
193
  upvar port tport
 
194
 
 
195
  return [::autoproxy::NTLMauthenticate $thost $tport]
 
196
 
 
197
}
 
198
 
 
199
 
 
200
proc NTLMCallback { context command args } {
 
201
 
 
202
    switch -exact -- $command {
 
203
        username    { return [::config::getKey proxyuser] }
 
204
        password { return [::config::getKey proxypass] }
 
205
        realm    { return "" }
 
206
        hostname { return [info host] }
 
207
        default  { return -code error unxpected }
 
208
 
 
209
}
 
210
 
 
211
proc NTLMauthenticate { thost tport } {
 
212
 
 
213
  variable options
 
214
  set phost $options(proxy_host)
 
215
  set pport $options(proxy_port)
 
216
 
 
217
  set s [socket $phost $pport]
 
218
  fconfigure $s -blocking 1 -buffering line -translation crlf
 
219
 
 
220
  set ctx [SASL::new -mechanism NTLM -callback [namespace origin NTLMCallback]]
 
221
  while {1} {
 
222
    set more_steps [SASL::step $ctx $challenge]
 
223
    set response [SASL::response $ctx]
 
224
    #puts "----"
 
225
    #puts "Sending NTLM message to proxy"
 
226
    #puts "NTLM key: [base64::encode -wrapchar {} $response]"
 
227
    puts $s "CONNECT $thost:$tport HTTP/1.1\nHost: $phost\nProxy-Connection: Keep-Alive\nConnection: Keep-Alive\nCache-Control: no-cache\nPragma: no-cache\nProxy-Authorization: NTLM [base64::encode -wrapchar {} $response]\n"
 
228
    #puts "----"
 
229
    if {!$more_steps} {break}
 
230
    #puts "Handling proxy reply"
 
231
 
 
232
    set response {}
 
233
    while {[set line [gets $s]] ne "" } {
 
234
      append response $line\r\n
 
235
      # break if headers done
 
236
      if {$line == ""} {
 
237
        break
 
238
      }
 
239
    }
 
240
    set length {}
 
241
    regexp {Content-Length: ([0-9]*)} $response -> length
 
242
    #puts "response length: $length"
 
243
    # puts $response
 
244
    if {$length eq {} } {
 
245
      set body [read $s]
 
246
    } else {
 
247
      set body [read $s [expr $length-1] ]
 
248
    }
 
249
    # puts $body
 
250
    regexp {Proxy-Authenticate: NTLM (.*)\r\n} $response -> challenge
 
251
    #puts "Server challenge: $challenge"
 
252
    set challenge [base64::decode $challenge]
 
253
   }
 
254
   #puts "Handshake completed"
 
255
   #puts "----"
 
256
 
 
257
   SASL::cleanup $ctx
 
258
 
 
259
   puts $socket ""
 
260
   set reply ""
 
261
   while {[gets $socket r] > 0} {
 
262
      lappend reply $r
 
263
   }
 
264
 
 
265
   set result [lindex $reply 0]
 
266
   if {! [regexp {^HTTP/1\.[01] +2[0-9][0-9]} $result]} {
 
267
      return -code error $result
 
268
   }
 
269
 
 
270
   fconfigure $s -translation binary -buffering none -blocking 0
 
271
   return $s
 
272
 
 
273
}
 
274
 
 
275
}
 
276
 
173
277
::snit::type Proxy {
174
278
 
175
279
        delegate method * to proxy
376
480
                }
377
481
 
378
482
                if { [::config::getKey proxytype] == "http"} {
379
 
                        status_log "registering http secure socket "
380
 
                        if { [catch {http::register https 443 HTTPsecureSocket} res]} {
381
 
                                MSN::logout
382
 
                                MSN::reconnect "Proxy returned error: $res"
383
 
                                return -1
 
483
                        if { [::config::getKey proxyauthmethod] == "ntlm" } {
 
484
                                status_log "registering ntlm socket"
 
485
                                ::http::config -proxyhost ""
 
486
                                if { [catch {http::register http 80 NTLMsocket} res]} {
 
487
                                        MSN::logout
 
488
                                        MSN::reconnect "Proxy returned error: $res"
 
489
                                        return -1
 
490
                                }
 
491
                                status_log "registering ntlm secure socket "
 
492
                                if { [catch {http::register https 443 NTLMsecureSocket} res]} {
 
493
                                        MSN::logout
 
494
                                        MSN::reconnect "Proxy returned error: $res"
 
495
                                 return -1
 
496
                                }
 
497
                        } else {
 
498
                                status_log "registering http secure socket "
 
499
                                if { [catch {http::register https 443 HTTPsecureSocket} res]} {
 
500
                                        MSN::logout
 
501
                                        MSN::reconnect "Proxy returned error: $res"
 
502
                                        return -1
 
503
                                }
384
504
                        }
385
505
                } else {
386
506
                        # http://wiki.tcl.tk/2627 :(