o b@s^dZddlZddlmZddlmZmZmZmZddl m Z ddl m Z Gddde j ZdS) z A Factory for SSH servers. See also L{twisted.conch.openssh_compat.factory} for OpenSSH compatibility. Maintainer: Paul Swartz N)error)_kex connection transportuserauth)protocol)Loggerc@sbeZdZdZeZejZe j e j dZ ddZddZddZd d Zd d Zd dZddZdS) SSHFactoryz$ A Factory for SSH servers. ) ssh-userauthsssh-connectioncCsZt|ds ||_t|ds||_|jr|jstdt|ds+||_dSdS)z4 Check for public and private keys. publicKeys privateKeyszno host keys, failingprimesN) hasattr getPublicKeysr getPrivateKeysr r ConchError getPrimesr selfr;/usr/lib/python3/dist-packages/twisted/conch/ssh/factory.py startFactory"s       zSSHFactory.startFactorycCsBtj||}|j|_|js|jddd|j D|_ |S)a= Create an instance of the server side of the SSH protocol. @type addr: L{twisted.internet.interfaces.IAddress} provider @param addr: The address at which the server will listen. @rtype: L{twisted.conch.ssh.transport.SSHServerTransport} @return: The built transport. zTdisabling non-fixed-group key exchange algorithms because we cannot find moduli filecSs$g|]}t|st|r|qSr)r isFixedGroupisEllipticCurve).0 kexAlgorithmrrr @sz,SSHFactory.buildProtocol..) rFactory buildProtocolr keyssupportedPublicKeysr _loginfosupportedKeyExchanges)raddrtrrrr/s zSSHFactory.buildProtocolcCtd)z Called when the factory is started to get the public portions of the servers host keys. Returns a dictionary mapping SSH key types to public key strings. @rtype: L{dict} zgetPublicKeys unimplementedNotImplementedErrorrrrrrGzSSHFactory.getPublicKeyscCr&)z Called when the factory is started to get the private portions of the servers host keys. Returns a dictionary mapping SSH key types to L{twisted.conch.ssh.keys.Key} objects. @rtype: L{dict} zgetPrivateKeys unimplementedr'rrrrrQr)zSSHFactory.getPrivateKeyscCsdS)z Called when the factory is started to get Diffie-Hellman generators and primes to use. Returns a dictionary mapping number of bits to lists of tuple of (generator, prime). @rtype: L{dict} Nrrrrrr[szSSHFactory.getPrimescs2t|jfddd}|d}t|j|S)z Return a tuple of (g, p) for a Diffe-Hellman process, with p being as close to bits bits as possible. @type bits: L{int} @rtype: L{tuple} cs t|S)N)abs)ibitsrrls z'SSHFactory.getDHPrime..)keyr)sortedr rrandomchoice)rr- primesKeysrealBitsrr,r getDHPrimedszSSHFactory.getDHPrimecCs |dks t|dr|j|SdS)z Return a class to use as a service for the given transport. @type transport: L{transport.SSHServerTransport} @type service: L{bytes} @rtype: subclass of L{service.SSHService} r avatarN)rservices)rrservicerrr getServiceps zSSHFactory.getServiceN)__name__ __module__ __qualname____doc__rr!rSSHServerTransportrrSSHUserAuthServerr SSHConnectionr7rrrrrr5r9rrrrr s    r )r=r1 twisted.conchrtwisted.conch.sshrrrrtwisted.internetrtwisted.loggerrrr rrrrs