Object
Implements a factory of OpenSSL cipher algorithms.
Maps the SSH name of a cipher to it’s corresponding OpenSSL name
Ruby’s OpenSSL bindings always return a key length of 16 for RC4 ciphers resulting in the error: OpenSSL::CipherError: key length too short. The following ciphers will override this key length.
Retrieves a new instance of the named algorithm. The new instance will be initialized using an iv and key generated from the given iv, key, shared, hash and digester values. Additionally, the cipher will be put into encryption or decryption mode, based on the value of the encrypt parameter.
# File lib/net/ssh/transport/cipher_factory.rb, line 69 69: def self.get(name, options={}) 70: ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'" 71: return IdentityCipher if ossl_name == "none" 72: cipher = OpenSSL::Cipher::Cipher.new(ossl_name) 73: 74: cipher.send(options[:encrypt] ? :encrypt : :decrypt) 75: 76: cipher.padding = 0 77: 78: cipher.extend(Net::SSH::Transport::CTR) if (name =~ /-ctr(@openssh.org)?$/) 79: 80: cipher.iv = Net::SSH::Transport::KeyExpander.expand_key(cipher.iv_len, options[:iv], options) if ossl_name != "rc4" 81: 82: key_len = KEY_LEN_OVERRIDE[name] || cipher.key_len 83: cipher.key_len = key_len 84: cipher.key = Net::SSH::Transport::KeyExpander.expand_key(key_len, options[:key], options) 85: cipher.update(" " * 1536) if (ossl_name == "rc4" && name != "arcfour") 86: 87: return cipher 88: end
Returns a two-element array containing the [ key-length, block-size ] for the named cipher algorithm. If the cipher algorithm is unknown, or is “none”, 0 is returned for both elements of the tuple.
# File lib/net/ssh/transport/cipher_factory.rb, line 94 94: def self.get_lengths(name) 95: ossl_name = SSH_TO_OSSL[name] 96: return [0, 0] if ossl_name.nil? || ossl_name == "none" 97: 98: cipher = OpenSSL::Cipher::Cipher.new(ossl_name) 99: key_len = KEY_LEN_OVERRIDE[name] || cipher.key_len 100: cipher.key_len = key_len 101: 102: return [key_len, ossl_name=="rc4" ? 8 : cipher.block_size] 103: end
Returns true if the underlying OpenSSL library supports the given cipher, and false otherwise.
# File lib/net/ssh/transport/cipher_factory.rb, line 58 58: def self.supported?(name) 59: ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'" 60: return true if ossl_name == "none" 61: return OpenSSL::Cipher.ciphers.include?(ossl_name) 62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.