giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.65k stars 267 forks source link

Clients certificate common name validation #538

Open sourabhyadavgit opened 4 years ago

sourabhyadavgit commented 4 years ago

Hi, I was working towards making use of openssl command getpeercert() to validate clients certificate on common name and if possible with SAN validation. Ie subject field validation. Intention is to make it password less Authentication with full mutual authentication. Will dummyAuthrizer support it? Issue with unix authorizer is that unix id's are AD based. So best is to use only cert Auth and dummyauthrizer. Here is what I was trying but connection was hanging without any cert from client end printed.

class MyHandler(FTPHandler):

def on_connect(self):
    print "%s:%s connected" % (self.remote_ip, self.remote_port)

Print(Self.socket.get_peer_certificate()) Print(self.get_repr_info())

Def main(): Context = ssl.SSLContext(ssl.protocol_tlsv1_2) Context.load_verify_location(cafile) Context. Load_cert_chain(certfile,keyfile) Handler = myhandler Handler.certfile= certfile Handler.keyfile=keyfile Handler.ssl_protocol = SSL.TLSv1_2_METHOD

If i can get and print client cert I intend to decrypt it further to check and match various fields like common name and SAN validations but at this point I can't even print what cert and ciphers are being used on connection.

Thanks,