File: services.rb

package info (click to toggle)
libnet-ssh-ruby 1.1.2-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,472 kB
  • ctags: 2,465
  • sloc: ruby: 10,848; makefile: 17
file content (146 lines) | stat: -rw-r--r-- 5,455 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#--
# =============================================================================
# Copyright (c) 2004,2005 Jamis Buck (jamis@37signals.com)
# All rights reserved.
#
# This source file is distributed as part of the Net::SSH Secure Shell Client
# library for Ruby. This file (and the library as a whole) may be used only as
# allowed by either the BSD license, or the Ruby license (or, by association
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
# distribution for the texts of these licenses.
# -----------------------------------------------------------------------------
# net-ssh website : http://net-ssh.rubyforge.org
# project website: http://rubyforge.org/projects/net-ssh
# =============================================================================
#++

module Net
  module SSH
    module Transport

      # Register the services that together implement the SSH transport layer.
      def register_services( container )
        container.namespace_define :transport do |b|
          b.kex_names { Hash.new }
          b.compression_algorithms { Hash.new }
          b.decompression_algorithms { Hash.new }

          b.cipher_factories { Hash.new }
          b.hmac_factories { Hash.new }
          b.key_factories { Hash.new }
          b.buffer_factories { Hash.new }
          b.bn_factories { Hash.new }
          b.digest_factories { Hash.new }

          b.ciphers( :model => :prototype ) { |c,|
            c.cipher_factories.fetch( c.crypto_backend ) }

          b.hmacs( :model => :prototype ) { |c,|
            c.hmac_factories.fetch( c.crypto_backend ) }

          b.keys( :model => :prototype ) { |c,|
            c.key_factories.fetch( c.crypto_backend ) }

          b.buffers( :model => :prototype ) { |c,|
            c.buffer_factories.fetch( c.crypto_backend ) }

          b.bns( :model => :prototype ) { |c,|
            c.bn_factories.fetch( c.crypto_backend ) }

          b.digesters( :model => :prototype ) { |c,|
            c.digest_factories.fetch( c.crypto_backend ) }

          b.identity_cipher do
            require 'net/ssh/transport/identity-cipher'
            IdentityCipher.new
          end

          b.outgoing_packet_stream :model => :prototype_deferred do |c,|
            require 'net/ssh/transport/packet-stream'
            OutgoingPacketStream.new(
              c.ciphers, c.hmacs, c.compression_algorithms )
          end

          b.incoming_packet_stream :model => :prototype_deferred do |c,point|
            require 'net/ssh/transport/packet-stream'
            stream = IncomingPacketStream.new(
              c.ciphers, c.hmacs, c.decompression_algorithms )
            stream.buffers = c.buffers
            stream.log = c.log_for( point )
            stream
          end

          b.algorithms do
            Hash[
              :host_key => [ "ssh-dss", "ssh-rsa" ],
              :kex => [ "diffie-hellman-group-exchange-sha1",
                        "diffie-hellman-group1-sha1" ],
              :encryption => [ "3des-cbc",
                               "aes128-cbc", 
                               "blowfish-cbc",
                               "aes256-cbc",
                               "aes192-cbc",
                               "idea-cbc",
                               "none" ],
              :hmac => [ "hmac-md5",
                         "hmac-sha1",
                         "hmac-md5-96",
                         "hmac-sha1-96",
                         "none" ],
              :compression => [ "none", "zlib" ],
              :languages => []
            ]
          end

          b.default_ssh_port { 22 }

          b.socket_factory do
            require 'socket'
            TCPSocket
          end

          b.version_negotiator do |c,point|
            require 'net/ssh/transport/version-negotiator'
            VersionNegotiator.new( c.log_for( point ) )
          end

          b.algorithm_negotiator do |c,point|
            require 'net/ssh/transport/algorithm-negotiator'
            AlgorithmNegotiator.new(
              c.log_for( point ),
              c.algorithms,
              c.buffers )
          end

          b.session do |c,point|
            require 'net/ssh/transport/session'

            args = [ c[:transport_host] ]
            args << c[:transport_options] if c.knows_key?(:transport_options)

            Session.new( *args ) do |s|
              s.logger               = c[:log_for, point]
              s.default_port         = c[:default_ssh_port]
              s.version_negotiator   = c[:version_negotiator]
              s.algorithm_negotiator = c[:algorithm_negotiator]
              s.socket_factory       = c[:socket_factory]
              s.packet_sender        = c[:outgoing_packet_stream]
              s.packet_receiver      = c[:incoming_packet_stream]
              s.ciphers              = c[:ciphers]
              s.hmacs                = c[:hmacs]
              s.kexs                 = c[:kex_names]
              s.compressors          = c[:compression_algorithms]
              s.decompressors        = c[:decompression_algorithms]
            end
          end

          b.require 'net/ssh/transport/ossl/services', "#{self}::OSSL"
          b.require 'net/ssh/transport/compress/services', "#{self}::Compress"
          b.require 'net/ssh/transport/kex/services', "#{self}::Kex"
        end
      end
      module_function :register_services

    end
  end
end