def _x_start_ok(self, client_properties, mechanism, response, locale): """ select security mechanism and locale This method selects a SASL security mechanism. ASL uses SASL (RFC2222) to negotiate authentication and encryption. PARAMETERS: client_properties: table client properties mechanism: shortstr selected security mechanism A single security mechanisms selected by the client, which must be one of those specified by the server. RULE: The client SHOULD authenticate using the highest- level security profile it can handle from the list provided by the server. RULE: The mechanism field MUST contain one of the security mechanisms proposed by the server in the Start method. If it doesn't, the server MUST close the socket. response: longstr security response data A block of opaque data passed to the security mechanism. The contents of this data are defined by the SASL security mechanism. For the PLAIN security mechanism this is defined as a field table holding two fields, LOGIN and PASSWORD. locale: shortstr selected message locale A single message local selected by the client, which must be one of those specified by the server. """ args = AMQPWriter() args.write_table(client_properties) args.write_shortstr(mechanism) args.write_longstr(response) args.write_shortstr(locale) self._send_method((10, 11), args)
def _x_start_ok(self, client_properties, mechanism, response, locale): """ select security mechanism and locale This method selects a SASL security mechanism. ASL uses SASL (RFC2222) to negotiate authentication and encryption. PARAMETERS: client_properties: table client properties mechanism: shortstr selected security mechanism A single security mechanisms selected by the client, which must be one of those specified by the server. RULE: The client SHOULD authenticate using the highest- level security profile it can handle from the list provided by the server. RULE: The mechanism field MUST contain one of the security mechanisms proposed by the server in the Start method. If it doesn't, the server MUST close the socket. response: longstr security response data A block of opaque data passed to the security mechanism. The contents of this data are defined by the SASL security mechanism. For the PLAIN security mechanism this is defined as a field table holding two fields, LOGIN and PASSWORD. locale: shortstr selected message locale A single message local selected by the client, which must be one of those specified by the server. """ args = AMQPWriter() args.write_table(client_properties) args.write_shortstr(mechanism) args.write_longstr(response) args.write_shortstr(locale) self._send_method((10, 11), args)
def __init__(self, host='localhost', userid='guest', password='******', login_method='AMQPLAIN', login_response=None, virtual_host='/', locale='en_US', client_properties=None, ssl=False, insist=False, connect_timeout=None, **kwargs): """ Create a connection to the specified host, which should be a 'host[:port]', such as 'localhost', or '1.2.3.4:5672' (defaults to 'localhost', if a port is not specified then 5672 is used) If login_response is not specified, one is built up for you from userid and password if they are present. The 'ssl' parameter may be simply True/False, or for Python >= 2.6 a dictionary of options to pass to ssl.wrap_socket() such as requiring certain certificates. """ if (login_response is None) \ and (userid is not None) \ and (password is not None): login_response = AMQPWriter() login_response.write_table({'LOGIN': userid, 'PASSWORD': password}) login_response = login_response.getvalue()[4:] #Skip the length #at the beginning d = {} d.update(LIBRARY_PROPERTIES) if client_properties: d.update(client_properties) self.known_hosts = '' while True: self.channels = {} # The connection object itself is treated as channel 0 super(Connection, self).__init__(self, 0) self.transport = None # Properties set in the Tune method self.channel_max = 65535 self.frame_max = 131072 self.heartbeat = 0 # Properties set in the Start method self.version_major = 0 self.version_minor = 0 self.server_properties = {} self.mechanisms = [] self.locales = [] # Let the transport.py module setup the actual # socket connection to the broker. # self.transport = create_transport(host, connect_timeout, ssl) self.method_reader = MethodReader(self.transport) self.method_writer = MethodWriter(self.transport, self.frame_max) self.wait(allowed_methods=[ (10, 10), # start ]) self._x_start_ok(d, login_method, login_response, locale) self._wait_tune_ok = True while self._wait_tune_ok: self.wait(allowed_methods=[ (10, 20), # secure (10, 30), # tune ]) host = self._x_open(virtual_host, insist=insist) if host is None: # we weren't redirected return # we were redirected, close the socket, loop and try again try: self.close() except Exception: pass
def __init__( self, host="localhost", userid="guest", password="******", login_method="AMQPLAIN", login_response=None, virtual_host="/", locale="en_US", client_properties=None, ssl=False, insist=False, connect_timeout=None, **kwargs ): """ Create a connection to the specified host, which should be a 'host[:port]', such as 'localhost', or '1.2.3.4:5672' (defaults to 'localhost', if a port is not specified then 5672 is used) If login_response is not specified, one is built up for you from userid and password if they are present. """ if (login_response is None) and (userid is not None) and (password is not None): login_response = AMQPWriter() login_response.write_table({"LOGIN": userid, "PASSWORD": password}) login_response = login_response.getvalue()[4:] # Skip the length # at the beginning d = {} d.update(LIBRARY_PROPERTIES) if client_properties: d.update(client_properties) self.known_hosts = "" while True: self.channels = {} # The connection object itself is treated as channel 0 super(Connection, self).__init__(self, 0) self.transport = None # Properties set in the Tune method self.channel_max = 65535 self.frame_max = 131072 self.heartbeat = 0 # Properties set in the Start method self.version_major = 0 self.version_minor = 0 self.server_properties = {} self.mechanisms = [] self.locales = [] # Let the transport.py module setup the actual # socket connection to the broker. # self.transport = create_transport(host, connect_timeout, ssl) self.method_reader = MethodReader(self.transport) self.method_writer = MethodWriter(self.transport, self.frame_max) self.wait(allowed_methods=[(10, 10)]) # start self._x_start_ok(d, login_method, login_response, locale) self._wait_tune_ok = True while self._wait_tune_ok: self.wait(allowed_methods=[(10, 20), (10, 30)]) # secure # tune host = self._x_open(virtual_host, insist=insist) if host is None: # we weren't redirected return # we were redirected, close the socket, loop and try again try: self.close() except Exception: pass