<s> from __future__ import print_function <EOL> import sys <EOL> from twisted . internet import defer , endpoints , protocol , ssl , task <EOL> certificate = ssl . Certificate . loadPEM ( <EOL> open ( "<STR_LIT>" ) . read ( ) <EOL> ) <EOL> def main ( reactor , host , port = <NUM_LIT> ) : <EOL> options = ssl . optionsForClientTLS ( host . decode ( "<STR_LIT:utf-8>" ) , <EOL> trustRoot = certificate ) <EOL> port = int ( port ) <EOL> done = defer . Deferred ( ) <EOL> class ShowCertificate ( protocol . Protocol ) : <EOL> def connectionMade ( self ) : <EOL> self . transport . write ( b"<STR_LIT>" ) <EOL> def dataReceived ( self , data ) : <EOL> certificate = ssl . Certificate ( self . transport . getPeerCertificate ( ) ) <EOL> print ( certificate ) <EOL> self . transport . loseConnection ( ) <EOL> def connectionLost ( self , reason ) : <EOL> if reason . check ( ssl . SSL . Error ) : <EOL> print ( reason . value ) <EOL> done . callback ( None ) <EOL> endpoints . connectProtocol ( <EOL> endpoints . SSL4ClientEndpoint ( reactor , host , port , options ) , <EOL> ShowCertificate ( ) <EOL> ) <EOL> return done <EOL> task . react ( main , sys . argv [ <NUM_LIT:1> : ] ) </s>
