Example #1
0
 def handle_connect(self):
     if self.config.core.use_ssl and has_ssl:
         if not self.config.core.verify_ssl:
             self.ssl = ssl.wrap_socket(self.socket,
                                        do_handshake_on_connect=False,
                                        suppress_ragged_eofs=True)
         else:
             verification = verify_ssl_cn(self.config.host,
                                          int(self.config.port))
             if verification is 'NoCertFound':
                 stderr('Can\'t get server certificate, SSL might be '
                        'disabled on the server.')
                 os.unlink(self.config.pid_file_path)
                 os._exit(1)
             elif verification is not None:
                 stderr('\nSSL Cert information: %s' % verification[1])
                 if verification[0] is False:
                     stderr("Invalid certficate, CN mismatch!")
                     os.unlink(self.config.pid_file_path)
                     os._exit(1)
             else:
                 stderr('WARNING! certficate information and CN validation '
                        'are not avilable. Is pyOpenSSL installed?')
                 stderr('Trying to connect anyway:')
             self.ssl = ssl.wrap_socket(self.socket,
                                        do_handshake_on_connect=False,
                                        suppress_ragged_eofs=True,
                                        cert_reqs=ssl.CERT_REQUIRED,
                                        ca_certs=self.ca_certs)
         stderr('\nSSL Handshake intiated...')
         error_count = 0
         while True:
             try:
                 self.ssl.do_handshake()
                 break
             except ssl.SSLError, err:
                 if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                     select.select([self.ssl], [], [])
                 elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                     select.select([], [self.ssl], [])
                 elif err.args[0] == 1:
                     stderr('SSL Handshake failed with error: %s' %
                            err.args[1])
                     os._exit(1)
                 else:
                     error_count = error_count + 1
                     if error_count > 5:
                         stderr(
                             'SSL Handshake failed (%d failed attempts)' %
                             error_count)
                         os._exit(1)
                     raise
             except Exception as e:
                 print >> sys.stderr, (
                     'SSL Handshake failed with error: %s' % e)
                 os._exit(1)
Example #2
0
 def handle_connect(self):
     if self.config.core.use_ssl and has_ssl:
         if not self.config.core.verify_ssl:
             self.ssl = ssl.wrap_socket(self.socket,
                                        do_handshake_on_connect=False,
                                        suppress_ragged_eofs=True)
         else:
             verification = verify_ssl_cn(self.config.host,
                                          int(self.config.port))
             if verification is 'NoCertFound':
                 stderr('Can\'t get server certificate, SSL might be '
                        'disabled on the server.')
                 os.unlink(self.config.pid_file_path)
                 os._exit(1)
             elif verification is not None:
                 stderr('\nSSL Cret information: %s' % verification[1])
                 if verification[0] is False:
                     stderr("Invalid cretficate, CN mismatch!")
                     os.unlink(self.config.pid_file_path)
                     os._exit(1)
             else:
                 stderr('WARNING! certficate information and CN validation '
                        'are not avilable. Is pyOpenSSL installed?')
                 stderr('Trying to connect anyway:')
             self.ssl = ssl.wrap_socket(self.socket,
                                        do_handshake_on_connect=False,
                                        suppress_ragged_eofs=True,
                                        cert_reqs=ssl.CERT_REQUIRED,
                                        ca_certs=self.ca_certs)
         stderr('\nSSL Handshake intiated...')
         error_count = 0
         while True:
             try:
                 self.ssl.do_handshake()
                 break
             except ssl.SSLError, err:
                 if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                     select.select([self.ssl], [], [])
                 elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                     select.select([], [self.ssl], [])
                 elif err.args[0] == 1:
                     stderr('SSL Handshake failed with error: %s' %
                            err.args[1])
                     os._exit(1)
                 else:
                     error_count = error_count + 1
                     if error_count > 5:
                         stderr('SSL Handshake failed (%d failed attempts)'
                                % error_count)
                         os._exit(1)
                     raise
             except Exception as e:
                 print >> sys.stderr, ('SSL Handshake failed with error: %s'
                                       % e)
                 os._exit(1)
Example #3
0
    def handle_connect(self):
        if settings.IRC_SERVER_SSL and has_ssl:
            if not settings.IRC_SERVER_VERIFY_SSL:
                self.ssl = ssl.wrap_socket(self.socket, do_handshake_on_connect=False, suppress_ragged_eofs=True)
            else:
                verification = verify_ssl_cn(settings.IRC_SERVER_HOST, int(settings.IRC_SERVER_PORT))

                if verification is 'NoCertFound':
                    self.log.error("Can't get server certificate, SSL might be disabled on the server.")
                    sys.exit(1)
                elif verification is not None:
                    self.log.error('\nSSL Cert information: %s' % verification[1])
                    if verification[0] is False:
                        self.log.error("Invalid certificate, CN mismatch!")
                        sys.exit(1)
                else:
                    self.log.error('WARNING! certificate information and CN validation are not available. '
                                   'Is pyOpenSSL installed?')
                    self.log.error('Trying to connect anyway:')
                self.ssl = ssl.wrap_socket(
                    self.socket,
                    do_handshake_on_connect=False,
                    suppress_ragged_eofs=True,
                    cert_reqs=ssl.CERT_REQUIRED,
                    ca_certs=self.ca_certs)

            self.log.info('\nSSL Handshake intiated...')
            error_count = 0
            while True:
                try:
                    self.ssl.do_handshake()
                    break
                except ssl.SSLError, err:
                    if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                        select.select([self.ssl], [], [])
                    elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                        select.select([], [self.ssl], [])
                    elif err.args[0] == 1:
                        self.log.error('SSL Handshake failed with error: %s' % err.args[1])
                        sys.exit(1)
                    else:
                        error_count += 1
                        if error_count > 5:
                            self.log.error('SSL Handshake failed (%d failed attempts)' % error_count)
                            sys.exit(1)
                        raise
                except Exception as e:
                    self.log.error('SSL Handshake failed with error: %s' % e)
                    sys.exit(1)