-
Notifications
You must be signed in to change notification settings - Fork 0
security.SecureConnection
The agutil.security module includes the SecureConnection class which provides a high-level interface for sending and receiving secure messages and files.
-
SecureConnection(address, port, password=None, rsabits=4096, timeout=3, logmethod=DummyLog) (constructor)
Opens a new secure connection to the address specified by opening a new
SecureSocketto use internally. If address is set to '' or 'listen', theSecureConnectionwill listen for an incoming connection on port. Otherwise, it attempts to connect to anotherSecureConnectionon the specified port at address. password and rsabits configure the internalSecureSocket, and are used for its constructor. timeout sets the default timeout on the internalSecureSocket. logmethod specifies a logging object to use. It defaults toagutil.DummyLog(which does not log anything). logmethod may either be anagutil.Loggerclass, or a bound method returned byagutil.Logger.bindToSender(). -
SecureConnection.send(msg):
Sends msg to the remote socket using RSA encryption. The RSA signature of msg is also sent. Returns a the task name used to send the msg. Use
confirm()to check if the task was a success -
SecureConnection.confirm(task, timeout=
-1):Waits for confirmation of the task from the remote socket. If timeout is a positive number, it waits at most timeout seconds. If timeout is
None, it blocks indefinitely. If timeout is-1, it uses the default timeout specified in the constructor. ReturnsTrueorFalseindicating success or failure of the task on the remote end. Raises asocket.Timeoutexception if the timeout expires. Confirmations are sent automatically by the remote socket, but must beconfirm()-ed manually. If a task fails or times out, it is the programmers responsibility to re-attempt the task, if desired. -
SecureConnection.read(decode=
True, timeout=-1):Waits for a message from the remote socket. If timeout is a positive number, it waits at most timeout seconds. If timeout is
None, it blocks indefinitely. If timeout is-1, it uses the default timeout specified in the constructor. ReturnsTrueorFalseindicating success or failure of the task on the remote end. Raises asocket.Timeoutexception if the timeout expires. If decode isTrue, the message will be decoded to a string when returned -
SecureConnection.sendfile(filename):
Prepares the file specified by filename to be sent and informs the remote socket that the file is available for transfer. Starts a background thread which waits for a response from the remote socket before encrypting and sending the file using AES CBC encryption. Returns a the task name used to send the file. Use
confirm()to check if the task was a success. -
SecureConnection.savefile(destination=
None, timeout=-1, force=False):Processes the oldest pending file transfer request or waits at most timeout seconds to receive one. If timeout is a positive number, it waits at most timeout seconds. If timeout is
None, it blocks indefinitely. If timeout is-1, it uses the default timeout specified in the constructor. ReturnsTrueorFalseindicating success or failure of the task on the remote end. Raises asocket.Timeoutexception if the timeout expires. If force is notTrue, this method will request user confirmation before completing the transfer. Once the transfer begins, the socket must receive at least one chunk every timeout seconds or it will raise asocket.Timeoutexception. destination should be the path where the file will be saved. If destination isNone, the file will be saved in the current directory, using the original filename. -
SecureConnection.shutdown(timeout=-1)
-
SecureConnection.close(timeout=-1)
Closes the underlying socket
-
SecureConnection.flush()
Waits for all files to finish sending