Пример #1
0
    def _on_www_authenticate(self, data):
        if self._check_error():
            return
        
        m = re.match('Basic\s*realm="([a-zA-Z0-9\-\s]+)"', data.strip())
        if m:
            logging.debug('mjpg client using basic authentication')
            
            auth_header = utils.build_basic_header(self._username, self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' % auth_header)
            self._seek_http()

            return

        m = re.match('Digest\s*realm="([a-zA-Z0-9\-\s]+)",\s*nonce="([a-zA-Z0-9]+)"', data.strip())
        if m:
            logging.debug('mjpg client using digest authentication')

            realm, nonce = m.groups()
            self._auth_digest_state['realm'] = realm
            self._auth_digest_state['nonce'] = nonce
    
            auth_header = utils.build_digest_header('GET', '/', self._username, self._password, self._auth_digest_state)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' % auth_header)
            self._seek_http()
            
            return

        logging.error('mjpg client unknown authentication header: "%s"' % data)
        self._seek_content_length()
Пример #2
0
    def _on_www_authenticate(self, data):
        if self._check_error():
            return

        data = data.strip()

        m = re.match('Basic\s*realm="([a-zA-Z0-9\-\s]+)"', data)
        if m:
            logging.debug('mjpg client using basic authentication')

            auth_header = utils.build_basic_header(self._username, self._password)
            self.write('GET / HTTP/1.1\r\nAuthorization: %s\r\nConnection: close\r\n\r\n' % auth_header)
            self._seek_http()

            return

        if data.startswith('Digest'):
            logging.debug('mjpg client using digest authentication')

            parts = data[7:].split(',')
            parts_dict = dict(p.split('=', 1) for p in parts)
            parts_dict = {p[0]: p[1].strip('"') for p in parts_dict.items()}

            self._auth_digest_state = parts_dict

            auth_header = utils.build_digest_header('GET', '/', self._username, self._password, self._auth_digest_state)
            self.write('GET / HTTP/1.1\r\nAuthorization: %s\r\nConnection: close\r\n\r\n' % auth_header)
            self._seek_http()

            return

        logging.error('mjpg client unknown authentication header: "%s"' % data)
        self._seek_content_length()
Пример #3
0
    def _on_www_authenticate(self, data):
        if self._check_error():
            return

        m = re.match('Basic\s*realm="([a-zA-Z0-9\-\s]+)"', data.strip())
        if m:
            logging.debug('mjpg client using basic authentication')

            auth_header = utils.build_basic_header(self._username,
                                                   self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' %
                       auth_header)
            self._seek_http()

            return

        m = re.match(
            'Digest\s*realm="([a-zA-Z0-9\-\s]+)",\s*nonce="([a-zA-Z0-9]+)"',
            data.strip())
        if m:
            logging.debug('mjpg client using digest authentication')

            realm, nonce = m.groups()
            self._auth_digest_state['realm'] = realm
            self._auth_digest_state['nonce'] = nonce

            auth_header = utils.build_digest_header('GET', '/', self._username,
                                                    self._password,
                                                    self._auth_digest_state)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' %
                       auth_header)
            self._seek_http()

            return

        logging.error('mjpg client unknown authentication header: "%s"' % data)
        self._seek_content_length()